@tiledesk/tiledesk-tybot-connector 2.0.10-rc8 → 2.0.10

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 (86) hide show
  1. package/CHANGELOG.md +2 -27
  2. package/ExtApi.js +8 -1
  3. package/ExtUtil.js +6 -5
  4. package/Logger.js +17 -26
  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/app.log +43056 -4268
  15. package/logs/app1.log +41129 -0
  16. package/logs/app2.log +14567 -45594
  17. package/logs/app6.log +29039 -0
  18. package/logs/app7.log +4726 -0
  19. package/package.json +2 -3
  20. package/services/AIService.js +1 -1
  21. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +18 -38
  22. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +2 -1
  23. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +3 -1
  24. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +3 -1
  25. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +9 -7
  26. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +10 -3
  27. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +9 -2
  28. package/tiledeskChatbotPlugs/directives/DirAddTags.js +4 -16
  29. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +0 -16
  30. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +1 -0
  31. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +4 -17
  32. package/tiledeskChatbotPlugs/directives/DirAssign.js +8 -5
  33. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +3 -1
  34. package/tiledeskChatbotPlugs/directives/DirAssistant.js +1 -0
  35. package/tiledeskChatbotPlugs/directives/DirBrevo.js +6 -4
  36. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -0
  37. package/tiledeskChatbotPlugs/directives/DirClose.js +2 -0
  38. package/tiledeskChatbotPlugs/directives/DirCode.js +1 -0
  39. package/tiledeskChatbotPlugs/directives/DirCondition.js +1 -0
  40. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +1 -0
  41. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -1
  42. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +1 -0
  43. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +5 -2
  44. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +1 -0
  45. package/tiledeskChatbotPlugs/directives/DirDepartment.js +3 -1
  46. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +3 -1
  47. package/tiledeskChatbotPlugs/directives/DirForm.js +3 -1
  48. package/tiledeskChatbotPlugs/directives/DirGptTask.js +1 -0
  49. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +55 -36
  50. package/tiledeskChatbotPlugs/directives/DirHubspot.js +1 -0
  51. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +4 -1
  52. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +4 -1
  53. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -0
  54. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +12 -8
  55. package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -6
  56. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +1 -0
  57. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +1 -0
  58. package/tiledeskChatbotPlugs/directives/DirMake.js +16 -1
  59. package/tiledeskChatbotPlugs/directives/DirMessage.js +3 -1
  60. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +1 -0
  61. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -1
  62. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +3 -0
  63. package/tiledeskChatbotPlugs/directives/DirQapla.js +1 -0
  64. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +3 -1
  65. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -1
  66. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +3 -1
  67. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -1
  68. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +3 -1
  69. package/tiledeskChatbotPlugs/directives/DirReply.js +18 -7
  70. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +13 -8
  71. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +3 -1
  72. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +1 -0
  73. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +1 -0
  74. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +4 -1
  75. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +3 -1
  76. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +1 -0
  77. package/tiledeskChatbotPlugs/directives/DirWait.js +1 -0
  78. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -0
  79. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +19 -19
  80. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +417 -0
  81. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +40 -6
  82. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +1 -0
  83. package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
  84. package/utils/TiledeskChatbotUtil.js +57 -19
  85. package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +0 -331
  86. package/tiledeskChatbotPlugs/directives/DirFlowLog.js +0 -88
@@ -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
 
@@ -17,7 +17,7 @@ class DirReply {
17
17
  this.requestId = context.requestId;
18
18
  this.token = context.token;
19
19
  this.tdcache = context.tdcache;
20
- this.supportRequest = this.context.supportRequest;
20
+ this.log = context.log;
21
21
  this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
22
22
 
23
23
  this.API_ENDPOINT = context.API_ENDPOINT;
@@ -25,7 +25,8 @@ class DirReply {
25
25
  projectId: this.context.projectId,
26
26
  token: this.context.token,
27
27
  APIURL: this.API_ENDPOINT,
28
- APIKEY: "___"
28
+ APIKEY: "___",
29
+ log: this.log
29
30
  });
30
31
  }
31
32
 
@@ -43,10 +44,10 @@ class DirReply {
43
44
  callback();
44
45
  return;
45
46
  }
46
- this.logger.info("Executing Action Reply ", directive.action)
47
+ this.logger.info("1 Execute action reply for " + directive.action.text)
47
48
 
48
49
  this.go(action, () => {
49
- this.logger.info("Action Reply terminated")
50
+ this.logger.info("6 End of action reply " + directive.action.text + " -> callback")
50
51
  callback();
51
52
  });
52
53
  }
@@ -67,16 +68,15 @@ class DirReply {
67
68
  const filler = new Filler();
68
69
  // fill text attribute
69
70
  message.text = filler.fill(message.text, requestAttributes);
71
+ this.logger.info("2 Sending reply " + message.text);
70
72
 
71
73
  if (message.metadata) {
72
74
  winston.debug("DirReply filling message 'metadata':", message.metadata);
73
75
  if (message.metadata.src) {
74
76
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
75
- this.logger.debug("Filled metadata.src with ", message.metadata.src);
76
77
  }
77
78
  if (message.metadata.name) {
78
79
  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);
92
+ TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
93
93
  winston.debug("DirReply command filled: " + command.message.text);
94
94
  }
95
95
  if (command.type === 'settings' && command.settings) {
@@ -143,6 +143,15 @@ 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
+
146
155
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
147
156
  winston.debug("DirReply reply with clean message: ", cleanMessage);
148
157
 
@@ -153,8 +162,10 @@ class DirReply {
153
162
  (err) => {
154
163
  if (err) {
155
164
  winston.error("DirReply Error sending reply: ", err);
165
+ this.logger.error("Error sending reply: " + err);
156
166
  }
157
167
  winston.verbose("DirReply reply message sent")
168
+ this.logger.info("5 Reply message sent");
158
169
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
159
170
  if (delay > 0 && delay <= 30000) { // prevent long delays
160
171
  setTimeout(() => {
@@ -20,6 +20,7 @@ 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;
23
24
  this.intentDir = new DirIntent(context);
24
25
  this.chatbot = context.chatbot;
25
26
  this.reply = context.reply;
@@ -30,7 +31,8 @@ class DirReplyV2 {
30
31
  projectId: this.context.projectId,
31
32
  token: this.context.token,
32
33
  APIURL: this.API_ENDPOINT,
33
- APIKEY: "___"
34
+ APIKEY: "___",
35
+ log: this.log
34
36
  });
35
37
  }
36
38
 
@@ -59,10 +61,11 @@ class DirReplyV2 {
59
61
  const message = action;
60
62
 
61
63
  let current; // debug only
62
- if (message.attributes.commands[1].message.text) {
63
- current = message.attributes.commands[1].message.text
64
+ if (this.log) {
65
+ if (message.attributes.commands[1].message.text) {
66
+ current = message.attributes.commands[1].message.text
67
+ }
64
68
  }
65
-
66
69
  let must_stop = false;
67
70
  // fill
68
71
  let requestAttributes = null;
@@ -71,9 +74,11 @@ class DirReplyV2 {
71
74
  await TiledeskChatbot.allParametersStatic(
72
75
  this.tdcache, this.requestId
73
76
  );
74
- // for (const [key, value] of Object.entries(requestAttributes)) {
75
- // const value_type = typeof value;
76
- // }
77
+ if (this.log) {
78
+ for (const [key, value] of Object.entries(requestAttributes)) {
79
+ const value_type = typeof value;
80
+ }
81
+ }
77
82
 
78
83
  TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
79
84
 
@@ -192,7 +197,7 @@ class DirReplyV2 {
192
197
  let command = commands[i];
193
198
  if (command.type === 'message' && command.message && command.message.text) {
194
199
  command.message.text = filler.fill(command.message.text, requestAttributes);
195
- TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
200
+ TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
196
201
  }
197
202
  }
198
203
  }
@@ -15,13 +15,15 @@ class DirSendEmail {
15
15
  this.context = context;
16
16
  this.tdcache = context.tdcache;
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
 
@@ -19,6 +19,7 @@ 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;
22
23
  }
23
24
 
24
25
  execute(directive, callback) {
@@ -77,6 +77,7 @@ class DirSetAttribute {
77
77
  throw new Error('context object is mandatory.');
78
78
  }
79
79
  this.context = context;
80
+ this.log = context.log;
80
81
  }
81
82
 
82
83
  execute(directive, callback) {
@@ -79,6 +79,7 @@ class DirSetAttributeV2 {
79
79
  }
80
80
  this.context = context;
81
81
  this.tdcache = context.tdcache;
82
+ this.log = context.log;
82
83
  }
83
84
 
84
85
  execute(directive, callback) {
@@ -198,7 +199,9 @@ class DirSetAttributeV2 {
198
199
  httpUtils.request(
199
200
  HTTPREQUEST, async (err, resbody) => {
200
201
  if (err) {
201
- winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
202
+ if (this.log) {
203
+ winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
204
+ }
202
205
  } else {
203
206
  winston.debug("(DirSetAttributeV2) Attributes saved: ", resbody);
204
207
  }
@@ -9,6 +9,7 @@ class DirSetConversationTags {
9
9
  throw new Error('context object is mandatory.');
10
10
  }
11
11
  this.context = context;
12
+ this.log = context.log;
12
13
  this.requestId = context.requestId;
13
14
 
14
15
  this.API_ENDPOINT = context.API_ENDPOINT;
@@ -16,7 +17,8 @@ class DirSetConversationTags {
16
17
  projectId: this.context.projectId,
17
18
  token: this.context.token,
18
19
  APIURL: this.API_ENDPOINT,
19
- APIKEY: "___"
20
+ APIKEY: "___",
21
+ log: this.log
20
22
  });
21
23
  }
22
24
 
@@ -11,6 +11,7 @@ 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;
14
15
  }
15
16
 
16
17
  async execute(directive, callback) {
@@ -12,6 +12,7 @@ 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;
15
16
  }
16
17
 
17
18
  execute(directive, callback) {
@@ -13,6 +13,7 @@ class DirWebRequest {
13
13
  this.context = context;
14
14
  this.tdcache = context.tdcache;
15
15
  this.requestId = context.requestId;
16
+ this.log = context.log;
16
17
  }
17
18
 
18
19
  execute(directive, callback) {