@tiledesk/tiledesk-server 2.1.41 → 2.2.4

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 (85) 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 +198 -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/chat21/chat21Contact.js +34 -8
  13. package/channels/chat21/chat21Handler.js +48 -5
  14. package/channels/chat21/chat21WebHook.js +34 -5
  15. package/channels/chat21/nativeauth.js +2 -2
  16. package/config/email.js +2 -1
  17. package/config/global.js +3 -0
  18. package/config/labels/widget.json +170 -16
  19. package/event/messageEvent.js +18 -1
  20. package/middleware/passport.js +10 -4
  21. package/models/actionsConstants.js +7 -0
  22. package/models/department.js +3 -0
  23. package/models/faq.js +8 -2
  24. package/models/faq_kb.js +6 -0
  25. package/models/message.js +10 -4
  26. package/models/messageConstants.js +3 -3
  27. package/models/request.js +33 -3
  28. package/package.json +31 -28
  29. package/pubmodules/emailNotification/requestNotification.js +380 -62
  30. package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
  31. package/pubmodules/messageTransformer/index.js +1 -1
  32. package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
  33. package/pubmodules/pubModulesManager.js +66 -14
  34. package/pubmodules/rules/conciergeBot.js +81 -49
  35. package/routes/auth.js +34 -10
  36. package/routes/campaigns.js +117 -25
  37. package/routes/faq.js +19 -0
  38. package/routes/faq_kb.js +13 -4
  39. package/routes/faqpub.js +1 -1
  40. package/routes/images.js +1 -1
  41. package/routes/jwt.js +0 -1
  42. package/routes/logs.js +26 -0
  43. package/routes/message.js +7 -2
  44. package/routes/messagesRoot.js +73 -16
  45. package/routes/project_user.js +36 -1
  46. package/routes/request.js +88 -12
  47. package/routes/requestUtilRoot.js +30 -0
  48. package/routes/urls.js +12 -0
  49. package/routes/users.js +5 -1
  50. package/services/BotSubscriptionNotifier.js +1 -0
  51. package/services/departmentService.js +29 -5
  52. package/services/emailService.js +1103 -298
  53. package/services/faqBotHandler.js +176 -61
  54. package/services/faqBotSupport.js +181 -117
  55. package/services/faqService.js +17 -14
  56. package/services/messageService.js +57 -9
  57. package/services/modulesManager.js +86 -23
  58. package/services/requestService.js +58 -17
  59. package/template/email/assignedEmailMessage.html +205 -0
  60. package/template/email/assignedRequest.html +44 -14
  61. package/template/email/beenInvitedExistingUser.html +2 -2
  62. package/template/email/beenInvitedNewUser.html +1 -1
  63. package/template/email/newMessage.html +31 -12
  64. package/template/email/passwordChanged.html +2 -3
  65. package/template/email/pooledEmailMessage.html +208 -0
  66. package/template/email/pooledRequest.html +41 -14
  67. package/template/email/resetPassword.html +2 -3
  68. package/template/email/sendTranscript.html +1 -1
  69. package/template/email/test.html +1 -1
  70. package/template/email/ticket.html +78 -52
  71. package/template/email/ticket.txt +5 -1
  72. package/template/email/verify.html +1 -1
  73. package/test/authentication.js +76 -4
  74. package/test/authenticationJwt.js +76 -2
  75. package/test/campaignsRoute.js +226 -0
  76. package/test/faqService.js +3 -3
  77. package/test/faqkbRoute.js +3 -2
  78. package/test/messageRootRoute.js +193 -0
  79. package/test/messageRoute.js +75 -0
  80. package/test/messageService.js +5 -5
  81. package/test/requestRoute.js +27 -9
  82. package/test/requestService.js +472 -11
  83. package/test-int/bot.js +673 -8
  84. package/websocket/webSocketServer.js +7 -4
  85. package/template/email/ticket-taking.txt +0 -7
@@ -52,15 +52,32 @@ class FaqBotSupport {
52
52
  }
53
53
  // usa api di sponziello parseReply: https://github.com/Tiledesk/tiledesk-nodejs-libs/blob/master/tiledesk-chatbot-util/index.js
54
54
 
55
- parseMicrolanguage(text, message, bot, faq, disableWebHook) {
55
+ parseMicrolanguage(text, message, bot, faq, disableWebHook, json) {
56
56
  var that = this;
57
57
  return new Promise(async (resolve, reject) => {
58
+ winston.debug('parseMicrolanguage message: ' + JSON.stringify(message) );
58
59
  var reply = TiledeskChatbotUtil.parseReply(text);
59
60
  winston.debug('parseReply: ' + JSON.stringify(reply) );
60
61
  var messageReply = reply.message;
61
62
 
62
63
  var msg_attributes = {"_raw_message": text};
63
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
+
64
81
  if (messageReply && messageReply.attributes) {
65
82
  for(const [key, value] of Object.entries(messageReply.attributes)) {
66
83
  msg_attributes[key] = value
@@ -68,10 +85,28 @@ class FaqBotSupport {
68
85
  }
69
86
 
70
87
  messageReply.attributes = msg_attributes;
71
-
72
-
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
+ }
73
106
 
74
- 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)) {
75
110
 
76
111
  winston.debug("bot.webhook_url "+ bot.webhook_url)
77
112
  var webhookurl = bot.webhook_url;
@@ -86,6 +121,11 @@ class FaqBotSupport {
86
121
  webhookurl = reply.webhook;
87
122
  }
88
123
  }
124
+
125
+ if (!webhookurl) {
126
+ winston.debug("webhookurl is undefined return standard");
127
+ return resolve(messageReply);
128
+ }
89
129
 
90
130
  var botWithSecret = await Faq_kb.findById(bot._id).select('+secret').exec();
91
131
 
@@ -112,11 +152,11 @@ class FaqBotSupport {
112
152
  },
113
153
  method: 'POST',
114
154
  json: true,
115
- 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},
116
156
  // }).then(response => {
117
157
  }, function(err, response, json){
118
158
  if (err) {
119
- winston.error("Error from webhook reply of getParsedMessage", err);
159
+ winston.error("Error from webhook reply of getParsedMessage. Return standard reply", err);
120
160
 
121
161
  return resolve(messageReply);
122
162
 
@@ -132,22 +172,45 @@ class FaqBotSupport {
132
172
  return resolve(bot_answer);
133
173
  */
134
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
+
135
180
  if (!json) { //the webhook return empty body
181
+ winston.verbose("The ChatBot webhook return no json. Return standard reply", response);
136
182
  return resolve(messageReply);
137
183
  }
138
- // if (response.statusCode >= 400) {
139
- // return reject(`HTTP Error: ${response.statusCode}`);
140
- // }
184
+
141
185
  winston.debug("webhookurl repl_message ", response);
142
186
 
143
187
  var text = undefined;
144
188
  if(json && json.text===undefined) {
189
+ winston.verbose("webhookurl json is defined but text not. return standard reply",{json:json, response:response});
145
190
  // text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
146
191
  return resolve(messageReply);
147
192
  }else {
148
193
  text = json.text;
149
194
  }
150
- 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) {
151
214
  return resolve(bot_answer);
152
215
  });
153
216
  });
@@ -162,115 +225,115 @@ class FaqBotSupport {
162
225
  // return this.parseMicrolanguageOld(text, message, bot, faq);
163
226
  }
164
227
 
165
- parseMicrolanguageOld(text, message, bot, faq) {
166
- var that = this;
167
- // text = "*"
168
- return new Promise(function(resolve, reject) {
169
- winston.debug("getParsedMessage ******",text);
170
- var repl_message = {};
171
-
172
- // cerca i bottoni eventualmente definiti
173
- var button_pattern = /^\*.*/mg; // buttons are defined as a line starting with an asterisk
174
- var text_buttons = text.match(button_pattern);
175
- if (text_buttons) {
176
- var text_with_removed_buttons = text.replace(button_pattern,"").trim();
177
- repl_message.text = text_with_removed_buttons
178
- var buttons = []
179
- text_buttons.forEach(element => {
180
- winston.debug("button ", element)
181
- var remove_extra_from_button = /^\*/mg;
182
- var button_text = element.replace(remove_extra_from_button, "").trim()
183
- var button = {}
184
- button["type"] = "text"
185
- button["value"] = button_text
186
- buttons.push(button)
187
- });
188
- repl_message.attributes =
189
- {
190
- attachment: {
191
- type:"template",
192
- buttons: buttons
193
- }
194
- }
195
- repl_message.type = MessageConstants.MESSAGE_TYPE.TEXT;
196
- } else {
197
- // no buttons
198
- repl_message.text = text
199
- repl_message.type = MessageConstants.MESSAGE_TYPE.TEXT;
200
- }
201
-
202
- var image_pattern = /^\\image:.*/mg;
203
- var imagetext = text.match(image_pattern);
204
- if (imagetext && imagetext.length>0) {
205
- var imageurl = imagetext[0].replace("\\image:","").trim();
206
- winston.debug("imageurl ", imageurl)
207
- var text_with_removed_image = text.replace(image_pattern,"").trim();
208
- repl_message.text = text_with_removed_image + " " + imageurl
209
- repl_message.metadata = {src: imageurl, width:200, height:200};
210
- repl_message.type = MessageConstants.MESSAGE_TYPE.IMAGE;
211
- }
212
-
213
- var frame_pattern = /^\\frame:.*/mg;
214
- var frametext = text.match(frame_pattern);
215
- if (frametext && frametext.length>0) {
216
- var frameurl = frametext[0].replace("\\frame:","").trim();
217
- winston.debug("frameurl ", frameurl)
218
- // var text_with_removed_image = text.replace(frame_pattern,"").trim();
219
- // repl_message.text = text_with_removed_image + " " + imageurl
220
- repl_message.metadata = {src: frameurl};
221
- repl_message.type = MessageConstants.MESSAGE_TYPE.FRAME;
222
- }
223
-
224
-
225
- var webhook_pattern = /^\\webhook:.*/mg;
226
- var webhooktext = text.match(webhook_pattern);
227
- if (webhooktext && webhooktext.length>0) {
228
- var webhookurl = webhooktext[0].replace("\\webhook:","").trim();
229
- winston.debug("webhookurl ", webhookurl)
230
-
231
- return request({
232
- uri : webhookurl,
233
- headers: {
234
- 'Content-Type': 'application/json'
235
- },
236
- method: 'POST',
237
- json: true,
238
- body: {payload:{text: text, bot: bot, message: message, faq: faq}},
239
- // }).then(response => {
240
- }, function(err, response, json){
241
- if (err) {
242
- bot_answer.text = err +' '+ response.text;
243
- bot_answer.type = MessageConstants.MESSAGE_TYPE.TEXT;
244
- winston.error("Error from webhook reply of getParsedMessage", err);
245
- return resolve(bot_answer);
246
- }
247
- // if (response.statusCode >= 400) {
248
- // return reject(`HTTP Error: ${response.statusCode}`);
249
- // }
250
- winston.debug("webhookurl repl_message ", response);
251
-
252
- var text = undefined;
253
- if(json && json.text===undefined) {
254
- text = 'Field text is not defined in the webhook respose of the faq with id: '+ faq._id+ ". Error: " + JSON.stringify(response);
255
- }else {
256
- text = json.text;
257
- }
258
-
259
-
260
- that.getParsedMessage(text,message, bot, faq).then(function(bot_answer) {
261
- return resolve(bot_answer);
262
- });
263
- });
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
+ // });
264
327
 
265
- }else {
266
- winston.debug("repl_message ", repl_message)
267
- return resolve(repl_message);
268
- }
328
+ // }else {
329
+ // winston.debug("repl_message ", repl_message)
330
+ // return resolve(repl_message);
331
+ // }
269
332
 
270
333
 
271
334
 
272
- });
273
- }
335
+ // });
336
+ // }
274
337
 
275
338
 
276
339
  getBotMessage(botAnswer, projectid, bot, message, threshold) {
@@ -305,8 +368,8 @@ class FaqBotSupport {
305
368
  // found = true;
306
369
  // return resolve(bot_answer);
307
370
 
308
- if (message.channel.name == "chat21") {
309
-
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);
310
373
  that.getParsedMessage(bot_answer.text,message, bot, faqs[0]).then(function(bot_answerres) {
311
374
 
312
375
  bot_answerres.defaultFallback=true;
@@ -315,6 +378,7 @@ class FaqBotSupport {
315
378
  });
316
379
 
317
380
  } else {
381
+ winston.debug("faqBotSupport message.channel.name is not chat21 returning default",message);
318
382
  return resolve(bot_answer);
319
383
  }
320
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,19 @@ 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': '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
66
+ { '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' },
67
+ { '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' },
68
+ { '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' },
69
+ { 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
70
+ { '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' },
71
+
72
+ // { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
73
+ { '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
74
  { '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
75
  { 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.', 'intent_display_name': 'no_action','topic': 'sample' },
73
76
 
@@ -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,