Commit 464663848aaa68ff46f2141f92a73294c432e48e
Merge branch 'development' of https://git.ziemers.de/edu/BeuthBot into development
Showing
28 changed files
with
839 additions
and
19 deletions
docker/rasa_nlu/volumes/data/api/intents/showFood.json
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | "parameters": [ |
11 | 11 | { |
12 | 12 | "id": "7b5df330-e1fc-4bb4-86de-5a51be29c836", |
13 | + "required": false, | |
13 | 14 | "dataType": "@date", |
14 | 15 | "name": "date", |
15 | 16 | "value": "$date", |
... | ... | @@ -17,6 +18,7 @@ |
17 | 18 | }, |
18 | 19 | { |
19 | 20 | "id": "f3da5ec9-d3e8-4263-9bc3-7d600784bd0d", |
21 | + "required": false, | |
20 | 22 | "dataType": "@dishtype", |
21 | 23 | "name": "dishtype", |
22 | 24 | "value": "$dishtype", |
... | ... | @@ -24,6 +26,7 @@ |
24 | 26 | }, |
25 | 27 | { |
26 | 28 | "id": "499e1a33-d7ef-4446-ae7d-30ab94c9e3a5", |
29 | + "required": false, | |
27 | 30 | "dataType": "@healthy", |
28 | 31 | "name": "healthy", |
29 | 32 | "value": "$healthy", |
... | ... | @@ -31,6 +34,7 @@ |
31 | 34 | }, |
32 | 35 | { |
33 | 36 | "id": "f53af932-a4f2-4fe5-be2d-eb96a30e9400", |
37 | + "required": false, | |
34 | 38 | "dataType": "@ingredients", |
35 | 39 | "name": "ingredients", |
36 | 40 | "value": "$ingredients", |
... | ... | @@ -38,6 +42,7 @@ |
38 | 42 | }, |
39 | 43 | { |
40 | 44 | "id": "b8c8ab1d-4190-4200-9540-2893a084a1fd", |
45 | + "required": false, | |
41 | 46 | "dataType": "@price", |
42 | 47 | "name": "price", |
43 | 48 | "value": "$price", |
... | ... | @@ -45,6 +50,7 @@ |
45 | 50 | }, |
46 | 51 | { |
47 | 52 | "id": "92607e59-96c8-4c61-8dc0-670c7b8c2b43", |
53 | + "required": false, | |
48 | 54 | "dataType": "@dishcategory", |
49 | 55 | "name": "dishcategory", |
50 | 56 | "value": "$dishcategory", | ... | ... |
docker/wildfly/volumes/conf/beuthbot.properties
... | ... | @@ -18,7 +18,7 @@ API_AI_TOKEN = XXXXX |
18 | 18 | TELEGRAM_WEBHOOK_URL = /telegram/getUpdates |
19 | 19 | |
20 | 20 | # Your Bot Token e.g.: 000000000:AAAAa0aAA_aaA-Aaaa0A0Aa_a0aa0A0AAAA |
21 | -TELEGRAM_BOT_TOKEN = 452768505:AAHNXEYi9nSHcmVc4b3799I00uTZmK53wl4\ | |
21 | +TELEGRAM_BOT_TOKEN = 451726698:AAH2qwZaWOgn1IU1CjJU-HjHDMODG6DEkN0 | |
22 | 22 | |
23 | 23 | |
24 | 24 | ... | ... |
docu/BeuthBot.postman_collection.json
0 → 100644
1 | +{ | |
2 | + "info": { | |
3 | + "name": "BeuthBot", | |
4 | + "_postman_id": "fd29548f-6b95-81d0-cae3-1233324d3846", | |
5 | + "description": "", | |
6 | + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | |
7 | + }, | |
8 | + "item": [ | |
9 | + { | |
10 | + "name": "Facebook", | |
11 | + "description": "", | |
12 | + "item": [ | |
13 | + { | |
14 | + "name": "FB setWebhook", | |
15 | + "request": { | |
16 | + "method": "GET", | |
17 | + "header": [], | |
18 | + "body": {}, | |
19 | + "url": { | |
20 | + "raw": "localhost:8080/facebook/setWebhook", | |
21 | + "host": [ | |
22 | + "localhost" | |
23 | + ], | |
24 | + "port": "8080", | |
25 | + "path": [ | |
26 | + "facebook", | |
27 | + "setWebhook" | |
28 | + ] | |
29 | + }, | |
30 | + "description": "" | |
31 | + }, | |
32 | + "response": [] | |
33 | + }, | |
34 | + { | |
35 | + "name": "FB getUpdates", | |
36 | + "request": { | |
37 | + "method": "POST", | |
38 | + "header": [ | |
39 | + { | |
40 | + "key": "Content-Type", | |
41 | + "value": "application/json" | |
42 | + } | |
43 | + ], | |
44 | + "body": { | |
45 | + "mode": "raw", | |
46 | + "raw": "{\"object\":\"page\",\"entry\":[{\"id\":\"163783704220143\",\"time\":1513427045712,\"messaging\":[{\"sender\":{\"id\":\"1385529261556255\"},\"recipient\":{\"id\":\"163783704220143\"},\"timestamp\":1513427044846,\"message\":{\"mid\":\"mid.$cAADOButO2l5mkI1R7lgX0gFO8FR5\",\"seq\":4370,\"text\":\"Hallo\"}}]}]}" | |
47 | + }, | |
48 | + "url": { | |
49 | + "raw": "localhost:8080/facebook/getUpdates", | |
50 | + "host": [ | |
51 | + "localhost" | |
52 | + ], | |
53 | + "port": "8080", | |
54 | + "path": [ | |
55 | + "facebook", | |
56 | + "getUpdates" | |
57 | + ] | |
58 | + }, | |
59 | + "description": "" | |
60 | + }, | |
61 | + "response": [] | |
62 | + } | |
63 | + ] | |
64 | + }, | |
65 | + { | |
66 | + "name": "Rasa", | |
67 | + "description": "", | |
68 | + "item": [ | |
69 | + { | |
70 | + "name": "Rasa parse", | |
71 | + "request": { | |
72 | + "method": "GET", | |
73 | + "header": [], | |
74 | + "body": {}, | |
75 | + "url": { | |
76 | + "raw": "localhost:5000/parse?q=Gerichte", | |
77 | + "host": [ | |
78 | + "localhost" | |
79 | + ], | |
80 | + "port": "5000", | |
81 | + "path": [ | |
82 | + "parse" | |
83 | + ], | |
84 | + "query": [ | |
85 | + { | |
86 | + "key": "q", | |
87 | + "value": "Gerichte", | |
88 | + "equals": true | |
89 | + } | |
90 | + ] | |
91 | + }, | |
92 | + "description": "" | |
93 | + }, | |
94 | + "response": [] | |
95 | + } | |
96 | + ] | |
97 | + }, | |
98 | + { | |
99 | + "name": "Telegram", | |
100 | + "description": "", | |
101 | + "item": [ | |
102 | + { | |
103 | + "name": "Telegram setWebhook", | |
104 | + "request": { | |
105 | + "method": "GET", | |
106 | + "header": [], | |
107 | + "body": {}, | |
108 | + "url": { | |
109 | + "raw": "" | |
110 | + }, | |
111 | + "description": "" | |
112 | + }, | |
113 | + "response": [] | |
114 | + }, | |
115 | + { | |
116 | + "name": "Telegram setWebhook", | |
117 | + "request": { | |
118 | + "method": "POST", | |
119 | + "header": [], | |
120 | + "body": {}, | |
121 | + "url": { | |
122 | + "raw": "localhost:8080/telegram/setWebhook", | |
123 | + "host": [ | |
124 | + "localhost" | |
125 | + ], | |
126 | + "port": "8080", | |
127 | + "path": [ | |
128 | + "telegram", | |
129 | + "setWebhook" | |
130 | + ] | |
131 | + }, | |
132 | + "description": "" | |
133 | + }, | |
134 | + "response": [] | |
135 | + } | |
136 | + ] | |
137 | + }, | |
138 | + { | |
139 | + "name": "Wildfly Home", | |
140 | + "request": { | |
141 | + "method": "GET", | |
142 | + "header": [], | |
143 | + "body": {}, | |
144 | + "url": { | |
145 | + "raw": "localhost/8080", | |
146 | + "host": [ | |
147 | + "localhost" | |
148 | + ], | |
149 | + "path": [ | |
150 | + "8080" | |
151 | + ] | |
152 | + }, | |
153 | + "description": "" | |
154 | + }, | |
155 | + "response": [] | |
156 | + } | |
157 | + ] | |
158 | +} | |
0 | 159 | \ No newline at end of file | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/daos/LogMessageDAO.java
0 → 100644
1 | +package de.bht.beuthbot.daos; | |
2 | + | |
3 | +import de.bht.beuthbot.model.entities.LogMessage; | |
4 | + | |
5 | +import javax.ejb.Remote; | |
6 | + | |
7 | +/** | |
8 | + * Created by Stephan Hausdörfer on 19.01.2018. | |
9 | + */ | |
10 | +@Remote | |
11 | +public interface LogMessageDAO extends GenericDAO<LogMessage, Long> { | |
12 | + | |
13 | + LogMessage createMessage(); | |
14 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/daos/LogMessageDAOImpl.java
0 → 100644
1 | +package de.bht.beuthbot.daos; | |
2 | + | |
3 | +import de.bht.beuthbot.model.entities.LogMessage; | |
4 | +import de.bht.beuthbot.model.entities.LogMessageImpl; | |
5 | + | |
6 | +import javax.ejb.Stateless; | |
7 | + | |
8 | +/** | |
9 | + * Created by Stephan Hausdörfer on 19.01.2018. | |
10 | + */ | |
11 | +@Stateless | |
12 | +public class LogMessageDAOImpl extends GenericHibernateDAO<LogMessage, LogMessageImpl, Long> implements LogMessageDAO { | |
13 | + | |
14 | + @Override | |
15 | + public LogMessage createMessage() { | |
16 | + return new LogMessageImpl(); | |
17 | + } | |
18 | +} | |
0 | 19 | \ No newline at end of file | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/daos/ReminderDAO.java
0 → 100644
1 | +package de.bht.beuthbot.daos; | |
2 | + | |
3 | +import de.bht.beuthbot.model.entities.Reminder; | |
4 | + | |
5 | +import javax.ejb.Remote; | |
6 | + | |
7 | +/** | |
8 | + * Created by Stephan Hausdörfer on 16.01.2018. | |
9 | + */ | |
10 | +@Remote | |
11 | +public interface ReminderDAO extends GenericDAO<Reminder, Long> { | |
12 | + | |
13 | + Reminder createReminder(); | |
14 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/daos/ReminderDAOImpl.java
0 → 100644
1 | +package de.bht.beuthbot.daos; | |
2 | + | |
3 | +import de.bht.beuthbot.model.entities.Reminder; | |
4 | +import de.bht.beuthbot.model.entities.ReminderImpl; | |
5 | + | |
6 | +import javax.ejb.Stateless; | |
7 | + | |
8 | +/** | |
9 | + * Created by Stephan Hausdörfer on 16.01.2018. | |
10 | + */ | |
11 | +@Stateless | |
12 | +public class ReminderDAOImpl extends GenericHibernateDAO<Reminder, ReminderImpl, Long> implements ReminderDAO { | |
13 | + | |
14 | + @Override | |
15 | + public Reminder createReminder() { | |
16 | + return new ReminderImpl(); | |
17 | + } | |
18 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/EntityName.java
... | ... | @@ -5,7 +5,7 @@ package de.bht.beuthbot.model; |
5 | 5 | */ |
6 | 6 | public enum EntityName { |
7 | 7 | |
8 | - DATE("date"), DISH_TYPE("dishtype"), HEALTHY("healthy"), INGREDIENTS("ingredients"), DISH_CATEGORY("dishcategory"), | |
8 | + DATE("date"), TIME("time"), DISH_TYPE("dishtype"), HEALTHY("healthy"), INGREDIENTS("ingredients"), DISH_CATEGORY("dishcategory"), | |
9 | 9 | DISH_NAME("dishname"), REMINDER_CYCLE("reminderCycle"); |
10 | 10 | |
11 | 11 | private String text; | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/entities/AppUserImpl.java
... | ... | @@ -13,7 +13,7 @@ import javax.persistence.Table; |
13 | 13 | * Postgres does not support creating a table named "user". |
14 | 14 | */ |
15 | 15 | @Entity |
16 | -@Table | |
16 | +@Table(name = "app_user") | |
17 | 17 | public class AppUserImpl extends EntityBaseImpl implements AppUser { |
18 | 18 | |
19 | 19 | private String facebookUserId; | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/entities/EntityBaseImpl.java
services/Common/src/main/java/de/bht/beuthbot/model/entities/GenericEntity.java
services/Common/src/main/java/de/bht/beuthbot/model/entities/GenericEntityAttribute.java
services/Common/src/main/java/de/bht/beuthbot/model/entities/GenericEntityAttributeValue.java
... | ... | @@ -11,7 +11,7 @@ import javax.persistence.Table; |
11 | 11 | * Supports complex nested types using a reference to a generic sub entity. |
12 | 12 | */ |
13 | 13 | @Entity |
14 | -@Table | |
14 | +@Table(name = "generic_entity_attribute_value") | |
15 | 15 | public class GenericEntityAttributeValue extends EntityBaseImpl { |
16 | 16 | |
17 | 17 | private Boolean valueAsBool; | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/entities/LogMessage.java
0 → 100644
1 | +package de.bht.beuthbot.model.entities; | |
2 | + | |
3 | +/** | |
4 | + * Created by Stephan Hausdörfer on 19.01.2018. | |
5 | + */ | |
6 | +public interface LogMessage extends EntityBase { | |
7 | + | |
8 | + long getUserId(); | |
9 | + | |
10 | + void setUserId(long userId); | |
11 | + | |
12 | + String getMessage(); | |
13 | + | |
14 | + void setMessage(String message); | |
15 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/entities/LogMessageImpl.java
0 → 100644
1 | +package de.bht.beuthbot.model.entities; | |
2 | + | |
3 | +import javax.persistence.Entity; | |
4 | +import javax.persistence.Table; | |
5 | + | |
6 | +/** | |
7 | + * Created by Stephan Hausdörfer on 19.01.2018. | |
8 | + */ | |
9 | +@Entity | |
10 | +@Table(name = "log_message") | |
11 | +public class LogMessageImpl extends EntityBaseImpl implements LogMessage { | |
12 | + | |
13 | + private long userId; | |
14 | + | |
15 | + private String message; | |
16 | + | |
17 | + | |
18 | + @Override | |
19 | + public long getUserId() { | |
20 | + return userId; | |
21 | + } | |
22 | + | |
23 | + @Override | |
24 | + public void setUserId(long userId) { | |
25 | + this.userId = userId; | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + public String getMessage() { | |
30 | + return message; | |
31 | + } | |
32 | + | |
33 | + @Override | |
34 | + public void setMessage(String message) { | |
35 | + this.message = message; | |
36 | + } | |
37 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/entities/Reminder.java
0 → 100644
1 | +package de.bht.beuthbot.model.entities; | |
2 | + | |
3 | +import de.bht.beuthbot.model.Messenger; | |
4 | +import de.bht.beuthbot.model.enumeration.ReminderCycle; | |
5 | + | |
6 | +import java.time.LocalDate; | |
7 | +import java.util.Map; | |
8 | + | |
9 | +/** | |
10 | + * Created by Stephan Hausdörfer on 16.01.2018. | |
11 | + */ | |
12 | +public interface Reminder extends EntityBase { | |
13 | + | |
14 | + long getUserId(); | |
15 | + | |
16 | + void setUserId(long userId); | |
17 | + | |
18 | + ReminderCycle getReminderCycle(); | |
19 | + | |
20 | + void setReminderCycle(ReminderCycle reminderCycle); | |
21 | + | |
22 | + LocalDate getCycleTime(); | |
23 | + | |
24 | + void setCycleTime(LocalDate cycleTime); | |
25 | + | |
26 | + Messenger getMessenger(); | |
27 | + | |
28 | + void setMessenger(Messenger messenger); | |
29 | + | |
30 | + String getIntent(); | |
31 | + | |
32 | + void setIntent(String intent); | |
33 | + | |
34 | + Map<String, String> getEntities(); | |
35 | + | |
36 | + void setEntities(Map<String, String> entities); | |
37 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/entities/ReminderImpl.java
0 → 100644
1 | +package de.bht.beuthbot.model.entities; | |
2 | + | |
3 | +import de.bht.beuthbot.model.Messenger; | |
4 | +import de.bht.beuthbot.model.enumeration.ReminderCycle; | |
5 | + | |
6 | +import javax.persistence.CollectionTable; | |
7 | +import javax.persistence.ElementCollection; | |
8 | +import javax.persistence.Entity; | |
9 | +import javax.persistence.Table; | |
10 | +import java.time.LocalDate; | |
11 | +import java.util.Map; | |
12 | + | |
13 | +/** | |
14 | + * Created by Stephan Hausdörfer on 16.01.2018. | |
15 | + */ | |
16 | +@Entity | |
17 | +@Table(name = "reminder") | |
18 | +public class ReminderImpl extends EntityBaseImpl implements Reminder { | |
19 | + | |
20 | + private long userId; | |
21 | + | |
22 | + private ReminderCycle reminderCycle; | |
23 | + | |
24 | + private LocalDate cycleTime; | |
25 | + | |
26 | + private Messenger messenger; | |
27 | + | |
28 | + private String intent; | |
29 | + | |
30 | + @ElementCollection | |
31 | + @CollectionTable(name = "reminder_entities") | |
32 | + private Map<String, String> entities; | |
33 | + | |
34 | + @Override | |
35 | + public long getUserId() { | |
36 | + return userId; | |
37 | + } | |
38 | + | |
39 | + @Override | |
40 | + public void setUserId(long userId) { | |
41 | + this.userId = userId; | |
42 | + } | |
43 | + | |
44 | + @Override | |
45 | + public ReminderCycle getReminderCycle() { | |
46 | + return reminderCycle; | |
47 | + } | |
48 | + | |
49 | + @Override | |
50 | + public void setReminderCycle(ReminderCycle reminderCycle) { | |
51 | + this.reminderCycle = reminderCycle; | |
52 | + } | |
53 | + | |
54 | + @Override | |
55 | + public LocalDate getCycleTime() { | |
56 | + return cycleTime; | |
57 | + } | |
58 | + | |
59 | + @Override | |
60 | + public void setCycleTime(LocalDate cycleTime) { | |
61 | + this.cycleTime = cycleTime; | |
62 | + } | |
63 | + | |
64 | + @Override | |
65 | + public Messenger getMessenger() { | |
66 | + return messenger; | |
67 | + } | |
68 | + | |
69 | + @Override | |
70 | + public void setMessenger(Messenger messenger) { | |
71 | + this.messenger = messenger; | |
72 | + } | |
73 | + | |
74 | + @Override | |
75 | + public String getIntent() { | |
76 | + return intent; | |
77 | + } | |
78 | + | |
79 | + @Override | |
80 | + public void setIntent(String intent) { | |
81 | + this.intent = intent; | |
82 | + } | |
83 | + | |
84 | + @Override | |
85 | + public Map<String, String> getEntities() { | |
86 | + return entities; | |
87 | + } | |
88 | + | |
89 | + @Override | |
90 | + public void setEntities(Map<String, String> entities) { | |
91 | + this.entities = entities; | |
92 | + } | |
93 | +} | ... | ... |
services/Common/src/main/java/de/bht/beuthbot/model/enumeration/ReminderCycle.java
0 → 100644
services/Common/src/main/java/de/bht/beuthbot/utils/DateStringExtractor.java
0 → 100644
1 | +package de.bht.beuthbot.utils; | |
2 | + | |
3 | +import javax.ejb.Local; | |
4 | +import java.time.DayOfWeek; | |
5 | +import java.time.LocalDate; | |
6 | +import java.time.format.TextStyle; | |
7 | +import java.util.Locale; | |
8 | + | |
9 | +public class DateStringExtractor { | |
10 | + public static LocalDate getLocalDateFromString(String dateString) { | |
11 | + LocalDate retrievedDate = LocalDate.now(); //initialize as current date | |
12 | + DayOfWeek today = retrievedDate.getDayOfWeek(); | |
13 | + | |
14 | + if(dateString.equals("TODAY")) { | |
15 | + return retrievedDate; | |
16 | + } else if(dateString.equals("TOMORROW")) { | |
17 | + retrievedDate = retrievedDate.plusDays(1); | |
18 | + } else if(dateString.equals("DAYAFTERTOMORROW")) { | |
19 | + retrievedDate = retrievedDate.plusDays(2); | |
20 | + } else if(dateString.equals("MONDAY") || dateString.equals("TUESDAY") || dateString.equals("WEDNESDAY") || dateString.equals("THURSDAY") || dateString.equals("FRIDAY") || dateString.equals("SATURDAY") || dateString.equals("SUNDAY")) { | |
21 | + DayOfWeek dayFromString = DayOfWeek.valueOf(dateString); | |
22 | + long distanceBetweenDates = dayFromString.getValue() - today.getValue(); | |
23 | + //if the distance between given days is equal to or smaller than 0 we can infer that the user is referring to the upcoming week | |
24 | + if(distanceBetweenDates <= 0) { | |
25 | + distanceBetweenDates += 7; | |
26 | + } | |
27 | + retrievedDate = retrievedDate.plusDays(distanceBetweenDates); | |
28 | + | |
29 | + } | |
30 | + | |
31 | + return retrievedDate; | |
32 | + } | |
33 | + | |
34 | + //This function takes a LocalDate and returns its Weekday Name in form of a string | |
35 | + public static String getWeekDayFromLocalDate(LocalDate date, boolean pretty, Locale locale) { | |
36 | + String weekDay = date.getDayOfWeek().getDisplayName(TextStyle.FULL, locale); | |
37 | + if(pretty) { //if pretty is set to true, we will return pretty names like "Today" and "Tomorrow" | |
38 | + if(LocalDate.now().getDayOfWeek().getValue() == date.getDayOfWeek().getValue()) { //TODAY | |
39 | + if(locale == Locale.GERMAN) { | |
40 | + weekDay = "heute"; | |
41 | + } else { | |
42 | + weekDay = "today"; | |
43 | + } | |
44 | + } else if(LocalDate.now().plusDays(1).getDayOfWeek().getValue() == date.getDayOfWeek().getValue()) { //TOMORROW | |
45 | + if(locale == Locale.GERMAN) { | |
46 | + weekDay = "morgen"; | |
47 | + } else { | |
48 | + weekDay = "tomorrow"; | |
49 | + } | |
50 | + } | |
51 | + } | |
52 | + return weekDay; | |
53 | + } | |
54 | + | |
55 | + public static String getGermanWeekDayFromLocalDate(LocalDate date, boolean pretty) { | |
56 | + return getWeekDayFromLocalDate(date, pretty, Locale.GERMAN); | |
57 | + } | |
58 | +} | ... | ... |
services/MainBot/src/main/java/de/bht/beuthbot/canteen/model/CanteenData.java
1 | 1 | package de.bht.beuthbot.canteen.model; |
2 | 2 | |
3 | +import de.bht.beuthbot.utils.DateStringExtractor; | |
3 | 4 | import org.slf4j.Logger; |
4 | 5 | import org.slf4j.LoggerFactory; |
5 | 6 | |
... | ... | @@ -84,8 +85,10 @@ public class CanteenData { |
84 | 85 | public final List<Dish> getDishesFiltered(final String pDate, final String pHealthy, final String pDishType, |
85 | 86 | final String pMarkings, final String pDishCategory) { |
86 | 87 | |
87 | - final LocalDate date = ("tomorrow".equals(pDate) ? LocalDate.now().plusDays(1) : LocalDate.now()); | |
88 | - | |
88 | + logger.debug("pDate: " + pDate); | |
89 | + //final LocalDate date = ("tomorrow".equals(pDate) ? LocalDate.now().plusDays(1) : LocalDate.now()); | |
90 | + final LocalDate date = DateStringExtractor.getLocalDateFromString(pDate); | |
91 | + logger.debug("resulting local date: " + date); | |
89 | 92 | final TrafficLight trafficLight = (pHealthy != null && !"".equals(pHealthy) ? TrafficLight.getTrafficLight(pHealthy): null); |
90 | 93 | |
91 | 94 | final DishType dishType = (pDishType != null && !"".equals(pDishType) ? DishType.getDishTypeByName(pDishType) : null); | ... | ... |
services/MainBot/src/main/java/de/bht/beuthbot/drools/DroolsService.java
1 | 1 | package de.bht.beuthbot.drools; |
2 | 2 | |
3 | - | |
4 | - | |
5 | - | |
6 | 3 | import com.google.gson.Gson; |
7 | 4 | |
8 | - | |
9 | 5 | import de.bht.beuthbot.attachments.AttachmentStore; |
10 | 6 | import de.bht.beuthbot.canteen.Parser; |
11 | 7 | import de.bht.beuthbot.canteen.model.CanteenData; |
12 | 8 | import de.bht.beuthbot.conf.Application; |
13 | 9 | import de.bht.beuthbot.daos.AppUserDAO; |
10 | +import de.bht.beuthbot.daos.LogMessageDAO; | |
14 | 11 | import de.bht.beuthbot.drools.model.DroolsMessage; |
15 | 12 | import de.bht.beuthbot.jms.ProcessQueue; |
16 | 13 | import de.bht.beuthbot.jms.ProcessQueueMessageProtocol; |
... | ... | @@ -18,6 +15,8 @@ import de.bht.beuthbot.jms.Target; |
18 | 15 | import de.bht.beuthbot.jms.TaskMessage; |
19 | 16 | import de.bht.beuthbot.model.Messenger; |
20 | 17 | import de.bht.beuthbot.model.entities.AppUser; |
18 | + | |
19 | +import de.bht.beuthbot.model.entities.LogMessage; | |
21 | 20 | import org.kie.api.KieServices; |
22 | 21 | import org.kie.api.runtime.KieContainer; |
23 | 22 | import org.kie.api.runtime.KieSession; |
... | ... | @@ -73,6 +72,9 @@ public class DroolsService implements MessageListener { |
73 | 72 | @Resource(lookup = "java:global/global/AppUserDAOImpl") |
74 | 73 | private AppUserDAO userDAO; |
75 | 74 | |
75 | + @Resource(lookup = "java:global/global/LogMessageDAOImpl") | |
76 | + private LogMessageDAO logMessageDAO; | |
77 | + | |
76 | 78 | @Inject |
77 | 79 | private Parser parser; |
78 | 80 | |
... | ... | @@ -143,7 +145,10 @@ public class DroolsService implements MessageListener { |
143 | 145 | } |
144 | 146 | AppUser finishedUser = userDAO.saveOrUpdate(tempUser); |
145 | 147 | |
146 | - | |
148 | + LogMessage logMessage = logMessageDAO.createMessage(); | |
149 | + logMessage.setUserId(finishedUser.getId()); | |
150 | + logMessage.setMessage(botMessage.getText()); | |
151 | + logMessageDAO.saveOrUpdate(logMessage); | |
147 | 152 | |
148 | 153 | ksession.setGlobal("canteenData", canteenData); |
149 | 154 | ksession.setGlobal("user", finishedUser); | ... | ... |
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/JAXActivator.java
0 → 100644
1 | +package de.bht.beuthbot.scheduler; | |
2 | + | |
3 | +import javax.ws.rs.ApplicationPath; | |
4 | +import javax.ws.rs.core.Application; | |
5 | + | |
6 | +/** | |
7 | + * JAXActivator is an arbitrary name, what is important is that javax.ws.rs.core.Application is extended | |
8 | + * and the @ApplicationPath annotation is used with a "rest" path. Without this the rest routes linked to | |
9 | + * from index.html would not be found. | |
10 | + */ | |
11 | +@ApplicationPath("") | |
12 | +public class JAXActivator extends Application { | |
13 | + // Left empty intentionally | |
14 | +} | ... | ... |
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
0 → 100644
1 | +package de.bht.beuthbot.scheduler; | |
2 | + | |
3 | +import de.bht.beuthbot.attachments.AttachmentStore; | |
4 | +import de.bht.beuthbot.daos.AppUserDAO; | |
5 | +import de.bht.beuthbot.daos.ReminderDAO; | |
6 | +import de.bht.beuthbot.jms.Target; | |
7 | +import de.bht.beuthbot.model.EntityName; | |
8 | +import de.bht.beuthbot.model.Intent; | |
9 | +import de.bht.beuthbot.model.Messenger; | |
10 | +import de.bht.beuthbot.model.entities.AppUser; | |
11 | +import de.bht.beuthbot.model.entities.Reminder; | |
12 | +import de.bht.beuthbot.model.enumeration.ReminderCycle; | |
13 | +import de.bht.beuthbot.utils.DateStringExtractor; | |
14 | + | |
15 | +import org.slf4j.Logger; | |
16 | +import org.slf4j.LoggerFactory; | |
17 | + | |
18 | +import de.bht.beuthbot.conf.Application; | |
19 | +import de.bht.beuthbot.jms.ProcessQueue; | |
20 | +import de.bht.beuthbot.jms.TaskMessage; | |
21 | + | |
22 | +import java.text.SimpleDateFormat; | |
23 | +import java.time.LocalDate; | |
24 | +import java.util.*; | |
25 | +import javax.annotation.PostConstruct; | |
26 | +import javax.annotation.Resource; | |
27 | +import javax.ejb.*; | |
28 | + | |
29 | +@Singleton | |
30 | +@Startup | |
31 | +public class SchedulerBean { | |
32 | + /** | |
33 | + * slf4j Logger | |
34 | + */ | |
35 | + private final Logger logger = LoggerFactory.getLogger(SchedulerBean.class); | |
36 | + //Timer object for call cycling | |
37 | + @Resource | |
38 | + TimerService timerService; | |
39 | + /** Injected JMS MessageQueue */ | |
40 | + @Resource(lookup = "java:global/global/ProcessQueueBean") | |
41 | + private ProcessQueue processQueue; | |
42 | + | |
43 | + /** Injected AttachmentStore */ | |
44 | + @Resource(lookup = "java:global/global/AttachmentStoreBean") | |
45 | + private AttachmentStore attachmentStore; | |
46 | + | |
47 | + /** BeuthBot Application Bean */ | |
48 | + @Resource(lookup = "java:global/global/ApplicationBean") | |
49 | + private Application application; | |
50 | + | |
51 | + /** Injected AppUserDAO */ | |
52 | + @Resource(lookup = "java:global/global/AppUserDAOImpl") | |
53 | + private AppUserDAO userDAO; | |
54 | + | |
55 | + /** Injected ReminderDAO */ | |
56 | + @Resource(lookup = "java:global/global/ReminderDAOImpl") | |
57 | + private ReminderDAO reminderDAO; | |
58 | + | |
59 | + boolean isActive = true; | |
60 | + | |
61 | + public SchedulerBean() { | |
62 | + | |
63 | + } | |
64 | + | |
65 | + //CONSTRUCTOR | |
66 | + @PostConstruct | |
67 | + public void init(){ | |
68 | + logger.debug("SchedulerBean initiated!"); | |
69 | + } | |
70 | + | |
71 | + @Schedule(hour="*", minute="*") | |
72 | + public void fetchReminders() { | |
73 | + logger.debug("SchedulerBean fired!"); | |
74 | + | |
75 | + if (!isActive) return; | |
76 | + | |
77 | + SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy KK:mm"); | |
78 | + String dateNow = formatter.format(new Date()); | |
79 | + | |
80 | + List<Reminder> reminders = reminderDAO.findAll(); | |
81 | + | |
82 | + for (Reminder reminder : reminders) { | |
83 | + //Check if date time now equals reminder date time | |
84 | + if(dateNow.equals(formatter.format(reminder.getCycleTime()))) { | |
85 | + Long messageID = 1L; | |
86 | + AppUser user = userDAO.findById(reminder.getUserId()); | |
87 | + Long messengerId = Long.valueOf(user.getFacebookUserId() == null ? user.getTelegramUserId() : user.getFacebookUserId()); | |
88 | + Messenger messenger = reminder.getMessenger(); | |
89 | + String text = ""; | |
90 | + String intent = reminder.getIntent(); | |
91 | + Map entities = reminder.getEntities(); | |
92 | + try { | |
93 | + TaskMessage message = new TaskMessage(1L, Target.MAINBOT, messageID, messengerId , messenger, text, null, intent, entities); | |
94 | + processQueue.route(new TaskMessage(message)); | |
95 | + } catch (Exception e) { | |
96 | + logger.error("Something went wrong while attempting to send reminder!", e); | |
97 | + } | |
98 | + } | |
99 | + } | |
100 | + } | |
101 | + | |
102 | + public Reminder createReminder(TaskMessage message, AppUser user) { | |
103 | + logger.debug("Creating reminder"); | |
104 | + | |
105 | + Messenger messenger = message.getMessenger(); | |
106 | + | |
107 | + | |
108 | + //Figure out when to remind the user | |
109 | + | |
110 | + //Set reminder cycle to one shot as a default | |
111 | + ReminderCycle cycle = ReminderCycle.ONCE; | |
112 | + //Extract the Date from the message | |
113 | + String messageDay = message.getEntities().getOrDefault("date", "TODAY"); | |
114 | + //If the date retrieved from the message contains a cycling parameter (e.g. "daily"), set the reminderCycle | |
115 | + switch(messageDay) { | |
116 | + case "DAILY": | |
117 | + cycle = ReminderCycle.DAILY; | |
118 | + break; | |
119 | + case "WEEKLY": | |
120 | + cycle = ReminderCycle.WEEKLY; | |
121 | + break; | |
122 | + case "MONTHLY": | |
123 | + cycle = ReminderCycle.MONTHLY; | |
124 | + break; | |
125 | + } | |
126 | + | |
127 | + LocalDate cycleDate = DateStringExtractor.getLocalDateFromString(messageDay); | |
128 | + | |
129 | + Date cycleTime; | |
130 | + try { | |
131 | + //Read out time for Reminder | |
132 | + | |
133 | + String messageTime = message.getEntities().getOrDefault("time",""); | |
134 | + //time should not be empty | |
135 | + if(!messageTime.equals("")) { | |
136 | + //get Date new for day, month, year | |
137 | + String dateNow = new SimpleDateFormat("dd.MM.yyyy").format(new Date()); | |
138 | + //remove all chars from time String (e.g. "10 Uhr") | |
139 | + String reminderTime = messageTime.replaceAll("[^0-9:]", ""); | |
140 | + //trim spaces | |
141 | + reminderTime = reminderTime.trim(); | |
142 | + //check if given time is e.g. "11:15" | |
143 | + if(reminderTime.contains(":")) { | |
144 | + //split for hours and minutes | |
145 | + String[] splittedTime = reminderTime.split(":"); | |
146 | + //add hours and minutes to date | |
147 | + if(splittedTime.length > 1) | |
148 | + dateNow = dateNow + " " + splittedTime[0] + ":" + splittedTime[1]; | |
149 | + } else { | |
150 | + //add hours from time and set to "00" | |
151 | + dateNow = dateNow + " " + reminderTime + ":" + "00"; | |
152 | + } | |
153 | + | |
154 | + SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy hh:mm"); | |
155 | + Date d = f.parse(dateNow); | |
156 | + long milliseconds = d.getTime(); | |
157 | + cycleTime = new Date(milliseconds); | |
158 | + | |
159 | + } else | |
160 | + cycleTime = new Date(); | |
161 | + | |
162 | + } catch (Exception e) { | |
163 | + return null; | |
164 | + } | |
165 | + //Figure out what we're reminding the user of | |
166 | + String intent = message.getEntities().getOrDefault("event","FALLBACK"); | |
167 | + | |
168 | + Map<String, String> entities = new HashMap<>(); | |
169 | + switch(intent) { | |
170 | + case "showFood": | |
171 | + intent = Intent.SHOW_FOOD.getText(); | |
172 | + logger.debug("Intent is show food"); | |
173 | + entities.put(EntityName.DATE.getText(), cycleDate.toString()); | |
174 | + entities.put(EntityName.TIME.getText(), cycleTime.toString()); | |
175 | + logger.debug("Entities added: " + entities); | |
176 | + break; | |
177 | + case "showCourses": | |
178 | + //TODO: add Courses functionality | |
179 | + break; | |
180 | + default: | |
181 | + intent = "FALLBACK"; | |
182 | + break; | |
183 | + } | |
184 | + | |
185 | + logger.debug("Creating reminder with date " + cycleDate.toString() + " and time " + cycleTime.toString()); | |
186 | + | |
187 | + Reminder reminder = reminderDAO.createReminder(); | |
188 | + reminder.setUserId(user.getId()); | |
189 | + reminder.setReminderCycle(cycle); | |
190 | + reminder.setCycleTime(cycleDate); | |
191 | + reminder.setMessenger(messenger); | |
192 | + reminder.setIntent(intent); | |
193 | + reminder.setEntities(entities); | |
194 | + | |
195 | + return reminderDAO.saveOrUpdate(reminder); | |
196 | + } | |
197 | + | |
198 | +} | ... | ... |
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
... | ... | @@ -32,16 +32,21 @@ import de.bht.beuthbot.drools.model.DroolsMessage; |
32 | 32 | |
33 | 33 | import de.bht.beuthbot.scheduler.SchedulerBean |
34 | 34 | import de.bht.beuthbot.jms.TaskMessage |
35 | -import de.bht.beuthbot.scheduler.model.ReminderCycle | |
36 | 35 | import java.util.Date |
37 | 36 | import java.text.SimpleDateFormat |
38 | 37 | import java.text.ParseException |
39 | 38 | import de.bht.beuthbot.model.Messenger |
40 | -import de.bht.beuthbot.scheduler.model.Reminder; | |
39 | + | |
40 | +import java.time.DayOfWeek; | |
41 | +import java.time.LocalDate | |
42 | +import de.bht.beuthbot.utils.DateStringExtractor | |
43 | +import de.bht.beuthbot.model.entities.Reminder; | |
41 | 44 | |
42 | 45 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; |
43 | 46 | global de.bht.beuthbot.model.entities.AppUser user; |
44 | 47 | |
48 | + | |
49 | + | |
45 | 50 | // ---------------------- GREETING ------------------------------------ |
46 | 51 | rule "Hello Drools" |
47 | 52 | dialect "java" |
... | ... | @@ -88,8 +93,12 @@ rule "Show dishes filtered" |
88 | 93 | when |
89 | 94 | m : DroolsMessage( getIntent().equals(Intent.SHOW_FOOD.getText()) && !entities.isEmpty() ) |
90 | 95 | then |
96 | + String day = m.getEntities().getOrDefault(EntityName.DATE.getText(), ""); | |
97 | + if(day != "") { | |
98 | + day = DateStringExtractor.getGermanWeekDayFromLocalDate(DateStringExtractor.getLocalDateFromString(day),true); | |
99 | + } | |
91 | 100 | modify( m ) { |
92 | - setText("Gerichte:\n" + canteenData.getDishesFilteredAsString( | |
101 | + setText("Diese Gerichte gibt es " + day + ":\n" + canteenData.getDishesFilteredAsString( | |
93 | 102 | (m.getEntities().containsKey(EntityName.DATE.getText()) ? m.getEntities().get(EntityName.DATE.getText()) : null), |
94 | 103 | (m.getEntities().containsKey(EntityName.HEALTHY.getText()) ? m.getEntities().get(EntityName.HEALTHY.getText()) : null), |
95 | 104 | (m.getEntities().containsKey(EntityName.DISH_TYPE.getText()) ? m.getEntities().get(EntityName.DISH_TYPE.getText()) : null), |
... | ... | @@ -126,7 +135,13 @@ rule "Create reminder" |
126 | 135 | then |
127 | 136 | SchedulerBean s = new SchedulerBean(); |
128 | 137 | TaskMessage message = new TaskMessage(m); |
129 | - String messageText = s.createReminder(message, user); | |
138 | + Reminder reminder = s.createReminder(message, user); | |
139 | + String messageText = ""; | |
140 | + if(reminder.getIntent() == Intent.SHOW_FOOD.getText()) { | |
141 | + messageText = "Ich werde dir " + DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleTime(), true) + " um " + new SimpleDateFormat("KK:mm").format(reminder.getCycleTime()) + " Uhr den Mensaplan mitteilen!"; | |
142 | + } else { | |
143 | + messageText = "Es war mir leider nicht möglich eine Erinnerung für dich anzulegen. Versuche es bitte noch einmal."; | |
144 | + } //TODO: Add other intents | |
130 | 145 | m.setText(messageText); |
131 | 146 | |
132 | 147 | end | ... | ... |
services/Rasa/src/main/java/de/bht/beuthbot/nlp/rasa/RasaConnector.java
... | ... | @@ -79,7 +79,8 @@ public class RasaConnector implements MessageListener { |
79 | 79 | logger.debug("{}: {}", response.getStatus(), responseAsString); |
80 | 80 | |
81 | 81 | RasaResponse rasaResponse = gson.fromJson(responseAsString, RasaResponse.class); |
82 | - TaskMessage messageToMainBot = new TaskMessage(new RasaMessage(incomingChatMessage, rasaResponse)); | |
82 | + RasaMessage rasaMessage = new RasaMessage(incomingChatMessage, rasaResponse); | |
83 | + TaskMessage messageToMainBot = new TaskMessage(rasaMessage); | |
83 | 84 | processQueue.route(messageToMainBot); |
84 | 85 | } catch (JMSException e) { |
85 | 86 | logger.error("Error while processing message.", e); | ... | ... |
services/Telegram/src/main/java/de/bht/beuthbot/messenger/telegram/TelegramReceiveAdapter.java
... | ... | @@ -13,6 +13,9 @@ import com.pengrad.telegrambot.response.GetFileResponse; |
13 | 13 | import de.bht.beuthbot.attachments.AttachmentStore; |
14 | 14 | import de.bht.beuthbot.conf.Application; |
15 | 15 | import de.bht.beuthbot.conf.Configuration; |
16 | +import de.bht.beuthbot.daos.AppUserDAO; | |
17 | +import de.bht.beuthbot.daos.LogMessageDAO; | |
18 | +import de.bht.beuthbot.daos.ReminderDAO; | |
16 | 19 | import de.bht.beuthbot.jms.ProcessQueue; |
17 | 20 | import de.bht.beuthbot.jms.TaskMessage; |
18 | 21 | import de.bht.beuthbot.messenger.telegram.model.TelegramAttachment; |
... | ... | @@ -20,6 +23,11 @@ import de.bht.beuthbot.messenger.telegram.model.TelegramMessage; |
20 | 23 | import de.bht.beuthbot.messenger.telegram.model.TelegramWebhookURL; |
21 | 24 | import de.bht.beuthbot.model.Attachment; |
22 | 25 | import de.bht.beuthbot.model.AttachmentType; |
26 | +import de.bht.beuthbot.model.Messenger; | |
27 | +import de.bht.beuthbot.model.entities.AppUser; | |
28 | +import de.bht.beuthbot.model.entities.LogMessage; | |
29 | +import de.bht.beuthbot.model.entities.Reminder; | |
30 | +import de.bht.beuthbot.model.enumeration.ReminderCycle; | |
23 | 31 | import org.apache.http.HttpStatus; |
24 | 32 | import org.slf4j.Logger; |
25 | 33 | import org.slf4j.LoggerFactory; |
... | ... | @@ -27,10 +35,14 @@ import org.slf4j.LoggerFactory; |
27 | 35 | import javax.annotation.PostConstruct; |
28 | 36 | import javax.annotation.Resource; |
29 | 37 | import javax.ws.rs.Consumes; |
38 | +import javax.ws.rs.GET; | |
30 | 39 | import javax.ws.rs.POST; |
31 | 40 | import javax.ws.rs.Path; |
32 | 41 | import javax.ws.rs.core.MediaType; |
33 | 42 | import javax.ws.rs.core.Response; |
43 | +import java.time.LocalDate; | |
44 | +import java.util.HashMap; | |
45 | +import java.util.List; | |
34 | 46 | |
35 | 47 | /** |
36 | 48 | * @Author: Christopher Kümmel on 5/14/2017. |
... | ... | @@ -56,6 +68,18 @@ public class TelegramReceiveAdapter { |
56 | 68 | /** com.pengrad.telegrambot.TelegramBot; */ |
57 | 69 | private TelegramBot bot; |
58 | 70 | |
71 | + /** Injected AppUserDAO */ | |
72 | + @Resource(lookup = "java:global/global/AppUserDAOImpl") | |
73 | + private AppUserDAO userDAO; | |
74 | + | |
75 | + /** Injected AppUserDAO */ | |
76 | + @Resource(lookup = "java:global/global/ReminderDAOImpl") | |
77 | + private ReminderDAO reminderDAO; | |
78 | + | |
79 | + /** Injected AppUserDAO */ | |
80 | + @Resource(lookup = "java:global/global/LogMessageDAOImpl") | |
81 | + private LogMessageDAO logMessageDAO; | |
82 | + | |
59 | 83 | /** |
60 | 84 | * Initialize TelegramBot with Token |
61 | 85 | */ |
... | ... | @@ -131,6 +155,52 @@ public class TelegramReceiveAdapter { |
131 | 155 | } |
132 | 156 | } |
133 | 157 | |
158 | + /** | |
159 | + * Test method for database | |
160 | + * @return Http response | |
161 | + */ | |
162 | + @GET | |
163 | + @Path("/testDatabase") | |
164 | + public Response testDatabase() { | |
165 | + logger.info("testDatabase: Start"); | |
166 | + AppUser user = userDAO.createUser(); | |
167 | + user.setFacebookUserId("88"); | |
168 | + user.setTelegramUserId("99"); | |
169 | + user.setProperty("test_key", "test_value"); | |
170 | + userDAO.saveOrUpdate(user); | |
171 | + logger.info("testDatabase: Speichern durchgefuehrt"); | |
172 | + | |
173 | + List<AppUser> userList = userDAO.findAll(); | |
174 | + String result = userList.get(0).getTelegramUserId(); | |
175 | + logger.info("TelegramUserId: " + result); | |
176 | + logger.info("testDatabase: Auslesen durchgefuehrt"); | |
177 | + | |
178 | + Reminder reminder = reminderDAO.createReminder(); | |
179 | + reminder.setMessenger(Messenger.TELEGRAM); | |
180 | + reminder.setReminderCycle(ReminderCycle.DAILY); | |
181 | + reminder.setCycleTime(LocalDate.now()); | |
182 | + Long userId = userList.get(0).getId(); | |
183 | + reminder.setUserId(userId); | |
184 | + reminder.setIntent("Intent"); | |
185 | + HashMap entities = new HashMap(); | |
186 | + entities.put("key1", "value2"); | |
187 | + entities.put("key2", "value2"); | |
188 | + reminder.setEntities(entities); | |
189 | + reminderDAO.saveOrUpdate(reminder); | |
190 | + | |
191 | + List<Reminder> reminders = reminderDAO.findAll(); | |
192 | + Reminder reminderResult = reminders.get(0); | |
193 | + logger.info("Reminder Cycle: " + reminderResult.getReminderCycle().toString()); | |
194 | + logger.info("Telegram ID via Reminder: " + userDAO.findById(reminderResult.getUserId()).getTelegramUserId()); | |
195 | + | |
196 | + LogMessage logMessage = logMessageDAO.createMessage(); | |
197 | + logMessage.setUserId(userList.get(0).getId()); | |
198 | + logMessage.setMessage("Message"); | |
199 | + logMessageDAO.saveOrUpdate(logMessage); | |
200 | + | |
201 | + return Response.status(HttpStatus.SC_OK).build(); | |
202 | + } | |
203 | + | |
134 | 204 | |
135 | 205 | /** |
136 | 206 | * RESTEasy HTTP Post to set Webhook | ... | ... |
services/Telegram/src/main/java/de/bht/beuthbot/messenger/telegram/TelegramSendAdapter.java
... | ... | @@ -103,9 +103,13 @@ public class TelegramSendAdapter implements MessageListener { |
103 | 103 | * @param message to send |
104 | 104 | */ |
105 | 105 | private void sendMessage(final Long senderId, final String message) { |
106 | + logger.debug("Message is " + message.length() + " characters long"); | |
106 | 107 | SendMessage request = new SendMessage(senderId, message); |
107 | 108 | SendResponse sendResponse = bot.execute(request); |
108 | 109 | logger.debug("Send message: " + sendResponse.isOk()); |
110 | + if(!sendResponse.isOk()) { | |
111 | + logger.debug("Sending message to user " + senderId + " failed: " + sendResponse.message()); | |
112 | + } | |
109 | 113 | } |
110 | 114 | |
111 | 115 | /** | ... | ... |
services/Telegram/src/main/java/de/bht/beuthbot/messenger/telegram/model/TelegramWebhookURL.java
0 → 100644
1 | +package de.bht.beuthbot.messenger.telegram.model; | |
2 | + | |
3 | +import de.bht.beuthbot.conf.Application; | |
4 | +import de.bht.beuthbot.conf.Configuration; | |
5 | + | |
6 | +import javax.annotation.Resource; | |
7 | + | |
8 | +public class TelegramWebhookURL { | |
9 | + /** BeuthBot Application Bean */ | |
10 | + @Resource(lookup = "java:global/global/ApplicationBean") | |
11 | + private Application application; | |
12 | + | |
13 | + private String url; | |
14 | + | |
15 | + public String getUrl() { | |
16 | + return url; | |
17 | + } | |
18 | + | |
19 | + public void setUrl(String url) { | |
20 | + /* | |
21 | + if(!botToken.equals(application.getConfiguration(Configuration.TELEGRAM_BOT_TOKEN))) { | |
22 | + return; | |
23 | + }*/ | |
24 | + this.url = url; | |
25 | + } | |
26 | + | |
27 | + @Override | |
28 | + public String toString() { | |
29 | + return url; | |
30 | + } | |
31 | +} | ... | ... |