@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,9 +1,10 @@
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
+ const winston = require('../../utils/winston');
7
8
 
8
9
  class DirMake {
9
10
 
@@ -19,13 +20,13 @@ class DirMake {
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
22
- if (this.log) { console.log("DirMake directive: ", directive); }
23
+ winston.verbose("Execute Make directive");
23
24
  let action;
24
25
  if (directive.action) {
25
26
  action = directive.action;
26
27
  }
27
28
  else {
28
- console.error("DirMake Incorrect directive: ", JSON.stringify(directive));
29
+ winston.warn("DirMake Incorrect directive: ", directive);
29
30
  callback();
30
31
  return;
31
32
  }
@@ -35,9 +36,9 @@ class DirMake {
35
36
  }
36
37
 
37
38
  async go(action, callback) {
38
- if (this.log) { console.log("DirMake action:", JSON.stringify(action)); }
39
+ winston.debug("(DirMake) Action: ", action);
39
40
  if (!this.tdcache) {
40
- console.error("Error: DirMake tdcache is mandatory");
41
+ winston.error("(DirMake) Error: tdcache is mandatory");
41
42
  callback();
42
43
  return;
43
44
  }
@@ -47,13 +48,6 @@ class DirMake {
47
48
  let trueIntentAttributes = action.trueIntentAttributes;
48
49
  let falseIntentAttributes = action.falseIntentAttributes;
49
50
 
50
- if (this.log) {
51
- console.log("DirMake trueIntent", trueIntent)
52
- console.log("DirMake falseIntent", falseIntent)
53
- console.log("DirMake trueIntentAttributes", trueIntentAttributes)
54
- console.log("DirMake falseIntentAttributes", falseIntentAttributes)
55
- }
56
-
57
51
  // default values?
58
52
  let status = null;
59
53
  let error = null;
@@ -67,13 +61,10 @@ class DirMake {
67
61
  let webhook_url = action.url;
68
62
  let bodyParameters = action.bodyParameters;
69
63
 
70
- if (this.log) {
71
- console.log("DirMake webhook_url: ", webhook_url);
72
- console.log("DirMake bodyParameters: ", JSON.stringify(bodyParameters));
73
- }
64
+ winston.debug("(DirMake) webhook_url: " + webhook_url);
74
65
 
75
66
  if (!bodyParameters) {
76
- console.error("Error: DirMake bodyParameters is undefined");
67
+ winston.error("(DirMake) Error: bodyParameters is undefined");
77
68
  error = "Missing body parameters";
78
69
  await this.#assignAttributes(action, status, error);
79
70
  if (falseIntent) {
@@ -86,7 +77,7 @@ class DirMake {
86
77
  }
87
78
 
88
79
  if (!webhook_url || webhook_url === '') {
89
- if (this.log) {console.error("DirMake ERROR - webhook_url is undefined or null or empty string:")};
80
+ winston.error("(DirMake) Error: webhook_url is undefined or null or empty string:")
90
81
  let status = 422;
91
82
  let error = 'Missing make webhook url';
92
83
  await this.#assignAttributes(action, status, error);
@@ -111,14 +102,12 @@ class DirMake {
111
102
  } else {
112
103
  url = action.url;
113
104
  }
114
- if (this.log) { console.log("DirMake MakeEndpoint URL: ", url); }
115
105
 
116
106
  const filler = new Filler();
117
107
  for (const [key, value] of Object.entries(bodyParameters)) {
118
108
  let filled_value = filler.fill(value, requestVariables);
119
109
  bodyParameters[key] = filled_value;
120
110
  }
121
- if (this.log) { console.log('DirMake bodyParameters filler: ', bodyParameters) }
122
111
 
123
112
  const MAKE_HTTPREQUEST = {
124
113
  url: url,
@@ -128,12 +117,12 @@ class DirMake {
128
117
  json: bodyParameters,
129
118
  method: "POST"
130
119
  }
131
- if (this.log) { console.log("DirMake MAKE_HTTPREQUEST", MAKE_HTTPREQUEST); }
120
+ winston.debug("(DirMake) Make HttpRequest ", MAKE_HTTPREQUEST);
132
121
  this.#myrequest(
133
122
  MAKE_HTTPREQUEST, async (err, res) => {
134
123
  if (err) {
135
124
  if (callback) {
136
- console.error("(httprequest) DirMake err:", err);
125
+ winston.error("(DirMake) err: ", err);
137
126
  // let status = 404;
138
127
  // let error = 'Make url not found';
139
128
  status = res.status;
@@ -148,9 +137,8 @@ class DirMake {
148
137
  return;
149
138
  }
150
139
  } else if (callback) {
151
- if (this.log) { console.log("(httprequest) DirMake resbody ", res); }
152
- // let status = 200;
153
- // let error = null;
140
+ winston.debug("(DirMake) resbody ", res);
141
+
154
142
  status = res.status;
155
143
  error = null;
156
144
  if (res.error) {
@@ -171,11 +159,10 @@ class DirMake {
171
159
  }
172
160
 
173
161
  async #assignAttributes(action, status, error) {
174
- if (this.log) {
175
- console.log("DirMake assignAttributes action:", action)
176
- console.log("DirMake assignAttributes status:", status)
177
- console.log("DirMake assignAttributes error:", error)
178
- }
162
+ winston.debug("(DirMake) assignAttributes action: ", action)
163
+ winston.debug("(DirMake) assignAttributes status: " + status)
164
+ winston.debug("(DirMake) assignAttributes error: ", error)
165
+
179
166
  if (this.context.tdcache) {
180
167
  if (action.assignStatusTo) {
181
168
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
@@ -183,23 +170,11 @@ class DirMake {
183
170
  if (action.assignErrorTo) {
184
171
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
185
172
  }
186
-
187
- // Debug log
188
- if (this.log) {
189
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
190
- for (const [key, value] of Object.entries(all_parameters)) {
191
- if (this.log) { console.log("DirMake request parameter:", key, "value:", value, "type:", typeof value) }
192
- }
193
- }
194
173
  }
195
174
  }
196
175
 
197
176
  // Advanced #myrequest function
198
177
  #myrequest(options, callback) {
199
- if (this.log) {
200
- console.log("API URL:", options.url);
201
- console.log("** Options:", JSON.stringify(options));
202
- }
203
178
  let axios_options = {
204
179
  url: options.url,
205
180
  method: options.method,
@@ -210,9 +185,6 @@ class DirMake {
210
185
  if (options.json !== null) {
211
186
  axios_options.data = options.json
212
187
  }
213
- if (this.log) {
214
- console.log("axios_options:", JSON.stringify(axios_options));
215
- }
216
188
  if (options.url.startsWith("https:")) {
217
189
  const httpsAgent = new https.Agent({
218
190
  rejectUnauthorized: false,
@@ -221,10 +193,6 @@ class DirMake {
221
193
  }
222
194
  axios(axios_options)
223
195
  .then((res) => {
224
- if (this.log) {
225
- console.log("Response for url:", options.url);
226
- console.log("Response headers:\n", JSON.stringify(res.headers));
227
- }
228
196
  if (callback) {
229
197
  callback(null, res);
230
198
  }
@@ -243,8 +211,8 @@ class DirMake {
243
211
  }
244
212
  return value;
245
213
  });
246
- console.error("(DirMake) An error occurred: ", error_log);
247
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
214
+ winston.error("(DirMake) An error occurred: ", error_log);
215
+ // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
248
216
  }
249
217
  if (callback) {
250
218
  let status = 1000;
@@ -295,7 +263,7 @@ class DirMake {
295
263
  });
296
264
  }
297
265
  else {
298
- if (this.log) { console.log("No trueIntentDirective specified"); }
266
+ winston.debug("(DirMake) No trueIntentDirective specified");
299
267
  if (callback) {
300
268
  callback();
301
269
  }
@@ -310,7 +278,7 @@ class DirMake {
310
278
  });
311
279
  }
312
280
  else {
313
- if (this.log) { console.log("No falseIntentDirective specified"); }
281
+ winston.debug("(DirMake) No falseIntentDirective specified");
314
282
  if (callback) {
315
283
  callback();
316
284
  }
@@ -1,5 +1,8 @@
1
- const { ExtApi } = require('../../ExtApi.js');
2
1
  const { Directives } = require('./Directives.js');
2
+ const { TiledeskClient } = require("@tiledesk/tiledesk-client");
3
+ const { TiledeskChatbot } = require("../../engine/TiledeskChatbot.js");
4
+ const { Filler } = require("../Filler");
5
+ const winston = require('../../utils/winston');
3
6
 
4
7
  class DirMessage {
5
8
 
@@ -8,20 +11,28 @@ class DirMessage {
8
11
  throw new Error('context object is mandatory.');
9
12
  }
10
13
  this.context = context;
11
- this.API_ENDPOINT = context.API_ENDPOINT,
12
- this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
14
+ this.API_ENDPOINT = context.API_ENDPOINT
13
15
  this.projectId = context.projectId;
14
16
  this.requestId = context.requestId;
17
+ this.tdcache = this.context.tdcache;
15
18
  this.token = context.token;
16
19
  this.log = this.context.log;
17
20
  this.supportRequest = this.context.supportRequest
21
+
22
+ this.tdClient = new TiledeskClient({
23
+ projectId: this.context.projectId,
24
+ token: this.context.token,
25
+ APIURL: this.API_ENDPOINT,
26
+ APIKEY: "___",
27
+ log: this.log
28
+ });
18
29
  }
19
30
 
20
31
  execute(directive, callback) {
32
+ winston.verbose("Execute Message directive");
21
33
  let action;
22
34
  if (directive.action) {
23
35
  action = directive.action;
24
- if (this.log) {console.log("got action:", JSON.stringify(action));}
25
36
  if (!action.attributes) {
26
37
  action.attributes = {}
27
38
  }
@@ -44,7 +55,6 @@ class DirMessage {
44
55
  // action.body.message.type = "text";
45
56
  // }
46
57
  // }
47
- // console.log("final message action:", JSON.stringify(action));
48
58
  }
49
59
  // DEPRECATED
50
60
  else if (directive.parameter) {
@@ -68,7 +78,7 @@ class DirMessage {
68
78
  // }
69
79
  }
70
80
  else {
71
- console.error("Incorrect directive:", directive);
81
+ winston.warn("DirMessage Incorrect directive: ", directive);
72
82
  callback();
73
83
  return;
74
84
  }
@@ -82,10 +92,10 @@ class DirMessage {
82
92
  });
83
93
  }
84
94
 
85
- go(action, callback) {
86
- // const message = action.body.message;
95
+ async go(action, callback) {
96
+ winston.debug("(DirMessage) Action: ", action);
87
97
  const message = action;
88
- if (this.log) {console.log("Message to extEndpoint:", JSON.stringify(message))};
98
+ winston.debug("(DirMessage) Message to extEndpoint:", message);
89
99
 
90
100
  if(!action.isInfo && this.supportRequest && !this.supportRequest.draft){
91
101
  callback();
@@ -98,25 +108,27 @@ class DirMessage {
98
108
  // return;
99
109
  // }
100
110
  // }
101
-
102
- const apiext = new ExtApi({
103
- TILEBOT_ENDPOINT: this.TILEBOT_ENDPOINT,
104
- log: false
105
- });
106
111
  if (message.text) {
107
112
  message.text = message.text.replace(/\\n/g, "\n");
113
+
114
+ let requestVariables = null;
115
+ requestVariables = await TiledeskChatbot.allParametersStatic(this.tdcache, this.requestId)
116
+
117
+ const filler = new Filler();
118
+ message.text = filler.fill(message.text, requestVariables);
108
119
  }
109
- // message.text = "Ciao1\n\nCIao2"
110
- // console.log("sendSupportMessageExt from dirmessage", message);
111
- apiext.sendSupportMessageExt(
112
- message,
113
- this.projectId,
120
+
121
+ this.tdClient.sendSupportMessage(
114
122
  this.requestId,
115
- this.token,
116
- () => {
117
- if (this.log) {console.log("Ext message sent.");}
123
+ message,
124
+ (err) => {
125
+ if (err) {
126
+ winston.err("(DirMessage) Error sending reply: ", err);
127
+ }
128
+ winston.debug("(DirMessage) Reply message sent: ", message);
118
129
  callback();
119
130
  });
131
+
120
132
  }
121
133
 
122
134
  // static firstMessageInfoFromCommands(commands) {
@@ -124,12 +136,8 @@ class DirMessage {
124
136
  // let text = "New message";
125
137
  // for (let i = 0; i < commands.length; i++) {
126
138
  // const command = commands[i];
127
- // console.log("cheking command", command)
128
139
  // if (command.type === "message") {
129
- // console.log("command.type: message!")
130
- // console.log("command.message.type!", command.message.type)
131
- // console.log("command.message.text!", command.message.text)
132
-
140
+
133
141
  // if (command.message.type) {
134
142
  // type = command.message.type;
135
143
  // }
@@ -143,7 +151,6 @@ class DirMessage {
143
151
  // type: type,
144
152
  // text: text
145
153
  // }
146
- // // console.log("message_info:", message_info);
147
154
  // return message_info;
148
155
  // }
149
156
 
@@ -1,6 +1,8 @@
1
1
  let axios = require('axios');
2
2
  let https = require("https");
3
3
  const { v4: uuidv4 } = require('uuid');
4
+ const winston = require('../../utils/winston');
5
+ const tilebotService = require('../../services/TilebotService');
4
6
 
5
7
  class DirMessageToBot {
6
8
 
@@ -17,14 +19,13 @@ class DirMessageToBot {
17
19
  }
18
20
 
19
21
  execute(directive, callback) {
20
- // console.log("exec intent:", JSON.stringify(directive));
22
+ winston.verbose("Execute MessageToBot directive");
21
23
  let action;
22
24
  if (directive.action) {
23
- // console.log("got intent action:", JSON.stringify(directive.action));
24
25
  action = directive.action;
25
26
  }
26
27
  else {
27
- console.error("Incorrect directive:", directive);
28
+ winston.warn("DirMessageToBot Incorrect directive: ", directive);
28
29
  callback();
29
30
  return;
30
31
  }
@@ -34,102 +35,22 @@ class DirMessageToBot {
34
35
  }
35
36
 
36
37
  go(action, callback) {
37
- // console.log("message action intent:", action);
38
+ winston.debug("(DirMessageToBot) Action: ", action);
39
+
38
40
  const message = action.message;
39
- // const projectId = this.supportRequest.id_project;
40
- // const requestId = this.supportRequest.request_id;
41
41
  const botId = this.supportRequest.bot_id;
42
42
 
43
43
  let outgoing_message = {
44
44
  "payload": message,
45
45
  "token": this.token
46
46
  }
47
- if (this.log) {console.log("sending message:", JSON.stringify(outgoing_message));}
47
+ winston.debug("(DirMessageToBot) sending message: ", outgoing_message);
48
48
 
49
- this.sendMessageToBot(this.TILEBOT_ENDPOINT, outgoing_message, botId, () => {
50
- // console.log("(DirMessageToBot) sendMessageToBot() req_body sent");
49
+ tilebotService.sendMessageToBot(outgoing_message, botId, () => {
51
50
  callback(true);
52
51
  });
53
52
  }
54
53
 
55
- /**
56
- * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
57
- * /${TILEBOT_ROUTE}/ext/${botId}
58
- *
59
- * @param {Object} message. The message to send
60
- * @param {string} botId. Tiledesk botId
61
- * @param {string} token. User token
62
- */
63
- sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
64
- const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
65
- // console.log("sendMessageToBot URL", url);
66
- const HTTPREQUEST = {
67
- url: url,
68
- headers: {
69
- 'Content-Type' : 'application/json'
70
- },
71
- json: message,
72
- method: 'POST'
73
- };
74
- this.myrequest(
75
- HTTPREQUEST,
76
- function(err, resbody) {
77
- if (err) {
78
- if (callback) {
79
- callback(err);
80
- }
81
- }
82
- else {
83
- if (callback) {
84
- callback(null, resbody);
85
- }
86
- }
87
- }, false
88
- );
89
- }
90
-
91
- myrequest(options, callback, log) {
92
- if (this.log) {
93
- console.log("API URL:", options.url);
94
- console.log("** Options:", JSON.stringify(options));
95
- }
96
- let axios_options = {
97
- url: options.url,
98
- method: options.method,
99
- data: options.json,
100
- params: options.params,
101
- headers: options.headers
102
- }
103
- if (options.url.startsWith("https:")) {
104
- const httpsAgent = new https.Agent({
105
- rejectUnauthorized: false,
106
- });
107
- axios_options.httpsAgent = httpsAgent;
108
- }
109
- axios(axios_options)
110
- .then((res) => {
111
- if (this.log) {
112
- console.log("Response for url:", options.url);
113
- console.log("Response headers:\n", JSON.stringify(res.headers));
114
- }
115
- if (res && res.status == 200 && res.data) {
116
- if (callback) {
117
- callback(null, res.data);
118
- }
119
- }
120
- else {
121
- if (callback) {
122
- callback(TiledeskClient.getErr({message: "Response status not 200"}, options, res), null, null);
123
- }
124
- }
125
- })
126
- .catch( (error) => {
127
- console.error("(DirMessageToBot) Axios error: ", JSON.stringify(error));
128
- if (callback) {
129
- callback(error, null, null);
130
- }
131
- });
132
- }
133
54
  }
134
55
 
135
56
  module.exports = { DirMessageToBot };
@@ -1,8 +1,9 @@
1
1
  // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const { Directives } = require('./Directives');
3
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
- const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
3
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
4
+ const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const winston = require('../../utils/winston');
6
7
 
7
8
  class DirMoveToAgent {
8
9
 
@@ -27,6 +28,7 @@ class DirMoveToAgent {
27
28
  }
28
29
 
29
30
  execute(directive, callback) {
31
+ winston.verbose("Execute MoveToAgent directive");
30
32
  directive.action = {};
31
33
  this.go(directive.action, () => {
32
34
  callback();
@@ -36,10 +38,10 @@ class DirMoveToAgent {
36
38
  async go(action, callback) {
37
39
  this.tdClient.moveToAgent(this.requestId, (err) => {
38
40
  if (err) {
39
- console.error("Error moving to agent:", err);
41
+ winston.error("DirMoveToAgent) Error moving to agent: ", err);
40
42
  }
41
43
  else {
42
- // console.log("Successfully moved to agent");
44
+ // Successfully moved to agent
43
45
  }
44
46
  callback();
45
47
  });
@@ -1,8 +1,9 @@
1
1
  // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const { Directives } = require('./Directives');
3
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
- const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
3
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
4
+ const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const winston = require('../../utils/winston');
6
7
 
7
8
  class DirMoveToUnassigned {
8
9
 
@@ -25,6 +26,7 @@ class DirMoveToUnassigned {
25
26
  }
26
27
 
27
28
  execute(directive, callback) {
29
+ winston.verbose("Execute MoveToUnassigned directive");
28
30
  directive.action = {};
29
31
  this.go(directive.action, () => {
30
32
  callback();
@@ -34,10 +36,10 @@ class DirMoveToUnassigned {
34
36
  async go(action, callback) {
35
37
  this.moveToUnassigned(this.requestId, (err) => {
36
38
  if (err) {
37
- console.error("Error moving to unassigned:", err);
39
+ winston.error("(DirMoveToUnassigned) Error moving to unassigned: ", err);
38
40
  }
39
41
  else {
40
- // console.log("Successfully moved to unassigned");
42
+ // Successfully moved to unassigned
41
43
  }
42
44
  callback();
43
45
  });