@tiledesk/tiledesk-server 2.1.40 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/.circleci/config.yml +54 -0
  2. package/.env.sample +1 -1
  3. package/.github/workflows/docker-community-push-latest.yml +22 -0
  4. package/.github/workflows/{docker-image-push.yml → docker-image-en-tag-push.yml} +1 -1
  5. package/.github/workflows/docker-image-tag-community-tag-push.yml +21 -0
  6. package/.github/workflows/{docker-push-latest.yml → docker-push-en-push-latest.yml} +1 -1
  7. package/CHANGELOG.md +195 -1
  8. package/Dockerfile +1 -1
  9. package/Dockerfile-en +1 -1
  10. package/README.md +5 -7
  11. package/app.js +12 -1
  12. package/channels/channelManager.js +1 -1
  13. package/channels/chat21/chat21Contact.js +34 -8
  14. package/channels/chat21/chat21Handler.js +48 -5
  15. package/channels/chat21/chat21WebHook.js +34 -9
  16. package/channels/chat21/nativeauth.js +2 -2
  17. package/channels/chat21/package-lock.json +3013 -0
  18. package/config/email.js +2 -0
  19. package/config/global.js +3 -0
  20. package/config/labels/widget.json +170 -16
  21. package/event/messageEvent.js +18 -1
  22. package/middleware/passport.js +10 -4
  23. package/migrations/1619185894304-request-remove-duplicated-request-by-request_id--autosync.js +67 -0
  24. package/models/actionsConstants.js +7 -0
  25. package/models/department.js +3 -0
  26. package/models/faq.js +8 -2
  27. package/models/faq_kb.js +6 -0
  28. package/models/message.js +10 -4
  29. package/models/messageConstants.js +9 -3
  30. package/models/request.js +33 -3
  31. package/package.json +31 -28
  32. package/pubmodules/emailNotification/requestNotification.js +483 -56
  33. package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
  34. package/pubmodules/messageTransformer/index.js +5 -1
  35. package/pubmodules/messageTransformer/messageTransformerInterceptor.js +4 -2
  36. package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
  37. package/pubmodules/messageTransformer/microLanguageTransformerInterceptor.js +67 -0
  38. package/pubmodules/pubModulesManager.js +66 -13
  39. package/pubmodules/rules/conciergeBot.js +81 -49
  40. package/routes/auth.js +46 -11
  41. package/routes/campaigns.js +117 -25
  42. package/routes/department.js +2 -2
  43. package/routes/faq.js +19 -0
  44. package/routes/faq_kb.js +13 -4
  45. package/routes/faqpub.js +1 -1
  46. package/routes/files.js +17 -2
  47. package/routes/images.js +1 -1
  48. package/routes/jwt.js +0 -1
  49. package/routes/logs.js +26 -0
  50. package/routes/message.js +7 -2
  51. package/routes/messagesRoot.js +73 -16
  52. package/routes/project_user.js +36 -1
  53. package/routes/request.js +88 -12
  54. package/routes/requestUtilRoot.js +30 -0
  55. package/routes/urls.js +12 -0
  56. package/routes/users.js +5 -1
  57. package/services/BotSubscriptionNotifier.js +1 -0
  58. package/services/departmentService.js +29 -5
  59. package/services/emailService.js +1170 -239
  60. package/services/faqBotHandler.js +176 -61
  61. package/services/faqBotSupport.js +182 -117
  62. package/services/faqService.js +18 -14
  63. package/services/messageService.js +57 -9
  64. package/services/modulesManager.js +86 -23
  65. package/services/requestService.js +58 -17
  66. package/template/email/assignedEmailMessage.html +205 -0
  67. package/template/email/assignedRequest.html +44 -14
  68. package/template/email/beenInvitedExistingUser.html +2 -2
  69. package/template/email/beenInvitedNewUser.html +1 -1
  70. package/template/email/newMessage.html +31 -12
  71. package/template/email/passwordChanged.html +2 -3
  72. package/template/email/pooledEmailMessage.html +208 -0
  73. package/template/email/pooledRequest.html +41 -14
  74. package/template/email/resetPassword.html +2 -3
  75. package/template/email/sendTranscript.html +1 -1
  76. package/template/email/test.html +1 -1
  77. package/template/email/ticket.html +191 -0
  78. package/template/email/ticket.txt +11 -0
  79. package/template/email/verify.html +1 -1
  80. package/test/authentication.js +76 -4
  81. package/test/authenticationJwt.js +76 -2
  82. package/test/campaignsRoute.js +226 -0
  83. package/test/faqService.js +3 -3
  84. package/test/faqkbRoute.js +3 -2
  85. package/test/messageRootRoute.js +193 -0
  86. package/test/messageRoute.js +75 -0
  87. package/test/messageService.js +39 -2
  88. package/test/requestRoute.js +27 -9
  89. package/test/requestService.js +472 -11
  90. package/test-int/bot.js +673 -8
  91. package/websocket/webSocketServer.js +7 -4
@@ -4,6 +4,7 @@
4
4
 
5
5
  const Faq = require('../models/faq');
6
6
  const Faq_kb = require('../models/faq_kb');
7
+ const MessageConstants = require('../models/messageConstants');
7
8
  var winston = require('../config/winston');
8
9
 
9
10
  var jwt = require('jsonwebtoken');
@@ -51,15 +52,32 @@ class FaqBotSupport {
51
52
  }
52
53
  // usa api di sponziello parseReply: https://github.com/Tiledesk/tiledesk-nodejs-libs/blob/master/tiledesk-chatbot-util/index.js
53
54
 
54
- parseMicrolanguage(text, message, bot, faq, disableWebHook) {
55
+ parseMicrolanguage(text, message, bot, faq, disableWebHook, json) {
55
56
  var that = this;
56
57
  return new Promise(async (resolve, reject) => {
58
+ winston.debug('parseMicrolanguage message: ' + JSON.stringify(message) );
57
59
  var reply = TiledeskChatbotUtil.parseReply(text);
58
60
  winston.debug('parseReply: ' + JSON.stringify(reply) );
59
61
  var messageReply = reply.message;
60
62
 
61
63
  var msg_attributes = {"_raw_message": text};
62
64
 
65
+ // prendi attributi e li mergi
66
+ // metadata prendi da messageReply SOLO SE CI SONO (DIVERSI NULL). Se riesci fai il merge
67
+ // prendi type e text
68
+
69
+ // if (message && message.attributes) {
70
+ // for(const [key, value] of Object.entries(message.attributes)) {
71
+ // msg_attributes[key] = value
72
+ // }
73
+ // }
74
+
75
+ if (json && json.attributes) {
76
+ for(const [key, value] of Object.entries(json.attributes)) {
77
+ msg_attributes[key] = value
78
+ }
79
+ }
80
+
63
81
  if (messageReply && messageReply.attributes) {
64
82
  for(const [key, value] of Object.entries(messageReply.attributes)) {
65
83
  msg_attributes[key] = value
@@ -67,10 +85,28 @@ class FaqBotSupport {
67
85
  }
68
86
 
69
87
  messageReply.attributes = msg_attributes;
70
-
71
-
88
+
89
+ // not used in faqBotHandler but used when the message is returned by webhook (subscription). So you must clone(add) all message fields here.
90
+ // winston.debug('message.language: '+ message.language );
91
+ // if (message.language) {
92
+ // messageReply.language = message.language;
93
+ // }
94
+
95
+ if (json && json.language) {
96
+ messageReply.language = json.language;
97
+ }
98
+
99
+ if (json && json.type) {
100
+ messageReply.type = json.type;
101
+ }
102
+
103
+ if (json && json.metadata) {
104
+ messageReply.metadata = json.metadata;
105
+ }
72
106
 
73
- if (disableWebHook === false && (faq.webhook_enabled === true || reply.webhook)) {
107
+
108
+ winston.debug('faq: ', faq );
109
+ if (disableWebHook === false && bot.webhook_enabled ===true && (faq.webhook_enabled === true || reply.webhook)) {
74
110
 
75
111
  winston.debug("bot.webhook_url "+ bot.webhook_url)
76
112
  var webhookurl = bot.webhook_url;
@@ -85,6 +121,11 @@ class FaqBotSupport {
85
121
  webhookurl = reply.webhook;
86
122
  }
87
123
  }
124
+
125
+ if (!webhookurl) {
126
+ winston.debug("webhookurl is undefined return standard");
127
+ return resolve(messageReply);
128
+ }
88
129
 
89
130
  var botWithSecret = await Faq_kb.findById(bot._id).select('+secret').exec();
90
131
 
@@ -111,11 +152,11 @@ class FaqBotSupport {
111
152
  },
112
153
  method: 'POST',
113
154
  json: true,
114
- body: {payload:{text: text, bot: bot, message: message, faq: faq}, token: token},
155
+ body: {payload:{text: text, bot: bot, message: message, intent: faq}, token: token},
115
156
  // }).then(response => {
116
157
  }, function(err, response, json){
117
158
  if (err) {
118
- winston.error("Error from webhook reply of getParsedMessage", err);
159
+ winston.error("Error from webhook reply of getParsedMessage. Return standard reply", err);
119
160
 
120
161
  return resolve(messageReply);
121
162
 
@@ -131,22 +172,45 @@ class FaqBotSupport {
131
172
  return resolve(bot_answer);
132
173
  */
133
174
  }
175
+ if (response.statusCode >= 400) {
176
+ winston.verbose("The ChatBot webhook return error http status code. Return standard reply", response);
177
+ return resolve(messageReply);
178
+ }
179
+
134
180
  if (!json) { //the webhook return empty body
181
+ winston.verbose("The ChatBot webhook return no json. Return standard reply", response);
135
182
  return resolve(messageReply);
136
183
  }
137
- // if (response.statusCode >= 400) {
138
- // return reject(`HTTP Error: ${response.statusCode}`);
139
- // }
184
+
140
185
  winston.debug("webhookurl repl_message ", response);
141
186
 
142
187
  var text = undefined;
143
188
  if(json && json.text===undefined) {
189
+ winston.verbose("webhookurl json is defined but text not. return standard reply",{json:json, response:response});
144
190
  // text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
145
191
  return resolve(messageReply);
146
192
  }else {
147
193
  text = json.text;
148
194
  }
149
- that.parseMicrolanguage(text, message, bot, faq, true).then(function(bot_answer) {
195
+ winston.debug("webhookurl text: "+ text);
196
+
197
+ // // let cloned_message = Object.assign({}, messageReply);
198
+ // let cloned_message = message;
199
+ // winston.debug("cloned_message : ",cloned_message);
200
+
201
+ // if (json.attributes) {
202
+ // if (!cloned_message.attributes) {
203
+ // cloned_message.attributes = {}
204
+ // }
205
+ // winston.debug("ChatBot webhook json.attributes: ",json.attributes);
206
+ // for(const [key, value] of Object.entries(json.attributes)) {
207
+ // cloned_message.attributes[key] = value
208
+ // }
209
+ // }
210
+
211
+ // winston.debug("cloned_message after attributes: ",cloned_message);
212
+
213
+ that.parseMicrolanguage(text, message, bot, faq, true, json).then(function(bot_answer) {
150
214
  return resolve(bot_answer);
151
215
  });
152
216
  });
@@ -161,115 +225,115 @@ class FaqBotSupport {
161
225
  // return this.parseMicrolanguageOld(text, message, bot, faq);
162
226
  }
163
227
 
164
- parseMicrolanguageOld(text, message, bot, faq) {
165
- var that = this;
166
- // text = "*"
167
- return new Promise(function(resolve, reject) {
168
- winston.debug("getParsedMessage ******",text);
169
- var repl_message = {};
170
-
171
- // cerca i bottoni eventualmente definiti
172
- var button_pattern = /^\*.*/mg; // buttons are defined as a line starting with an asterisk
173
- var text_buttons = text.match(button_pattern);
174
- if (text_buttons) {
175
- var text_with_removed_buttons = text.replace(button_pattern,"").trim();
176
- repl_message.text = text_with_removed_buttons
177
- var buttons = []
178
- text_buttons.forEach(element => {
179
- winston.debug("button ", element)
180
- var remove_extra_from_button = /^\*/mg;
181
- var button_text = element.replace(remove_extra_from_button, "").trim()
182
- var button = {}
183
- button["type"] = "text"
184
- button["value"] = button_text
185
- buttons.push(button)
186
- });
187
- repl_message.attributes =
188
- {
189
- attachment: {
190
- type:"template",
191
- buttons: buttons
192
- }
193
- }
194
- repl_message.type = "text";
195
- } else {
196
- // no buttons
197
- repl_message.text = text
198
- repl_message.type = "text";
199
- }
200
-
201
- var image_pattern = /^\\image:.*/mg;
202
- var imagetext = text.match(image_pattern);
203
- if (imagetext && imagetext.length>0) {
204
- var imageurl = imagetext[0].replace("\\image:","").trim();
205
- winston.debug("imageurl ", imageurl)
206
- var text_with_removed_image = text.replace(image_pattern,"").trim();
207
- repl_message.text = text_with_removed_image + " " + imageurl
208
- repl_message.metadata = {src: imageurl, width:200, height:200};
209
- repl_message.type = "image";
210
- }
211
-
212
- var frame_pattern = /^\\frame:.*/mg;
213
- var frametext = text.match(frame_pattern);
214
- if (frametext && frametext.length>0) {
215
- var frameurl = frametext[0].replace("\\frame:","").trim();
216
- winston.debug("frameurl ", frameurl)
217
- // var text_with_removed_image = text.replace(frame_pattern,"").trim();
218
- // repl_message.text = text_with_removed_image + " " + imageurl
219
- repl_message.metadata = {src: frameurl};
220
- repl_message.type = "frame";
221
- }
222
-
223
-
224
- var webhook_pattern = /^\\webhook:.*/mg;
225
- var webhooktext = text.match(webhook_pattern);
226
- if (webhooktext && webhooktext.length>0) {
227
- var webhookurl = webhooktext[0].replace("\\webhook:","").trim();
228
- winston.debug("webhookurl ", webhookurl)
229
-
230
- return request({
231
- uri : webhookurl,
232
- headers: {
233
- 'Content-Type': 'application/json'
234
- },
235
- method: 'POST',
236
- json: true,
237
- body: {payload:{text: text, bot: bot, message: message, faq: faq}},
238
- // }).then(response => {
239
- }, function(err, response, json){
240
- if (err) {
241
- bot_answer.text = err +' '+ response.text;
242
- bot_answer.type = "text";
243
- winston.error("Error from webhook reply of getParsedMessage", err);
244
- return resolve(bot_answer);
245
- }
246
- // if (response.statusCode >= 400) {
247
- // return reject(`HTTP Error: ${response.statusCode}`);
248
- // }
249
- winston.debug("webhookurl repl_message ", response);
250
-
251
- var text = undefined;
252
- if(json && json.text===undefined) {
253
- text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
254
- }else {
255
- text = json.text;
256
- }
257
-
258
-
259
- that.getParsedMessage(text,message, bot, faq).then(function(bot_answer) {
260
- return resolve(bot_answer);
261
- });
262
- });
228
+ // parseMicrolanguageOld(text, message, bot, faq) {
229
+ // var that = this;
230
+ // // text = "*"
231
+ // return new Promise(function(resolve, reject) {
232
+ // winston.debug("getParsedMessage ******",text);
233
+ // var repl_message = {};
234
+
235
+ // // cerca i bottoni eventualmente definiti
236
+ // var button_pattern = /^\*.*/mg; // buttons are defined as a line starting with an asterisk
237
+ // var text_buttons = text.match(button_pattern);
238
+ // if (text_buttons) {
239
+ // var text_with_removed_buttons = text.replace(button_pattern,"").trim();
240
+ // repl_message.text = text_with_removed_buttons
241
+ // var buttons = []
242
+ // text_buttons.forEach(element => {
243
+ // winston.debug("button ", element)
244
+ // var remove_extra_from_button = /^\*/mg;
245
+ // var button_text = element.replace(remove_extra_from_button, "").trim()
246
+ // var button = {}
247
+ // button["type"] = "text"
248
+ // button["value"] = button_text
249
+ // buttons.push(button)
250
+ // });
251
+ // repl_message.attributes =
252
+ // {
253
+ // attachment: {
254
+ // type:"template",
255
+ // buttons: buttons
256
+ // }
257
+ // }
258
+ // repl_message.type = MessageConstants.MESSAGE_TYPE.TEXT;
259
+ // } else {
260
+ // // no buttons
261
+ // repl_message.text = text
262
+ // repl_message.type = MessageConstants.MESSAGE_TYPE.TEXT;
263
+ // }
264
+
265
+ // var image_pattern = /^\\image:.*/mg;
266
+ // var imagetext = text.match(image_pattern);
267
+ // if (imagetext && imagetext.length>0) {
268
+ // var imageurl = imagetext[0].replace("\\image:","").trim();
269
+ // winston.debug("imageurl ", imageurl)
270
+ // var text_with_removed_image = text.replace(image_pattern,"").trim();
271
+ // repl_message.text = text_with_removed_image + " " + imageurl
272
+ // repl_message.metadata = {src: imageurl, width:200, height:200};
273
+ // repl_message.type = MessageConstants.MESSAGE_TYPE.IMAGE;
274
+ // }
275
+
276
+ // var frame_pattern = /^\\frame:.*/mg;
277
+ // var frametext = text.match(frame_pattern);
278
+ // if (frametext && frametext.length>0) {
279
+ // var frameurl = frametext[0].replace("\\frame:","").trim();
280
+ // winston.debug("frameurl ", frameurl)
281
+ // // var text_with_removed_image = text.replace(frame_pattern,"").trim();
282
+ // // repl_message.text = text_with_removed_image + " " + imageurl
283
+ // repl_message.metadata = {src: frameurl};
284
+ // repl_message.type = MessageConstants.MESSAGE_TYPE.FRAME;
285
+ // }
286
+
287
+
288
+ // var webhook_pattern = /^\\webhook:.*/mg;
289
+ // var webhooktext = text.match(webhook_pattern);
290
+ // if (webhooktext && webhooktext.length>0) {
291
+ // var webhookurl = webhooktext[0].replace("\\webhook:","").trim();
292
+ // winston.debug("webhookurl ", webhookurl)
293
+
294
+ // return request({
295
+ // uri : webhookurl,
296
+ // headers: {
297
+ // 'Content-Type': 'application/json'
298
+ // },
299
+ // method: 'POST',
300
+ // json: true,
301
+ // body: {payload:{text: text, bot: bot, message: message, faq: faq}},
302
+ // // }).then(response => {
303
+ // }, function(err, response, json){
304
+ // if (err) {
305
+ // bot_answer.text = err +' '+ response.text;
306
+ // bot_answer.type = MessageConstants.MESSAGE_TYPE.TEXT;
307
+ // winston.error("Error from webhook reply of getParsedMessage", err);
308
+ // return resolve(bot_answer);
309
+ // }
310
+ // // if (response.statusCode >= 400) {
311
+ // // return reject(`HTTP Error: ${response.statusCode}`);
312
+ // // }
313
+ // winston.debug("webhookurl repl_message ", response);
314
+
315
+ // var text = undefined;
316
+ // if(json && json.text===undefined) {
317
+ // text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
318
+ // }else {
319
+ // text = json.text;
320
+ // }
321
+
322
+
323
+ // that.getParsedMessage(text,message, bot, faq).then(function(bot_answer) {
324
+ // return resolve(bot_answer);
325
+ // });
326
+ // });
263
327
 
264
- }else {
265
- winston.debug("repl_message ", repl_message)
266
- return resolve(repl_message);
267
- }
328
+ // }else {
329
+ // winston.debug("repl_message ", repl_message)
330
+ // return resolve(repl_message);
331
+ // }
268
332
 
269
333
 
270
334
 
271
- });
272
- }
335
+ // });
336
+ // }
273
337
 
274
338
 
275
339
  getBotMessage(botAnswer, projectid, bot, message, threshold) {
@@ -304,8 +368,8 @@ class FaqBotSupport {
304
368
  // found = true;
305
369
  // return resolve(bot_answer);
306
370
 
307
- if (message.channel.name == "chat21") {
308
-
371
+ if (message.channel.name == "chat21") { //why this contition on chat21 channel? bacause only chat21 support parsed replies?
372
+ winston.debug("faqBotSupport message.channel.name is chat21",message);
309
373
  that.getParsedMessage(bot_answer.text,message, bot, faqs[0]).then(function(bot_answerres) {
310
374
 
311
375
  bot_answerres.defaultFallback=true;
@@ -314,6 +378,7 @@ class FaqBotSupport {
314
378
  });
315
379
 
316
380
  } else {
381
+ winston.debug("faqBotSupport message.channel.name is not chat21 returning default",message);
317
382
  return resolve(bot_answer);
318
383
  }
319
384
 
@@ -2,12 +2,13 @@ var Faq = require("../models/faq");
2
2
  var Faq_kb = require("../models/faq_kb");
3
3
  var winston = require('../config/winston');
4
4
  const botEvent = require('../event/botEvent');
5
+ const ActionsConstants = require('../models/actionsConstants');
5
6
 
6
7
 
7
8
  class FaqService {
8
9
 
9
10
 
10
- create(name, url, projectid, user_id, type, description, webhook_url) {
11
+ create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language) {
11
12
  var that = this;
12
13
  return new Promise(function (resolve, reject) {
13
14
 
@@ -18,7 +19,9 @@ class FaqService {
18
19
  url: url,
19
20
  id_project: projectid,
20
21
  webhook_url: webhook_url,
22
+ webhook_enabled: webhook_enabled,
21
23
  type: type,
24
+ language: language,
22
25
  trashed: false,
23
26
  createdBy: user_id,
24
27
  updatedBy: user_id
@@ -55,19 +58,20 @@ class FaqService {
55
58
  var faqsArray = [
56
59
  { 'question': 'Hi', 'answer': 'Hi', 'topic': 'greetings' },
57
60
  { 'question': 'Hello', 'answer': 'Hello', 'topic': 'greetings' },
58
- { 'question': 'Who are you?', 'answer': 'Hi, I\'m a bot 🤖. You can find more about me [here](https://tiledesk.com/chatbot-for-customer-service).\ntdImage:http://dialogflow-proxy-tiledesk.herokuapp.com/images/tily-welcomebot.gif\n* See the website https://tiledesk.com/\n* Menu', 'topic': 'greetings' },
59
- { 'question': '👨🏻‍🦰 I want an agent', 'answer': '\\agent', 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
60
- //TODO RIABILITARE? { 'question': 'Ok close', 'answer': '\\close', 'topic': 'internal' },
61
- { 'question': '\\start', 'answer': 'Hello 👋. I\'m a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻‍🦰 I want an agent','topic': 'internal' },
62
- { 'question': 'Menu', 'answer': 'Choose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻‍🦰 I want an agent','topic': 'internal' },
63
- { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Menu\n* See the docs https://docs.tiledesk.com/\n* 👨🏻‍🦰 I want an agent', 'topic': 'internal' }, //TODO se metto spazio n * nn va
64
- { 'question': 'What can you do?', 'answer': 'Using natural language processing, I\'m able to find the best answer for your users. I also support images, videos etc.. Let\'s try:\n* Sample Image\n* Sample Video\n* Sample Action tdAction:action1\n* Sample Frame\n* Sample Webhook\n* Menu', 'topic': 'sample' },
65
- { 'question': 'Sample Image', 'answer': 'tdImage:https://tiledesk.com/tiledesk-logo-x1.png\n* What can you do?\n* Menu', 'topic': 'sample' },
66
- { 'question': 'Sample Frame', 'answer': 'tdFrame:https://www.emanueleferonato.com/wp-content/uploads/2019/02/runner/\n* What can you do?\n* Menu', 'topic': 'sample' },
67
- { 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Menu', 'topic': 'sample' },
68
- { 'question': 'Where are you', 'answer': 'We are here ❤️\ntdFrame:https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d6087916.923447935!2d8.234804542117423!3d41.836572992140624!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d4fe82448dd203%3A0xe22cf55c24635e6f!2sItaly!5e0!3m2!1sen!2sit!4v1613657475377!5m2!1sen!2sit\n* Menu', 'topic': 'sample' },
69
- { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
70
- { 'question': 'Sample Action', 'answer': 'Hello 👋 Would you like to take a closer look at our offer?\n* Yes, please tdAction:yes_action\n* No tdAction:no_action', 'topic': 'sample' },
61
+ { 'question': 'Who are you?', 'answer': 'Hi, I\'m a bot 🤖. You can find more about me [here](https://tiledesk.com/chatbot-for-customer-service).\ntdImage:https://console.tiledesk.com/assets/images/tily-welcomebot.gif\n* See the website https://tiledesk.com/\n* Back to start tdAction:start', 'topic': 'greetings' },
62
+ { 'question': '👨🏻‍🦰 I want an agent', 'answer': 'We are looking for an operator.. '+ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
63
+ { 'question': 'Close\nResolved', 'answer': ActionsConstants.CHAT_ACTION_MESSAGE.CLOSE, 'topic': 'internal' },
64
+ { 'question': '\\start', 'answer': 'Hello 👋. I\'m a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻‍🦰 I want an agent', 'intent_display_name': 'start', 'topic': 'internal' },
65
+ // { 'question': 'Menu', 'answer': 'Choose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻‍🦰 I want an agent','topic': 'internal' },
66
+ { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻‍🦰 I want an agent', 'topic': 'internal' }, //TODO se metto spazio n * nn va
67
+ { 'question': 'What can you do?', 'answer': 'Using natural language processing, I\'m able to find the best answer for your users. I also support images, videos etc.. Let\'s try:\n* Sample Image\n* Sample Video\n* Sample Action tdAction:action1\n* Sample Frame\n* Back to start tdAction:start', 'topic': 'sample' },
68
+ { 'question': 'Sample Image', 'answer': 'tdImage:https://tiledesk.com/tiledesk-logo-x1.png\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
69
+ { 'question': 'Sample Frame', 'answer': 'tdFrame:https://www.emanueleferonato.com/wp-content/uploads/2019/02/runner/\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
70
+ { 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
71
+ { 'question': 'Where are you', 'answer': 'We are here ❤️\ntdFrame:https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d6087916.923447935!2d8.234804542117423!3d41.836572992140624!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d4fe82448dd203%3A0xe22cf55c24635e6f!2sItaly!5e0!3m2!1sen!2sit!4v1613657475377!5m2!1sen!2sit\n* Back to start tdAction:start', 'topic': 'sample' },
72
+
73
+ // { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
74
+ { 'question': 'Sample Action', 'answer': 'Hello 👋 Would you like to take a closer look at our offer?\n* Yes, please tdAction:yes_action\n* No tdAction:no_action','intent_display_name': 'action1', 'topic': 'sample' },
71
75
  { 'question': 'Yes Action', 'answer': 'Great! Take a look here:\n* Tiledesk Pricing https://tiledesk.com/pricing-cloud/', 'intent_display_name': 'yes_action','topic': 'sample' },
72
76
  { 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.', 'intent_display_name': 'no_action','topic': 'sample' },
73
77
 
@@ -21,33 +21,81 @@ class MessageService {
21
21
  return this.changeStatus(id, status);
22
22
  }
23
23
  }
24
- create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language, channel_type, channel) {
25
24
 
26
- winston.debug('message.create called');
25
+ create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language, channel_type, channel) {
26
+ let message = {
27
+ sender: sender,
28
+ senderFullname: senderFullname,
29
+ recipient: recipient,
30
+ text: text,
31
+ id_project: id_project,
32
+ createdBy: createdBy,
33
+ status: status,
34
+ attributes: attributes,
35
+ type: type,
36
+ metadata: metadata,
37
+ language: language,
38
+ channel_type: channel_type,
39
+ channel: channel
40
+ };
41
+ return this.save(message);
42
+ }
27
43
 
44
+ save(message) {
28
45
  var that = this;
46
+ winston.debug('message.save called');
47
+
48
+ let sender = message.sender;
49
+ let senderFullname = message.senderFullname;
50
+ let recipient = message.recipient;
51
+ let recipientFullname = message.recipientFullname;
52
+ let text = message.text;
53
+ let id_project = message.id_project;
54
+ let createdBy = message.createdBy;
55
+ let status = message.status;
56
+ let attributes = message.attributes;
57
+ let type = message.type;
58
+ let metadata = message.metadata;
59
+ let language = message.language;
60
+ let channel_type = message.channel_type;
61
+ let channel = message.channel;
62
+
63
+
64
+
29
65
  return new Promise(function (resolve, reject) {
30
66
 
31
67
  if (!createdBy) {
32
68
  createdBy = sender;
33
69
  }
34
70
 
35
- var beforeMessage = {sender:sender, senderFullname:senderFullname, recipient:recipient
71
+ var beforeMessage = {sender:sender, senderFullname:senderFullname
72
+ , recipient:recipient, recipientFullname: recipientFullname
36
73
  , text:text, id_project:id_project, createdBy:createdBy, status:status, attributes:attributes,
37
74
  type:type, metadata:metadata, language:language, channel_type: channel_type, channel: channel};
38
75
 
39
76
  var messageToCreate = beforeMessage;
40
- winston.debug('messageToCreate',messageToCreate);
77
+ winston.debug('messageToCreate before',messageToCreate);
41
78
  // messageEvent.emit('message.create.simple.before', {beforeMessage:beforeMessage});
42
79
 
43
80
 
44
81
 
45
82
  messagePromiseEvent.emit('message.create.simple.before', {beforeMessage:beforeMessage}).then(results => {
46
- winston.debug('message.create.simple.before', results);
47
-
48
- if (results && results.beforeMessage) {
49
- messageToCreate = results.beforeMessage;
83
+ winston.debug('message.create.simple.before results', results);
84
+ winston.debug('message.create.simple.before results prototype: ' + Object.prototype.toString.call(results));
85
+
86
+ if (results) {
87
+ winston.debug('message.create.simple.before results.length: '+ results.length); //TODO ELIMINA DOPO CHE CREA CRASH
88
+ }
89
+
90
+ /*
91
+ if (results ) { //NN HA MAI FUNZIONATO. LA MADIFICA DEL VALORE AVVENIVA PER PUNTATORE
92
+ winston.info('message.create.simple.before results.beforeMessage', results[0].beforeMessage);
93
+ messageToCreate = results[0].beforeMessage;
50
94
  }
95
+ */
96
+
97
+ winston.debug('messageToCreate', messageToCreate);
98
+
51
99
 
52
100
  // if (id_project) {
53
101
 
@@ -55,8 +103,8 @@ class MessageService {
55
103
  sender: messageToCreate.sender,
56
104
  senderFullname: messageToCreate.senderFullname,
57
105
  recipient: messageToCreate.recipient,
106
+ recipientFullname: messageToCreate.recipientFullname, //for direct
58
107
  type: messageToCreate.type,
59
- // recipientFullname: recipientFullname,
60
108
  text: messageToCreate.text,
61
109
  id_project: messageToCreate.id_project,
62
110
  createdBy: messageToCreate.createdBy,