@tiledesk/tiledesk-tybot-connector 0.5.0 → 2.0.0

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 (100) hide show
  1. package/ExtApi.js +4 -83
  2. package/ExtUtil.js +0 -1
  3. package/Logger.js +105 -0
  4. package/TdCache.js +5 -3
  5. package/TiledeskClientTest.js +5 -28
  6. package/TiledeskExpression.js +6 -47
  7. package/{models → engine}/IntentForm.js +30 -44
  8. package/{models → engine}/IntentsMachineFactory.js +5 -4
  9. package/{models → engine}/MongodbBotsDataSource.js +31 -55
  10. package/{models → engine}/MongodbIntentsMachine.js +6 -5
  11. package/{models → engine}/TiledeskChatbot.js +82 -259
  12. package/{models → engine}/TiledeskChatbotConst.js +9 -0
  13. package/{models → engine}/TiledeskIntentsMachine.js +5 -15
  14. package/{models → engine/mock}/MockBotsDataSource.js +3 -19
  15. package/{models → engine/mock}/MockTdCache.js +0 -9
  16. package/index.js +103 -380
  17. package/logs/app.log +12723 -277
  18. package/logs/app1.log +62258 -0
  19. package/logs/app2.log +46280 -0
  20. package/logs/app3.log +31686 -0
  21. package/logs/app4.log +46163 -0
  22. package/logs/app5.log +33173 -0
  23. package/models/faq.js +2 -5
  24. package/package.json +5 -2
  25. package/{TiledeskServices → services}/AIService.js +4 -3
  26. package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
  27. package/{models/faqService.js → services/FaqService.js} +4 -3
  28. package/services/IntegrationService.js +43 -0
  29. package/services/TilebotService.js +47 -0
  30. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
  31. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
  32. package/tiledeskChatbotPlugs/Filler.js +0 -1
  33. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  34. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  35. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  36. package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
  37. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  38. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
  39. package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
  40. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
  41. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
  42. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
  43. package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
  44. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
  45. package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
  46. package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
  47. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
  48. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
  49. package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
  50. package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
  51. package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
  52. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
  53. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
  54. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
  55. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
  56. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
  57. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  58. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  59. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  60. package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
  61. package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
  62. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
  63. package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
  64. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  65. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
  66. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
  67. package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
  68. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
  69. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  70. package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
  71. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  72. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
  73. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
  74. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
  75. package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
  76. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
  77. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  78. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
  79. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
  80. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
  81. package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
  82. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
  83. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
  84. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
  85. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
  86. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
  87. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  88. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  89. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
  90. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
  91. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
  92. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
  93. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
  94. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
  95. package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
  96. package/utils/HttpUtils.js +128 -0
  97. package/{models → utils}/TiledeskChatbotUtil.js +164 -234
  98. package/utils/winston.js +42 -0
  99. package/TiledeskServices/utils.js +0 -99
  100. /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
@@ -1,10 +1,11 @@
1
1
  const axios = require("axios").default;
2
- const { TiledeskChatbot } = require("../../models/TiledeskChatbot");
2
+ const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
3
3
  const { Filler } = require("../Filler");
4
4
  const { DirIntent } = require("./DirIntent");
5
5
  let https = require("https");
6
6
  require('dotenv').config();
7
-
7
+ const winston = require('../../utils/winston');
8
+ const integrationService = require("../../services/IntegrationService");
8
9
 
9
10
  class DirBrevo {
10
11
 
@@ -15,19 +16,21 @@ class DirBrevo {
15
16
  this.context = context;
16
17
  this.tdcache = this.context.tdcache;
17
18
  this.requestId = this.context.requestId;
19
+ this.projectId = this.context.projectId;
20
+ this.token = this.context.token;
18
21
  this.intentDir = new DirIntent(context);
19
22
  this.API_ENDPOINT = this.context.API_ENDPOINT;
20
23
  this.log = context.log;
21
24
  }
22
25
 
23
26
  execute(directive, callback) {
24
- if (this.log) { console.log("DirBrevo directive: ", directive); }
27
+ winston.verbose("Execute DirBrevo directive");
25
28
  let action;
26
29
  if (directive.action) {
27
30
  action = directive.action;
28
31
  }
29
32
  else {
30
- console.error("DirBrevo Incorrect directive: ", JSON.stringify(directive));
33
+ winston.warn("(DirBrevo) Incorrect directive: ", directive);
31
34
  callback();
32
35
  return;
33
36
  }
@@ -37,9 +40,9 @@ class DirBrevo {
37
40
  }
38
41
 
39
42
  async go(action, callback) {
40
- if (this.log) { console.log("DirBrevo action:", JSON.stringify(action)); }
43
+ winston.debug("(DirBrevo) Action: ", action);
41
44
  if (!this.tdcache) {
42
- console.error("Error: DirBrevo tdcache is mandatory");
45
+ winston.error("(DirBrevo) Error: tdcache is mandatory");
43
46
  callback();
44
47
  return;
45
48
  }
@@ -49,12 +52,11 @@ class DirBrevo {
49
52
  let trueIntentAttributes = action.trueIntentAttributes;
50
53
  let falseIntentAttributes = action.falseIntentAttributes;
51
54
 
52
- if (this.log) {
53
- console.log("DirBrevo trueIntent", trueIntent)
54
- console.log("DirBrevo falseIntent", falseIntent)
55
- console.log("DirBrevo trueIntentAttributes", trueIntentAttributes)
56
- console.log("DirBrevo falseIntentAttributes", falseIntentAttributes)
57
- }
55
+ winston.debug("(DirBrevo) trueIntent " + trueIntent)
56
+ winston.debug("(DirBrevo) falseIntent " + falseIntent)
57
+ winston.debug("(DirBrevo) trueIntentAttributes " + trueIntentAttributes)
58
+ winston.debug("(DirBrevo) falseIntentAttributes " + falseIntentAttributes)
59
+
58
60
 
59
61
  let requestVariables = null;
60
62
  requestVariables =
@@ -64,25 +66,21 @@ class DirBrevo {
64
66
 
65
67
  //let token = action.token;
66
68
  let bodyParameters = action.bodyParameters;
67
- if (this.log) { console.log("DirBrevo bodyParameters: ", bodyParameters); }
69
+ winston.debug("(DirBrevo) bodyParameters: ", bodyParameters);
68
70
 
69
71
  if (!bodyParameters || bodyParameters === '') {
70
- if (this.log) { console.error("DirBrevo ERROR - bodyParameters is undefined or null or empty string") };
72
+ winston.error("(DirBrevo) Error: bodyParameters is undefined or null or empty string");
71
73
  callback();
72
74
  return;
73
75
  }
74
76
 
75
77
  const brevo_base_url = process.env.BREVO_ENDPOINT || "https://api.brevo.com/v3"
76
- if (this.log) { console.log("DirBrevo brevo_base_url ", brevo_base_url); }
78
+ winston.debug("(DirBrevo) brevo_base_url: " + brevo_base_url);
77
79
 
78
- let key = await this.getKeyFromIntegrations();
79
- if (this.log) { console.log('DirBrevo key Debug1: ', key) }
80
- // ONLY FOR DEBUG CANCELLARE!!!!!
81
- // if (process.env.BREVO_DEBUG == '1') {
82
- // key = process.env.BREVO_TOKEN;
83
- // }
80
+ let key = await integrationService.getKeyFromIntegrations(this.projectId, 'Brevo', this.token);
81
+ winston.debug("(DirBrevo) key: ", key)
84
82
  if (!key) {
85
- if (this.log) { console.log("DirBrevo - Key not found in Integrations."); }
83
+ winston.debug("(DirBrevo) - Key not found in Integrations.");
86
84
  if (falseIntent) {
87
85
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
88
86
  callback(true);
@@ -92,22 +90,22 @@ class DirBrevo {
92
90
 
93
91
  const filler = new Filler();
94
92
  for (const [key, value] of Object.entries(bodyParameters)) {
95
- if (this.log) { console.log("bodyParam:", key, "value:", value) }
93
+ winston.debug("(DirBrevo) bodyParam: " + key + " value: " + value)
96
94
  let filled_value = filler.fill(value, requestVariables);
97
95
  bodyParameters[key] = filled_value;
98
96
  }
99
- if (this.log) { console.log('DirBrevo bodyParameters filler: ', bodyParameters) }
97
+ winston.debug("(DirBrevo) bodyParameters filler: ", bodyParameters)
100
98
 
101
99
  // CREATE THE JSON FOR BREVO
102
100
  let brevo_email = '';
103
101
  let brevo_bodyParameters = {};
104
102
  for (const [key, value] of Object.entries(bodyParameters)) {
105
- if (this.log) { console.log("bodyParam:", key, "value:", value) }
103
+ winston.debug("(DirBrevo) bodyParam: " + key + " value: " + value)
106
104
  if (key === 'email') {brevo_email = value}
107
105
  else { brevo_bodyParameters[key] = value;}
108
106
  }
109
- if (this.log) { console.log('DirBrevo brevo_email: ', brevo_email) }
110
- if (this.log) { console.log('DirBrevo brevo_bodyParameters: ', brevo_bodyParameters) }
107
+ winston.debug("(DirBrevo) brevo_email: " + brevo_email)
108
+ winston.debug("(DirBrevo) brevo_bodyParameters: ", brevo_bodyParameters)
111
109
 
112
110
 
113
111
  let json = {
@@ -123,10 +121,9 @@ class DirBrevo {
123
121
  "info@mytest.com"
124
122
  ]
125
123
  }
126
- if (this.log) { console.log('DirBrevo key Debug2: ', key) }
127
- //----------------
128
- if (this.log) {console.log("DirBrevo brevo_base_url ",brevo_base_url);}
129
- if (this.log) { console.log('DirBrevo json: ', json) }
124
+
125
+ winston.debug("(DirBrevo) brevo_base_url: " + brevo_base_url);
126
+ winston.debug("(DirBrevo) json: ", json);
130
127
  const BREVO_HTTPREQUEST = {
131
128
  url: brevo_base_url + '/contacts',
132
129
  headers: {
@@ -137,16 +134,14 @@ class DirBrevo {
137
134
  json: json,
138
135
  method: "POST"
139
136
  }
140
- if (this.log) { console.log("DirBrevo BREVO_HTTPREQUEST", JSON.stringify(BREVO_HTTPREQUEST)); }
137
+ winston.debug("(DirBrevo) HttpRequest ", BREVO_HTTPREQUEST);
141
138
 
142
139
  this.#myrequest(
143
140
  BREVO_HTTPREQUEST, async (err, resbody) => {
144
141
  if (err) {
145
142
  if (callback) {
146
- if (this.log) {
147
- console.error("(httprequest) DirBrevo err response:", err.response)
148
- console.error("(httprequest) DirBrevo err data:", err.response.data)
149
- };
143
+ winston.debug("(DirBrevo) err response: ", err.response)
144
+ winston.debug("(DirBrevo) err data:", err.response.data)
150
145
 
151
146
  let result = null;
152
147
  let status = null;
@@ -164,9 +159,9 @@ class DirBrevo {
164
159
  }
165
160
 
166
161
  if (this.log) {
167
- console.error("(httprequest) DirBrevo err data result:", result); // CONTROLLA IL VALORE
168
- console.error("(httprequest) DirBrevo err data status:", status);
169
- console.error("(httprequest) DirBrevo err data error:", error);
162
+ winston.error("(DirBrevo) DirBrevo err data result:", result); // CONTROLLA IL VALORE
163
+ winston.error("(DirBrevo) DirBrevo err data status:", status);
164
+ winston.error("(DirBrevo) DirBrevo err data error:", error);
170
165
  }
171
166
 
172
167
  await this.#assignAttributes(action, status, result, error);
@@ -179,7 +174,7 @@ class DirBrevo {
179
174
  return;
180
175
  }
181
176
  } else if (callback) {
182
- if (this.log) { console.log("DirBrevo resbody: ", JSON.stringify(resbody, null, 2).slice(2, -1)); }
177
+ winston.debug("(DirBrevo) resbody: ", resbody);
183
178
 
184
179
  let status = 201;
185
180
  let error = null;
@@ -199,12 +194,10 @@ class DirBrevo {
199
194
  }
200
195
 
201
196
  async #assignAttributes(action, status, result, error) {
202
- if (this.log) {
203
- console.log("DirBrevo assignAttributes action:", action)
204
- console.log("DirBrevo assignAttributes status:", status)
205
- console.log("DirBrevo assignAttributes result:", result)
206
- console.log("DirBrevo assignAttributes error:", error)
207
- }
197
+ winston.debug("(DirBrevo) assignAttributes action: ", action)
198
+ winston.debug("(DirBrevo) assignAttributes status: " + status)
199
+ winston.debug("(DirBrevo) assignAttributes result: ", result)
200
+ winston.debug("(DirBrevo) assignAttributes error: ", error)
208
201
  if (this.context.tdcache) {
209
202
  if (action.assignStatusTo) {
210
203
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
@@ -215,22 +208,10 @@ class DirBrevo {
215
208
  if (action.assignErrorTo) {
216
209
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
217
210
  }
218
-
219
- // Debug log
220
- if (this.log) {
221
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
222
- for (const [key, value] of Object.entries(all_parameters)) {
223
- if (this.log) { console.log("DirBrevo request parameter:", key, "value:", value, "type:", typeof value) }
224
- }
225
- }
226
211
  }
227
212
  }
228
213
 
229
214
  #myrequest(options, callback) {
230
- if (this.log) {
231
- console.log("** API URL:", options.url);
232
- console.log("** Options:", JSON.stringify(options));
233
- }
234
215
  let axios_options = {
235
216
  url: options.url,
236
217
  method: options.method,
@@ -240,9 +221,6 @@ class DirBrevo {
240
221
  if (options.json !== null) {
241
222
  axios_options.data = options.json
242
223
  }
243
- if (this.log) {
244
- console.log("axios_options:", JSON.stringify(axios_options));
245
- }
246
224
  if (options.url.startsWith("https:")) {
247
225
  const httpsAgent = new https.Agent({
248
226
  rejectUnauthorized: false,
@@ -251,11 +229,6 @@ class DirBrevo {
251
229
  }
252
230
  axios(axios_options)
253
231
  .then((res) => {
254
- if (this.log) {
255
- console.log("Response for url:", options.url);
256
- console.log("Response headers:\n", JSON.stringify(res.headers));
257
- console.log("Response status:", JSON.stringify(res.status));
258
- }
259
232
  if (res && (res.status == 200 || res.status == 201) && res.data) {
260
233
  if (callback) {
261
234
  callback(null, res.data);
@@ -284,7 +257,6 @@ class DirBrevo {
284
257
  if (falseIntent) {
285
258
  falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
286
259
  }
287
- if (this.log) { console.log('DirBrevo executeCondition/result', result) }
288
260
  if (result === true) {
289
261
  if (trueIntentDirective) {
290
262
  this.intentDir.execute(trueIntentDirective, () => {
@@ -294,7 +266,7 @@ class DirBrevo {
294
266
  });
295
267
  }
296
268
  else {
297
- if (this.log) { console.log("No trueIntentDirective specified"); }
269
+ winston.debug("(DirBrevo) No trueIntentDirective specified");
298
270
  if (callback) {
299
271
  callback();
300
272
  }
@@ -309,45 +281,13 @@ class DirBrevo {
309
281
  });
310
282
  }
311
283
  else {
312
- if (this.log) { console.log("No falseIntentDirective specified"); }
284
+ winston.debug("(DirBrevo) No falseIntentDirective specified");
313
285
  if (callback) {
314
286
  callback();
315
287
  }
316
288
  }
317
289
  }
318
290
  }
319
-
320
- async getKeyFromIntegrations() {
321
- return new Promise((resolve) => {
322
-
323
- const INTEGRATIONS_HTTPREQUEST = {
324
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/Brevo",
325
- headers: {
326
- 'Content-Type': 'application/json',
327
- 'Authorization': 'JWT ' + this.context.token
328
- },
329
- method: "GET"
330
- }
331
- if (this.log) { console.log("Brevo INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
332
-
333
- this.#myrequest(
334
- INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
335
- if (err) {
336
- resolve(null);
337
- } else {
338
-
339
- if (integration &&
340
- integration.value) {
341
- resolve(integration.value.apikey)
342
- }
343
- else {
344
- resolve(null)
345
- }
346
- }
347
- })
348
- })
349
- }
350
-
351
291
  }
352
292
 
353
293
  module.exports = { DirBrevo }
@@ -1,6 +1,7 @@
1
1
  const { Filler } = require('../Filler');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { DirIntent } = require('./DirIntent');
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirCaptureUserReply {
6
7
  constructor(context) {
@@ -19,12 +20,13 @@ class DirCaptureUserReply {
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
23
+ winston.verbose("Execute CaptureUserReply directive");
22
24
  let action;
23
25
  if (directive.action) {
24
26
  action = directive.action;
25
27
  }
26
28
  else {
27
- console.error("Incorrect directive:", JSON.stringify(directive));
29
+ winston.warn("DirCaptureUserReply Incorrect directive: ", directive);
28
30
  callback();
29
31
  return;
30
32
  }
@@ -34,34 +36,23 @@ class DirCaptureUserReply {
34
36
  }
35
37
 
36
38
  async go(action, callback) {
39
+ winston.debug("(DirCaptureUserReply) Action: ", action);
37
40
  const goToIntent = action.goToIntent;
38
- // console.log("(DirCaptureUserReply) goToIntent:", goToIntent);
39
41
  let lockedAction = await this.chatbot.currentLockedAction(this.requestId);
40
- // console.log("(DirCaptureUserReply) lockedAction:", lockedAction);
41
42
  if (!lockedAction) {
42
- // console.log("(DirCaptureUserReply) !lockedAction");
43
43
  const intent_name = this.reply.attributes.intent_info.intent_name
44
- const actionId = action["_tdActionId"];
45
- // console.log("(DirCaptureUserReply) intent_name:", intent_name);
46
- // console.log("(DirCaptureUserReply) actionId:", actionId);
44
+ const actionId = action["_tdActionId"];;
47
45
  await this.chatbot.lockIntent(this.requestId, intent_name);
48
- // console.log("(DirCaptureUserReply) lockIntent");
49
46
  await this.chatbot.lockAction(this.requestId, actionId);
50
- // console.log("(DirCaptureUserReply) lockAction");
51
- // let _lockedAction = await this.chatbot.currentLockedAction(this.requestId);
52
- // let _lockedIntent = await this.chatbot.currentLockedIntent(this.requestId);
53
- // console.log("(DirCaptureUserReply) _lockedAction", _lockedAction)
54
- // console.log("(DirCaptureUserReply) _lockedIntent", _lockedIntent)
55
47
  callback();
56
48
  return;
57
49
  } else {
58
50
  try {
59
51
  await this.chatbot.unlockIntent(this.requestId);
60
52
  await this.chatbot.unlockAction(this.requestId);
61
- // console.log("unlo")
62
53
  }
63
54
  catch(e) {
64
- console.error("Error", e)
55
+ winston.error("(DirCaptureUserReply) Error: ", e)
65
56
  }
66
57
 
67
58
  }
@@ -69,13 +60,12 @@ class DirCaptureUserReply {
69
60
  const user_reply = this.message.text;
70
61
  if (this.context.tdcache) {
71
62
  if (action.assignResultTo) {
72
- if (this.log) {console.log("assign assignResultTo:", action.assignResultTo);}
63
+ winston.debug("(DirCaptureUserReply) assign assignResultTo: " + action.assignResultTo);
73
64
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignResultTo, user_reply);
74
65
  }
75
66
  }
76
67
 
77
68
  if (callback) {
78
- // console.log("(DirCaptureUserReply) #executeGoTo(goToIntent)", goToIntent)
79
69
  if (goToIntent) {
80
70
  this.#executeGoTo(goToIntent, () => {
81
71
  callback(); // continue the flow
@@ -88,7 +78,7 @@ class DirCaptureUserReply {
88
78
  }
89
79
  }
90
80
  catch(error) {
91
- console.error("error is", error);
81
+ winston.error("(DirCaptureUserReply) error: ", error);
92
82
  }
93
83
  }
94
84
 
@@ -1,5 +1,5 @@
1
1
 
2
- const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
2
+ const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
3
3
 
4
4
  class DirClearTranscript {
5
5
 
@@ -1,6 +1,7 @@
1
1
 
2
2
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
3
- const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
3
+ const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirClose {
6
7
 
@@ -24,9 +25,10 @@ class DirClose {
24
25
  }
25
26
 
26
27
  execute(directive, callback) {
28
+ winston.verbose("Execute Close directive");
27
29
  this.tdClient.closeRequest(this.requestId, async (err) => {
28
30
  if (err) {
29
- console.error("Error in 'close directive':", err);
31
+ winston.error("(DirClose) Error: ", err);
30
32
  }
31
33
  else {
32
34
  await this.chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT);
@@ -1,6 +1,7 @@
1
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
1
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
2
2
  const { TiledeskExpression } = require('../../TiledeskExpression');
3
3
  const { TiledeskRequestVariables } = require('../TiledeskRequestVariables');
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirCode {
6
7
 
@@ -13,11 +14,13 @@ class DirCode {
13
14
  }
14
15
 
15
16
  execute(directive, callback) {
17
+ winston.verbose("Execute Code directive");
16
18
  let action;
17
19
  if (directive.action) {
18
20
  action = directive.action
19
21
  }
20
22
  else {
23
+ winston.warn("DirCode Incorrect directive: ", directive);
21
24
  callback();
22
25
  return;
23
26
  }
@@ -28,10 +31,10 @@ class DirCode {
28
31
  }
29
32
 
30
33
  async go(action, callback) {
31
- // console.log("action.source:", action.source)
34
+ winston.debug("(DirCode) Action: ", action);
32
35
  const source_code = action.source;
33
36
  if (!source_code || source_code.trim() === "") {
34
- if (this.log) {console.log("Invalid source_code");}
37
+ winston.error("(DirCode) Invalid source_code");
35
38
  callback();
36
39
  return;
37
40
  }
@@ -44,44 +47,34 @@ class DirCode {
44
47
  await TiledeskChatbot.allParametersStatic(
45
48
  this.context.tdcache, this.context.requestId
46
49
  );
47
- if (this.log) {console.log("Attributes:", JSON.stringify(attributes))}
50
+ winston.debug("(DirCode) Attributes:", attributes)
48
51
  }
49
52
  else {
50
- console.error("(DirCode) No this.context.tdcache");
53
+ winston.error("(DirCode) No this.context.tdcache");
51
54
  callback();
52
55
  return;
53
56
  }
54
- // console.log("before variables:", variables);
55
- // for (const [key, value] of Object.entries(attributes)) {
56
- // script_context[key] = value;
57
- // }
57
+
58
58
  let variablesManager = new TiledeskRequestVariables(this.context.requestId, this.context.tdcache, attributes);
59
59
  script_context.context = variablesManager;
60
- // console.log("script_context:", script_context);
60
+
61
61
  const tdExpression = new TiledeskExpression();
62
- //console.log("tdExpression:", tdExpression.evaluateJavascriptExpression);
62
+
63
63
  try {
64
64
  const result = new TiledeskExpression().evaluateJavascriptExpression(source_code, script_context);
65
- // console.log("result:", result);
66
- // console.log("script_context.tiledeskVars:", script_context.tiledeskVars);
67
- for (const [key, value] of Object.entries(script_context.context.ops.set)) {
68
- // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
69
- // await variablesManager.set(key, value);
65
+
66
+ for (const [key, value] of Object.entries(script_context.context.ops.set)) {;
70
67
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
71
68
  }
72
- // if (this.log) {
73
- // let newvars_set = await variablesManager.all();
74
- // console.log("newvars_set:", newvars_set);
75
- // }
76
69
  for (const [key, value] of Object.entries(script_context.context.ops.del)) {
77
- // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
78
70
  await variablesManager.delete(key);
79
71
  }
72
+
80
73
  const newvars_del = await variablesManager.all();
81
- // console.log("newvars_del:", newvars_del);
74
+
82
75
  }
83
76
  catch(err) {
84
- console.error("(DirCode) An error occurred:", err);
77
+ winston.error("(DirCode) An error occurred: ", err);
85
78
  }
86
79
  callback();
87
80
  return;
@@ -1,7 +1,8 @@
1
1
  const { DirIntent } = require('./DirIntent');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { TiledeskExpression } = require('../../TiledeskExpression');
4
4
  const ms = require('minimist-string');
5
+ const winston = require('../../utils/winston');
5
6
 
6
7
  class DirCondition {
7
8
 
@@ -15,7 +16,7 @@ class DirCondition {
15
16
  }
16
17
 
17
18
  execute(directive, callback) {
18
- // console.log("Condition...")
19
+ winston.verbose("Execute Condition directive");
19
20
  let action;
20
21
  if (directive.action) {
21
22
  action = directive.action
@@ -34,6 +35,7 @@ class DirCondition {
34
35
  }
35
36
  }
36
37
  else {
38
+ winston.warn("DirCondition Incorrect directive: ", directive);
37
39
  callback();
38
40
  return;
39
41
  }
@@ -44,10 +46,12 @@ class DirCondition {
44
46
  }
45
47
 
46
48
  async go(action, callback) {
49
+ winston.debug("(DirCondition) Action: ", action);
47
50
  const scriptCondition = action.scriptCondition;
48
51
  const jsonCondition = action.jsonCondition;
49
- if (this.log) {console.log("scriptCondition:", scriptCondition);}
50
- if (this.log) {console.log("jsonCondition:", JSON.stringify(jsonCondition));}
52
+ winston.debug("(DirCondition) scriptCondition:", scriptCondition);
53
+ winston.debug("(DirCondition) jsonCondition:", jsonCondition);
54
+
51
55
  // const condition = action.condition;
52
56
  let trueIntent = action.trueIntent;
53
57
  let falseIntent = action.falseIntent;
@@ -58,24 +62,24 @@ class DirCondition {
58
62
  if (falseIntent && falseIntent.trim() === "") {
59
63
  falseIntent = null;
60
64
  }
61
- if (this.log) {console.log("condition action:", action);}
65
+ winston.debug("(DirCondition) condition action: ", action);
62
66
  if (!trueIntent && !falseIntent) {
63
- if (this.log) {console.log("Invalid condition, no intents specified");}
67
+ winston.error("(DirCondition) Invalid condition, no intents specified");
64
68
  callback();
65
69
  return;
66
70
  }
67
71
  if (scriptCondition === null && jsonCondition === null) {
68
- if (this.log) {console.log("Invalid condition, scriptCondition & jsonCondition null");}
72
+ winston.error("(DirCondition) Invalid condition, scriptCondition & jsonCondition null");
69
73
  callback();
70
74
  return;
71
75
  }
72
76
  if (scriptCondition !== null && scriptCondition.trim === "") {
73
- if (this.log) {console.log("Invalid condition, scriptCondition is empty");}
77
+ winston.error("(DirCondition) Invalid condition, scriptCondition is empty");
74
78
  callback();
75
79
  return;
76
80
  }
77
81
  else if (jsonCondition && jsonCondition.groups === null) {
78
- if (this.log) {console.log("Invalid jsonCondition, no groups:", JSON.stringify(jsonCondition));}
82
+ winston.error("(DirCondition) Invalid jsonCondition, no groups:", jsonCondition);
79
83
  callback();
80
84
  return;
81
85
  }
@@ -93,12 +97,12 @@ class DirCondition {
93
97
  await TiledeskChatbot.allParametersStatic(
94
98
  this.context.tdcache, this.context.requestId
95
99
  );
96
- if (this.log) {console.log("Variables:", JSON.stringify(variables))}
100
+ winston.debug("(DirCondition) Variables:", variables)
97
101
  }
98
102
  else {
99
- console.error("(DirCondition) No this.context.tdcache");
103
+ winston.error("(DirCondition) No this.context.tdcache");
100
104
  }
101
- if (this.log) {console.log("condition:", scriptCondition);}
105
+ winston.debug("(DirCondition) condition:", scriptCondition);
102
106
  // const result = await this.evaluateCondition(scriptCondition, variables);
103
107
  let result;
104
108
  if (scriptCondition) {
@@ -107,19 +111,17 @@ class DirCondition {
107
111
  }
108
112
  else if (jsonCondition) {
109
113
  const expression = TiledeskExpression.JSONGroupsToExpression(jsonCondition.groups, variables);
110
- // console.log("full json condition expression:", expression);
111
114
  result = new TiledeskExpression().evaluateStaticExpression(expression);
112
115
  }
113
- if (this.log) {console.log("executed condition:", scriptCondition, "result:", result);}
116
+ winston.debug("(DirCondition) executed condition: " + JSON.stringify(scriptCondition) + " result: " + JSON.stringify(result));
114
117
  if (result === true) {
115
118
  if (trueIntentDirective) {
116
119
  this.intentDir.execute(trueIntentDirective, () => {
117
- // console.log("result === true. stopOnConditionMet?", stopOnConditionMet);
118
120
  callback(stopOnConditionMet);
119
121
  });
120
122
  }
121
123
  else {
122
- if (this.log) {console.log("No trueIntentDirective specified");}
124
+ winston.debug("(DirCondition) No trueIntentDirective specified");
123
125
  callback();
124
126
  return;
125
127
  }
@@ -127,12 +129,11 @@ class DirCondition {
127
129
  else {
128
130
  if (falseIntentDirective) {
129
131
  this.intentDir.execute(falseIntentDirective, () => {
130
- // console.log("result === false. stopOnConditionMet?", stopOnConditionMet);
131
132
  callback(stopOnConditionMet);
132
133
  });
133
134
  }
134
135
  else {
135
- if (this.log) {console.log("No falseIntentDirective specified");}
136
+ winston.debug("(DirCondition) No falseIntentDirective specified");
136
137
  callback();
137
138
  return;
138
139
  }
@@ -141,14 +142,7 @@ class DirCondition {
141
142
 
142
143
  // async evaluateCondition(_condition, variables) {
143
144
  // let condition = _condition.replace("$", "$data.");
144
- // if (this.log) {
145
- // console.log("Evaluating expression:", condition);
146
- // console.log("With variables:", variables);
147
- // }
148
145
  // const result = new TiledeskExpression().evaluate(condition, variables)
149
- // if (this.log) {
150
- // console.log("Expression result:", result);
151
- // }
152
146
  // return result;
153
147
  // }
154
148