@tiledesk/tiledesk-tybot-connector 2.0.9 → 2.0.10-rc10

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 (88) hide show
  1. package/CHANGELOG.md +27 -2
  2. package/ExtApi.js +1 -8
  3. package/ExtUtil.js +5 -6
  4. package/Logger.js +28 -17
  5. package/engine/IntentForm.js +0 -1
  6. package/engine/IntentsMachineFactory.js +4 -4
  7. package/engine/MongodbBotsDataSource.js +0 -1
  8. package/engine/MongodbIntentsMachine.js +0 -1
  9. package/engine/TiledeskChatbot.js +11 -16
  10. package/engine/TiledeskIntentsMachine.js +1 -2
  11. package/engine/mock/MockBotsDataSource.js +1 -2
  12. package/index.js +22 -25
  13. package/logs/app.log +4727 -44700
  14. package/logs/app2.log +46280 -0
  15. package/logs/app3.log +31686 -0
  16. package/logs/app4.log +46163 -0
  17. package/logs/app5.log +39983 -0
  18. package/logs/app6.log +21337 -0
  19. package/package.json +3 -2
  20. package/services/AIService.js +1 -1
  21. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +38 -18
  22. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
  23. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
  24. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
  25. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
  26. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
  27. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
  28. package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +332 -0
  29. package/tiledeskChatbotPlugs/directives/DirAddTags.js +16 -4
  30. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +16 -0
  31. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +0 -1
  32. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +16 -0
  33. package/tiledeskChatbotPlugs/directives/DirAssign.js +5 -8
  34. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -3
  35. package/tiledeskChatbotPlugs/directives/DirAssistant.js +0 -1
  36. package/tiledeskChatbotPlugs/directives/DirBrevo.js +4 -6
  37. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +0 -1
  38. package/tiledeskChatbotPlugs/directives/DirClose.js +0 -2
  39. package/tiledeskChatbotPlugs/directives/DirCode.js +0 -1
  40. package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -1
  41. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
  42. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +1 -3
  43. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +0 -1
  44. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +2 -5
  45. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +0 -1
  46. package/tiledeskChatbotPlugs/directives/DirDepartment.js +1 -3
  47. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +1 -3
  48. package/tiledeskChatbotPlugs/directives/DirFlowLog.js +88 -0
  49. package/tiledeskChatbotPlugs/directives/DirForm.js +1 -3
  50. package/tiledeskChatbotPlugs/directives/DirGptTask.js +0 -1
  51. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -55
  52. package/tiledeskChatbotPlugs/directives/DirHubspot.js +0 -1
  53. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +1 -4
  54. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -4
  55. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -2
  56. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +8 -12
  57. package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -5
  58. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +0 -1
  59. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
  60. package/tiledeskChatbotPlugs/directives/DirMake.js +1 -16
  61. package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -3
  62. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
  63. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +1 -4
  64. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -3
  65. package/tiledeskChatbotPlugs/directives/DirQapla.js +0 -1
  66. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -3
  67. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -2
  68. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -3
  69. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +1 -3
  70. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +1 -3
  71. package/tiledeskChatbotPlugs/directives/DirReply.js +8 -19
  72. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -13
  73. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -3
  74. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +0 -1
  75. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
  76. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -4
  77. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +1 -3
  78. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
  79. package/tiledeskChatbotPlugs/directives/DirWait.js +0 -1
  80. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
  81. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +19 -19
  82. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +6 -40
  83. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +0 -1
  84. package/tiledeskChatbotPlugs/directives/Directives.js +3 -0
  85. package/utils/TiledeskChatbotUtil.js +19 -57
  86. package/TdCache copy.js +0 -242
  87. package/logs/app1.log +0 -16071
  88. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +0 -417
@@ -17,16 +17,15 @@ class DirReply {
17
17
  this.requestId = context.requestId;
18
18
  this.token = context.token;
19
19
  this.tdcache = context.tdcache;
20
- this.log = context.log;
21
- this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
20
+ this.supportRequest = this.context.supportRequest;
21
+ this.logger = new Logger({ request_id: this.requestId, dev: this.supportRequest.draft, intent_id: this.context.reply.attributes.intent_info.intent_id });
22
22
 
23
23
  this.API_ENDPOINT = context.API_ENDPOINT;
24
24
  this.tdClient = new TiledeskClient({
25
25
  projectId: this.context.projectId,
26
26
  token: this.context.token,
27
27
  APIURL: this.API_ENDPOINT,
28
- APIKEY: "___",
29
- log: this.log
28
+ APIKEY: "___"
30
29
  });
31
30
  }
32
31
 
@@ -44,10 +43,10 @@ class DirReply {
44
43
  callback();
45
44
  return;
46
45
  }
47
- this.logger.info("1 Execute action reply for " + directive.action.text)
46
+ this.logger.info("Executing Action Reply ", directive.action)
48
47
 
49
48
  this.go(action, () => {
50
- this.logger.info("6 End of action reply " + directive.action.text + " -> callback")
49
+ this.logger.info("Action Reply terminated")
51
50
  callback();
52
51
  });
53
52
  }
@@ -68,15 +67,16 @@ class DirReply {
68
67
  const filler = new Filler();
69
68
  // fill text attribute
70
69
  message.text = filler.fill(message.text, requestAttributes);
71
- this.logger.info("2 Sending reply " + message.text);
72
70
 
73
71
  if (message.metadata) {
74
72
  winston.debug("DirReply filling message 'metadata':", message.metadata);
75
73
  if (message.metadata.src) {
76
74
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
75
+ this.logger.debug("Filled metadata.src with ", message.metadata.src);
77
76
  }
78
77
  if (message.metadata.name) {
79
78
  message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
79
+ this.logger.debug("Filled metadata.name with ", message.metadata.name);
80
80
  }
81
81
  }
82
82
  winston.debug("DirReply filling commands'. Message:", message);
@@ -89,7 +89,7 @@ class DirReply {
89
89
  let command = commands[i];
90
90
  if (command.type === 'message' && command.message && command.message.text) {
91
91
  command.message.text = filler.fill(command.message.text, requestAttributes);
92
- TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
92
+ TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
93
93
  winston.debug("DirReply command filled: " + command.message.text);
94
94
  }
95
95
  if (command.type === 'settings' && command.settings) {
@@ -143,15 +143,6 @@ class DirReply {
143
143
  }
144
144
 
145
145
  let cleanMessage = message;
146
- this.logger.info("3 Sending reply (text) " + cleanMessage.text);
147
- this.logger.info("4 Sending reply with clean message " + JSON.stringify(cleanMessage));
148
- // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
149
- // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
150
- // console.log("invalid message", cleanMessage);
151
- // callback(); // cancel reply operation
152
- // return;
153
- // }
154
-
155
146
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
156
147
  winston.debug("DirReply reply with clean message: ", cleanMessage);
157
148
 
@@ -162,10 +153,8 @@ class DirReply {
162
153
  (err) => {
163
154
  if (err) {
164
155
  winston.error("DirReply Error sending reply: ", err);
165
- this.logger.error("Error sending reply: " + err);
166
156
  }
167
157
  winston.verbose("DirReply reply message sent")
168
- this.logger.info("5 Reply message sent");
169
158
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
170
159
  if (delay > 0 && delay <= 30000) { // prevent long delays
171
160
  setTimeout(() => {
@@ -20,7 +20,6 @@ class DirReplyV2 {
20
20
  this.requestId = context.requestId;
21
21
  this.token = context.token;
22
22
  this.tdcache = context.tdcache;
23
- this.log = context.log;
24
23
  this.intentDir = new DirIntent(context);
25
24
  this.chatbot = context.chatbot;
26
25
  this.reply = context.reply;
@@ -31,8 +30,7 @@ class DirReplyV2 {
31
30
  projectId: this.context.projectId,
32
31
  token: this.context.token,
33
32
  APIURL: this.API_ENDPOINT,
34
- APIKEY: "___",
35
- log: this.log
33
+ APIKEY: "___"
36
34
  });
37
35
  }
38
36
 
@@ -61,11 +59,10 @@ class DirReplyV2 {
61
59
  const message = action;
62
60
 
63
61
  let current; // debug only
64
- if (this.log) {
65
- if (message.attributes.commands[1].message.text) {
66
- current = message.attributes.commands[1].message.text
67
- }
62
+ if (message.attributes.commands[1].message.text) {
63
+ current = message.attributes.commands[1].message.text
68
64
  }
65
+
69
66
  let must_stop = false;
70
67
  // fill
71
68
  let requestAttributes = null;
@@ -74,11 +71,9 @@ class DirReplyV2 {
74
71
  await TiledeskChatbot.allParametersStatic(
75
72
  this.tdcache, this.requestId
76
73
  );
77
- if (this.log) {
78
- for (const [key, value] of Object.entries(requestAttributes)) {
79
- const value_type = typeof value;
80
- }
81
- }
74
+ // for (const [key, value] of Object.entries(requestAttributes)) {
75
+ // const value_type = typeof value;
76
+ // }
82
77
 
83
78
  TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
84
79
 
@@ -197,7 +192,7 @@ class DirReplyV2 {
197
192
  let command = commands[i];
198
193
  if (command.type === 'message' && command.message && command.message.text) {
199
194
  command.message.text = filler.fill(command.message.text, requestAttributes);
200
- TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
195
+ TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
201
196
  }
202
197
  }
203
198
  }
@@ -15,15 +15,13 @@ class DirSendEmail {
15
15
  this.context = context;
16
16
  this.tdcache = context.tdcache;
17
17
  this.requestId = context.requestId;
18
- this.log = context.log;
19
18
 
20
19
  this.API_ENDPOINT = context.API_ENDPOINT;
21
20
  this.tdClient = new TiledeskClient({
22
21
  projectId: this.context.projectId,
23
22
  token: this.context.token,
24
23
  APIURL: this.API_ENDPOINT,
25
- APIKEY: "___",
26
- log: this.log
24
+ APIKEY: "___"
27
25
  });
28
26
  }
29
27
 
@@ -19,7 +19,6 @@ class DirSendWhatsapp {
19
19
  this.requestId = this.context.requestId;
20
20
  this.intentDir = new DirIntent(context);
21
21
  this.API_ENDPOINT = this.context.API_ENDPOINT;
22
- this.log = context.log;
23
22
  }
24
23
 
25
24
  execute(directive, callback) {
@@ -77,7 +77,6 @@ class DirSetAttribute {
77
77
  throw new Error('context object is mandatory.');
78
78
  }
79
79
  this.context = context;
80
- this.log = context.log;
81
80
  }
82
81
 
83
82
  execute(directive, callback) {
@@ -79,7 +79,6 @@ class DirSetAttributeV2 {
79
79
  }
80
80
  this.context = context;
81
81
  this.tdcache = context.tdcache;
82
- this.log = context.log;
83
82
  }
84
83
 
85
84
  execute(directive, callback) {
@@ -199,9 +198,7 @@ class DirSetAttributeV2 {
199
198
  httpUtils.request(
200
199
  HTTPREQUEST, async (err, resbody) => {
201
200
  if (err) {
202
- if (this.log) {
203
- winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
204
- }
201
+ winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
205
202
  } else {
206
203
  winston.debug("(DirSetAttributeV2) Attributes saved: ", resbody);
207
204
  }
@@ -9,7 +9,6 @@ class DirSetConversationTags {
9
9
  throw new Error('context object is mandatory.');
10
10
  }
11
11
  this.context = context;
12
- this.log = context.log;
13
12
  this.requestId = context.requestId;
14
13
 
15
14
  this.API_ENDPOINT = context.API_ENDPOINT;
@@ -17,8 +16,7 @@ class DirSetConversationTags {
17
16
  projectId: this.context.projectId,
18
17
  token: this.context.token,
19
18
  APIURL: this.API_ENDPOINT,
20
- APIKEY: "___",
21
- log: this.log
19
+ APIKEY: "___"
22
20
  });
23
21
  }
24
22
 
@@ -11,7 +11,6 @@ class DirUnlockIntent {
11
11
  throw new Error('tdcache (TdCache) object is mandatory.');
12
12
  }
13
13
  this.tdcache = context.tdcache;
14
- this.log = context.log;
15
14
  }
16
15
 
17
16
  async execute(directive, callback) {
@@ -12,7 +12,6 @@ class DirWait {
12
12
  this.chatbot = context.chatbot;
13
13
  this.tdcache = context.tdcache;
14
14
  this.requestId = context.requestId;
15
- this.log = context.log;
16
15
  }
17
16
 
18
17
  execute(directive, callback) {
@@ -13,7 +13,6 @@ class DirWebRequest {
13
13
  this.context = context;
14
14
  this.tdcache = context.tdcache;
15
15
  this.requestId = context.requestId;
16
- this.log = context.log;
17
16
  }
18
17
 
19
18
  execute(directive, callback) {
@@ -4,6 +4,7 @@ const { Filler } = require('../Filler');
4
4
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
5
5
  const { DirIntent } = require('./DirIntent');
6
6
  const winston = require('../../utils/winston');
7
+ const { Logger } = require('../../Logger');
7
8
 
8
9
  class DirWebRequestV2 {
9
10
 
@@ -17,6 +18,7 @@ class DirWebRequestV2 {
17
18
  this.chatbot = context.chatbot;
18
19
  this.intentDir = new DirIntent(context);
19
20
  this.log = context.log;
21
+ this.logger = new Logger({ request_id: this.requestId, dev: this.supportRequest.draft, intent_id: this.context.reply.attributes.intent_info.intent_id });
20
22
  }
21
23
 
22
24
  execute(directive, callback) {
@@ -30,7 +32,9 @@ class DirWebRequestV2 {
30
32
  callback();
31
33
  return;
32
34
  }
35
+ this.logger.info("Executing WebRequest action ", directive.action)
33
36
  this.go(action, (stop) => {
37
+ this.logger.info("WebRequest action terminated")
34
38
  callback(stop);
35
39
  }).catch((err) => {
36
40
  // do not nothing
@@ -50,10 +54,10 @@ class DirWebRequestV2 {
50
54
  let trueIntentAttributes = action.trueIntentAttributes;
51
55
  let falseIntentAttributes = action.falseIntentAttributes;
52
56
 
53
- winston.debug("DirWebRequestV2 trueIntent " + trueIntent)
54
- winston.debug("DirWebRequestV2 falseIntent " + falseIntent)
55
- winston.debug("DirWebRequestV2 trueIntentAttributes " + trueIntentAttributes)
56
- winston.debug("DirWebRequestV2 falseIntentAttributes " + falseIntentAttributes)
57
+ winston.debug("DirWebRequestV2 trueIntent " + trueIntent)
58
+ winston.debug("DirWebRequestV2 falseIntent " + falseIntent)
59
+ winston.debug("DirWebRequestV2 trueIntentAttributes " + trueIntentAttributes)
60
+ winston.debug("DirWebRequestV2 falseIntentAttributes " + falseIntentAttributes)
57
61
 
58
62
  let requestAttributes = null;
59
63
  requestAttributes =
@@ -65,6 +69,7 @@ class DirWebRequestV2 {
65
69
  const url = filler.fill(action.url, requestAttributes);
66
70
 
67
71
  let headers = await this.getHeadersFromAction(action, filler, requestAttributes).catch( async (err) => {
72
+ this.logger.error("WebRequest: error getting headers");
68
73
  await this.chatbot.addParameter("flowError", "Error getting headers");
69
74
  if (falseIntent) {
70
75
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -76,6 +81,7 @@ class DirWebRequestV2 {
76
81
  });
77
82
 
78
83
  let json = await this.getJsonFromAction(action, filler, requestAttributes).catch( async (err) => {
84
+ this.logger.error("WebRequest: error parsing json body");
79
85
  await this.chatbot.addParameter("flowError", "Error parsing json body");
80
86
  if (falseIntent) {
81
87
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -107,8 +113,10 @@ class DirWebRequestV2 {
107
113
  let error = res.error;
108
114
  await this.#assignAttributes(action, resbody, status, error)
109
115
  winston.debug("DirWebRequestV2 resbody:", resbody);
116
+ this.logger.info("WebRequest resbody: ", resbody);
110
117
 
111
118
  if (err) {
119
+ this.logger.error("WebRequest error: ", err);
112
120
  winston.log("webRequest error: ", err);
113
121
  if (callback) {
114
122
  if (falseIntent) {
@@ -130,6 +138,8 @@ class DirWebRequestV2 {
130
138
  return;
131
139
  }
132
140
  else {
141
+ this.logger.warn("WebRequest status ", status);
142
+ this.logger.error("WebRequest error ", error);
133
143
  if (falseIntent) {
134
144
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
135
145
  callback(true);
@@ -228,6 +238,7 @@ class DirWebRequestV2 {
228
238
  }
229
239
  if (result === true) {
230
240
  if (trueIntentDirective) {
241
+ this.logger.info("WebRequest: executing true condition");
231
242
  this.intentDir.execute(trueIntentDirective, () => {
232
243
  if (callback) {
233
244
  callback();
@@ -235,6 +246,7 @@ class DirWebRequestV2 {
235
246
  });
236
247
  }
237
248
  else {
249
+ this.logger.info("WebRequest: no block connected to true condition");
238
250
  winston.debug("DirWebRequestV2 No trueIntentDirective specified");
239
251
  if (callback) {
240
252
  callback();
@@ -243,6 +255,7 @@ class DirWebRequestV2 {
243
255
  }
244
256
  else {
245
257
  if (falseIntentDirective) {
258
+ this.logger.info("WebRequest: executing false condition");
246
259
  this.intentDir.execute(falseIntentDirective, () => {
247
260
  if (callback) {
248
261
  callback();
@@ -250,6 +263,7 @@ class DirWebRequestV2 {
250
263
  });
251
264
  }
252
265
  else {
266
+ this.logger.info("WebRequest: no block connected to false condition");
253
267
  winston.debug("DirWebRequestV2 No falseIntentDirective specified");
254
268
  if (callback) {
255
269
  callback();
@@ -302,21 +316,7 @@ class DirWebRequestV2 {
302
316
  }
303
317
  })
304
318
  .catch((err) => {
305
- if (this.log) {
306
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
307
- let cache = [];
308
- let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
309
- if (typeof value === 'object' && value != null) {
310
- if (cache.indexOf(value) !== -1) {
311
- return;
312
- }
313
- cache.push(value);
314
- }
315
- return value;
316
- });
317
- winston.error("(DirWebRequestv2) An error occurred: ", error_log);
318
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
319
- }
319
+ // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
320
320
  if (callback) {
321
321
  let status = 1000;
322
322
  let cache = [];
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
4
4
  const winston = require('../../utils/winston');
5
5
  let axios = require('axios');
6
+ const { Logger } = require('../../Logger');
6
7
 
7
8
  class DirWebResponse {
8
9
 
@@ -15,7 +16,7 @@ class DirWebResponse {
15
16
  this.requestId = context.requestId;
16
17
  this.token = context.token;
17
18
  this.tdcache = context.tdcache;
18
- this.log = context.log;
19
+ this.logger = new Logger({ request_id: this.requestId, dev: this.supportRequest.draft, intent_id: this.context.reply.attributes.intent_info.intent_id });
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
@@ -29,8 +30,9 @@ class DirWebResponse {
29
30
  callback();
30
31
  return;
31
32
  }
33
+ this.logger.info("Executing WebResponse action ", directive.action)
32
34
  this.go(action, () => {
33
- // return stop true?
35
+ this.logger.info("WebResponse action terminated")
34
36
  callback();
35
37
  });
36
38
  }
@@ -59,6 +61,8 @@ class DirWebResponse {
59
61
  payload: json
60
62
  }
61
63
 
64
+ this.logger.debug("WebResponse payload: ", webResponse);
65
+
62
66
  const topic = `/webhooks/${this.requestId}`;
63
67
 
64
68
  try {
@@ -96,42 +100,4 @@ class DirWebResponse {
96
100
 
97
101
  }
98
102
 
99
-
100
-
101
- /**
102
- * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
103
- * /${TILEBOT_ROUTE}/ext/${botId}
104
- *
105
- * @param {Object} webResponse. The webhook response to send back
106
- * @param {Object} projectId. The projectId
107
- * @param {string} botId. Tiledesk botId
108
- * @param {string} token. User token
109
- */
110
- // function sendResponse(webResponse, projectId, botId, callback) {
111
- // const url = `${WEBHOOK_URL}/${projectId}/${botId}`;
112
- // const HTTPREQUEST = {
113
- // url: url,
114
- // headers: {
115
- // 'Content-Type': 'application/json'
116
- // },
117
- // json: webResponse,
118
- // method: 'POST'
119
- // };
120
- // myrequest(
121
- // HTTPREQUEST,
122
- // function (err, resbody) {
123
- // if (err) {
124
- // if (callback) {
125
- // callback(err);
126
- // }
127
- // }
128
- // else {
129
- // if (callback) {
130
- // callback(null, resbody);
131
- // }
132
- // }
133
- // }, false
134
- // );
135
- // }
136
-
137
103
  module.exports = { DirWebResponse };
@@ -13,7 +13,6 @@ class DirWhatsappByAttribute {
13
13
  }
14
14
  this.context = context;
15
15
  this.API_ENDPOINT = context.API_ENDPOINT;
16
- this.log = context.log;
17
16
  }
18
17
 
19
18
  execute(directive, callback) {
@@ -58,7 +58,10 @@ class Directives {
58
58
  static MOVE_TO_UNASSIGNED = "move_to_unassigned";
59
59
  static CONNECT_BLOCK = "connect_block";
60
60
  static ADD_TAGS = 'add_tags'
61
+ static WEBHOOK = 'webhook';
61
62
  static WEB_RESPONSE = "web_response";
63
+ static FLOW_LOG = "flow_log";
64
+ static ADD_KB_CONTENT = "add_kb_content";
62
65
 
63
66
  // static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
64
67
  // static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
@@ -252,24 +252,24 @@ class TiledeskChatbotUtil {
252
252
  }
253
253
  }
254
254
 
255
- static fillCommandAttachments(command, variables, log) {
256
- if (log) { winston.debug("(TiledeskChatbotUtils) Filling command button: ", command) }
255
+ static fillCommandAttachments(command, variables) {
256
+ winston.debug("(TiledeskChatbotUtils) Filling command button: ", command)
257
257
  if (command.message && command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0) {
258
258
  let buttons = command.message.attributes.attachment.buttons;
259
259
  const filler = new Filler();
260
260
  buttons.forEach(button => {
261
261
  if (button.link) {
262
262
  button.link = filler.fill(button.link, variables);
263
- if (log) { winston.debug("(TiledeskChatbotUtils) button.link filled: " + button.link) }
263
+ winston.debug("(TiledeskChatbotUtils) button.link filled: " + button.link)
264
264
  }
265
265
  if (button.value) {
266
266
  button.value = filler.fill(button.value, variables);
267
- if (log) { winston.debug("(TiledeskChatbotUtils) button.value filled: " + button.value) }
267
+ winston.debug("(TiledeskChatbotUtils) button.value filled: " + button.value)
268
268
  }
269
269
  });
270
270
  }
271
271
  else {
272
- if (log) { winston.debug("(TiledeskChatbotUtils) No attachments to fill in command") }
272
+ winston.debug("(TiledeskChatbotUtils) No attachments to fill in command")
273
273
  }
274
274
  }
275
275
 
@@ -319,55 +319,31 @@ class TiledeskChatbotUtil {
319
319
  json_buttons.forEach(button => {
320
320
  if (button.value && button.type === "action" && button.action) {
321
321
  button.show_echo = true;
322
- // console.log("pushing:", button)
323
322
  final_buttons.push(button);
324
323
  }
325
324
  else if (button.value && button.type === "text") {
326
325
  button.show_echo = true;
327
- // console.log("pushing:", button)
328
326
  final_buttons.push(button);
329
327
  }
330
328
  else if (button.value && button.type === "url" && button.link) {
331
329
  button.show_echo = true;
332
- // console.log("pushing:", button)
333
330
  final_buttons.push(button);
334
331
  }
335
332
  else {
336
- console.log("Invalid button. Skipping:", JSON.stringify(button) );
333
+ winston.verbose("Invalid button. Skipping:", button);
337
334
  }
338
335
  });
339
336
  }
340
-
341
- // "buttons": [
342
- // {
343
- // "type": "action",
344
- // "value": "Button1", // obbligatorio sempre
345
- // "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
346
- // "show_echo": true, // lo inserisco sempre
347
- // "alias": "button1 alias"
348
- // },
349
- // {
350
- // "type": "text",
351
- // "value": "Button2 text", // obbligatorio sempre
352
- // "show_echo": true // lo inserisco sempre
353
- // },
354
- // {
355
- // "type": "url",
356
- // "value": "Button3 link", // obbligatorio sempre
357
- // "link": "http://", // obbligatorio
358
- // "show_echo": true // lo inserisco sempre
359
- // }
360
- // ]
361
337
  }
362
338
  catch(error) {
363
- console.error("Invalid json_buttons:", error)
339
+ winston.warn("Invalid json_buttons:", error)
364
340
  }
365
341
  if (final_buttons && final_buttons.length > 0) {
366
342
  command.message.attributes.attachment.buttons = final_buttons;
367
343
  delete command.message.attributes.attachment.json_buttons;
368
344
  }
369
345
  else {
370
- console.log("Invalid json_buttons. Skipping")
346
+ winston.verbose("Invalid json_buttons. Skipping...")
371
347
  }
372
348
  }
373
349
  }
@@ -520,7 +496,7 @@ class TiledeskChatbotUtil {
520
496
  static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
521
497
  // update request context
522
498
  try {
523
- if (chatbot.log) { winston.debug("Updating request variables. Message:", message); }
499
+ winston.debug("Updating request variables. Message:", message);
524
500
  const messageId = message._id;
525
501
  const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
526
502
 
@@ -591,12 +567,12 @@ class TiledeskChatbotUtil {
591
567
  }
592
568
 
593
569
  if (message && message.request && message.request.lead) {
594
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname); }
570
+ winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname);
595
571
  let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
596
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
572
+ winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
597
573
  if (message.request.lead.email && !currentLeadEmail) {
598
574
  // worth saving
599
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
575
+ winston.debug("(TiledeskChatbotUtil) worth saving email");
600
576
  try {
601
577
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
602
578
  }
@@ -605,10 +581,10 @@ class TiledeskChatbotUtil {
605
581
  }
606
582
  }
607
583
  let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
608
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
584
+ winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
609
585
  if (message.request.lead.fullname && !currentLeadName) {
610
586
  // worth saving
611
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
587
+ winston.debug("(TiledeskChatbotUtil) worth saving email");
612
588
  try {
613
589
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
614
590
  }
@@ -685,10 +661,10 @@ class TiledeskChatbotUtil {
685
661
  message.attributes = {}
686
662
  }
687
663
  message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
688
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload); }
664
+ winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload);
689
665
  }
690
666
  if (message.attributes) {
691
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes); }
667
+ winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes);
692
668
 
693
669
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
694
670
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
@@ -722,12 +698,12 @@ class TiledeskChatbotUtil {
722
698
 
723
699
 
724
700
  const _bot = chatbot.bot; // aka FaqKB
725
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot); }
701
+ winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot);
726
702
 
727
703
  if (_bot.attributes && _bot.attributes.globals) {
728
- if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals); }
704
+ winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals);
729
705
  _bot.attributes.globals.forEach(async (global_var) => {
730
- if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value); }
706
+ winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value);
731
707
  await chatbot.addParameter(global_var.key, global_var.value);
732
708
  });
733
709
  }
@@ -740,20 +716,6 @@ class TiledeskChatbotUtil {
740
716
  // }
741
717
  // );
742
718
 
743
- if (chatbot.log) {
744
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) requestId: " + requestId); }
745
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Key: " + TiledeskChatbotConst.REQ_PROJECT_ID_KEY); }
746
-
747
- let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
748
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) request parameter proj_: " + proj_); }
749
-
750
- const all_parameters = await chatbot.allParameters();
751
- for (const [key, value] of Object.entries(all_parameters)) {
752
- const value_type = typeof value;
753
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Request Attribute: " + key + " value: " + value + " type: " + value_type); }
754
-
755
- }
756
- }
757
719
  } catch(error) {
758
720
  winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
759
721
  process.exit(1)