@tiledesk/tiledesk-tybot-connector 0.5.0 → 0.5.1-rc1

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 (102) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/ExtApi.js +4 -83
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +113 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/{models → engine}/IntentForm.js +30 -44
  9. package/{models → engine}/IntentsMachineFactory.js +5 -4
  10. package/{models → engine}/MongodbBotsDataSource.js +31 -55
  11. package/{models → engine}/MongodbIntentsMachine.js +6 -5
  12. package/{models → engine}/TiledeskChatbot.js +82 -259
  13. package/{models → engine}/TiledeskChatbotConst.js +9 -0
  14. package/{models → engine}/TiledeskIntentsMachine.js +5 -15
  15. package/{models → engine/mock}/MockBotsDataSource.js +2 -19
  16. package/{models → engine/mock}/MockTdCache.js +0 -9
  17. package/index.js +106 -380
  18. package/logs/app.log +11557 -277
  19. package/logs/app1.log +62258 -0
  20. package/logs/app2.log +46280 -0
  21. package/logs/app3.log +31686 -0
  22. package/logs/app4.log +46163 -0
  23. package/logs/app5.log +33173 -0
  24. package/models/faq.js +2 -5
  25. package/package.json +5 -2
  26. package/{TiledeskServices → services}/AIService.js +4 -3
  27. package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
  28. package/{models/faqService.js → services/FaqService.js} +4 -3
  29. package/services/IntegrationService.js +43 -0
  30. package/services/TilebotService.js +47 -0
  31. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +68 -142
  32. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
  33. package/tiledeskChatbotPlugs/Filler.js +0 -1
  34. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  35. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  36. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  37. package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
  38. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  39. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
  40. package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
  41. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
  42. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
  43. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
  44. package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
  45. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
  46. package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
  47. package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
  48. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
  49. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
  50. package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
  51. package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
  52. package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
  53. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
  54. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
  55. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
  56. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
  57. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
  58. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  59. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  60. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  61. package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
  62. package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
  63. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
  64. package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
  65. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  66. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
  67. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
  68. package/tiledeskChatbotPlugs/directives/DirIntent.js +12 -104
  69. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
  70. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  71. package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
  72. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  73. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
  74. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
  75. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
  76. package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
  77. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
  78. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  79. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
  80. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
  81. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
  82. package/tiledeskChatbotPlugs/directives/DirReply.js +34 -37
  83. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
  84. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
  85. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
  86. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
  87. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
  88. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  89. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  90. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
  91. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
  92. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
  93. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
  94. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +23 -64
  95. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
  96. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  97. package/utils/HttpUtils.js +128 -0
  98. package/{models → utils}/TiledeskChatbotUtil.js +140 -234
  99. package/utils/winston.js +42 -0
  100. package/TdCache copy.js +0 -242
  101. package/TiledeskServices/utils.js +0 -99
  102. /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
@@ -1,11 +1,12 @@
1
1
  const { TiledeskExpression } = require('../TiledeskExpression');
2
2
  const { Filler } = require('../tiledeskChatbotPlugs/Filler');
3
- const { TiledeskChatbotConst } = require('./TiledeskChatbotConst');
4
- const { TiledeskChatbot } = require('./TiledeskChatbot.js');
3
+ const { TiledeskChatbotConst } = require('../engine/TiledeskChatbotConst');
4
+ const { TiledeskChatbot } = require('../engine/TiledeskChatbot.js');
5
5
  let parser = require('accept-language-parser');
6
6
  const { Directives } = require('../tiledeskChatbotPlugs/directives/Directives.js');
7
7
  require('dotenv').config();
8
8
  let axios = require('axios');
9
+ const winston = require('./winston');
9
10
 
10
11
  class TiledeskChatbotUtil {
11
12
 
@@ -26,26 +27,20 @@ class TiledeskChatbotUtil {
26
27
  }
27
28
  if (parts.length > 1) {
28
29
  let json_string = explicit_intent_name.substring(parts[0].length);
29
- // console.log("json_string (params)", json_string);
30
30
  try {
31
31
  intent.parameters = JSON.parse(json_string);
32
32
  // if (intent.parameters) {
33
33
  // for (const [key, value] of Object.entries(intent.parameters)) {
34
- // console.log("Checking type of:", key, value);
35
34
  // if (typeof value === "object") {
36
- // console.log("Checking type of is object:", key);
37
35
  // intent.parameters["_tdTypeOf:" + key] = "object";
38
36
  // }
39
37
  // else if (typeof value === "string") {
40
- // console.log("Checking type of is string:", key);
41
38
  // intent.parameters["_tdTypeOf:" + key] = "string";
42
39
  // }
43
40
  // else if (typeof value === "number") {
44
- // console.log("Checking type of is number:", key);
45
41
  // intent.parameters["_tdTypeOf:" + key] = "number";
46
42
  // }
47
43
  // else if (typeof value === "boolean") {
48
- // console.log("Checking type of is boolean:", key);
49
44
  // intent.parameters["_tdTypeOf:" + key] = "boolean";
50
45
  // }
51
46
  // }
@@ -53,7 +48,7 @@ class TiledeskChatbotUtil {
53
48
 
54
49
  }
55
50
  catch (err) {
56
- console.log("error on intent.parameters = JSON.parse(json_string)", err);
51
+ winston.error("(TiledeskChatbotUtils) Error on parse json_string ", err)
57
52
  }
58
53
  }
59
54
  return intent;
@@ -139,7 +134,7 @@ class TiledeskChatbotUtil {
139
134
  if (message && message.attributes && message.attributes.commands) {
140
135
  let commands = message.attributes.commands;
141
136
  if (commands.length %2 != 0) {
142
- console.log("Error. commands.length cannot be an odd number");
137
+ winston.error("(TiledeskChatbotUtils) Error: commands.length cannot be an odd number")
143
138
  return null;
144
139
  }
145
140
  const MAX_VALUE = commands.length - 1;
@@ -166,27 +161,15 @@ class TiledeskChatbotUtil {
166
161
  let commands = message.attributes.commands;
167
162
  message.text = "";
168
163
  for (let i = commands.length - 1; i >= 0; i--) {
169
- // console.log("...commands[" + i + "]");
170
164
  if (commands[i].type === "message") { // is a message, not wait
171
- // console.log("commands[i]:", commands[i].message.text);
172
- // console.log("commands[i]:", lang, (commands[i].message["lang"] === lang));
173
-
174
165
  // if (commands[i].message["lang"] && !(commands[i].message["lang"] === lang)) { // if there is a filter and the filter is false, remove
175
166
  const jsonCondition = commands[i].message["_tdJSONCondition"];
176
- // console.log("jsonCondition:", jsonCondition);
177
167
  if (jsonCondition) {
178
- // const expression = TiledeskExpression.JSONGroupsToExpression(jsonCondition.groups);
179
168
  const expression = TiledeskExpression.JSONGroupToExpression(jsonCondition);
180
- // console.log("full json condition expression eval on command.message:", expression);
181
169
  const conditionResult = new TiledeskExpression().evaluateStaticExpression(expression, variables);
182
- // console.log("conditionResult:", conditionResult);
183
- // FALSE
184
- // console.log("commands[i]lang:", commands[i]);
185
170
  if (conditionResult === false) {
186
- // console.log("deleting command:", commands[i]);
187
171
  commands.splice(i, 1);
188
172
  if (commands[i-1]) {
189
- // console.log("commands[i-1]?:", commands[i-1]);
190
173
  if (commands[i-1].type === "wait") {
191
174
  commands.splice(i-1, 1);
192
175
  i--;
@@ -194,19 +177,13 @@ class TiledeskChatbotUtil {
194
177
  }
195
178
  }
196
179
  else {
197
- // console.log("comands[i]:", commands[i], commands[i].message, commands[i].message.text)
198
180
  if (commands[i] && commands[i].message && commands[i].message.text) {
199
- // console.log("curr text:", message.text)
200
181
  if (message.text === "") {
201
182
  message.text = commands[i].message.text;
202
183
  }
203
184
  else {
204
185
  message.text = (commands[i].message.text + "\n\n" + message.text).trim();
205
186
  }
206
- // console.log("new text:", message.text)
207
- }
208
- else {
209
- // console.log("commands@", commands[i])
210
187
  }
211
188
  }
212
189
  }
@@ -215,11 +192,6 @@ class TiledeskChatbotUtil {
215
192
  }
216
193
  }
217
194
  }
218
- // for (let i = 0; i < commands.length; i++) {
219
- // if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
220
- // if (this.log) {console.log("[" + commands[i].message.lang + "]commands[i].message.text:", commands[i].message.text);}
221
- // }
222
- // }
223
195
  }
224
196
  }
225
197
 
@@ -229,20 +201,15 @@ class TiledeskChatbotUtil {
229
201
  let commands = message.attributes.commands;
230
202
 
231
203
  for (let i = commands.length - 1; i >= 0; i--) {
232
- // console.log("...commands[" + i + "]");
233
204
  if (commands[i].type === "message") { // is a message, not a "wait"
234
- // console.log("commands[i]:", commands[i].message.text);
235
- // let textEmpty = false;
236
205
  if (commands[i].message) {
237
206
  if (commands[i].message.type === "text") { // check text commands
238
207
  if (( commands[i].message.text && commands[i].message.text.trim() === "") || !commands[i].message.text) {
239
- // console.log("deleting command:", commands[i]);
240
208
  commands.splice(i, 1);
241
209
  if (commands[i-1]) {
242
210
  if (commands[i-1].type === "wait") {
243
211
  commands.splice(i-1, 1);
244
212
  i--;
245
- // console.log("deleted wait");
246
213
  }
247
214
  }
248
215
  }
@@ -250,15 +217,10 @@ class TiledeskChatbotUtil {
250
217
  }
251
218
  }
252
219
  }
253
- // for (let i = 0; i < commands.length; i++) {
254
- // if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
255
- // if (this.log) {console.log("[" + commands[i].message.lang + "]commands[i].message.text:", commands[i].message.text);}
256
- // }
257
- // }
258
220
  }
259
221
  }
260
222
  catch(error) {
261
- log.error("error while checking", error)
223
+ winston.error("(TiledeskChatbotUtils) Error while checking message ", error)
262
224
  }
263
225
  return message;
264
226
  }
@@ -278,11 +240,8 @@ class TiledeskChatbotUtil {
278
240
  if (!message) {
279
241
  return;
280
242
  }
281
- // console.log("compute delay...", message)
282
243
  if (message.attributes.commands.length > 0) {
283
- // console.log("going on delay")
284
244
  let commands = message.attributes.commands;
285
- // console.log("got commands", commands)
286
245
  let totalWaitTime = 0;
287
246
  for (let i = commands.length - 1; i >= 0; i--) {
288
247
  if (commands[i].type === "wait") { // is a wait
@@ -294,50 +253,38 @@ class TiledeskChatbotUtil {
294
253
  }
295
254
 
296
255
  static fillCommandAttachments(command, variables, log) {
297
- if (log) {
298
- console.log("filling command button:", JSON.stringify(command))
299
- }
300
- if (command.message && command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0){
256
+ if (log) { winston.debug("(TiledeskChatbotUtils) Filling command button: ", command) }
257
+ if (command.message && command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0) {
301
258
  let buttons = command.message.attributes.attachment.buttons;
302
259
  const filler = new Filler();
303
260
  buttons.forEach(button => {
304
261
  if (button.link) {
305
262
  button.link = filler.fill(button.link, variables);
306
- if (log) {
307
- console.log("button.link filled:", button.link)
308
- }
263
+ if (log) { winston.debug("(TiledeskChatbotUtils) button.link filled: " + button.link) }
309
264
  }
310
265
  if (button.value) {
311
266
  button.value = filler.fill(button.value, variables);
312
- if (log) {
313
- console.log("button.value filled:", button.value)
314
- }
267
+ if (log) { winston.debug("(TiledeskChatbotUtils) button.value filled: " + button.value) }
315
268
  }
316
269
  });
317
270
  }
318
- else if (log) {
319
- console.log("No attachments to fill in command")
271
+ else {
272
+ if (log) { winston.debug("(TiledeskChatbotUtils) No attachments to fill in command") }
320
273
  }
321
274
  }
322
275
 
323
276
  static allReplyButtons(message) {
324
277
  let all_buttons = [];
325
278
  if (message.attributes && message.attributes.commands) {
326
- // console.log("message.attributes ok")
327
279
  let commands = message.attributes.commands;
328
280
  if (commands.length > 0) {
329
- // console.log("commands ok", commands.length)
330
281
  for (let i = 0; i < commands.length; i++) {
331
282
  let command = commands[i];
332
- // console.log("got command:", command)s
333
283
  if (command.type === 'message' && command.message) {
334
- if (command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0){
335
- // console.log("command with buttons ok:")
284
+ if (command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0) {
336
285
  let buttons = command.message.attributes.attachment.buttons;
337
-
338
286
  buttons.forEach(button => {
339
287
  if (button.type === "action") {
340
- // console.log("pushing button:", button);
341
288
  all_buttons.push(button);
342
289
  }
343
290
  });
@@ -349,6 +296,63 @@ class TiledeskChatbotUtil {
349
296
  return all_buttons;
350
297
  }
351
298
 
299
+ static replaceJSONButtons(message, flow_attributes) {
300
+ let all_buttons = [];
301
+ if (message.attributes && message.attributes.commands) {
302
+ let commands = message.attributes.commands;
303
+ if (commands.length > 0) {
304
+ for (let i = 0; i < commands.length; i++) {
305
+ let command = commands[i];
306
+ if (command.type === 'message' && command.message) {
307
+ if (command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.json_buttons){
308
+ // console.log("command with buttons ok:")
309
+ let json_buttons_string = command.message.attributes.attachment.json_buttons;
310
+ let json_buttons = null;
311
+ let final_buttons = [];
312
+ try {
313
+ // fill buttons
314
+ const filler = new Filler();
315
+ json_buttons_string = filler.fill(json_buttons_string, flow_attributes);
316
+ // console.log("json_buttons_string:", json_buttons_string);
317
+ json_buttons = JSON.parse(json_buttons_string);
318
+ if (Array.isArray(json_buttons)) {
319
+ json_buttons.forEach(button => {
320
+ if (button.value && button.type === "action" && button.action) {
321
+ button.show_echo = true;
322
+ final_buttons.push(button);
323
+ }
324
+ else if (button.value && button.type === "text") {
325
+ button.show_echo = true;
326
+ final_buttons.push(button);
327
+ }
328
+ else if (button.value && button.type === "url" && button.link) {
329
+ button.show_echo = true;
330
+ final_buttons.push(button);
331
+ }
332
+ else {
333
+ winston.verbose("Invalid button. Skipping:", button);
334
+ }
335
+ });
336
+ }
337
+ }
338
+ catch(error) {
339
+ winston.warn("Invalid json_buttons:", error)
340
+ }
341
+ if (final_buttons && final_buttons.length > 0) {
342
+ command.message.attributes.attachment.buttons = final_buttons;
343
+ delete command.message.attributes.attachment.json_buttons;
344
+ }
345
+ else {
346
+ winston.verbose("Invalid json_buttons. Skipping...")
347
+ }
348
+ }
349
+ }
350
+ }
351
+ }
352
+ }
353
+ return all_buttons;
354
+ }
355
+
352
356
  static buttonByText(text, buttons) {
353
357
  if (buttons === null || text === null) {
354
358
  return null;
@@ -363,12 +367,10 @@ class TiledeskChatbotUtil {
363
367
  }
364
368
  else if (button.alias && button.alias.trim() !== "") { // search in button alias
365
369
  let alias = button.alias.split(",");
366
- // console.log("alias splitted:", alias);
367
370
  if (alias.length > 0) {
368
371
  for (let ii = 0; ii < alias.length; ii++) {
369
372
  alias[ii] = alias[ii].toLowerCase().trim();
370
373
  }
371
- // console.log("alias proc:", alias);
372
374
  if (alias.indexOf(search_text) > -1) {
373
375
  selected_button = button;
374
376
  break;
@@ -376,12 +378,10 @@ class TiledeskChatbotUtil {
376
378
  }
377
379
  }
378
380
  }
379
-
380
381
  return selected_button;
381
382
  }
382
383
 
383
384
  static stripEmoji(str) {
384
- // console.log("checking:", str);
385
385
  if (str === null) {
386
386
  return str;
387
387
  }
@@ -398,7 +398,6 @@ class TiledeskChatbotUtil {
398
398
  const chatbot_name = chatbot.bot.name.trim();
399
399
  if (message && message.text && message.text.trim() !== "" && message.sender !== "_tdinternal" && !this.isHiddenMessage(message)) {
400
400
  let transcript = await chatbot.getParameter("transcript");
401
- // console.log("transcript got:", transcript);
402
401
  const _name_of = name_of(message, chatbot_name);
403
402
  if (transcript) {
404
403
  transcript = transcript + "\n" + _name_of + message.text;
@@ -406,10 +405,7 @@ class TiledeskChatbotUtil {
406
405
  else {
407
406
  transcript = _name_of + " " + message.text;
408
407
  }
409
- // console.log("transcript update:", transcript);
410
408
  await chatbot.addParameter("transcript", transcript);
411
- // let transcript2 = await chatbot.getParameter("transcript");
412
- // console.log("transcript updated:", transcript2);
413
409
  }
414
410
 
415
411
  function name_of(message, chatbot_name) {
@@ -436,39 +432,32 @@ class TiledeskChatbotUtil {
436
432
  static transcriptJSON(transcript) {
437
433
  const regexp = /(<.*>)/gm;
438
434
  const parts = transcript.split(regexp);
439
- // console.log("parts:", parts);
440
- // console.log("typeof parts:", typeof parts);
441
- // console.log("length parts:", parts.length);
442
- // console.log("Array.isArray(parts):", Array.isArray(parts));
435
+ winston.debug("(TiledeskChatbotUtils) transcriptJSON parts: ", parts)
436
+
443
437
  let messages = [];
444
438
  let current_message;
445
439
  try {
446
440
  for (let i = 0; i < parts.length; i++) {
447
441
  let row = parts[i];
448
- // console.log("row:", row)
449
442
  if (row.startsWith("<bot:")) {
450
- // console.log("start with", row)
451
443
  current_message = {
452
444
  "role": "assistant"
453
445
  }
454
446
  }
455
447
  else if (row.startsWith("<user:")) {
456
- // console.log("start with", row)
457
448
  current_message = {
458
449
  "role": "user"
459
450
  }
460
451
  }
461
452
  else if (current_message) {
462
- // console.log("adding text", row)
463
453
  current_message["content"] = row.trim();
464
454
  messages.push(current_message);
465
455
  }
466
456
  };
467
457
  }
468
458
  catch(error) {
469
- console.error("err:", error);
459
+ winston.error("(TiledeskChatbotUtils) transcriptJSON err: ", error);
470
460
  }
471
- // console.log("messages:", messages);
472
461
  return messages;
473
462
  }
474
463
 
@@ -489,41 +478,42 @@ class TiledeskChatbotUtil {
489
478
 
490
479
  static lastUserMessageFrom(msg) {
491
480
  let message = {};
492
- message["senderFullname"] = msg["senderFullname"]; // ex. "Bot"
493
- message["type"] = msg["type"]; // ex. "text",
494
- message["channel_type"] = msg["channel_type"]; // ex. "group",
495
- message["status"] = msg["status"]; // ex. 0,
496
- message["id"] = msg["_id"]; // ex. "6538cda46cb4d8002cf2317a",
497
- message["sender"] = msg["sender"]; // ex. "system",
498
- message["recipient"] = msg["recipient"]; // ex. "support-group-65203e12f8c0cf002cf4110b-4066a69c8b464646a3ff25f9f41575bb",
499
- message["text"] = msg["text"]; // ex. "\\start",
500
- message["createdBy"] = msg["createdBy"]; // ex. "system",
501
- message["attributes"] = msg["attributes"]; // ex. { "subtype": "info" }
481
+ message["senderFullname"] = msg["senderFullname"]; // ex. "Bot"
482
+ message["type"] = msg["type"]; // ex. "text",
483
+ message["channel_type"] = msg["channel_type"]; // ex. "group",
484
+ message["status"] = msg["status"]; // ex. 0,
485
+ message["id"] = msg["_id"]; // ex. "6538cda46cb4d8002cf2317a",
486
+ message["sender"] = msg["sender"]; // ex. "system",
487
+ message["recipient"] = msg["recipient"]; // ex. "support-group-65203e12f8c0cf002cf4110b-4066a69c8b464646a3ff25f9f41575bb",
488
+ message["text"] = msg["text"]; // ex. "\\start",
489
+ message["createdBy"] = msg["createdBy"]; // ex. "system",
490
+ message["attributes"] = msg["attributes"]; // ex. { "subtype": "info" }
502
491
  message["metadata"] = msg["metadata"];
503
- message["channel"] = msg["channel"]; // ex. { "name": "chat21" }
492
+ message["channel"] = msg["channel"]; // ex. { "name": "chat21" }
504
493
  return message;
505
494
  }
506
495
 
507
496
  static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
508
497
  // update request context
509
498
  try {
510
- if (chatbot.log) {console.log("Updating request variables. Message:", JSON.stringify(message));}
499
+ if (chatbot.log) { winston.debug("Updating request variables. Message:", message); }
511
500
  const messageId = message._id;
512
501
  const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
513
- // await chatbot.addParameter("chatbot", chatbot);
502
+
514
503
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_URL, chat_url);
515
- // console.log("Adding proj_", projectId);
516
504
  await chatbot.addParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY, projectId);
517
- // TODO add projectName too
518
505
  await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUEST_ID_KEY, requestId);
506
+
519
507
  if (chatbot.bot) {
520
508
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
521
509
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_ID_KEY, chatbot.bot._id);
522
510
  }
511
+
523
512
  if (chatbotToken) {
524
513
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
525
514
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
526
515
  }
516
+
527
517
  if (process.env.TILEDESK_API) {
528
518
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
529
519
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
@@ -534,7 +524,6 @@ class TiledeskChatbotUtil {
534
524
  }
535
525
 
536
526
  if (message.text && message.sender !== "_tdinternal") {
537
- // await chatbot.addParameter(TiledeskChatbotConst.USER_INPUT, true); // set userInput
538
527
  await chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT); // user wrote, delete userInput, replyv2 will not trigger timeout action
539
528
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY, message.text); // DEPRECATED
540
529
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY, message.text);
@@ -552,44 +541,18 @@ class TiledeskChatbotUtil {
552
541
 
553
542
  // get image
554
543
  if (message.type && message.type === "image" && message.metadata) {
555
- // "text": "\nimage text",
556
- // "id_project": "65203e12f8c0cf002cf4110b",
557
- // "createdBy": "8ac52a30-133f-4ee1-8b4b-96055bb81757",
558
- // "metadata": {
559
- // "height": 905,
560
- // "name": "tiledesk_Open graph_general.png",
561
- // "src": "https://firebasestorage.googleapis.com/v0/b/chat21-pre-01.appspot.com/o/public%2Fimages%2F8ac52a30-133f-4ee1-8b4b-96055bb81757%2Fda5bbc8d-5174-49a8-a041-3d9355242da5%2Ftiledesk_Open%20graph_general.png?alt=media&token=be82fecb-3cd1-45b9-a135-c2c57a932862",
562
- // "type": "image/png",
563
- // "uid": "lo68iyq5",
564
- // "width": 1724
565
- // }
566
544
  if (message.metadata.src) {
567
- await chatbot.addParameter("lastUserImageURL", message.metadata.src);
568
- await chatbot.addParameter("lastUserImageName", message.metadata.name);
569
- await chatbot.addParameter("lastUserImageWidth", message.metadata.width);
570
- await chatbot.addParameter("lastUserImageHeight", message.metadata.height);
571
- await chatbot.addParameter("lastUserImageType", message.metadata.type);
572
- }
573
- }
574
- // else {
575
- // await chatbot.addParameter("lastUserImageURL", null);
576
- // await chatbot.addParameter("lastUserImageName", null);
577
- // await chatbot.addParameter("lastUserImageWidth", null);
578
- // await chatbot.addParameter("lastUserImageHeight", null);
579
- // await chatbot.addParameter("lastUserImageType", null);
580
- // }
545
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_URL, message.metadata.src);
546
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_NAME, message.metadata.name);
547
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_WIDTH, message.metadata.width);
548
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_HEIGHT, message.metadata.height);
549
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_TYPE, message.metadata.type);
550
+ }
551
+ }
552
+
581
553
  // get document
582
554
  if (message.type && message.type === "file" && message.metadata) {
583
- // "type": "file",
584
- // "text": "[LIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf](https://firebasestorage.googleapis.com/v0/b/chat21-pre-01.appspot.com/o/public%2Fimages%2F8ac52a30-133f-4ee1-8b4b-96055bb81757%2F502265ee-4f4a-47a4-9375-172bb0e6bf39%2FLIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf?alt=media&token=a09d065a-9b56-4507-8960-344cc294e4d1)\nistruzioni",
585
- // "metadata": {
586
- // "name": "LIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf",
587
- // "src": "https://firebasestorage.googleapis.com/v0/b/chat21-pre-01.appspot.com/o/public%2Fimages%2F8ac52a30-133f-4ee1-8b4b-96055bb81757%2F502265ee-4f4a-47a4-9375-172bb0e6bf39%2FLIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf?alt=media&token=a09d065a-9b56-4507-8960-344cc294e4d1",
588
- // "type": "application/pdf",
589
- // "uid": "lo68oz8i"
590
- // }
591
- if (message.metadata.src) {
592
-
555
+ if (message.metadata.src) {
593
556
  await chatbot.addParameter("lastUserDocumentURL", message.metadata.src); // legacy. will be deprecated
594
557
  const url_as_attachment = message.metadata.src;
595
558
  await chatbot.addParameter("lastUserDocumentAsAttachmentURL", url_as_attachment);
@@ -602,44 +565,34 @@ class TiledeskChatbotUtil {
602
565
  await chatbot.addParameter("lastUserDocumentType", message.metadata.type);
603
566
  }
604
567
  }
605
- // else {
606
- // await chatbot.addParameter("lastUserDocumentURL", null);
607
- // await chatbot.addParameter("lastUserDocumentName", null);
608
- // await chatbot.addParameter("lastUserDocumentType", null);
609
- // }
568
+
610
569
  if (message && message.request && message.request.lead) {
611
- if (chatbot.log) {console.log("lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)}
570
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname); }
612
571
  let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
613
- if (chatbot.log) {console.log("You lead email from attributes:", currentLeadEmail, "message.request.lead.email:", message.request.lead.email);}
572
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
614
573
  if (message.request.lead.email && !currentLeadEmail) {
615
574
  // worth saving
616
- if (chatbot.log) {console.log("worth saving email. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)}
575
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
617
576
  try {
618
577
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
619
578
  }
620
579
  catch(error) {
621
- console.error("Error on setting userEmail:", error);
580
+ winston.error("(TiledeskChatbotUtil) Error on setting userEmail:", error);
622
581
  }
623
582
  }
624
583
  let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
625
- if (chatbot.log) {console.log("You lead name from attributes:", currentLeadName, "message.request.lead.fullname:", message.request.lead.fullname)}
626
- // if (message.request.lead.fullname && message.request.lead.fullname.startsWith("guest#") && !currentLeadName) {
627
- // if (message.request.lead.fullname) {
584
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
628
585
  if (message.request.lead.fullname && !currentLeadName) {
629
586
  // worth saving
630
- if (chatbot.log) {console.log("worth saving fullname. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)}
587
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
631
588
  try {
632
589
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
633
590
  }
634
591
  catch(error) {
635
- console.error("Error on setting userFullname:", error);
592
+ winston.error("(TiledeskChatbotUtil) Error on setting userFullname: ", error);
636
593
  }
637
- // }
638
- // else {
639
- // // console.log("!lead.fullname");
640
- // }
641
594
  }
642
- // console.log("Getting userPhone:", JSON.stringify(message.request));
595
+
643
596
  if (message.request.lead.phone) {
644
597
  await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_PHONE_KEY, message.request.lead.phone);
645
598
  }
@@ -667,15 +620,12 @@ class TiledeskChatbotUtil {
667
620
  if (message.request && message.request.location && message.request.location.city) {
668
621
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
669
622
  }
670
- // console.log("message.request.language", message.request["language"]);
671
623
  if (message.request) {
672
624
  let user_language = message.request["language"];
673
625
  if (message.request["language"]) {
674
- // console.log("HTTP language:", message.request["language"]);
675
626
  var languages = parser.parse(message.request["language"]);
676
- // console.log("languages:", languages);
677
627
  if (languages && languages.length > 0 && languages[0].code) {
678
- user_language = languages[0].code;
628
+ user_language = languages[0].code;
679
629
  }
680
630
  }
681
631
  await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
@@ -693,7 +643,6 @@ class TiledeskChatbotUtil {
693
643
  }
694
644
  }
695
645
  }
696
- // console.log("message.request.language", message.request["language"])
697
646
  if (message.request && message.request.department) {
698
647
  // It was an error when getting this from widget message's attributes
699
648
  // await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
@@ -711,29 +660,24 @@ class TiledeskChatbotUtil {
711
660
  if (!message.attributes) {
712
661
  message.attributes = {}
713
662
  }
714
- message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload}
715
- if (chatbot.log) {console.log("FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
716
- // if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
663
+ message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
664
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload); }
717
665
  }
718
666
  if (message.attributes) {
719
- if (chatbot.log) {console.log("Ok message.attributes", JSON.stringify(message.attributes));}
720
- // if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > Ok message.attributes", JSON.stringify(message.attributes));}
667
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes); }
668
+
721
669
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
722
670
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
723
671
  if (message.attributes.payload) {
724
672
  try {
725
673
  for (const [key, value] of Object.entries(message.attributes.payload)) {
726
- // const value = all_parameters[key];
727
674
  const value_type = typeof value;
728
- //if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
729
- //await chatbot.addParameter(key, String(value));
730
- // console.log("Adding from message.attributes:", key, "->", value);
731
675
  await chatbot.addParameter(key, value);
732
676
  }
733
677
  await chatbot.addParameter("payload", message.attributes.payload);
734
678
  }
735
679
  catch(err) {
736
- console.error("Error importing message payload in request variables:", err);
680
+ winston.error("(TiledeskChatbotUtil) Error importing message payload in request variables: ", err);
737
681
  }
738
682
  }
739
683
 
@@ -754,14 +698,12 @@ class TiledeskChatbotUtil {
754
698
 
755
699
 
756
700
  const _bot = chatbot.bot; // aka FaqKB
757
- if (chatbot.log) {
758
- console.log("Adding Globals to context..., chatbot.attributes?", JSON.stringify(_bot));
759
- }
701
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot); }
760
702
 
761
703
  if (_bot.attributes && _bot.attributes.globals) {
762
- if (chatbot.log) {console.log("Got Globals:", JSON.stringify(_bot.attributes.globals));}
704
+ if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals); }
763
705
  _bot.attributes.globals.forEach(async (global_var) => {
764
- if (chatbot.log) {console.log("Adding global:", global_var.key, "value:", global_var.value);}
706
+ if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value); }
765
707
  await chatbot.addParameter(global_var.key, global_var.value);
766
708
  });
767
709
  }
@@ -775,52 +717,23 @@ class TiledeskChatbotUtil {
775
717
  // );
776
718
 
777
719
  if (chatbot.log) {
778
- // console.log("tdcache:", chatbot.tdcache);
779
- console.log("requestId:", requestId);
780
- console.log("KEY:", TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
781
- // console.log("TiledeskChatbot:", TiledeskChatbot);
720
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) requestId: " + requestId); }
721
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Key: " + TiledeskChatbotConst.REQ_PROJECT_ID_KEY); }
722
+
782
723
  let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
783
- console.log("request parameter proj_:", proj_);
724
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) request parameter proj_: " + proj_); }
725
+
784
726
  const all_parameters = await chatbot.allParameters();
785
727
  for (const [key, value] of Object.entries(all_parameters)) {
786
- // const value = all_parameters[key];
787
728
  const value_type = typeof value;
788
- if (chatbot.log) {console.log("REQUEST ATTRIBUTE:", key, "VALUE:", value, "TYPE:", value_type)}
729
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Request Attribute: " + key + " value: " + value + " type: " + value_type); }
730
+
789
731
  }
790
732
  }
791
733
  } catch(error) {
792
- console.error("Error", error)
734
+ winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
793
735
  process.exit(1)
794
736
  }
795
- // message["attributes"]: {
796
- // "departmentId": "63c980054f857c00350535bc",
797
- // "departmentName": "Default Department",
798
- // "client": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
799
- // "sourcePage": "https://tiledesk-html-site.tiledesk.repl.co/custom-attributes.html",
800
- // "projectId": "63c980054f857c00350535b8",
801
- // "payload": {
802
- // "user_country": "Italy",
803
- // "user_code": "E001"
804
- // },
805
- // "userFullname": "guest#7216 ",
806
- // "requester_id": "7216926a-84c3-4bd5-aa79-8bd763094dc0",
807
- // "ipAddress": "79.8.190.172",
808
- // "sourceTitle": "Custom attributes",
809
- // "widgetVer": "v.5.0.53-rc.4",
810
- // "subtype": "info",
811
- // "decoded_jwt": {
812
- // "_id": "7216926a-84c3-4bd5-aa79-8bd763094dc0",
813
- // "firstname": "guest#7216",
814
- // "id": "7216926a-84c3-4bd5-aa79-8bd763094dc0",
815
- // "fullName": "guest#7216 ",
816
- // "iat": 1674201892,
817
- // "aud": "https://tiledesk.com",
818
- // "iss": "https://tiledesk.com",
819
- // "sub": "guest",
820
- // "jti": "f053af3d-14ca-411b-9903-78bd74e24218"
821
- // }
822
- // let userFullname = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
823
- // console.log("userFullname:", userFullname);
824
737
  }
825
738
 
826
739
  static actionsToDirectives(actions) {
@@ -837,21 +750,17 @@ class TiledeskChatbotUtil {
837
750
  }
838
751
 
839
752
  static addConnectAction(reply) {
840
- // console.log("reply foraddConnectAction:", reply);
841
753
  if (reply && reply.attributes && reply.attributes.nextBlockAction) {
842
754
  if (reply.actions) {
843
755
  reply.actions.push(reply.attributes.nextBlockAction);
844
- // console.log("actions are:", reply.actions)
845
756
  }
846
757
  }
847
758
  }
848
759
 
849
760
  static validateRequestId(requestId, projectId) {
850
- // console.log("checking requestId:", requestId, projectId)
851
761
  let isValid = false;
852
762
  if (requestId.startsWith("support-group-")) {
853
763
  const parts = requestId.split("-");
854
- // console.log("parts support request:", parts);
855
764
  if (parts.length >= 4) {
856
765
  isValid = (parts[0] === "support" && parts[1] === "group" && parts[2] === projectId && parts[3].length > 0);
857
766
  }
@@ -860,7 +769,6 @@ class TiledeskChatbotUtil {
860
769
  }
861
770
  } else if (requestId.startsWith("automation-request-")) {
862
771
  const parts = requestId.split("-");
863
- // console.log("parts automation request:", parts);
864
772
  if (parts.length === 4) {
865
773
  isValid = (parts[0] === "automation" && parts[1] === "request" && parts[2] === projectId && parts[3].length > 0);
866
774
  }
@@ -895,19 +803,18 @@ class TiledeskChatbotUtil {
895
803
  TiledeskChatbotConst.REQ_TRANSCRIPT_KEY,
896
804
  TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_KEY,
897
805
  TiledeskChatbotConst.REQ_DECODED_JWT_KEY,
898
- "lastUserImageURL", // image
899
- "lastUserImageName", // image
900
- "lastUserImageWidth", // image
901
- "lastUserImageHeight", // image
902
- "lastUserImageType", // image
903
- "lastUserDocumentURL", // file
904
- "lastUserDocumentName", // file
905
- "lastUserDocumentType", // file
906
- "ticketId",
806
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_URL,
807
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_NAME,
808
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_WIDTH,
809
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_HEIGHT,
810
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_TYPE,
811
+ TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_URL,
812
+ TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_NAME,
813
+ TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_TYPE,
814
+ TiledeskChatbotConst.REQ_TICKET_ID_KEY,
907
815
  TiledeskChatbotConst.REQ_CHAT_CHANNEL,
908
- "user_lead_id",
909
- "userLeadId",
910
- "lastUserText",
816
+ TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY,
817
+ TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY,
911
818
  TiledeskChatbotConst.REQ_REQUESTER_IS_AUTHENTICATED_KEY,
912
819
  TiledeskChatbotConst.USER_INPUT,
913
820
  TiledeskChatbotConst.REQ_CHATBOT_TOKEN,
@@ -916,7 +823,6 @@ class TiledeskChatbotUtil {
916
823
  let userParams = {};
917
824
  if (flowAttributes) {
918
825
  for (const [key, value] of Object.entries(flowAttributes)) {
919
- // console.log(key, value);
920
826
  // There is a bug that moves the requestId as a key in request attributes, so: && !key.startsWith("support-group-")
921
827
  if (!key.startsWith("_") && !RESERVED.some(e => e === key) && !key.startsWith("support-group-")) {
922
828
  userParams[key] = value;
@@ -960,8 +866,8 @@ class TiledeskChatbotUtil {
960
866
 
961
867
  myrequest(options, callback, log) {
962
868
  if (log) {
963
- console.log("API URL:", options.url);
964
- console.log("** Options:", JSON.stringify(options));
869
+ winston.debug("(TiledeskChatbotUtil) myrequest API URL: " + options.url);
870
+ winston.debug("(TiledeskChatbotUtil) myrequest Options URL: ", options);
965
871
  }
966
872
  axios(
967
873
  {
@@ -973,8 +879,8 @@ class TiledeskChatbotUtil {
973
879
  })
974
880
  .then((res) => {
975
881
  if (log) {
976
- console.log("Response for url:", options.url);
977
- console.log("Response headers:\n", JSON.stringify(res.headers));
882
+ winston.debug("(TiledeskChatbotUtil) Response for url: " + options.url);
883
+ winston.debug("(TiledeskChatbotUtil) Response headers:\n", options);
978
884
  }
979
885
  if (res && res.status == 200 && res.data) {
980
886
  if (callback) {
@@ -988,7 +894,7 @@ class TiledeskChatbotUtil {
988
894
  }
989
895
  })
990
896
  .catch((error) => {
991
- console.error("(TiledeskChatbotUtil) Axios error: ", JSON.stringify(error));
897
+ winston.error("(TiledeskChatbotUtil) Axios error: ", error.response.data);
992
898
  if (callback) {
993
899
  callback(error, null, null);
994
900
  }