@tiledesk/tiledesk-tybot-connector 0.4.2 → 0.5.0-rc2

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 (87) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/ExtApi.js +3 -13
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +86 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/index.js +87 -273
  9. package/logs/app.log +12983 -275
  10. package/logs/app1.log +62258 -0
  11. package/logs/app2.log +46280 -0
  12. package/logs/app3.log +28864 -0
  13. package/models/IntentForm.js +30 -44
  14. package/models/IntentsMachineFactory.js +4 -3
  15. package/models/MockBotsDataSource.js +1 -17
  16. package/models/MockTdCache.js +0 -9
  17. package/models/MongodbBotsDataSource.js +29 -53
  18. package/models/MongodbIntentsMachine.js +5 -4
  19. package/models/TiledeskChatbot.js +79 -258
  20. package/models/TiledeskChatbotConst.js +9 -0
  21. package/models/TiledeskChatbotUtil.js +180 -232
  22. package/models/TiledeskIntentsMachine.js +5 -14
  23. package/models/faqKbService.js +0 -1
  24. package/package.json +5 -2
  25. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
  26. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
  27. package/tiledeskChatbotPlugs/Filler.js +0 -1
  28. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  29. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  30. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  31. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  32. package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
  33. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
  34. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
  35. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
  36. package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
  37. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
  38. package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
  39. package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
  40. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
  41. package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
  42. package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
  43. package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
  44. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
  45. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
  46. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
  47. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
  48. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
  49. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  50. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  51. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  52. package/tiledeskChatbotPlugs/directives/DirForm.js +15 -22
  53. package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
  54. package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
  55. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  56. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
  57. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
  58. package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
  59. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
  60. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  61. package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
  62. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  63. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
  64. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
  65. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
  66. package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
  67. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
  68. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  69. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
  70. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
  71. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
  72. package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
  73. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
  74. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
  75. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
  76. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
  77. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
  78. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  79. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  80. package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
  81. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
  82. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
  83. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
  84. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
  85. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  86. package/utils/winston.js +42 -0
  87. package/TdCache copy.js +0 -242
@@ -4,6 +4,7 @@ const { TiledeskMath } = require('../../TiledeskMath');
4
4
  const { TiledeskString } = require('../../TiledeskString');
5
5
  const { Filler } = require('../Filler');
6
6
  const validate = require('jsonschema').validate;
7
+ const winston = require('../../utils/winston');
7
8
 
8
9
  const schema = {
9
10
  "type": "object",
@@ -80,37 +81,39 @@ class DirSetAttribute {
80
81
  }
81
82
 
82
83
  execute(directive, callback) {
84
+ winston.verbose("Execute SetAttribute directive");
83
85
  let action;
84
86
  if (directive.action) {
85
87
  action = directive.action
86
88
  }
87
89
  else {
90
+ winston.warn("DirSetAttribute Incorrect directive: ", directive);
88
91
  callback();
89
92
  return;
90
93
  }
91
- // console.log("go DirAssign with action:", action);
92
94
  this.go(action, () => {
93
95
  callback();
94
96
  });
95
97
  }
96
98
 
97
99
  async go(action, callback) {
100
+ winston.debug("(DirSetAttribute) Action: ", action);
98
101
  let res = validate(action, schema);
99
102
  if (!res.valid) {
100
- if (this.log) {console.error("(DirSetAttribute) Invalid action:", res.errors)};
103
+ winston.error("(DirSetAttribute) Invalid action:", res.errors);
101
104
  callback();
102
105
  return;
103
106
  }
104
107
 
105
108
  if(action.operation.operators === undefined && action.operation.operands.length !== 1) {
106
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators === undefined && operands.length !== 1")};
109
+ winston.error("(DirSetAttribute) Invalid action: operators === undefined && operands.length !== 1");
107
110
  callback();
108
111
  return;
109
112
  }
110
113
 
111
114
 
112
115
  if (action.operation.operators !== undefined && action.operation.operators.length !== action.operation.operands.length - 1) {
113
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators.length !== operands.length - 1")};
116
+ winston.error("(DirSetAttribute) Invalid action: operators.length !== operands.length - 1");
114
117
  callback();
115
118
  return;
116
119
  }
@@ -4,6 +4,7 @@ const { TiledeskMath } = require('../../TiledeskMath');
4
4
  const { TiledeskString } = require('../../TiledeskString');
5
5
  const { Filler } = require('../Filler');
6
6
  const validate = require('jsonschema').validate;
7
+ const winston = require('../../utils/winston');
7
8
 
8
9
  const schema = {
9
10
  "type": "object",
@@ -81,86 +82,66 @@ class DirSetAttributeV2 {
81
82
  }
82
83
 
83
84
  execute(directive, callback) {
85
+ winston.verbose("Execute SetAttributeV2 directive");
84
86
  let action;
85
87
  if (directive.action) {
86
88
  action = directive.action
87
89
  }
88
90
  else {
91
+ winston.warn("DirSetAttributeV2 Incorrect directive: ", directive);
89
92
  callback();
90
93
  return;
91
94
  }
92
- // console.log("go DirAssign with action:", action);
93
95
  this.go(action, () => {
94
96
  callback();
95
97
  });
96
98
  }
97
99
 
98
100
  async go(action, callback) {
99
- if (this.log) {console.log("(DirSetAttribute) action before filling:", JSON.stringify(action));}
100
- // if (!action) {
101
- // if (this.log) {console.log("(SetAttributeV2) Error 'action' is missing");}
102
- // callback();
103
- // return;
104
- // }
101
+ winston.debug("(DirSetAttributeV2) Action: ", action);
102
+
105
103
  if (action && !action.operation) {
106
- if (this.log) {console.log("(SetAttributeV2) Error operation is mandatory");}
104
+ winston.error("(DirSetAttributeV2) Error operation is mandatory");
107
105
  callback();
106
+ return;
108
107
  }
109
108
  if (action && action.operation && action.operation.operands) {
110
- if (this.log) {console.log("(SetAttributeV2) filling in setattribute...");}
109
+ winston.debug("(DirSetAttributeV2) filling in setattribute...");
111
110
  await this.fillValues(action.operation.operands);
112
111
  }
113
- if (this.log) { console.log("action.operation.operands.length", action.operation.operands.length); }
114
- if (this.log) { console.log("action.operation.operands[0].type", action.operation.operands[0].type); }
115
112
 
116
113
  // FUN FACT: THIS TOOK A LOT OF EFFORT BUT IT WAS NEVER USED. YOU CAN SIMPLY CREATE A JSON ATTRIBUTE APPLYING
117
114
  // JSONparse FUNCTION TO AN ATTRIBUTE.
118
115
  // DEPRECATED because type = json is not available in the UI!
119
116
  if (action.operation.operands && action.operation.operands.length === 1 && action.operation.operands[0].type === "json") {
120
- if (this.log) {console.log("(SetAttributeV2) setting json value...");}
121
- if (this.log) { console.log("(SetAttributeV2) setting json value... destination:", action.destination); }
122
117
  const json_value = JSON.parse(action.operation.operands[0].value);
123
- if (this.log) { console.log("(SetAttributeV2) json_value:", json_value); }
124
118
  await this.saveAttribute(action.destination, json_value);
125
119
  // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.destination, json_value);
126
120
  callback();
127
121
  return; // on json types no operations are permitted beyond assignment
128
122
  }
129
- if (this.log) {console.log("filled in setattribute:", action.operation);}
130
- // let res = validate(action, schema);
131
- // if (res.errors) {
132
- // console.log("(DirSetAttribute) failed validation action:", JSON.stringify(action));
133
- // console.log("DirSetAttribute validation errors:", res.errors);
134
- // }
135
- // if (!res.valid) {
136
- // if (this.log) {console.error("(DirSetAttribute) Invalid action:", res.errors)};
137
- // callback();
138
- // return;
139
- // }
123
+ winston.debug("(DirSetAttributeV2) filled in setattribute:", action.operation);
124
+
140
125
  if (action.operation?.operators === undefined && action.operation?.operands?.length !== 1) {
141
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators === undefined && operands.length !== 1")};
126
+ winston.error("(DirSetAttributeV2) Invalid action: operators === undefined && operands.length !== 1")
142
127
  callback();
143
128
  return;
144
129
  }
145
130
  if (action.operation?.operators !== undefined && action.operation?.operators?.length !== action.operation?.operands?.length - 1) {
146
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators.length !== operands.length - 1")};
131
+ winston.error("(DirSetAttributeV2) Invalid action: operators.length !== operands.length - 1")
147
132
  callback();
148
133
  return;
149
134
  }
150
135
  // if (action && action.operation && action.operation.operands) {
151
- // console.log("filling in setattribute...");
152
136
  // await this.fillValues(action.operation.operands);
153
137
  // }
154
- // console.log("dirsetattribute, action.operation.operands:", action.operation.operands);
155
138
  try {
156
139
  const expression = TiledeskExpression.JSONOperationToExpression(action.operation?.operators, action.operation?.operands);
157
140
  const attributes = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
158
- // console.log("dirsetattribute, attributes:", attributes);
159
141
  if (attributes) {
160
142
  attributes.TiledeskMath = TiledeskMath;
161
143
  attributes.TiledeskString = TiledeskString;
162
144
  const result = new TiledeskExpression().evaluateJavascriptExpression(expression, attributes);
163
- // console.log("filling in setattribute, result:", result);
164
145
  // THE GOAL OF ATTRIBUTE-FILLING THE "DESTINATION" FIELD IS TO SUPPORT DYNAMIC ATTRIBUTES
165
146
  // (ATTRS WHOSE NAME IS UNKNOWN AD DESIGN-TIME)
166
147
  // STILL UNSUPPORTED IN UI
@@ -169,7 +150,7 @@ class DirSetAttributeV2 {
169
150
  }
170
151
  }
171
152
  catch(err) {
172
- console.error("SetAttributeV2 error:", err);
153
+ winston.error("(DirSetAttributeV2) error:", err);
173
154
  }
174
155
 
175
156
  // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, destination, result);
@@ -177,12 +158,9 @@ class DirSetAttributeV2 {
177
158
  }
178
159
 
179
160
  async saveAttribute(key, value, persist) {
180
- if (this.log) {
181
- console.log("SetAttributeV2 saving attribute:", key, value, persist);
182
- }
161
+ winston.debug("(DirSetAttributeV2) saving attribute: " + key + " " + value + " " + persist);
183
162
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
184
163
  // if (persist) {
185
- // console.log("SetAttributeV2 persisting...");
186
164
  // await this.persistOnTiledesk(destination, result);
187
165
  // }
188
166
 
@@ -216,19 +194,15 @@ class DirSetAttributeV2 {
216
194
  json: json,
217
195
  method: 'POST'
218
196
  }
219
- if (this.log) { console.log("SetAttribute. HTTPREQUEST: ", HTTPREQUEST); }
197
+ winston.debug("(DirSetAttributeV2) HttpRequest: ", HTTPREQUEST);
220
198
  this.#myrequest(
221
199
  HTTPREQUEST, async (err, resbody) => {
222
200
  if (err) {
223
201
  if (this.log) {
224
- console.error("SetAttribute. persistOnTiledesk() error:", err);
202
+ winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
225
203
  }
226
- // callback();
227
- // return;
228
204
  } else {
229
- if (this.log) { console.log("SetAttribute. Attributes saved.", JSON.stringify(resbody)); }
230
- // callback();
231
- // return;
205
+ winston.debug("(DirSetAttributeV2) Attributes saved: ", resbody);
232
206
  }
233
207
  }
234
208
  );
@@ -237,13 +211,10 @@ class DirSetAttributeV2 {
237
211
 
238
212
  async fillDestination(destination) {
239
213
  if (this.tdcache) {
240
- // console.log("tdcache in setattribute...", this.tdcache);
241
214
  const requestAttributes =
242
215
  await TiledeskChatbot.allParametersStatic(this.tdcache, this.context.requestId);
243
- // console.log("requestAttributes in setattribute...", requestAttributes);
244
216
  const filler = new Filler();
245
217
  destination = filler.fill(destination, requestAttributes);
246
- // console.log("setattribute, final destination:", destination);
247
218
  }
248
219
  return destination
249
220
  }
@@ -276,27 +247,21 @@ class DirSetAttributeV2 {
276
247
  // ]
277
248
  try {
278
249
  if (this.tdcache) {
279
- // console.log("tdcache in setattribute...", this.tdcache);
280
250
  const requestAttributes =
281
251
  await TiledeskChatbot.allParametersStatic(this.tdcache, this.context.requestId);
282
- // console.log("requestAttributes in setattribute...", requestAttributes);
283
252
  const filler = new Filler();
284
253
  operands.forEach(operand => {
285
- // if (!operand.isVariable) {
286
- // console.log("setattribute, liquid operand:", operand);
287
- operand.value = filler.fill(operand.value, requestAttributes);
288
- // console.log("setattribute, final operand:", operand);
289
- // }
254
+ operand.value = filler.fill(operand.value, requestAttributes);
290
255
  });
291
256
  }
292
257
  }
293
258
  catch(error) {
294
- console.error("Error while filling operands:", error);
259
+ winston.error("(DirSetAttributeV2) Error while filling operands: ", error);
295
260
  }
296
261
  }
297
262
 
298
263
  convertOperandValues(operands) {
299
- console.log("Converting operands:", operands);
264
+ winston.debug("(DirSetAttributeV2) Converting operands:", operands);
300
265
  // operation: {
301
266
  // operators: ["addAsNumber", "subtractAsNumber", "divideAsNumber", "multiplyAsNumber"],
302
267
  // operands: [
@@ -309,35 +274,24 @@ class DirSetAttributeV2 {
309
274
  try {
310
275
  operands.forEach(operand => {
311
276
  if (operand.type) {
312
- console.log("Converting operands - operand.type:", operand.type.toLowerCase());
313
277
  if (operand.type.toLowerCase() === "number") {
314
- console.log("Converting operands - number");
315
278
  operand.value = Number(operand.value);
316
- console.log("new value:", operand.value);
317
- console.log("new value type:", typeof operand.value);
318
279
  }
319
280
  else if (operand.type.toLowerCase() === "json") {
320
- console.log("Converting operands - json, value =", operand.value);
321
281
  operand.value = JSON.parse(operand.value);
322
- console.log("new value:", operand.value);
323
- console.log("new value type:", typeof operand.value);
324
282
  }
325
283
  else {
326
- console.log("Converting operands - ??");
284
+ winston.warn("Converting operands - ??");
327
285
  }
328
286
  }
329
287
  });
330
288
  }
331
289
  catch(error) {
332
- console.error("Error while converting operands:", error);
290
+ winston.error("(DirSetAttributeV2) Error while converting operands: ", error);
333
291
  }
334
292
  }
335
293
 
336
294
  #myrequest(options, callback) {
337
- if (this.log) {
338
- console.log("API URL:", options.url);
339
- console.log("** Options:", JSON.stringify(options));
340
- }
341
295
  let axios_options = {
342
296
  url: options.url,
343
297
  method: options.method,
@@ -347,9 +301,6 @@ class DirSetAttributeV2 {
347
301
  if (options.json !== null) {
348
302
  axios_options.data = options.json
349
303
  }
350
- if (this.log) {
351
- console.log("axios_options:", JSON.stringify(axios_options));
352
- }
353
304
  if (options.url.startsWith("https:")) {
354
305
  const httpsAgent = new https.Agent({
355
306
  rejectUnauthorized: false,
@@ -358,10 +309,6 @@ class DirSetAttributeV2 {
358
309
  }
359
310
  axios(axios_options)
360
311
  .then((res) => {
361
- if (this.log) {
362
- console.log("Response for url:", options.url);
363
- console.log("Response headers:\n", JSON.stringify(res.headers));
364
- }
365
312
  if (res && res.status == 200 && res.data) {
366
313
  if (callback) {
367
314
  callback(null, res.data);
@@ -1,5 +1,6 @@
1
1
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const { Filler } = require('../Filler');
3
+ const winston = require('../../utils/winston');
3
4
 
4
5
  class DirSetConversationTags {
5
6
 
@@ -22,11 +23,13 @@ class DirSetConversationTags {
22
23
  }
23
24
 
24
25
  execute(directive, callback) {
26
+ winston.verbose("Execute SetConversationTags directive");
25
27
  let action;
26
28
  if (directive.action) {
27
29
  action = directive.action
28
30
  }
29
31
  else {
32
+ winston.warn("DirSetAttribute Incorrect directive: ", directive);
30
33
  callback();
31
34
  return;
32
35
  }
@@ -36,11 +39,11 @@ class DirSetConversationTags {
36
39
  }
37
40
 
38
41
  async go(action, callback) {
39
- if (this.log) {console.log("(DirSetConversationTags) Adding conversation tags:", action.depName);}
42
+ winston.debug("(DirSetConversationTags) Action: ", action);
40
43
  let tagsString = action.tags;
41
44
  tagsString = tagsString.replace(/ /g,"");
42
45
  if (tagsString.length === 0) {
43
- if (this.log) {console.error("(DirSetConversationTags) Invalid action: tags string is empty")};
46
+ winston.debug("(DirSetConversationTags) Invalid action: tags string is empty");
44
47
  callback();
45
48
  return;
46
49
  }
@@ -53,15 +56,15 @@ class DirSetConversationTags {
53
56
  }
54
57
  }
55
58
  catch(error) {
56
- console.error("Error while filling operands:", error);
59
+ winston.error("(DirSetConversationTags) Error while filling operands: ", error);
57
60
  }
58
61
  this.moveToDepartment(this.requestId, depName, (deps) => {
59
62
  if (!deps) {
60
- if (this.log) {console.log("Dep not found");}
63
+ winston.debug("(DirSetConversationTags) Dep not found");
61
64
  callback();
62
65
  return
63
66
  }
64
- if (this.log) {console.log("Switched to dept:", depName, "action:", JSON.stringify(action));}
67
+ winston.debug("(DirSetConversationTags) Switched to dept: " + depName + " action: ", JSON.stringify(action));
65
68
  if (action.triggerBot) {
66
69
  let dep = null;
67
70
  let i;
@@ -73,7 +76,7 @@ class DirSetConversationTags {
73
76
  }
74
77
  }
75
78
  if (dep && dep.hasBot === true && dep.id_bot) {
76
- if (this.log) {console.log("Sending hidden /start message to bot in dept");}
79
+ winston.debug("(DirSetConversationTags) Sending hidden /start message to bot in dept");
77
80
  const message = {
78
81
  type: "text",
79
82
  text: "/start",
@@ -85,15 +88,14 @@ class DirSetConversationTags {
85
88
  this.requestId,
86
89
  message, (err) => {
87
90
  if (err) {
88
- console.error("Error sending hidden message:", err.message);
91
+ winston.error("(DirSetConversationTags) Error sending hidden message: " + err.message);
89
92
  }
90
- if (this.log) {console.log("Hidden message sent.");}
91
93
  callback();
92
94
  });
93
95
  }
94
96
  }
95
97
  else {
96
- if (this.log) {console.log("No action.triggerBot");}
98
+ winston.debug("(DirSetConversationTags) No action.triggerBot");
97
99
  callback();
98
100
  }
99
101
  });
@@ -101,9 +103,8 @@ class DirSetConversationTags {
101
103
 
102
104
  moveToDepartment(requestId, depName, callback) {
103
105
  this.tdClient.getAllDepartments((err, deps) => {
104
- if (this.log) {console.log("deps:", JSON.stringify(deps));}
105
106
  if (err) {
106
- console.error("getAllDepartments() error:", err);
107
+ winston.error("(DirSetConversationTags) getAllDepartments() error: ", err);
107
108
  callback();
108
109
  return;
109
110
  }
@@ -119,11 +120,11 @@ class DirSetConversationTags {
119
120
  if (dep) {
120
121
  this.tdClient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
121
122
  if (err) {
122
- console.error("DirDepartment error:", err);
123
+ winston.debug("(DirSetConversationTags) error:", err);
123
124
  callback();
124
125
  }
125
126
  else {
126
- console.log("DirDepartment response:",JSON.stringify(res));
127
+ winston.debug("(DirSetConversationTags) response: ", res);
127
128
  callback(deps);
128
129
  }
129
130
  });
@@ -1,3 +1,4 @@
1
+ const winston = require('../../utils/winston');
1
2
 
2
3
  class DirUnlockIntent {
3
4
 
@@ -14,6 +15,7 @@ class DirUnlockIntent {
14
15
  }
15
16
 
16
17
  async execute(directive, callback) {
18
+ winston.verbose("Execute UnlockIntent directive");
17
19
  let action;
18
20
  if (directive.action) {
19
21
  action = directive.action;
@@ -21,13 +23,13 @@ class DirUnlockIntent {
21
23
  else {
22
24
  action = {}
23
25
  }
24
- if (this.log) {console.log("Unlocking current intent");}
25
26
  this.go(action, () => {
26
27
  callback();
27
28
  });
28
29
  }
29
30
 
30
31
  async go(action, callback) {
32
+ winston.debug("(DirUnlockIntent) Action: ", action);
31
33
  await DirUnlockIntent.unlockIntent(this.tdcache, this.context.requestId);
32
34
  if (callback) {
33
35
  callback();
@@ -35,7 +37,6 @@ class DirUnlockIntent {
35
37
  }
36
38
 
37
39
  // async execute(requestId, callback) {
38
- // console.log("Unocking intent");
39
40
  // await this.unlockIntent(requestId);
40
41
  // callback();
41
42
  // }
@@ -43,7 +44,6 @@ class DirUnlockIntent {
43
44
  static async unlockIntent(tdcache, requestId) {
44
45
  await tdcache.del("tilebot:requests:" + requestId + ":locked");
45
46
  // await this.tdcache.del("tilebot:requests:" + requestId + ":locked");
46
- // console.log("unlocked.")
47
47
  }
48
48
 
49
49
  }
@@ -1,5 +1,6 @@
1
1
 
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
+ const winston = require('../../utils/winston');
3
4
 
4
5
  class DirWait {
5
6
 
@@ -16,6 +17,7 @@ class DirWait {
16
17
 
17
18
  execute(directive, callback) {
18
19
  // 500ms < wait-time < 10.000ms
20
+ winston.verbose("Execute Wait directive");
19
21
  let action;
20
22
  if (directive.action) {
21
23
  action = directive.action;
@@ -41,22 +43,19 @@ class DirWait {
41
43
  millis: 500
42
44
  }
43
45
  }
44
- // console.log("____-----_", action)
46
+
45
47
  this.go(action, () => {
46
- // console.log("YES", callback)
47
48
  callback();
48
49
  })
49
50
  }
50
51
 
51
52
  async go(action, callback) {
53
+ winston.debug("(DirWait) Action: ", action);
52
54
  // reset step?
53
55
  // const step_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":step";
54
- // console.log("step_key:", step_key);
55
56
  if (action && action.millis >= 1000) {//2000 * 60) { // at list 2 minutes waiting time to reset the steps counter
56
57
  // await this.tdcache.set(step_key, 0);
57
- // console.log("resetting steps counter");
58
58
  await TiledeskChatbot.resetStep(this.tdcache, this.requestId);
59
- // console.log("step_key after:", await this.tdcache.get( step_key ));
60
59
  }
61
60
  setTimeout(() => {
62
61
  callback();
@@ -3,6 +3,7 @@ let https = require("https");
3
3
  const { Filler } = require('../Filler');
4
4
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
5
5
  const { TiledeskJSONEval } = require('../../TiledeskJSONEval');
6
+ const winston = require('../../utils/winston');
6
7
 
7
8
  class DirWebRequest {
8
9
  constructor(context) {
@@ -16,12 +17,13 @@ class DirWebRequest {
16
17
  }
17
18
 
18
19
  execute(directive, callback) {
20
+ winston.verbose("Execute WebRequest directive");
19
21
  let action;
20
22
  if (directive.action) {
21
23
  action = directive.action;
22
24
  }
23
25
  else {
24
- console.error("Incorrect directive:", JSON.stringify(directive));
26
+ winston.warn("DirWebRequest Incorrect directive: ", directive);
25
27
  callback();
26
28
  return;
27
29
  }
@@ -31,7 +33,7 @@ class DirWebRequest {
31
33
  }
32
34
 
33
35
  async go(action, callback) {
34
- if (this.log) {console.log("webRequest action:", JSON.stringify(action));}
36
+ winston.debug("(DirWebRequest) Action: ", action);
35
37
  let requestVariables = null;
36
38
  if (this.tdcache) {
37
39
  requestVariables =
@@ -46,7 +48,6 @@ class DirWebRequest {
46
48
  if (action.headersString) {
47
49
  let headersDict = action.headersString
48
50
  for (const [key, value] of Object.entries(headersDict)) {
49
- if (this.log) {console.log("header:", key, "value:", value)}
50
51
  let filled_value = filler.fill(value, requestVariables);
51
52
  headers[key] = filled_value;
52
53
  }
@@ -58,30 +59,29 @@ class DirWebRequest {
58
59
  json = JSON.parse(jsonBody);
59
60
  }
60
61
  catch(err) {
61
- console.error("Error parsing webRequest jsonBody:", jsonBody);
62
+ winston.debug("(DirWebRequest) Error parsing webRequest jsonBody: ", jsonBody);
62
63
  }
63
64
  }
64
65
 
65
- if (this.log) {console.log("webRequest URL", url);}
66
+ winston.verbose("(DirWebRequest) webRequest URL " + url);
66
67
  const HTTPREQUEST = {
67
68
  url: url,
68
69
  headers: headers,
69
70
  json: json,
70
71
  method: action.method
71
72
  };
72
- if (this.log) {console.log("webRequest HTTPREQUEST", HTTPREQUEST);}
73
+ winston.debug("(DirWebRequest) HttpRequest ", HTTPREQUEST);
73
74
  this.myrequest(
74
75
  HTTPREQUEST, async (err, resbody) => {
75
- if (this.log) {console.log("webRequest resbody:", resbody);}
76
+ winston.debug("(DirWebRequest) resbody: ", resbody);
76
77
  if (err) {
77
- if (this.log) {console.error("webRequest error:", err);}
78
+ winston.error("(DirWebRequest) error:", err);
78
79
  if (callback) {
79
80
  callback();
80
81
  }
81
82
  }
82
83
  else if (callback) {
83
84
  if (action.assignTo && this.context.tdcache && resbody) { // DEPRECATED
84
- if (this.log) {console.log("(webRequest) this.requestId:", this.context.requestId);}
85
85
  let attributes =
86
86
  await TiledeskChatbot.allParametersStatic(
87
87
  this.context.tdcache, this.context.requestId);
@@ -89,18 +89,8 @@ class DirWebRequest {
89
89
  let attributeValue;
90
90
  const filler = new Filler();
91
91
  attributeValue = filler.fill(resbody, attributes);
92
- if (this.log) {console.log("(webRequest) Attributes:", JSON.stringify(attributes));}
93
92
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignTo, attributeValue);
94
- if (this.log) {
95
- console.log("(webRequest) Assigned:", action.assignTo, "=", attributeValue);
96
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
97
- for (const [key, value] of Object.entries(all_parameters)) {
98
- const value_type = typeof value;
99
- if (this.log) {console.log("(webRequest) request parameter:", key, "value:", value, "type:", value_type)}
100
- }
101
- }
102
93
  } else if (action.assignments && this.context.tdcache && resbody) {
103
- if (this.log) {console.log("(webRequest) action.assignments for request:", this.context.requestId);}
104
94
  let json_body;
105
95
  if (typeof resbody === "string") {
106
96
  json_body = {
@@ -110,35 +100,21 @@ class DirWebRequest {
110
100
  else {
111
101
  json_body = resbody
112
102
  }
113
- if (this.log) {console.log("(webRequest) action.assignments json_body:", json_body);}
114
- let attributes =
115
- await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
116
- if (this.log) {console.log("(webRequest) action.assignments attributes:", attributes);}
103
+ let attributes = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
117
104
  const assignments = action.assignments;
118
- if (this.log) {console.log("(webRequest) assignments:", assignments);}
119
105
  for (const [attr_name, attr_eval_expression] of Object.entries(assignments)) {
120
- if (this.log) {console.log("", attr_name, attr_eval_expression);}
121
106
  let attributeValue;
122
107
  try {
123
108
  attributeValue = TiledeskJSONEval.eval(json_body, attr_eval_expression);
124
- if (this.log) {console.log("(webRequest) Assigning to:", attr_name, "value:", attributeValue);}
125
109
  }
126
110
  catch(err) {
127
- console.error("Error:", err);
111
+ winston.error("(DirWebRequest) Error:", err);
128
112
  }
129
113
  try {
130
114
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, attr_name, attributeValue);
131
115
  }
132
116
  catch(err) {
133
- console.error("Error:", err);
134
- }
135
- }
136
- if (this.log) {
137
- console.log("(webRequest) All attributes:");
138
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
139
- for (const [key, value] of Object.entries(all_parameters)) {
140
- const value_type = typeof value;
141
- if (this.log) {console.log("(webRequest) request attribute:", key, "value:", value, "type:", value_type)}
117
+ winston.error("(DirWebRequest) Error: ", err);
142
118
  }
143
119
  }
144
120
  }
@@ -149,10 +125,6 @@ class DirWebRequest {
149
125
  }
150
126
 
151
127
  myrequest(options, callback) {
152
- if (this.log) {
153
- console.log("API URL:", options.url);
154
- console.log("** Options:", JSON.stringify(options));
155
- }
156
128
  let axios_options = {
157
129
  url: options.url,
158
130
  method: options.method,
@@ -162,9 +134,6 @@ class DirWebRequest {
162
134
  if (options.json !== null) {
163
135
  axios_options.data = options.json
164
136
  }
165
- if (this.log) {
166
- console.log("axios_options:", JSON.stringify(axios_options));
167
- }
168
137
  if (options.url.startsWith("https:")) {
169
138
  const httpsAgent = new https.Agent({
170
139
  rejectUnauthorized: false,
@@ -173,10 +142,6 @@ class DirWebRequest {
173
142
  }
174
143
  axios(axios_options)
175
144
  .then((res) => {
176
- if (this.log) {
177
- console.log("Response for url:", options.url);
178
- console.log("Response headers:\n", JSON.stringify(res.headers));
179
- }
180
145
  if (res && res.status == 200 && res.data) {
181
146
  if (callback) {
182
147
  callback(null, res.data);
@@ -189,7 +154,7 @@ class DirWebRequest {
189
154
  }
190
155
  })
191
156
  .catch( (error) => {
192
- console.error("(DirWebRequest) Axios error: ", JSON.stringify(error));
157
+ winston.error("(DirWebRequest) Axios error: ", error.response.data);
193
158
  if (callback) {
194
159
  callback(error, null);
195
160
  }