@tiledesk/tiledesk-tybot-connector 2.0.8-rc2 → 2.0.8

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 (82) hide show
  1. package/CHANGELOG.md +5 -31
  2. package/ExtApi.js +8 -1
  3. package/ExtUtil.js +6 -5
  4. package/Logger.js +13 -30
  5. package/TdCache copy.js +242 -0
  6. package/engine/IntentForm.js +1 -0
  7. package/engine/IntentsMachineFactory.js +4 -4
  8. package/engine/MongodbBotsDataSource.js +1 -0
  9. package/engine/MongodbIntentsMachine.js +1 -0
  10. package/engine/TiledeskChatbot.js +16 -11
  11. package/engine/TiledeskIntentsMachine.js +2 -1
  12. package/engine/mock/MockBotsDataSource.js +2 -1
  13. package/index.js +25 -22
  14. package/logs/app1.log +1310 -0
  15. package/package.json +2 -3
  16. package/services/AIService.js +1 -1
  17. package/services/IntegrationService.js +1 -1
  18. package/services/TilebotService.js +1 -1
  19. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +18 -24
  20. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +2 -1
  21. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +3 -1
  22. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +3 -1
  23. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +9 -7
  24. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +10 -3
  25. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +9 -2
  26. package/tiledeskChatbotPlugs/directives/DirAddTags.js +3 -1
  27. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +1 -0
  28. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +1 -0
  29. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +1 -0
  30. package/tiledeskChatbotPlugs/directives/DirAssign.js +8 -5
  31. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +3 -1
  32. package/tiledeskChatbotPlugs/directives/DirAssistant.js +1 -0
  33. package/tiledeskChatbotPlugs/directives/DirBrevo.js +6 -4
  34. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -0
  35. package/tiledeskChatbotPlugs/directives/DirClose.js +2 -0
  36. package/tiledeskChatbotPlugs/directives/DirCode.js +1 -0
  37. package/tiledeskChatbotPlugs/directives/DirCondition.js +1 -0
  38. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +1 -0
  39. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -1
  40. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +1 -0
  41. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +5 -2
  42. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +1 -0
  43. package/tiledeskChatbotPlugs/directives/DirDepartment.js +3 -1
  44. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +3 -1
  45. package/tiledeskChatbotPlugs/directives/DirForm.js +3 -1
  46. package/tiledeskChatbotPlugs/directives/DirGptTask.js +1 -0
  47. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +55 -36
  48. package/tiledeskChatbotPlugs/directives/DirHubspot.js +1 -0
  49. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +4 -1
  50. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +4 -1
  51. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -0
  52. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +12 -8
  53. package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -6
  54. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +1 -0
  55. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +1 -0
  56. package/tiledeskChatbotPlugs/directives/DirMake.js +16 -1
  57. package/tiledeskChatbotPlugs/directives/DirMessage.js +3 -1
  58. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +1 -0
  59. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -1
  60. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +3 -0
  61. package/tiledeskChatbotPlugs/directives/DirQapla.js +1 -0
  62. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +3 -1
  63. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -1
  64. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +3 -1
  65. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -1
  66. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +3 -1
  67. package/tiledeskChatbotPlugs/directives/DirReply.js +18 -7
  68. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +13 -8
  69. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +3 -1
  70. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +1 -0
  71. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +1 -0
  72. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +4 -1
  73. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +3 -1
  74. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +1 -0
  75. package/tiledeskChatbotPlugs/directives/DirWait.js +1 -0
  76. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -0
  77. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +16 -1
  78. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +417 -0
  79. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +39 -0
  80. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +1 -0
  81. package/tiledeskChatbotPlugs/directives/Directives.js +0 -1
  82. package/utils/TiledeskChatbotUtil.js +57 -19
@@ -3,7 +3,6 @@ const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
3
3
  const { Filler } = require("../Filler");
4
4
  let https = require("https");
5
5
  const { DirIntent } = require("./DirIntent");
6
- const winston = require('../../utils/winston');
7
6
  const httpUtils = require("../../utils/HttpUtils");
8
7
  require('dotenv').config();
9
8
 
@@ -18,16 +17,17 @@ class DirGptTask {
18
17
  this.requestId = this.context.requestId;
19
18
  this.intentDir = new DirIntent(context);
20
19
  this.API_ENDPOINT = this.context.API_ENDPOINT;
20
+ this.log = context.log;
21
21
  }
22
22
 
23
23
  execute(directive, callback) {
24
- winston.verbose("Execute GptTask directive");
24
+ if (this.log) { console.log("GptTask directive: ", directive); }
25
25
  let action;
26
26
  if (directive.action) {
27
27
  action = directive.action;
28
28
  }
29
29
  else {
30
- winston.warn("DirGptTask Incorrect directive: ", directive);
30
+ console.error("Incorrect directive: ", JSON.stringify(directive));
31
31
  callback();
32
32
  return;
33
33
  }
@@ -37,9 +37,9 @@ class DirGptTask {
37
37
  }
38
38
 
39
39
  async go(action, callback) {
40
- winston.debug("(DirGptTask) Action: ", action);
40
+ if (this.log) { console.log("DirGptTask action:", JSON.stringify(action)); }
41
41
  if (!this.tdcache) {
42
- winston.error("(DirGptTask) Error: tdcache is mandatory");
42
+ console.error("Error: DirGptTask tdcache is mandatory");
43
43
  callback();
44
44
  return;
45
45
  }
@@ -49,16 +49,18 @@ class DirGptTask {
49
49
  let trueIntentAttributes = action.trueIntentAttributes;
50
50
  let falseIntentAttributes = action.falseIntentAttributes;
51
51
 
52
- winston.debug("(DirGptTask) trueIntent " + trueIntent)
53
- winston.debug("(DirGptTask) falseIntent " + falseIntent)
54
- winston.debug("(DirGptTask) trueIntentAttributes " + trueIntentAttributes)
55
- winston.debug("(DirGptTask) falseIntentAttributes " + falseIntentAttributes)
52
+ if (this.log) {
53
+ console.log("DirGptTask trueIntent", trueIntent)
54
+ console.log("DirGptTask falseIntent", falseIntent)
55
+ console.log("DirGptTask trueIntentAttributes", trueIntentAttributes)
56
+ console.log("DirGptTask falseIntentAttributes", falseIntentAttributes)
57
+ }
56
58
 
57
59
  // default value
58
60
  let answer = "No answer.";
59
61
 
60
62
  if (!action.question || action.question === '') {
61
- winston.debug("(DirGptTask) Error: question attribute is mandatory. Executing condition false...")
63
+ console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
62
64
  if (falseIntent) {
63
65
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
64
66
  callback(true);
@@ -80,11 +82,13 @@ class DirGptTask {
80
82
  let max_tokens = action.max_tokens;
81
83
  let temperature = action.temperature;
82
84
 
83
- winston.debug("(DirGptTask) max_tokens: " + max_tokens);
84
- winston.debug("(DirGptTask) temperature: " + temperature);
85
+ if (this.log) {
86
+ console.log("DirGptTask max_tokens: ", max_tokens);
87
+ console.log("DirGptTask temperature: ", temperature);
88
+ }
85
89
 
86
90
  const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
87
- winston.debug("(DirGptTask) openai_url ", openai_url);
91
+ if (this.log) { console.log("DirGptTask openai_url ", openai_url); }
88
92
 
89
93
  const INTEGRATIONS_HTTPREQUEST = {
90
94
  url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
@@ -94,7 +98,7 @@ class DirGptTask {
94
98
  },
95
99
  method: "GET"
96
100
  }
97
- winston.debug("(DirGptTask) INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST);
101
+ if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
98
102
 
99
103
  httpUtils.request(
100
104
  INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
@@ -106,7 +110,7 @@ class DirGptTask {
106
110
  // return;
107
111
  }
108
112
  } else if (callback) {
109
- winston.debug("(DirGptTask) get integration resbody: ", integration);
113
+ if (this.log) { console.log("DirGptTask get integration resbody: ", integration); }
110
114
 
111
115
  let key;
112
116
  if (integration &&
@@ -117,7 +121,8 @@ class DirGptTask {
117
121
  // key not present in integrations - for retro compatibility search in kbsettings
118
122
  if (!key) {
119
123
 
120
- winston.debug("(DirGptTask) Key not found in Integrations. Searching in kb settings...");
124
+ // if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings...")}
125
+ if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
121
126
 
122
127
  const KB_HTTPREQUEST = {
123
128
  url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
@@ -127,15 +132,16 @@ class DirGptTask {
127
132
  },
128
133
  method: "GET"
129
134
  }
130
- winston.debug("(DirGptTask) KB_HTTPREQUEST", KB_HTTPREQUEST);
135
+ if (this.log) { console.log("DirGptTask KB_HTTPREQUEST", KB_HTTPREQUEST); }
131
136
 
132
137
  httpUtils.request(
133
138
  KB_HTTPREQUEST, async (err, resbody) => {
134
139
  if (err) {
135
140
  if (callback) {
136
141
  console.error("(httprequest) DirGptTask Get KnowledgeBase err:", err.message);
137
- console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
138
-
142
+ if (this.log) {
143
+ console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
144
+ }
139
145
  await this.#assignAttributes(action, answer);
140
146
  if (falseIntent) {
141
147
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -146,7 +152,7 @@ class DirGptTask {
146
152
  return;
147
153
  }
148
154
  } else if (callback) {
149
- winston.debug("(DirGptTask) Get KnowledgeBase settings resbody:", resbody);
155
+ if (this.log) { console.log("DirGptTask Get KnowledgeBase settings resbody:", resbody); }
150
156
 
151
157
  if (!resbody.gptkey) {
152
158
  await this.#assignAttributes(action, answer);
@@ -160,7 +166,7 @@ class DirGptTask {
160
166
 
161
167
  } else {
162
168
 
163
- winston.debug("(DirGptTask) Key found in KbSettings");
169
+ if (this.log) { console.log("DirGptTask - Key found in KbSettings") };
164
170
 
165
171
  key = resbody.gptkey;
166
172
 
@@ -182,7 +188,7 @@ class DirGptTask {
182
188
  message.content = action.context;
183
189
  json.messages.unshift(message);
184
190
  }
185
- winston.debug("(DirGptTask) json: ", json);
191
+ if (this.log) { console.log("DirGptTask json: ", json) }
186
192
 
187
193
  const HTTPREQUEST = {
188
194
  url: openai_url,
@@ -193,12 +199,14 @@ class DirGptTask {
193
199
  json: json,
194
200
  method: 'POST'
195
201
  }
196
- winston.debug("(DirGptTask) HTTPREQUEST: ", HTTPREQUEST);
202
+ if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
197
203
  httpUtils.request(
198
204
  HTTPREQUEST, async (err, resbody) => {
199
205
  if (err) {
200
- console.error("(httprequest) DirGptTask openai err:", err);
201
- console.error("(httprequest) DirGptTask openai err:", err.response.data);
206
+ if (this.log) {
207
+ console.error("(httprequest) DirGptTask openai err:", err);
208
+ console.error("(httprequest) DirGptTask openai err:", err.response.data);
209
+ }
202
210
  await this.#assignAttributes(action, answer);
203
211
  if (falseIntent) {
204
212
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -208,7 +216,7 @@ class DirGptTask {
208
216
  callback();
209
217
  return;
210
218
  } else {
211
- winston.debug("(DirGptTask) resbody: ", JSON.stringify(resbody));
219
+ if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
212
220
  answer = resbody.choices[0].message.content;
213
221
  let answer_json = await this.convertToJson(answer);
214
222
  await this.#assignAttributes(action, answer_json);
@@ -228,7 +236,7 @@ class DirGptTask {
228
236
  )
229
237
  } else {
230
238
 
231
- winston.debug("(DirGptTask) Key found in Integrations");
239
+ if (this.log) { console.log("DirGptTask - Key found in Integrations") };
232
240
 
233
241
  let json = {
234
242
  "model": action.model,
@@ -248,7 +256,7 @@ class DirGptTask {
248
256
  message.content = action.context;
249
257
  json.messages.unshift(message);
250
258
  }
251
- winston.debug("(DirGptTask) json: ", json);
259
+ if (this.log) { console.log("DirGptTask json: ", json) }
252
260
 
253
261
  const HTTPREQUEST = {
254
262
  url: openai_url,
@@ -259,12 +267,14 @@ class DirGptTask {
259
267
  json: json,
260
268
  method: 'POST'
261
269
  }
262
- winston.debug("(DirGptTask) HTTPREQUEST: ", HTTPREQUEST);
270
+ if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
263
271
  httpUtils.request(
264
272
  HTTPREQUEST, async (err, resbody) => {
265
273
  if (err) {
266
- console.error("(httprequest) DirGptTask openai err:", err);
267
- console.error("(httprequest) DirGptTask openai err:", err.response.data);
274
+ if (this.log) {
275
+ console.error("(httprequest) DirGptTask openai err:", err);
276
+ console.error("(httprequest) DirGptTask openai err:", err.response.data);
277
+ }
268
278
  await this.#assignAttributes(action, answer);
269
279
  if (falseIntent) {
270
280
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -274,7 +284,7 @@ class DirGptTask {
274
284
  callback();
275
285
  return;
276
286
  } else {
277
- winston.debug("(DirGptTask) resbody: ", JSON.stringify(resbody));
287
+ if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
278
288
  answer = resbody.choices[0].message.content;
279
289
  // check if answer is a json
280
290
  let answer_json = await this.convertToJson(answer);
@@ -328,7 +338,7 @@ class DirGptTask {
328
338
  })
329
339
  }
330
340
  else {
331
- winston.debug("(DirGptTask) No trueIntentDirective specified");
341
+ if (this.log) { console.log("No trueIntentDirective specified"); }
332
342
  if (callback) {
333
343
  callback();
334
344
  }
@@ -343,7 +353,7 @@ class DirGptTask {
343
353
  });
344
354
  }
345
355
  else {
346
- winston.debug("(DirGptTask) No falseIntentDirective specified");
356
+ if (this.log) { console.log("No falseIntentDirective specified"); }
347
357
  if (callback) {
348
358
  callback();
349
359
  }
@@ -352,8 +362,10 @@ class DirGptTask {
352
362
  }
353
363
 
354
364
  async #assignAttributes(action, answer) {
355
- winston.debug("(DirGptTask) assignAttributes action:", action)
356
- winston.debug("(DirGptTask) assignAttributes answer:", answer)
365
+ if (this.log) {
366
+ console.log("assignAttributes action:", action)
367
+ console.log("assignAttributes answer:", answer)
368
+ }
357
369
  if (this.context.tdcache) {
358
370
  if (action.assignReplyTo && answer) {
359
371
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
@@ -361,6 +373,13 @@ class DirGptTask {
361
373
  // if (action.assignSourceTo && source) {
362
374
  // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
363
375
  // }
376
+ // Debug log
377
+ if (this.log) {
378
+ const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
379
+ for (const [key, value] of Object.entries(all_parameters)) {
380
+ if (this.log) { console.log("(gpttask) request parameter:", key, "value:", value, "type:", typeof value) }
381
+ }
382
+ }
364
383
  }
365
384
  }
366
385
 
@@ -20,6 +20,7 @@ class DirHubspot {
20
20
  this.token = this.context.token;
21
21
  this.intentDir = new DirIntent(context);
22
22
  this.API_ENDPOINT = this.context.API_ENDPOINT;
23
+ this.log = context.log;
23
24
  }
24
25
 
25
26
  execute(directive, callback) {
@@ -1,3 +1,4 @@
1
+ // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
3
  const { DirIntent } = require('./DirIntent');
3
4
  const ms = require('minimist-string');
@@ -13,12 +14,14 @@ class DirIfOnlineAgents {
13
14
  this.context = context;
14
15
  this.intentDir = new DirIntent(context);
15
16
  this.API_ENDPOINT = context.API_ENDPOINT;
17
+ this.log = context.log;
16
18
 
17
19
  this.tdClient = new TiledeskClient({
18
20
  projectId: this.context.projectId,
19
21
  token: this.context.token,
20
22
  APIURL: this.API_ENDPOINT,
21
- APIKEY: "___"
23
+ APIKEY: "___",
24
+ log: this.log
22
25
  });
23
26
  }
24
27
 
@@ -1,3 +1,4 @@
1
+ // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { DirIntent } = require('./DirIntent');
2
3
  const axios = require("axios").default;
3
4
  let https = require("https");
@@ -16,12 +17,14 @@ class DirIfOnlineAgentsV2 {
16
17
  this.chatbot = context.chatbot;
17
18
  this.intentDir = new DirIntent(context);
18
19
  this.API_ENDPOINT = context.API_ENDPOINT;
20
+ this.log = context.log;
19
21
 
20
22
  this.tdClient = new TiledeskClient({
21
23
  projectId: this.context.projectId,
22
24
  token: this.context.token,
23
25
  APIURL: this.API_ENDPOINT,
24
26
  APIKEY: "___",
27
+ log: this.log
25
28
  });
26
29
 
27
30
  }
@@ -203,7 +206,7 @@ class DirIfOnlineAgentsV2 {
203
206
  }
204
207
  resolve(resbody);
205
208
  }
206
- });
209
+ }, this.log);
207
210
  });
208
211
 
209
212
  }
@@ -1,3 +1,4 @@
1
+ // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  let axios = require('axios');
2
3
  const { DirIntent } = require('./DirIntent');
3
4
  let https = require("https");
@@ -15,6 +16,7 @@ class DirIfOpenHours {
15
16
  this.context = context;
16
17
  this.API_ENDPOINT = context.API_ENDPOINT;
17
18
  this.intentDir = new DirIntent(context);
19
+ this.log = context.log;
18
20
  }
19
21
 
20
22
  execute(directive, callback) {
@@ -1,7 +1,6 @@
1
1
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const { DirIntent } = require('./DirIntent');
3
3
  const ms = require('minimist-string');
4
- const winston = require('../../utils/winston');
5
4
 
6
5
  class DirIfOpenHours {
7
6
 
@@ -12,13 +11,15 @@ class DirIfOpenHours {
12
11
 
13
12
  this.context = context;
14
13
  this.intentDir = new DirIntent(context);
14
+ this.log = context.log;
15
15
 
16
16
  this.API_ENDPOINT = context.API_ENDPOINT;
17
17
  this.tdClient = new TiledeskClient({
18
18
  projectId: this.context.projectId,
19
19
  token: this.context.token,
20
20
  APIURL: this.API_ENDPOINT,
21
- APIKEY: "___"
21
+ APIKEY: "___",
22
+ log: this.log
22
23
  });
23
24
  }
24
25
 
@@ -31,6 +32,9 @@ class DirIfOpenHours {
31
32
  let params;
32
33
  params = this.parseParams(directive.parameter);
33
34
  if (!params.trueIntent && !params.falseIntent) {
35
+ if (this.log) {
36
+ console.log("missing both params.trueIntent & params.falseIntent");
37
+ }
34
38
  callback();
35
39
  return;
36
40
  }
@@ -62,14 +66,14 @@ class DirIfOpenHours {
62
66
  if (falseIntent && falseIntent.trim() === "") {
63
67
  falseIntent = null;
64
68
  }
65
- winston.verbose("(DirIfOpenHours) Action:", action);
69
+ if (this.log) {console.log("condition action:", action);}
66
70
  if (!trueIntent && !falseIntent) {
67
- winston.error("(DirIfOpenHours) Error: missing both action.trueIntent & action.falseIntent");
68
- callback();
71
+ if (this.log) {console.log("Invalid condition, no intents specified");}
72
+ callback();
69
73
  return;
70
74
  }
71
75
  this.tdClient.openNow((err, result) => {
72
- winston.error("(DirIfOpenHours) openNow():", result)
76
+ if (this.log) {console.log("openNow():", result);}
73
77
  if (err) {
74
78
  console.error("*** DirIfOpenHours Error:", err);
75
79
  callback();
@@ -77,7 +81,7 @@ class DirIfOpenHours {
77
81
  else if (result && result.isopen) {
78
82
  if (trueIntent) {
79
83
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
80
- winston.debug("(DirIfOpenHours) (openHours) => trueIntent ");
84
+ if (this.log) {console.log("DirIfOpenHours (openHours) => trueIntent");}
81
85
  this.intentDir.execute(intentDirective, () => {
82
86
  callback(stopOnConditionMet);
83
87
  });
@@ -89,7 +93,7 @@ class DirIfOpenHours {
89
93
  }
90
94
  else if (falseIntent) {
91
95
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
92
- winston.debug("(DirIfOpenHours) (openHours) => falseIntent ");
96
+ if (this.log) {console.log("DirIfOpenHours (openHours) => falseIntent", falseIntent);}
93
97
  this.intentDir.execute(intentDirective, () => {
94
98
  callback(stopOnConditionMet);
95
99
  });
@@ -16,6 +16,7 @@ class DirIntent {
16
16
  this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
17
17
  this.supportRequest = context.supportRequest;
18
18
  this.token = context.token;
19
+ this.log = context.log;
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
@@ -61,12 +62,10 @@ class DirIntent {
61
62
  "recipient": requestId,
62
63
  "text": intent_command,
63
64
  "id_project": projectId,
64
- "request": this.supportRequest,
65
- // "request": {
66
- // "request_id": requestId,
67
- // "id_project": projectId
68
- // // "bot_id": botId
69
- // }
65
+ "request": {
66
+ "request_id": requestId,
67
+ "id_project": projectId
68
+ }
70
69
  },
71
70
  "token": this.token
72
71
  }
@@ -13,6 +13,7 @@ class DirJSONCondition {
13
13
  this.chatbot = context.chatbot;
14
14
  this.chatbot = context.chatbot;
15
15
  this.intentDir = new DirIntent(context);
16
+ this.log = context.log;
16
17
  }
17
18
 
18
19
  execute(directive, callback) {
@@ -12,6 +12,7 @@ class DirLockIntent {
12
12
  throw new Error('tdcache (TdCache) object is mandatory.');
13
13
  }
14
14
  this.tdcache = this.context.tdcache;
15
+ this.log = context.log;
15
16
  }
16
17
 
17
18
  async execute(directive, callback) {
@@ -16,6 +16,7 @@ class DirMake {
16
16
  this.tdcache = this.context.tdcache;
17
17
  this.requestId = this.context.requestId;
18
18
  this.intentDir = new DirIntent(context);
19
+ this.log = context.log;
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
@@ -198,7 +199,21 @@ class DirMake {
198
199
 
199
200
  })
200
201
  .catch((err) => {
201
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
202
+ if (this.log) {
203
+ // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
204
+ let cache = [];
205
+ let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
206
+ if (typeof value === 'object' && value != null) {
207
+ if (cache.indexOf(value) !== -1) {
208
+ return;
209
+ }
210
+ cache.push(value);
211
+ }
212
+ return value;
213
+ });
214
+ winston.error("(DirMake) An error occurred: ", error_log);
215
+ // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
216
+ }
202
217
  if (callback) {
203
218
  let status = 1000;
204
219
  let cache = [];
@@ -16,13 +16,15 @@ class DirMessage {
16
16
  this.requestId = context.requestId;
17
17
  this.tdcache = this.context.tdcache;
18
18
  this.token = context.token;
19
+ this.log = this.context.log;
19
20
  this.supportRequest = this.context.supportRequest
20
21
 
21
22
  this.tdClient = new TiledeskClient({
22
23
  projectId: this.context.projectId,
23
24
  token: this.context.token,
24
25
  APIURL: this.API_ENDPOINT,
25
- APIKEY: "___"
26
+ APIKEY: "___",
27
+ log: this.log
26
28
  });
27
29
  }
28
30
 
@@ -15,6 +15,7 @@ class DirMessageToBot {
15
15
  this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
16
16
  this.supportRequest = context.supportRequest;
17
17
  this.token = context.token;
18
+ this.log = context.log;
18
19
  }
19
20
 
20
21
  execute(directive, callback) {
@@ -1,3 +1,4 @@
1
+ // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { Directives } = require('./Directives');
2
3
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
4
  const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
@@ -13,13 +14,15 @@ class DirMoveToAgent {
13
14
  this.context = context;
14
15
  this.tdcache = context.tdcache;
15
16
  this.requestId = context.requestId;
17
+ this.log = context.log;
16
18
 
17
19
  this.API_ENDPOINT = context.API_ENDPOINT;
18
20
  this.tdClient = new TiledeskClient({
19
21
  projectId: this.context.projectId,
20
22
  token: this.context.token,
21
23
  APIURL: this.API_ENDPOINT,
22
- APIKEY: "___"
24
+ APIKEY: "___",
25
+ log: this.log
23
26
  });
24
27
 
25
28
  }
@@ -1,3 +1,4 @@
1
+ // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { Directives } = require('./Directives');
2
3
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
4
  const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
@@ -12,6 +13,7 @@ class DirMoveToUnassigned {
12
13
  }
13
14
  this.context = context;
14
15
  this.requestId = context.requestId;
16
+ this.log = context.log;
15
17
 
16
18
  this.API_ENDPOINT = context.API_ENDPOINT;
17
19
  this.tdClient = new TiledeskClient({
@@ -19,6 +21,7 @@ class DirMoveToUnassigned {
19
21
  token: this.context.token,
20
22
  APIURL: this.API_ENDPOINT,
21
23
  APIKEY: "___",
24
+ log: this.log
22
25
  });
23
26
  }
24
27
 
@@ -21,6 +21,7 @@ class DirQapla {
21
21
  this.token = this.context.token;
22
22
  this.intentDir = new DirIntent(context);
23
23
  this.API_ENDPOINT = this.context.API_ENDPOINT;
24
+ this.log = context.log;
24
25
  }
25
26
 
26
27
  execute(directive, callback) {
@@ -15,13 +15,15 @@ class DirRandomReply {
15
15
  this.requestId = context.requestId;
16
16
  this.token = context.token;
17
17
  this.tdcache = context.tdcache;
18
+ this.log = context.log;
18
19
 
19
20
  this.API_ENDPOINT = context.API_ENDPOINT;
20
21
  this.tdClient = new TiledeskClient({
21
22
  projectId: this.context.projectId,
22
23
  token: this.context.token,
23
24
  APIURL: this.API_ENDPOINT,
24
- APIKEY: "___"
25
+ APIKEY: "___",
26
+ log: this.log
25
27
  });
26
28
  }
27
29
 
@@ -16,7 +16,8 @@ class DirRemoveCurrentBot {
16
16
  projectId: this.context.projectId,
17
17
  token: this.context.token,
18
18
  APIURL: this.API_ENDPOINT,
19
- APIKEY: "___"
19
+ APIKEY: "___",
20
+ log: this.log
20
21
  });
21
22
  }
22
23
 
@@ -11,13 +11,15 @@ class DirReplaceBot {
11
11
  }
12
12
  this.context = context;
13
13
  this.requestId = context.requestId;
14
+ this.log = context.log;
14
15
 
15
16
  this.API_ENDPOINT = context.API_ENDPOINT;
16
17
  this.tdClient = new TiledeskClient({
17
18
  projectId: this.context.projectId,
18
19
  token: this.context.token,
19
20
  APIURL: this.API_ENDPOINT,
20
- APIKEY: "___"
21
+ APIKEY: "___",
22
+ log: this.log
21
23
  });
22
24
  }
23
25
 
@@ -15,13 +15,15 @@ class DirReplaceBotV2 {
15
15
  }
16
16
  this.context = context;
17
17
  this.requestId = context.requestId;
18
+ this.log = context.log;
18
19
 
19
20
  this.API_ENDPOINT = context.API_ENDPOINT;
20
21
  this.tdClient = new TiledeskClient({
21
22
  projectId: this.context.projectId,
22
23
  token: this.context.token,
23
24
  APIURL: this.API_ENDPOINT,
24
- APIKEY: "___"
25
+ APIKEY: "___",
26
+ log: this.log
25
27
  });
26
28
  }
27
29
 
@@ -15,13 +15,15 @@ class DirReplaceBotV3 {
15
15
  }
16
16
  this.context = context;
17
17
  this.requestId = context.requestId;
18
+ this.log = context.log;
18
19
 
19
20
  this.API_ENDPOINT = context.API_ENDPOINT;
20
21
  this.tdClient = new TiledeskClient({
21
22
  projectId: this.context.projectId,
22
23
  token: this.context.token,
23
24
  APIURL: this.API_ENDPOINT,
24
- APIKEY: "___"
25
+ APIKEY: "___",
26
+ log: this.log
25
27
  });
26
28
  }
27
29