Commit 209f860ada0f6edb690971849ed3c75ccad1ee70

Authored by Neocortexxx
1 parent 0ee70d95

New Reminder text and Droolslogic

docker/rasa_nlu/volumes/data/api/intents/createReminder.json
... ... @@ -26,10 +26,19 @@
26 26 },
27 27 {
28 28 "id": "b8be17f8-0174-401c-b5a4-fabacaf8cfd6",
  29 + "required": false,
29 30 "dataType": "@eventDate",
30 31 "name": "eventDate",
31 32 "value": "$eventDate",
32 33 "isList": false
  34 + },
  35 + {
  36 + "id": "efe0fc3c-12c1-4596-b708-629f85eff4d4",
  37 + "required": false,
  38 + "dataType": "@sys.time",
  39 + "name": "time",
  40 + "value": "$time",
  41 + "isList": false
33 42 }
34 43 ],
35 44 "messages": [
... ...
docker/rasa_nlu/volumes/data/api/intents/createReminder_usersays_de.json
1 1 [
2 2 {
3   - "id": "048b511c-bfd1-4c84-bcaf-b0e5682ae312",
  3 + "id": "67f7964a-dce7-4850-bc8d-1c54cc9322f9",
  4 + "data": [
  5 + {
  6 + "text": "Schicke mir ",
  7 + "userDefined": false
  8 + },
  9 + {
  10 + "text": "täglich",
  11 + "alias": "date",
  12 + "meta": "@date",
  13 + "userDefined": true
  14 + },
  15 + {
  16 + "text": " um ",
  17 + "userDefined": false
  18 + },
  19 + {
  20 + "text": "9:15",
  21 + "alias": "time",
  22 + "meta": "@sys.time",
  23 + "userDefined": true
  24 + },
  25 + {
  26 + "text": " den ",
  27 + "userDefined": false
  28 + },
  29 + {
  30 + "text": "Mensaplan",
  31 + "alias": "event",
  32 + "meta": "@event",
  33 + "userDefined": false
  34 + }
  35 + ],
  36 + "isTemplate": false,
  37 + "count": 0
  38 + },
  39 + {
  40 + "id": "57817744-75c2-4506-9aa9-c4fe64c79cf7",
  41 + "data": [
  42 + {
  43 + "text": "Schick mir ",
  44 + "userDefined": false
  45 + },
  46 + {
  47 + "text": "jeden Tag",
  48 + "alias": "date",
  49 + "meta": "@date",
  50 + "userDefined": true
  51 + },
  52 + {
  53 + "text": " um ",
  54 + "userDefined": false
  55 + },
  56 + {
  57 + "text": "10:30",
  58 + "alias": "time",
  59 + "meta": "@sys.time",
  60 + "userDefined": true
  61 + },
  62 + {
  63 + "text": " was es in der ",
  64 + "userDefined": false
  65 + },
  66 + {
  67 + "text": "Mensa",
  68 + "alias": "event",
  69 + "meta": "@event",
  70 + "userDefined": true
  71 + },
  72 + {
  73 + "text": " gibt",
  74 + "userDefined": false
  75 + }
  76 + ],
  77 + "isTemplate": false,
  78 + "count": 0
  79 + },
  80 + {
  81 + "id": "dfb1541a-6488-46fc-9780-3e8c1e59a8d0",
  82 + "data": [
  83 + {
  84 + "text": "Schick mir ",
  85 + "userDefined": false
  86 + },
  87 + {
  88 + "text": "jeden Tag",
  89 + "alias": "date",
  90 + "meta": "@date",
  91 + "userDefined": true
  92 + },
  93 + {
  94 + "text": " um ",
  95 + "userDefined": false
  96 + },
  97 + {
  98 + "text": "12",
  99 + "alias": "time",
  100 + "meta": "@sys.time",
  101 + "userDefined": true
  102 + },
  103 + {
  104 + "text": " den ",
  105 + "userDefined": false
  106 + },
  107 + {
  108 + "text": "Mensaplan",
  109 + "alias": "event",
  110 + "meta": "@event",
  111 + "userDefined": true
  112 + }
  113 + ],
  114 + "isTemplate": false,
  115 + "count": 0
  116 + },
  117 + {
  118 + "id": "cb34aa7b-a3d5-44bb-ae99-8517a3cd87a1",
  119 + "data": [
  120 + {
  121 + "text": "Sag mir ",
  122 + "userDefined": false
  123 + },
  124 + {
  125 + "text": "morgen",
  126 + "alias": "date",
  127 + "meta": "@date",
  128 + "userDefined": false
  129 + },
  130 + {
  131 + "text": " um ",
  132 + "userDefined": false
  133 + },
  134 + {
  135 + "text": "10 Uhr",
  136 + "alias": "time",
  137 + "meta": "@sys.time",
  138 + "userDefined": true
  139 + },
  140 + {
  141 + "text": " was es zu ",
  142 + "userDefined": false
  143 + },
  144 + {
  145 + "text": "essen",
  146 + "alias": "event",
  147 + "meta": "@event",
  148 + "userDefined": false
  149 + },
  150 + {
  151 + "text": " gibt",
  152 + "userDefined": false
  153 + }
  154 + ],
  155 + "isTemplate": false,
  156 + "count": 0
  157 + },
  158 + {
  159 + "id": "e57f06f3-b85b-430c-9f80-d5eea3add061",
4 160 "data": [
5 161 {
6 162 "text": "Sag mir ",
... ... @@ -27,7 +183,7 @@
27 183 "count": 0
28 184 },
29 185 {
30   - "id": "3db29b3b-0dae-4960-b1b8-2472086f9ab2",
  186 + "id": "66d04c31-2ae0-431d-a9fd-9f978280e255",
31 187 "data": [
32 188 {
33 189 "text": "Sag mir ",
... ... @@ -58,7 +214,7 @@
58 214 "count": 0
59 215 },
60 216 {
61   - "id": "15128099-9cc8-4d75-b463-8a9c14cbbe71",
  217 + "id": "6355f4ca-616b-4679-a97f-218d132c9548",
62 218 "data": [
63 219 {
64 220 "text": "Erinner mich ",
... ... @@ -85,7 +241,7 @@
85 241 "count": 0
86 242 },
87 243 {
88   - "id": "3ac087fd-5dec-4da0-892e-da5158942427",
  244 + "id": "3bd103d7-59ae-4d78-85e2-7c18832eb2c9",
89 245 "data": [
90 246 {
91 247 "text": "Schick mir ",
... ... @@ -112,7 +268,7 @@
112 268 "count": 0
113 269 },
114 270 {
115   - "id": "e3964a35-45c4-486e-9f0c-570ebbb65c41",
  271 + "id": "be93cedf-afc5-4e2c-9a74-2e712bd2003b",
116 272 "data": [
117 273 {
118 274 "text": "Schick mir ",
... ... @@ -139,7 +295,7 @@
139 295 "count": 0
140 296 },
141 297 {
142   - "id": "0c89a079-064f-4d8f-9aa5-93d0cd17d289",
  298 + "id": "90359a1d-f4c6-4d0b-8c68-e0d533310bf2",
143 299 "data": [
144 300 {
145 301 "text": "Erinnere mich ",
... ... @@ -166,7 +322,7 @@
166 322 "count": 0
167 323 },
168 324 {
169   - "id": "1f6e6f74-a322-4a2c-852b-5603b21cc197",
  325 + "id": "c89bd8fc-05ac-4a83-805c-791bc34875d2",
170 326 "data": [
171 327 {
172 328 "text": "Erinner mich ",
... ... @@ -193,7 +349,7 @@
193 349 "count": 0
194 350 },
195 351 {
196   - "id": "8fddff73-5b7f-4323-8406-22278c29a921",
  352 + "id": "506ac56c-af5d-417b-8f6d-4756a26f961e",
197 353 "data": [
198 354 {
199 355 "text": "Ich möchte ",
... ... @@ -224,7 +380,7 @@
224 380 "count": 0
225 381 },
226 382 {
227   - "id": "b986f29a-4e3f-4d5e-80ec-f8a24bf65682",
  383 + "id": "3a1f5110-eca8-488f-86b7-6a2eb14af696",
228 384 "data": [
229 385 {
230 386 "text": "Ich möchte ",
... ... @@ -255,7 +411,7 @@
255 411 "count": 0
256 412 },
257 413 {
258   - "id": "283d3114-0f98-439b-97dc-4533acae7819",
  414 + "id": "52aed8c1-f5d1-4ac5-b70e-713f4030d91a",
259 415 "data": [
260 416 {
261 417 "text": "Ich möchte ",
... ... @@ -296,7 +452,7 @@
296 452 "count": 0
297 453 },
298 454 {
299   - "id": "8cc39102-5715-4aab-a75b-dce15852daf0",
  455 + "id": "9b459ffc-24ae-4abd-89ca-ee40555b7c79",
300 456 "data": [
301 457 {
302 458 "text": "Ich möchte ",
... ... @@ -337,7 +493,7 @@
337 493 "count": 0
338 494 },
339 495 {
340   - "id": "30cfae78-6f8a-4342-8510-df3668148c1b",
  496 + "id": "e498660c-8e55-4847-b874-09789e622efe",
341 497 "data": [
342 498 {
343 499 "text": "Ich will ",
... ... @@ -378,7 +534,7 @@
378 534 "count": 0
379 535 },
380 536 {
381   - "id": "da87cf85-1e1d-473c-b2f8-d4783cb912a8",
  537 + "id": "4c82899c-5dfe-4408-8554-e27da2c697d9",
382 538 "data": [
383 539 {
384 540 "text": "Ich will ",
... ... @@ -409,7 +565,7 @@
409 565 "count": 0
410 566 },
411 567 {
412   - "id": "e0205bbe-d5fd-456c-8da1-302e7e47090c",
  568 + "id": "b25fbdf2-c155-43b1-a293-e88eae55e2f8",
413 569 "data": [
414 570 {
415 571 "text": "Ich will ",
... ... @@ -440,7 +596,7 @@
440 596 "count": 0
441 597 },
442 598 {
443   - "id": "3b09fc0e-cf73-4752-8510-1896b086fce0",
  599 + "id": "0899dbf0-698c-4e34-a2b3-bc94d3de86ba",
444 600 "data": [
445 601 {
446 602 "text": "Ich möchte ",
... ... @@ -471,7 +627,7 @@
471 627 "count": 0
472 628 },
473 629 {
474   - "id": "66cbbf17-d8b3-4ed6-b619-cf73396cb99a",
  630 + "id": "8b8db57f-ba18-4527-a639-d47fb47a3a4b",
475 631 "data": [
476 632 {
477 633 "text": "Ich möchte ",
... ... @@ -502,7 +658,7 @@
502 658 "count": 0
503 659 },
504 660 {
505   - "id": "0f080528-e477-4fbe-8e10-74c93b90b956",
  661 + "id": "a5fa7401-96dc-4a5c-93c9-9a57fc45d567",
506 662 "data": [
507 663 {
508 664 "text": "Ich möchte ",
... ... @@ -533,7 +689,7 @@
533 689 "count": 0
534 690 },
535 691 {
536   - "id": "fa1ef3a4-6e89-4de9-b935-b5c483a2a528",
  692 + "id": "a0c7e8cf-620f-47df-bf60-b7e217ec137e",
537 693 "data": [
538 694 {
539 695 "text": "Erinnere mich jeden ",
... ... @@ -560,7 +716,7 @@
560 716 "count": 0
561 717 },
562 718 {
563   - "id": "fe089fe4-6be1-4a66-b1f5-1b646faacc90",
  719 + "id": "043ba90b-2cd0-4411-b7ae-2e48f407bbae",
564 720 "data": [
565 721 {
566 722 "text": "Erinner mich ",
... ... @@ -587,7 +743,7 @@
587 743 "count": 0
588 744 },
589 745 {
590   - "id": "786a4f45-8367-4442-bb67-ae585ae4a593",
  746 + "id": "75c7a2e0-54ca-47b6-bf5c-661d45ffacb3",
591 747 "data": [
592 748 {
593 749 "text": "Erinnere mich ",
... ...
docker/wildfly/volumes/conf/beuthbot.properties
1   -WEB_URL = https://tlhiuqrvbl.localtunnel.me
  1 +WEB_URL = https://eoiqzqzwvt.localtunnel.me
2 2  
3 3  
4 4 # Webhook token you set in the Facebook App Settings
... ...
docu/attachmentstore.md
... ... @@ -10,7 +10,7 @@
10 10  
11 11 ## Description
12 12  
13   -The AttachmentStore represents a Service to persist Data in any variation. For example: an audio-file from a messenger need to be stored locally to be processed further.
  13 +The AttachmentStore represents a Service to persist Data in any variation. For example: an audio-file from a _messenger need to be stored locally to be processed further.
14 14  
15 15 ## Functionality
16 16  
... ...
docu/facebook.md
... ... @@ -27,7 +27,7 @@
27 27  
28 28 ##### ii. Facebook App
29 29  
30   -- after you created the app, add the 'messenger product' in the control panel on the left side
  30 +- after you created the app, add the '_messenger product' in the control panel on the left side
31 31 - generate an messaging key for your Facebook page and store it under 'FACEBOOK_BOT_TOKEN' in the config.properties
32 32 - setup a webhook by using your webhook address (https://yourdomain.com/rest/facebook/getUpdates) and the identification key set in 'FACEBOOK_WEBHOOK_TOKEN' in the config.properties
33 33 - subscribe the webhook to your Facebook page
... ...
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
... ... @@ -15,6 +15,8 @@ import de.bht.beuthbot.conf.Configuration;
15 15 import de.bht.beuthbot.jms.ProcessQueue;
16 16 import de.bht.beuthbot.jms.TaskMessage;
17 17  
  18 +import java.text.ParseException;
  19 +import java.text.SimpleDateFormat;
18 20 import java.util.*;
19 21 import javax.annotation.PostConstruct;
20 22 import javax.annotation.Resource;
... ... @@ -48,7 +50,7 @@ public class SchedulerBean {
48 50 //list of reminders to be populated with data from the DB
49 51 private ArrayList<Reminder> _reminders = new ArrayList<>();
50 52  
51   - boolean isActive = false;
  53 + boolean isActive = true;
52 54  
53 55 public SchedulerBean() {
54 56  
... ... @@ -67,31 +69,78 @@ public class SchedulerBean {
67 69  
68 70 if (!isActive) return;
69 71  
70   - Long messageID = 1L;
71   - Long senderID = 1L; //TODO: Fill with correct value from DB
72   - Messenger messenger = Messenger.TELEGRAM; //TODO: Fill with correct value from DB
73   - String text = "";
74   - String intent = "remind";
75   - Map entities = Collections.emptyMap();
  72 + SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy KK:mm");
  73 + String dateNow = formatter.format(new Date());
  74 +
  75 + for (Reminder reminder : _reminders) {
  76 + //Check if date time now equals reminder date time
  77 + if(dateNow.equals(formatter.format(reminder.getCycleDate()))) {
  78 + Long messageID = 1L;
  79 + Long senderID = reminder.getUserID(); //TODO: Fill with correct value from DB
  80 + Messenger messenger = reminder.getMessenger(); //TODO: Fill with correct value from DB
  81 + String text = "";
  82 + String intent = "showFood";
  83 + Map entities = Collections.emptyMap();
  84 + try {
  85 + TaskMessage message = new TaskMessage(1L, Target.MAINBOT, messageID, senderID, messenger, text, null, intent, entities);
  86 + processQueue.route(new TaskMessage(message));
  87 + } catch (Exception e) {
  88 + logger.error("Something went wrong while attempting to send reminder!", e);
  89 + }
  90 + }
  91 + }
  92 + }
  93 +
  94 + public String createReminder(TaskMessage message) {
  95 + Long user = message.getSenderID();
  96 + ReminderCycle cycle = ReminderCycle.DAILY;
  97 + Messenger messener = message.getMessenger();
  98 + String intent = message.getEntities().getOrDefault("event","");
  99 + Date date;
76 100 try {
77   - TaskMessage message = new TaskMessage(1L, Target.MAINBOT, messageID, senderID, messenger, text, null, intent, entities);
78   - processQueue.route(new TaskMessage(message));
  101 + //Read out time for Reminder
  102 +
  103 + String messageTime = message.getEntities().getOrDefault("time","");
  104 + //time should not be empty
  105 + if(!messageTime.equals("")) {
  106 + //get Date new for day, month, year
  107 + String dateNow = new SimpleDateFormat("dd.MM.yyyy").format(new Date());
  108 + //remove all chars from time String (e.g. "10 Uhr")
  109 + String reminderTime = messageTime.replaceAll("[^0-9:]", "");
  110 + //trim spaces
  111 + reminderTime = reminderTime.trim();
  112 + //check if given time is e.g. "11:15"
  113 + if(reminderTime.contains(":")) {
  114 + //split for hours and minutes
  115 + String[] splittedTime = reminderTime.split(":");
  116 + //add hours and minutes to date
  117 + if(splittedTime.length > 1)
  118 + dateNow = dateNow + " " + splittedTime[0] + ":" + splittedTime[1];
  119 + } else {
  120 + //add hours from time and set to "00"
  121 + dateNow = dateNow + " " + reminderTime + ":" + "00";
  122 + }
  123 +
  124 + SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy hh:mm");
  125 + Date d = f.parse(dateNow);
  126 + long milliseconds = d.getTime();
  127 + date = new Date(milliseconds);
  128 +
  129 + } else
  130 + date = new Date();
79 131  
80 132 } catch (Exception e) {
81   - logger.error("Something went wrong while attempting to send reminder!", e);
  133 + return "Fehler beim Anlegen der Erinnerung";
82 134 }
83 135  
  136 + Reminder reminder = new Reminder(user, cycle, date, messener, intent);
  137 + _reminders.add(reminder);
84 138  
  139 + return "Erinnerung erstellt:\n" +
  140 + "Wann: um " + new SimpleDateFormat("KK:mm").format(reminder.getCycleDate()) + " Uhr\n" +
  141 + "Was: " + reminder.getIntent();
85 142  
86   -
87   - }
88   -
89   - public boolean createReminder(TaskMessage message) {
90   - //Reminder newReminder = new Reminder(message.getSenderID()); //, reminderCycle, cycleDate);
91 143 //TODO: Insert the new Reminder into Database
92   -
93   - return true;
94   -
95 144 }
96 145  
97 146 }
... ...
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/model/Reminder.java
1 1 package de.bht.beuthbot.scheduler.model;
2 2  
3   -import de.bht.beuthbot.scheduler.model.ReminderCycle;
  3 +import de.bht.beuthbot.model.Messenger;
4 4  
5 5 import java.util.Date;
6 6  
... ... @@ -11,11 +11,33 @@ public class Reminder {
11 11 private ReminderCycle _reminderCycle;
12 12 //Date of Cycle
13 13 private Date _cycleDate;
  14 + //Used Messenger
  15 + private Messenger _messenger;
  16 + //Intent after Reminder is triggered
  17 + private String _intent;
14 18  
15   - public Reminder(Long userID, ReminderCycle reminderCycle, Date cycleDate) {
  19 + public Reminder(Long userID, ReminderCycle reminderCycle, Date cycleDate, Messenger messenger, String intent) {
16 20 _userID = userID;
17 21 _reminderCycle = reminderCycle;
18 22 _cycleDate = cycleDate;
  23 + _messenger = messenger;
  24 + _intent = intent;
  25 + }
  26 +
  27 + public Messenger getMessenger() {
  28 + return _messenger;
  29 + }
  30 +
  31 + public void setMessenger(Messenger messenger) {
  32 + _messenger = messenger;
  33 + }
  34 +
  35 + public String getIntent() {
  36 + return _intent;
  37 + }
  38 +
  39 + public void setIntent(String intent) {
  40 + _intent = intent;
19 41 }
20 42  
21 43 public Long getUserID() {
... ...
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
... ... @@ -31,7 +31,13 @@ import de.bht.beuthbot.model.EntityName;
31 31 import de.bht.beuthbot.drools.model.DroolsMessage;
32 32  
33 33 import de.bht.beuthbot.scheduler.SchedulerBean
34   -import de.bht.beuthbot.jms.TaskMessage;
  34 +import de.bht.beuthbot.jms.TaskMessage
  35 +import de.bht.beuthbot.scheduler.model.ReminderCycle
  36 +import java.util.Date
  37 +import java.text.SimpleDateFormat
  38 +import java.text.ParseException
  39 +import de.bht.beuthbot.model.Messenger
  40 +import de.bht.beuthbot.scheduler.model.Reminder;
35 41  
36 42 global de.bht.beuthbot.canteen.model.CanteenData canteenData;
37 43  
... ... @@ -118,7 +124,9 @@ rule &quot;Create reminder&quot;
118 124  
119 125 then
120 126 SchedulerBean s = new SchedulerBean();
121   - if (s.createReminder(new TaskMessage(m)) == true) { m.setText("Ich werde dich erinnern!"); }
  127 + TaskMessage message = new TaskMessage(m);
  128 + String messageText = s.createReminder(message);
  129 + m.setText(messageText);
122 130  
123 131 end
124 132  
... ...
src/main/plantuml/model.puml
... ... @@ -5,7 +5,7 @@ class Message {
5 5 ID: Long
6 6 messageID: String
7 7 senderID: String
8   - messenger: Messenger
  8 + _messenger: Messenger
9 9 text: String
10 10 attechments: Attachment[]
11 11 }
... ...