@tiledesk/tiledesk-tybot-connector 0.4.2 → 0.5.0-rc2

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 (87) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/ExtApi.js +3 -13
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +86 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/index.js +87 -273
  9. package/logs/app.log +12983 -275
  10. package/logs/app1.log +62258 -0
  11. package/logs/app2.log +46280 -0
  12. package/logs/app3.log +28864 -0
  13. package/models/IntentForm.js +30 -44
  14. package/models/IntentsMachineFactory.js +4 -3
  15. package/models/MockBotsDataSource.js +1 -17
  16. package/models/MockTdCache.js +0 -9
  17. package/models/MongodbBotsDataSource.js +29 -53
  18. package/models/MongodbIntentsMachine.js +5 -4
  19. package/models/TiledeskChatbot.js +79 -258
  20. package/models/TiledeskChatbotConst.js +9 -0
  21. package/models/TiledeskChatbotUtil.js +180 -232
  22. package/models/TiledeskIntentsMachine.js +5 -14
  23. package/models/faqKbService.js +0 -1
  24. package/package.json +5 -2
  25. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
  26. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
  27. package/tiledeskChatbotPlugs/Filler.js +0 -1
  28. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  29. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  30. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  31. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  32. package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
  33. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
  34. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
  35. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
  36. package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
  37. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
  38. package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
  39. package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
  40. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
  41. package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
  42. package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
  43. package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
  44. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
  45. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
  46. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
  47. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
  48. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
  49. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  50. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  51. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  52. package/tiledeskChatbotPlugs/directives/DirForm.js +15 -22
  53. package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
  54. package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
  55. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  56. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
  57. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
  58. package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
  59. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
  60. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  61. package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
  62. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  63. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
  64. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
  65. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
  66. package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
  67. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
  68. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  69. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
  70. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
  71. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
  72. package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
  73. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
  74. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
  75. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
  76. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
  77. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
  78. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  79. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  80. package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
  81. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
  82. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
  83. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
  84. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
  85. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  86. package/utils/winston.js +42 -0
  87. package/TdCache copy.js +0 -242
@@ -6,6 +6,7 @@ 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('../utils/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,105 @@ 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
+ console.log("type json_buttons_string:", typeof json_buttons_string);
318
+ try {
319
+ json_buttons = JSON.parse(json_buttons_string);
320
+ console.log("json_buttons (parsed): ", json_buttons);
321
+ } catch(err) {
322
+ console.error("Error parsing json_buttons_string: ", err)
323
+ }
324
+
325
+ console.log("after try type json_buttons: ", typeof json_buttons, json_buttons);
326
+ console.log("Array.isArray(json_buttons): ", Array.isArray(json_buttons));
327
+ if (Array.isArray(json_buttons)) {
328
+ console.log("json_buttons is array");
329
+ json_buttons.forEach(button => {
330
+ console.log("analyze button:", button);
331
+ console.log("button.value:", typeof button.value, button.value);
332
+ console.log("button.type:", typeof button.type, button.type);
333
+ console.log("button.action:", typeof button.action, button.action);
334
+ console.log("final_buttons:", final_buttons);
335
+ if (button.value && button.type === "action" && button.action) {
336
+ console.log("Case 1");
337
+ button.show_echo = true;
338
+ // console.log("pushing:", button)
339
+ final_buttons.push(button);
340
+ }
341
+ else if (button.value && button.type === "text") {
342
+ console.log("Case 2");
343
+ button.show_echo = true;
344
+ // console.log("pushing:", button)
345
+ final_buttons.push(button);
346
+ }
347
+ else if (button.value && button.type === "url" && button.link) {
348
+ console.log("Case 3");
349
+ button.show_echo = true;
350
+ // console.log("pushing:", button)
351
+ final_buttons.push(button);
352
+ }
353
+ else {
354
+ console.log("Invalid button. Skipping:", JSON.stringify(button) );
355
+ }
356
+ });
357
+ }
358
+
359
+ // "buttons": [
360
+ // {
361
+ // "type": "action",
362
+ // "value": "Button1", // obbligatorio sempre
363
+ // "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
364
+ // "show_echo": true, // lo inserisco sempre
365
+ // "alias": "button1 alias"
366
+ // },
367
+ // {
368
+ // "type": "text",
369
+ // "value": "Button2 text", // obbligatorio sempre
370
+ // "show_echo": true // lo inserisco sempre
371
+ // },
372
+ // {
373
+ // "type": "url",
374
+ // "value": "Button3 link", // obbligatorio sempre
375
+ // "link": "http://", // obbligatorio
376
+ // "show_echo": true // lo inserisco sempre
377
+ // }
378
+ // ]
379
+ }
380
+ catch(error) {
381
+ console.error("Invalid json_buttons:", error)
382
+ }
383
+ if (final_buttons && final_buttons.length > 0) {
384
+ command.message.attributes.attachment.buttons = final_buttons;
385
+ delete command.message.attributes.attachment.json_buttons;
386
+ }
387
+ else {
388
+ console.log("Invalid json buttons. Skipped:", JSON.stringify(final_buttons));
389
+ }
390
+ }
391
+ }
392
+ }
393
+ }
394
+ }
395
+ return all_buttons;
396
+ }
397
+
352
398
  static buttonByText(text, buttons) {
353
399
  if (buttons === null || text === null) {
354
400
  return null;
@@ -363,12 +409,10 @@ class TiledeskChatbotUtil {
363
409
  }
364
410
  else if (button.alias && button.alias.trim() !== "") { // search in button alias
365
411
  let alias = button.alias.split(",");
366
- // console.log("alias splitted:", alias);
367
412
  if (alias.length > 0) {
368
413
  for (let ii = 0; ii < alias.length; ii++) {
369
414
  alias[ii] = alias[ii].toLowerCase().trim();
370
415
  }
371
- // console.log("alias proc:", alias);
372
416
  if (alias.indexOf(search_text) > -1) {
373
417
  selected_button = button;
374
418
  break;
@@ -376,12 +420,10 @@ class TiledeskChatbotUtil {
376
420
  }
377
421
  }
378
422
  }
379
-
380
423
  return selected_button;
381
424
  }
382
425
 
383
426
  static stripEmoji(str) {
384
- // console.log("checking:", str);
385
427
  if (str === null) {
386
428
  return str;
387
429
  }
@@ -398,7 +440,6 @@ class TiledeskChatbotUtil {
398
440
  const chatbot_name = chatbot.bot.name.trim();
399
441
  if (message && message.text && message.text.trim() !== "" && message.sender !== "_tdinternal" && !this.isHiddenMessage(message)) {
400
442
  let transcript = await chatbot.getParameter("transcript");
401
- // console.log("transcript got:", transcript);
402
443
  const _name_of = name_of(message, chatbot_name);
403
444
  if (transcript) {
404
445
  transcript = transcript + "\n" + _name_of + message.text;
@@ -406,10 +447,7 @@ class TiledeskChatbotUtil {
406
447
  else {
407
448
  transcript = _name_of + " " + message.text;
408
449
  }
409
- // console.log("transcript update:", transcript);
410
450
  await chatbot.addParameter("transcript", transcript);
411
- // let transcript2 = await chatbot.getParameter("transcript");
412
- // console.log("transcript updated:", transcript2);
413
451
  }
414
452
 
415
453
  function name_of(message, chatbot_name) {
@@ -436,39 +474,32 @@ class TiledeskChatbotUtil {
436
474
  static transcriptJSON(transcript) {
437
475
  const regexp = /(<.*>)/gm;
438
476
  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));
477
+ winston.debug("(TiledeskChatbotUtils) transcriptJSON parts: ", parts)
478
+
443
479
  let messages = [];
444
480
  let current_message;
445
481
  try {
446
482
  for (let i = 0; i < parts.length; i++) {
447
483
  let row = parts[i];
448
- // console.log("row:", row)
449
484
  if (row.startsWith("<bot:")) {
450
- // console.log("start with", row)
451
485
  current_message = {
452
486
  "role": "assistant"
453
487
  }
454
488
  }
455
489
  else if (row.startsWith("<user:")) {
456
- // console.log("start with", row)
457
490
  current_message = {
458
491
  "role": "user"
459
492
  }
460
493
  }
461
494
  else if (current_message) {
462
- // console.log("adding text", row)
463
495
  current_message["content"] = row.trim();
464
496
  messages.push(current_message);
465
497
  }
466
498
  };
467
499
  }
468
500
  catch(error) {
469
- console.error("err:", error);
501
+ winston.error("(TiledeskChatbotUtils) transcriptJSON err: ", error);
470
502
  }
471
- // console.log("messages:", messages);
472
503
  return messages;
473
504
  }
474
505
 
@@ -489,41 +520,42 @@ class TiledeskChatbotUtil {
489
520
 
490
521
  static lastUserMessageFrom(msg) {
491
522
  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" }
523
+ message["senderFullname"] = msg["senderFullname"]; // ex. "Bot"
524
+ message["type"] = msg["type"]; // ex. "text",
525
+ message["channel_type"] = msg["channel_type"]; // ex. "group",
526
+ message["status"] = msg["status"]; // ex. 0,
527
+ message["id"] = msg["_id"]; // ex. "6538cda46cb4d8002cf2317a",
528
+ message["sender"] = msg["sender"]; // ex. "system",
529
+ message["recipient"] = msg["recipient"]; // ex. "support-group-65203e12f8c0cf002cf4110b-4066a69c8b464646a3ff25f9f41575bb",
530
+ message["text"] = msg["text"]; // ex. "\\start",
531
+ message["createdBy"] = msg["createdBy"]; // ex. "system",
532
+ message["attributes"] = msg["attributes"]; // ex. { "subtype": "info" }
502
533
  message["metadata"] = msg["metadata"];
503
- message["channel"] = msg["channel"]; // ex. { "name": "chat21" }
534
+ message["channel"] = msg["channel"]; // ex. { "name": "chat21" }
504
535
  return message;
505
536
  }
506
537
 
507
538
  static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
508
539
  // update request context
509
540
  try {
510
- if (chatbot.log) {console.log("Updating request variables. Message:", JSON.stringify(message));}
541
+ if (chatbot.log) { winston.debug("Updating request variables. Message:", message); }
511
542
  const messageId = message._id;
512
543
  const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
513
- // await chatbot.addParameter("chatbot", chatbot);
544
+
514
545
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_URL, chat_url);
515
- // console.log("Adding proj_", projectId);
516
546
  await chatbot.addParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY, projectId);
517
- // TODO add projectName too
518
547
  await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUEST_ID_KEY, requestId);
548
+
519
549
  if (chatbot.bot) {
520
550
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
521
551
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_ID_KEY, chatbot.bot._id);
522
552
  }
553
+
523
554
  if (chatbotToken) {
524
555
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
525
556
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
526
557
  }
558
+
527
559
  if (process.env.TILEDESK_API) {
528
560
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
529
561
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
@@ -534,7 +566,6 @@ class TiledeskChatbotUtil {
534
566
  }
535
567
 
536
568
  if (message.text && message.sender !== "_tdinternal") {
537
- // await chatbot.addParameter(TiledeskChatbotConst.USER_INPUT, true); // set userInput
538
569
  await chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT); // user wrote, delete userInput, replyv2 will not trigger timeout action
539
570
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY, message.text); // DEPRECATED
540
571
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY, message.text);
@@ -552,44 +583,18 @@ class TiledeskChatbotUtil {
552
583
 
553
584
  // get image
554
585
  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
586
  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
- // }
587
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_URL, message.metadata.src);
588
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_NAME, message.metadata.name);
589
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_WIDTH, message.metadata.width);
590
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_HEIGHT, message.metadata.height);
591
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_TYPE, message.metadata.type);
592
+ }
593
+ }
594
+
581
595
  // get document
582
596
  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
-
597
+ if (message.metadata.src) {
593
598
  await chatbot.addParameter("lastUserDocumentURL", message.metadata.src); // legacy. will be deprecated
594
599
  const url_as_attachment = message.metadata.src;
595
600
  await chatbot.addParameter("lastUserDocumentAsAttachmentURL", url_as_attachment);
@@ -602,44 +607,34 @@ class TiledeskChatbotUtil {
602
607
  await chatbot.addParameter("lastUserDocumentType", message.metadata.type);
603
608
  }
604
609
  }
605
- // else {
606
- // await chatbot.addParameter("lastUserDocumentURL", null);
607
- // await chatbot.addParameter("lastUserDocumentName", null);
608
- // await chatbot.addParameter("lastUserDocumentType", null);
609
- // }
610
+
610
611
  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)}
612
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname); }
612
613
  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);}
614
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
614
615
  if (message.request.lead.email && !currentLeadEmail) {
615
616
  // 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)}
617
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
617
618
  try {
618
619
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
619
620
  }
620
621
  catch(error) {
621
- console.error("Error on setting userEmail:", error);
622
+ winston.error("(TiledeskChatbotUtil) Error on setting userEmail:", error);
622
623
  }
623
624
  }
624
625
  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) {
626
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
628
627
  if (message.request.lead.fullname && !currentLeadName) {
629
628
  // 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)}
629
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
631
630
  try {
632
631
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
633
632
  }
634
633
  catch(error) {
635
- console.error("Error on setting userFullname:", error);
634
+ winston.error("(TiledeskChatbotUtil) Error on setting userFullname: ", error);
636
635
  }
637
- // }
638
- // else {
639
- // // console.log("!lead.fullname");
640
- // }
641
636
  }
642
- // console.log("Getting userPhone:", JSON.stringify(message.request));
637
+
643
638
  if (message.request.lead.phone) {
644
639
  await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_PHONE_KEY, message.request.lead.phone);
645
640
  }
@@ -667,15 +662,12 @@ class TiledeskChatbotUtil {
667
662
  if (message.request && message.request.location && message.request.location.city) {
668
663
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
669
664
  }
670
- // console.log("message.request.language", message.request["language"]);
671
665
  if (message.request) {
672
666
  let user_language = message.request["language"];
673
667
  if (message.request["language"]) {
674
- // console.log("HTTP language:", message.request["language"]);
675
668
  var languages = parser.parse(message.request["language"]);
676
- // console.log("languages:", languages);
677
669
  if (languages && languages.length > 0 && languages[0].code) {
678
- user_language = languages[0].code;
670
+ user_language = languages[0].code;
679
671
  }
680
672
  }
681
673
  await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
@@ -693,7 +685,6 @@ class TiledeskChatbotUtil {
693
685
  }
694
686
  }
695
687
  }
696
- // console.log("message.request.language", message.request["language"])
697
688
  if (message.request && message.request.department) {
698
689
  // It was an error when getting this from widget message's attributes
699
690
  // await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
@@ -711,29 +702,24 @@ class TiledeskChatbotUtil {
711
702
  if (!message.attributes) {
712
703
  message.attributes = {}
713
704
  }
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))}
705
+ message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
706
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload); }
717
707
  }
718
708
  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));}
709
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes); }
710
+
721
711
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
722
712
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
723
713
  if (message.attributes.payload) {
724
714
  try {
725
715
  for (const [key, value] of Object.entries(message.attributes.payload)) {
726
- // const value = all_parameters[key];
727
716
  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
717
  await chatbot.addParameter(key, value);
732
718
  }
733
719
  await chatbot.addParameter("payload", message.attributes.payload);
734
720
  }
735
721
  catch(err) {
736
- console.error("Error importing message payload in request variables:", err);
722
+ winston.error("(TiledeskChatbotUtil) Error importing message payload in request variables: ", err);
737
723
  }
738
724
  }
739
725
 
@@ -754,14 +740,12 @@ class TiledeskChatbotUtil {
754
740
 
755
741
 
756
742
  const _bot = chatbot.bot; // aka FaqKB
757
- if (chatbot.log) {
758
- console.log("Adding Globals to context..., chatbot.attributes?", JSON.stringify(_bot));
759
- }
743
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot); }
760
744
 
761
745
  if (_bot.attributes && _bot.attributes.globals) {
762
- if (chatbot.log) {console.log("Got Globals:", JSON.stringify(_bot.attributes.globals));}
746
+ if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals); }
763
747
  _bot.attributes.globals.forEach(async (global_var) => {
764
- if (chatbot.log) {console.log("Adding global:", global_var.key, "value:", global_var.value);}
748
+ if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value); }
765
749
  await chatbot.addParameter(global_var.key, global_var.value);
766
750
  });
767
751
  }
@@ -775,52 +759,23 @@ class TiledeskChatbotUtil {
775
759
  // );
776
760
 
777
761
  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);
762
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) requestId: " + requestId); }
763
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Key: " + TiledeskChatbotConst.REQ_PROJECT_ID_KEY); }
764
+
782
765
  let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
783
- console.log("request parameter proj_:", proj_);
766
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) request parameter proj_: " + proj_); }
767
+
784
768
  const all_parameters = await chatbot.allParameters();
785
769
  for (const [key, value] of Object.entries(all_parameters)) {
786
- // const value = all_parameters[key];
787
770
  const value_type = typeof value;
788
- if (chatbot.log) {console.log("REQUEST ATTRIBUTE:", key, "VALUE:", value, "TYPE:", value_type)}
771
+ if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Request Attribute: " + key + " value: " + value + " type: " + value_type); }
772
+
789
773
  }
790
774
  }
791
775
  } catch(error) {
792
- console.error("Error", error)
776
+ winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
793
777
  process.exit(1)
794
778
  }
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
779
  }
825
780
 
826
781
  static actionsToDirectives(actions) {
@@ -837,21 +792,17 @@ class TiledeskChatbotUtil {
837
792
  }
838
793
 
839
794
  static addConnectAction(reply) {
840
- // console.log("reply foraddConnectAction:", reply);
841
795
  if (reply && reply.attributes && reply.attributes.nextBlockAction) {
842
796
  if (reply.actions) {
843
797
  reply.actions.push(reply.attributes.nextBlockAction);
844
- // console.log("actions are:", reply.actions)
845
798
  }
846
799
  }
847
800
  }
848
801
 
849
802
  static validateRequestId(requestId, projectId) {
850
- // console.log("checking requestId:", requestId, projectId)
851
803
  let isValid = false;
852
804
  if (requestId.startsWith("support-group-")) {
853
805
  const parts = requestId.split("-");
854
- // console.log("parts support request:", parts);
855
806
  if (parts.length >= 4) {
856
807
  isValid = (parts[0] === "support" && parts[1] === "group" && parts[2] === projectId && parts[3].length > 0);
857
808
  }
@@ -860,7 +811,6 @@ class TiledeskChatbotUtil {
860
811
  }
861
812
  } else if (requestId.startsWith("automation-request-")) {
862
813
  const parts = requestId.split("-");
863
- // console.log("parts automation request:", parts);
864
814
  if (parts.length === 4) {
865
815
  isValid = (parts[0] === "automation" && parts[1] === "request" && parts[2] === projectId && parts[3].length > 0);
866
816
  }
@@ -895,19 +845,18 @@ class TiledeskChatbotUtil {
895
845
  TiledeskChatbotConst.REQ_TRANSCRIPT_KEY,
896
846
  TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_KEY,
897
847
  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",
848
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_URL,
849
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_NAME,
850
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_WIDTH,
851
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_HEIGHT,
852
+ TiledeskChatbotConst.REQ_LAST_USER_IMAGE_TYPE,
853
+ TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_URL,
854
+ TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_NAME,
855
+ TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_TYPE,
856
+ TiledeskChatbotConst.REQ_TICKET_ID_KEY,
907
857
  TiledeskChatbotConst.REQ_CHAT_CHANNEL,
908
- "user_lead_id",
909
- "userLeadId",
910
- "lastUserText",
858
+ TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY,
859
+ TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY,
911
860
  TiledeskChatbotConst.REQ_REQUESTER_IS_AUTHENTICATED_KEY,
912
861
  TiledeskChatbotConst.USER_INPUT,
913
862
  TiledeskChatbotConst.REQ_CHATBOT_TOKEN,
@@ -916,7 +865,6 @@ class TiledeskChatbotUtil {
916
865
  let userParams = {};
917
866
  if (flowAttributes) {
918
867
  for (const [key, value] of Object.entries(flowAttributes)) {
919
- // console.log(key, value);
920
868
  // There is a bug that moves the requestId as a key in request attributes, so: && !key.startsWith("support-group-")
921
869
  if (!key.startsWith("_") && !RESERVED.some(e => e === key) && !key.startsWith("support-group-")) {
922
870
  userParams[key] = value;
@@ -960,8 +908,8 @@ class TiledeskChatbotUtil {
960
908
 
961
909
  myrequest(options, callback, log) {
962
910
  if (log) {
963
- console.log("API URL:", options.url);
964
- console.log("** Options:", JSON.stringify(options));
911
+ winston.debug("(TiledeskChatbotUtil) myrequest API URL: " + options.url);
912
+ winston.debug("(TiledeskChatbotUtil) myrequest Options URL: ", options);
965
913
  }
966
914
  axios(
967
915
  {
@@ -973,8 +921,8 @@ class TiledeskChatbotUtil {
973
921
  })
974
922
  .then((res) => {
975
923
  if (log) {
976
- console.log("Response for url:", options.url);
977
- console.log("Response headers:\n", JSON.stringify(res.headers));
924
+ winston.debug("(TiledeskChatbotUtil) Response for url: " + options.url);
925
+ winston.debug("(TiledeskChatbotUtil) Response headers:\n", options);
978
926
  }
979
927
  if (res && res.status == 200 && res.data) {
980
928
  if (callback) {
@@ -988,7 +936,7 @@ class TiledeskChatbotUtil {
988
936
  }
989
937
  })
990
938
  .catch((error) => {
991
- console.error("(TiledeskChatbotUtil) Axios error: ", JSON.stringify(error));
939
+ winston.error("(TiledeskChatbotUtil) Axios error: ", error.response.data);
992
940
  if (callback) {
993
941
  callback(error, null, null);
994
942
  }