Commit 7d394baaa7f8fe20197b03004b1c32d085325a6a
1 parent
022a517b
Improved Scheduler service.
Showing
10 changed files
with
174 additions
and
26 deletions
docker/rasa_nlu/volumes/data/api/intents/showFood.json
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | "parameters": [ | 10 | "parameters": [ |
11 | { | 11 | { |
12 | "id": "7b5df330-e1fc-4bb4-86de-5a51be29c836", | 12 | "id": "7b5df330-e1fc-4bb4-86de-5a51be29c836", |
13 | + "required": false, | ||
13 | "dataType": "@date", | 14 | "dataType": "@date", |
14 | "name": "date", | 15 | "name": "date", |
15 | "value": "$date", | 16 | "value": "$date", |
@@ -17,6 +18,7 @@ | @@ -17,6 +18,7 @@ | ||
17 | }, | 18 | }, |
18 | { | 19 | { |
19 | "id": "f3da5ec9-d3e8-4263-9bc3-7d600784bd0d", | 20 | "id": "f3da5ec9-d3e8-4263-9bc3-7d600784bd0d", |
21 | + "required": false, | ||
20 | "dataType": "@dishtype", | 22 | "dataType": "@dishtype", |
21 | "name": "dishtype", | 23 | "name": "dishtype", |
22 | "value": "$dishtype", | 24 | "value": "$dishtype", |
@@ -24,6 +26,7 @@ | @@ -24,6 +26,7 @@ | ||
24 | }, | 26 | }, |
25 | { | 27 | { |
26 | "id": "499e1a33-d7ef-4446-ae7d-30ab94c9e3a5", | 28 | "id": "499e1a33-d7ef-4446-ae7d-30ab94c9e3a5", |
29 | + "required": false, | ||
27 | "dataType": "@healthy", | 30 | "dataType": "@healthy", |
28 | "name": "healthy", | 31 | "name": "healthy", |
29 | "value": "$healthy", | 32 | "value": "$healthy", |
@@ -31,6 +34,7 @@ | @@ -31,6 +34,7 @@ | ||
31 | }, | 34 | }, |
32 | { | 35 | { |
33 | "id": "f53af932-a4f2-4fe5-be2d-eb96a30e9400", | 36 | "id": "f53af932-a4f2-4fe5-be2d-eb96a30e9400", |
37 | + "required": false, | ||
34 | "dataType": "@ingredients", | 38 | "dataType": "@ingredients", |
35 | "name": "ingredients", | 39 | "name": "ingredients", |
36 | "value": "$ingredients", | 40 | "value": "$ingredients", |
@@ -38,6 +42,7 @@ | @@ -38,6 +42,7 @@ | ||
38 | }, | 42 | }, |
39 | { | 43 | { |
40 | "id": "b8c8ab1d-4190-4200-9540-2893a084a1fd", | 44 | "id": "b8c8ab1d-4190-4200-9540-2893a084a1fd", |
45 | + "required": false, | ||
41 | "dataType": "@price", | 46 | "dataType": "@price", |
42 | "name": "price", | 47 | "name": "price", |
43 | "value": "$price", | 48 | "value": "$price", |
@@ -45,6 +50,7 @@ | @@ -45,6 +50,7 @@ | ||
45 | }, | 50 | }, |
46 | { | 51 | { |
47 | "id": "92607e59-96c8-4c61-8dc0-670c7b8c2b43", | 52 | "id": "92607e59-96c8-4c61-8dc0-670c7b8c2b43", |
53 | + "required": false, | ||
48 | "dataType": "@dishcategory", | 54 | "dataType": "@dishcategory", |
49 | "name": "dishcategory", | 55 | "name": "dishcategory", |
50 | "value": "$dishcategory", | 56 | "value": "$dishcategory", |
docker/wildfly/volumes/conf/beuthbot.properties
@@ -18,7 +18,7 @@ API_AI_TOKEN = XXXXX | @@ -18,7 +18,7 @@ API_AI_TOKEN = XXXXX | ||
18 | TELEGRAM_WEBHOOK_URL = /telegram/getUpdates | 18 | TELEGRAM_WEBHOOK_URL = /telegram/getUpdates |
19 | 19 | ||
20 | # Your Bot Token e.g.: 000000000:AAAAa0aAA_aaA-Aaaa0A0Aa_a0aa0A0AAAA | 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 |
services/Common/src/main/java/de/bht/beuthbot/model/EntityName.java
@@ -5,7 +5,7 @@ package de.bht.beuthbot.model; | @@ -5,7 +5,7 @@ package de.bht.beuthbot.model; | ||
5 | */ | 5 | */ |
6 | public enum EntityName { | 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 | DISH_NAME("dishname"), REMINDER_CYCLE("reminderCycle"); | 9 | DISH_NAME("dishname"), REMINDER_CYCLE("reminderCycle"); |
10 | 10 | ||
11 | private String text; | 11 | private String text; |
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 | package de.bht.beuthbot.canteen.model; | 1 | package de.bht.beuthbot.canteen.model; |
2 | 2 | ||
3 | +import de.bht.beuthbot.utils.DateStringExtractor; | ||
3 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
4 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
5 | 6 | ||
@@ -84,8 +85,10 @@ public class CanteenData { | @@ -84,8 +85,10 @@ public class CanteenData { | ||
84 | public final List<Dish> getDishesFiltered(final String pDate, final String pHealthy, final String pDishType, | 85 | public final List<Dish> getDishesFiltered(final String pDate, final String pHealthy, final String pDishType, |
85 | final String pMarkings, final String pDishCategory) { | 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 | final TrafficLight trafficLight = (pHealthy != null && !"".equals(pHealthy) ? TrafficLight.getTrafficLight(pHealthy): null); | 92 | final TrafficLight trafficLight = (pHealthy != null && !"".equals(pHealthy) ? TrafficLight.getTrafficLight(pHealthy): null); |
90 | 93 | ||
91 | final DishType dishType = (pDishType != null && !"".equals(pDishType) ? DishType.getDishTypeByName(pDishType) : null); | 94 | final DishType dishType = (pDishType != null && !"".equals(pDishType) ? DishType.getDishTypeByName(pDishType) : null); |
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
@@ -3,11 +3,13 @@ package de.bht.beuthbot.scheduler; | @@ -3,11 +3,13 @@ package de.bht.beuthbot.scheduler; | ||
3 | import de.bht.beuthbot.attachments.AttachmentStore; | 3 | import de.bht.beuthbot.attachments.AttachmentStore; |
4 | import de.bht.beuthbot.jms.Target; | 4 | import de.bht.beuthbot.jms.Target; |
5 | import de.bht.beuthbot.model.Attachment; | 5 | import de.bht.beuthbot.model.Attachment; |
6 | +import de.bht.beuthbot.model.EntityName; | ||
6 | import de.bht.beuthbot.model.Intent; | 7 | import de.bht.beuthbot.model.Intent; |
7 | import de.bht.beuthbot.model.Messenger; | 8 | import de.bht.beuthbot.model.Messenger; |
8 | import de.bht.beuthbot.model.entities.AppUser; | 9 | import de.bht.beuthbot.model.entities.AppUser; |
9 | import de.bht.beuthbot.scheduler.model.Reminder; | 10 | import de.bht.beuthbot.scheduler.model.Reminder; |
10 | import de.bht.beuthbot.scheduler.model.ReminderCycle; | 11 | import de.bht.beuthbot.scheduler.model.ReminderCycle; |
12 | +import de.bht.beuthbot.utils.DateStringExtractor; | ||
11 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
12 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
13 | 15 | ||
@@ -18,6 +20,7 @@ import de.bht.beuthbot.jms.TaskMessage; | @@ -18,6 +20,7 @@ import de.bht.beuthbot.jms.TaskMessage; | ||
18 | 20 | ||
19 | import java.text.ParseException; | 21 | import java.text.ParseException; |
20 | import java.text.SimpleDateFormat; | 22 | import java.text.SimpleDateFormat; |
23 | +import java.time.LocalDate; | ||
21 | import java.util.*; | 24 | import java.util.*; |
22 | import javax.annotation.PostConstruct; | 25 | import javax.annotation.PostConstruct; |
23 | import javax.annotation.Resource; | 26 | import javax.annotation.Resource; |
@@ -75,14 +78,14 @@ public class SchedulerBean { | @@ -75,14 +78,14 @@ public class SchedulerBean { | ||
75 | 78 | ||
76 | for (Reminder reminder : _reminders) { | 79 | for (Reminder reminder : _reminders) { |
77 | //Check if date time now equals reminder date time | 80 | //Check if date time now equals reminder date time |
78 | - if(dateNow.equals(formatter.format(reminder.getCycleDate()))) { | 81 | + if(dateNow.equals(formatter.format(reminder.getCycleTime()))) { |
79 | Long messageID = 1L; | 82 | Long messageID = 1L; |
80 | AppUser user = reminder.getUser(); //TODO: Fill with correct value from DB | 83 | AppUser user = reminder.getUser(); //TODO: Fill with correct value from DB |
81 | Long messengerId = Long.valueOf(user.getFacebookUserId() == null ? user.getTelegramUserId() : user.getFacebookUserId()); | 84 | Long messengerId = Long.valueOf(user.getFacebookUserId() == null ? user.getTelegramUserId() : user.getFacebookUserId()); |
82 | Messenger messenger = reminder.getMessenger(); //TODO: Fill with correct value from DB | 85 | Messenger messenger = reminder.getMessenger(); //TODO: Fill with correct value from DB |
83 | String text = ""; | 86 | String text = ""; |
84 | - String intent = "showFood"; | ||
85 | - Map entities = Collections.emptyMap(); | 87 | + String intent = reminder.getIntent(); |
88 | + Map entities = reminder.getEntities(); | ||
86 | try { | 89 | try { |
87 | TaskMessage message = new TaskMessage(1L, Target.MAINBOT, messageID, messengerId , messenger, text, null, intent, entities); | 90 | TaskMessage message = new TaskMessage(1L, Target.MAINBOT, messageID, messengerId , messenger, text, null, intent, entities); |
88 | processQueue.route(new TaskMessage(message)); | 91 | processQueue.route(new TaskMessage(message)); |
@@ -93,12 +96,34 @@ public class SchedulerBean { | @@ -93,12 +96,34 @@ public class SchedulerBean { | ||
93 | } | 96 | } |
94 | } | 97 | } |
95 | 98 | ||
96 | - public String createReminder(TaskMessage message, AppUser user) { | 99 | + public Reminder createReminder(TaskMessage message, AppUser user) { |
100 | + logger.debug("Creating reminder"); | ||
101 | + | ||
102 | + Messenger messenger = message.getMessenger(); | ||
103 | + | ||
104 | + | ||
105 | + //Figure out when to remind the user | ||
106 | + | ||
107 | + //Set reminder cycle to one shot as a default | ||
108 | + ReminderCycle cycle = ReminderCycle.ONCE; | ||
109 | + //Extract the Date from the message | ||
110 | + String messageDay = message.getEntities().getOrDefault("date", "TODAY"); | ||
111 | + //If the date retrieved from the message contains a cycling parameter (e.g. "daily"), set the reminderCycle | ||
112 | + switch(messageDay) { | ||
113 | + case "DAILY": | ||
114 | + cycle = ReminderCycle.DAILY; | ||
115 | + break; | ||
116 | + case "WEEKLY": | ||
117 | + cycle = ReminderCycle.WEEKLY; | ||
118 | + break; | ||
119 | + case "MONTHLY": | ||
120 | + cycle = ReminderCycle.MONTHLY; | ||
121 | + break; | ||
122 | + } | ||
123 | + | ||
124 | + LocalDate cycleDate = DateStringExtractor.getLocalDateFromString(messageDay); | ||
97 | 125 | ||
98 | - ReminderCycle cycle = ReminderCycle.DAILY; | ||
99 | - Messenger messener = message.getMessenger(); | ||
100 | - String intent = message.getEntities().getOrDefault("event",""); | ||
101 | - Date date; | 126 | + Date cycleTime; |
102 | try { | 127 | try { |
103 | //Read out time for Reminder | 128 | //Read out time for Reminder |
104 | 129 | ||
@@ -126,21 +151,39 @@ public class SchedulerBean { | @@ -126,21 +151,39 @@ public class SchedulerBean { | ||
126 | SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy hh:mm"); | 151 | SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy hh:mm"); |
127 | Date d = f.parse(dateNow); | 152 | Date d = f.parse(dateNow); |
128 | long milliseconds = d.getTime(); | 153 | long milliseconds = d.getTime(); |
129 | - date = new Date(milliseconds); | 154 | + cycleTime = new Date(milliseconds); |
130 | 155 | ||
131 | } else | 156 | } else |
132 | - date = new Date(); | 157 | + cycleTime = new Date(); |
133 | 158 | ||
134 | } catch (Exception e) { | 159 | } catch (Exception e) { |
135 | - return "Fehler beim Anlegen der Erinnerung"; | 160 | + return null; |
161 | + } | ||
162 | + //Figure out what we're reminding the user of | ||
163 | + String intent = message.getEntities().getOrDefault("event","FALLBACK"); | ||
164 | + | ||
165 | + Map<String, String> entities = new HashMap<>(); | ||
166 | + switch(intent) { | ||
167 | + case "showFood": | ||
168 | + intent = Intent.SHOW_FOOD.getText(); | ||
169 | + logger.debug("Intent is show food"); | ||
170 | + entities.put(EntityName.DATE.getText(), cycleDate.toString()); | ||
171 | + entities.put(EntityName.TIME.getText(), cycleTime.toString()); | ||
172 | + logger.debug("Entities added: " + entities); | ||
173 | + break; | ||
174 | + case "showCourses": | ||
175 | + //TODO: add Courses functionality | ||
176 | + break; | ||
177 | + default: | ||
178 | + intent = "FALLBACK"; | ||
179 | + break; | ||
136 | } | 180 | } |
137 | 181 | ||
138 | - Reminder reminder = new Reminder(user, cycle, date, messener, intent); | 182 | + logger.debug("Creating reminder with date " + cycleDate.toString() + " and time " + cycleTime.toString()); |
183 | + Reminder reminder = new Reminder(user, cycle, cycleDate, cycleTime, messenger, intent, entities); | ||
139 | _reminders.add(reminder); | 184 | _reminders.add(reminder); |
140 | 185 | ||
141 | - return "Erinnerung erstellt:\n" + | ||
142 | - "Wann: um " + new SimpleDateFormat("KK:mm").format(reminder.getCycleDate()) + " Uhr\n" + | ||
143 | - "Was: " + reminder.getIntent(); | 186 | + return reminder; |
144 | 187 | ||
145 | //TODO: Insert the new Reminder into Database | 188 | //TODO: Insert the new Reminder into Database |
146 | } | 189 | } |
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/model/Reminder.java
1 | package de.bht.beuthbot.scheduler.model; | 1 | package de.bht.beuthbot.scheduler.model; |
2 | 2 | ||
3 | +import de.bht.beuthbot.model.Intent; | ||
3 | import de.bht.beuthbot.model.Messenger; | 4 | import de.bht.beuthbot.model.Messenger; |
4 | import de.bht.beuthbot.model.entities.AppUser; | 5 | import de.bht.beuthbot.model.entities.AppUser; |
5 | 6 | ||
7 | +import java.time.LocalDate; | ||
6 | import java.util.Date; | 8 | import java.util.Date; |
9 | +import java.util.HashMap; | ||
10 | +import java.util.Map; | ||
7 | 11 | ||
8 | public class Reminder { | 12 | public class Reminder { |
9 | //TODO: Replace with User Object | 13 | //TODO: Replace with User Object |
@@ -11,18 +15,25 @@ public class Reminder { | @@ -11,18 +15,25 @@ public class Reminder { | ||
11 | //Reminder cycle | 15 | //Reminder cycle |
12 | private ReminderCycle _reminderCycle; | 16 | private ReminderCycle _reminderCycle; |
13 | //Date of Cycle | 17 | //Date of Cycle |
14 | - private Date _cycleDate; | 18 | + private LocalDate _cycleDate; |
19 | + //Time of cycle | ||
20 | + private Date _cycleTime; | ||
21 | + //private | ||
15 | //Used Messenger | 22 | //Used Messenger |
16 | private Messenger _messenger; | 23 | private Messenger _messenger; |
17 | //Intent after Reminder is triggered | 24 | //Intent after Reminder is triggered |
18 | private String _intent; | 25 | private String _intent; |
26 | + //Entities | ||
27 | + private final Map<String, String> _entities; | ||
19 | 28 | ||
20 | - public Reminder(AppUser user, ReminderCycle reminderCycle, Date cycleDate, Messenger messenger, String intent) { | 29 | + public Reminder(AppUser user, ReminderCycle reminderCycle, LocalDate cycleDate, Date cycleTime, Messenger messenger, String intent, Map<String, String> entities) { |
21 | _user = user; | 30 | _user = user; |
22 | _reminderCycle = reminderCycle; | 31 | _reminderCycle = reminderCycle; |
23 | _cycleDate = cycleDate; | 32 | _cycleDate = cycleDate; |
33 | + _cycleTime = cycleTime; | ||
24 | _messenger = messenger; | 34 | _messenger = messenger; |
25 | _intent = intent; | 35 | _intent = intent; |
36 | + _entities = entities; | ||
26 | } | 37 | } |
27 | 38 | ||
28 | public Messenger getMessenger() { | 39 | public Messenger getMessenger() { |
@@ -57,11 +68,17 @@ public class Reminder { | @@ -57,11 +68,17 @@ public class Reminder { | ||
57 | _reminderCycle = reminderCycle; | 68 | _reminderCycle = reminderCycle; |
58 | } | 69 | } |
59 | 70 | ||
60 | - public Date getCycleDate() { | 71 | + public LocalDate getCycleDate() { |
61 | return _cycleDate; | 72 | return _cycleDate; |
62 | } | 73 | } |
63 | 74 | ||
64 | - public void setCycleDate(Date cycleDate) { | 75 | + public void setCycleDate(LocalDate cycleDate) { |
65 | _cycleDate = cycleDate; | 76 | _cycleDate = cycleDate; |
66 | } | 77 | } |
78 | + | ||
79 | + public Date getCycleTime() { return _cycleTime; } | ||
80 | + | ||
81 | + public void setCycleTime(Date cycleTime) { _cycleTime = cycleTime; } | ||
82 | + | ||
83 | + public Map<String, String> getEntities() { return _entities; } | ||
67 | } | 84 | } |
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
@@ -39,9 +39,15 @@ import java.text.ParseException | @@ -39,9 +39,15 @@ import java.text.ParseException | ||
39 | import de.bht.beuthbot.model.Messenger | 39 | import de.bht.beuthbot.model.Messenger |
40 | import de.bht.beuthbot.scheduler.model.Reminder; | 40 | import de.bht.beuthbot.scheduler.model.Reminder; |
41 | 41 | ||
42 | +import java.time.DayOfWeek; | ||
43 | +import java.time.LocalDate | ||
44 | +import de.bht.beuthbot.utils.DateStringExtractor; | ||
45 | + | ||
42 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; | 46 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; |
43 | global de.bht.beuthbot.model.entities.AppUser user; | 47 | global de.bht.beuthbot.model.entities.AppUser user; |
44 | 48 | ||
49 | + | ||
50 | + | ||
45 | // ---------------------- GREETING ------------------------------------ | 51 | // ---------------------- GREETING ------------------------------------ |
46 | rule "Hello Drools" | 52 | rule "Hello Drools" |
47 | dialect "java" | 53 | dialect "java" |
@@ -88,8 +94,12 @@ rule "Show dishes filtered" | @@ -88,8 +94,12 @@ rule "Show dishes filtered" | ||
88 | when | 94 | when |
89 | m : DroolsMessage( getIntent().equals(Intent.SHOW_FOOD.getText()) && !entities.isEmpty() ) | 95 | m : DroolsMessage( getIntent().equals(Intent.SHOW_FOOD.getText()) && !entities.isEmpty() ) |
90 | then | 96 | then |
97 | + String day = m.getEntities().getOrDefault(EntityName.DATE.getText(), ""); | ||
98 | + if(day != "") { | ||
99 | + day = DateStringExtractor.getGermanWeekDayFromLocalDate(DateStringExtractor.getLocalDateFromString(day),true); | ||
100 | + } | ||
91 | modify( m ) { | 101 | modify( m ) { |
92 | - setText("Gerichte:\n" + canteenData.getDishesFilteredAsString( | 102 | + setText("Diese Gerichte gibt es " + day + ":\n" + canteenData.getDishesFilteredAsString( |
93 | (m.getEntities().containsKey(EntityName.DATE.getText()) ? m.getEntities().get(EntityName.DATE.getText()) : null), | 103 | (m.getEntities().containsKey(EntityName.DATE.getText()) ? m.getEntities().get(EntityName.DATE.getText()) : null), |
94 | (m.getEntities().containsKey(EntityName.HEALTHY.getText()) ? m.getEntities().get(EntityName.HEALTHY.getText()) : null), | 104 | (m.getEntities().containsKey(EntityName.HEALTHY.getText()) ? m.getEntities().get(EntityName.HEALTHY.getText()) : null), |
95 | (m.getEntities().containsKey(EntityName.DISH_TYPE.getText()) ? m.getEntities().get(EntityName.DISH_TYPE.getText()) : null), | 105 | (m.getEntities().containsKey(EntityName.DISH_TYPE.getText()) ? m.getEntities().get(EntityName.DISH_TYPE.getText()) : null), |
@@ -126,7 +136,13 @@ rule "Create reminder" | @@ -126,7 +136,13 @@ rule "Create reminder" | ||
126 | then | 136 | then |
127 | SchedulerBean s = new SchedulerBean(); | 137 | SchedulerBean s = new SchedulerBean(); |
128 | TaskMessage message = new TaskMessage(m); | 138 | TaskMessage message = new TaskMessage(m); |
129 | - String messageText = s.createReminder(message, user); | 139 | + Reminder reminder = s.createReminder(message, user); |
140 | + String messageText = ""; | ||
141 | + if(reminder.getIntent() == Intent.SHOW_FOOD.getText()) { | ||
142 | + messageText = "Ich werde dir " + DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleDate(), true) + " um " + new SimpleDateFormat("KK:mm").format(reminder.getCycleTime()) + " Uhr den Mensaplan mitteilen!"; | ||
143 | + } else { | ||
144 | + messageText = "Es war mir leider nicht möglich eine Erinnerung für dich anzulegen. Versuche es bitte noch einmal."; | ||
145 | + } //TODO: Add other intents | ||
130 | m.setText(messageText); | 146 | m.setText(messageText); |
131 | 147 | ||
132 | end | 148 | end |
services/Rasa/src/main/java/de/bht/beuthbot/nlp/rasa/RasaConnector.java
@@ -79,7 +79,8 @@ public class RasaConnector implements MessageListener { | @@ -79,7 +79,8 @@ public class RasaConnector implements MessageListener { | ||
79 | logger.debug("{}: {}", response.getStatus(), responseAsString); | 79 | logger.debug("{}: {}", response.getStatus(), responseAsString); |
80 | 80 | ||
81 | RasaResponse rasaResponse = gson.fromJson(responseAsString, RasaResponse.class); | 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 | processQueue.route(messageToMainBot); | 84 | processQueue.route(messageToMainBot); |
84 | } catch (JMSException e) { | 85 | } catch (JMSException e) { |
85 | logger.error("Error while processing message.", e); | 86 | logger.error("Error while processing message.", e); |
services/Telegram/src/main/java/de/bht/beuthbot/messenger/telegram/TelegramSendAdapter.java
@@ -103,9 +103,13 @@ public class TelegramSendAdapter implements MessageListener { | @@ -103,9 +103,13 @@ public class TelegramSendAdapter implements MessageListener { | ||
103 | * @param message to send | 103 | * @param message to send |
104 | */ | 104 | */ |
105 | private void sendMessage(final Long senderId, final String message) { | 105 | private void sendMessage(final Long senderId, final String message) { |
106 | + logger.debug("Message is " + message.length() + " characters long"); | ||
106 | SendMessage request = new SendMessage(senderId, message); | 107 | SendMessage request = new SendMessage(senderId, message); |
107 | SendResponse sendResponse = bot.execute(request); | 108 | SendResponse sendResponse = bot.execute(request); |
108 | logger.debug("Send message: " + sendResponse.isOk()); | 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 | /** |