@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,8 +1,9 @@
1
1
  let axios = require('axios');
2
2
  let https = require("https");
3
3
  const { Filler } = require('../Filler');
4
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
+ const { TiledeskChatbot } = require('../../engine/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
  }
@@ -1,8 +1,9 @@
1
1
  let axios = require('axios');
2
2
  let https = require("https");
3
3
  const { Filler } = require('../Filler');
4
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
5
5
  const { DirIntent } = require('./DirIntent');
6
+ const winston = require('../../utils/winston');
6
7
 
7
8
  class DirWebRequestV2 {
8
9
 
@@ -19,12 +20,13 @@ class DirWebRequestV2 {
19
20
  }
20
21
 
21
22
  execute(directive, callback) {
23
+ winston.verbose("Execute WebRequestV2 directive");
22
24
  let action;
23
25
  if (directive.action) {
24
26
  action = directive.action;
25
27
  }
26
28
  else {
27
- console.error("Incorrect directive:", JSON.stringify(directive));
29
+ winston.warn("DirWebRequestV2 Incorrect directive: ", directive);
28
30
  callback();
29
31
  return;
30
32
  }
@@ -36,9 +38,9 @@ class DirWebRequestV2 {
36
38
  }
37
39
 
38
40
  async go(action, callback) {
39
- if (this.log) { console.log("DirWebRequest action:", JSON.stringify(action)); }
41
+ winston.debug("DirWebRequestV2 action:", action);
40
42
  if (!this.tdcache) {
41
- console.error("Error: DirWebRequest tdcache is mandatory");
43
+ winston.error("Error: DirWebRequestV2 tdcache is mandatory");
42
44
  callback();
43
45
  return;
44
46
  }
@@ -48,12 +50,10 @@ class DirWebRequestV2 {
48
50
  let trueIntentAttributes = action.trueIntentAttributes;
49
51
  let falseIntentAttributes = action.falseIntentAttributes;
50
52
 
51
- if (this.log) {
52
- console.log("DirWebRequest trueIntent", trueIntent)
53
- console.log("DirWebRequest falseIntent", falseIntent)
54
- console.log("DirWebRequest trueIntentAttributes", trueIntentAttributes)
55
- console.log("DirWebRequest falseIntentAttributes", falseIntentAttributes)
56
- }
53
+ winston.debug("DirWebRequestV2 trueIntent " + trueIntent)
54
+ winston.debug("DirWebRequestV2 falseIntent " + falseIntent)
55
+ winston.debug("DirWebRequestV2 trueIntentAttributes " + trueIntentAttributes)
56
+ winston.debug("DirWebRequestV2 falseIntentAttributes " + falseIntentAttributes)
57
57
 
58
58
  let requestAttributes = null;
59
59
  requestAttributes =
@@ -88,7 +88,7 @@ class DirWebRequestV2 {
88
88
 
89
89
  let timeout = this.#webrequest_timeout(action, 20000, 1, 300000);
90
90
 
91
- if (this.log) {console.log("webRequest URL", url);}
91
+ winston.debug("DirWebRequestV2 webRequest URL " + url);
92
92
 
93
93
  const HTTPREQUEST = {
94
94
  url: url,
@@ -97,22 +97,19 @@ class DirWebRequestV2 {
97
97
  method: action.method,
98
98
  timeout: timeout
99
99
  };
100
- if (this.log) { console.log("webRequest HTTPREQUEST", HTTPREQUEST); }
100
+ winston.debug("DirWebRequestV2 HttpRequest: ", HTTPREQUEST);
101
101
 
102
102
  this.#myrequest(
103
103
  HTTPREQUEST, async (err, res) => {
104
- if (this.log && err) {
105
- console.log("webRequest error:", err);
106
- }
107
- if (this.log) { console.log("DirWebRequest res:", res); }
104
+
108
105
  let resbody = res.data;
109
106
  let status = res.status;
110
107
  let error = res.error;
111
108
  await this.#assignAttributes(action, resbody, status, error)
112
- if (this.log) { console.log("webRequest resbody:", resbody); }
109
+ winston.debug("DirWebRequestV2 resbody:", resbody);
113
110
 
114
111
  if (err) {
115
- if (this.log) { console.error("webRequest error:", err); }
112
+ winston.log("webRequest error: ", err);
116
113
  if (callback) {
117
114
  if (falseIntent) {
118
115
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -177,7 +174,7 @@ class DirWebRequestV2 {
177
174
  resolve(json);
178
175
  }
179
176
  catch (err) {
180
- if (this.log) { console.error("Error parsing webRequest jsonBody:", jsonBody, err) };
177
+ winston.error("DirWebRequestV2 Error parsing webRequest jsonBody: " + JSON.stringify(jsonBody) + "\nError: " + JSON.stringify(err));
181
178
  reject("Error parsing jsonBody");
182
179
  }
183
180
  }
@@ -210,7 +207,7 @@ class DirWebRequestV2 {
210
207
  }
211
208
  resolve(json);
212
209
  } catch (err) {
213
- if (this.log) { console.error("Error parsing webRequest formData:", formData, err) };
210
+ winston.error("DirWebRequestV2 Error parsing webRequest formData: " + JSON.stringify(formData) + "\nError: " + JSON.stringify(err));
214
211
  reject("Error parsing formData");
215
212
  }
216
213
  }
@@ -238,7 +235,7 @@ class DirWebRequestV2 {
238
235
  });
239
236
  }
240
237
  else {
241
- if (this.log) { console.log("No trueIntentDirective specified"); }
238
+ winston.debug("DirWebRequestV2 No trueIntentDirective specified");
242
239
  if (callback) {
243
240
  callback();
244
241
  }
@@ -253,7 +250,7 @@ class DirWebRequestV2 {
253
250
  });
254
251
  }
255
252
  else {
256
- if (this.log) { console.log("No falseIntentDirective specified"); }
253
+ winston.debug("DirWebRequestV2 No falseIntentDirective specified");
257
254
  if (callback) {
258
255
  callback();
259
256
  }
@@ -262,53 +259,22 @@ class DirWebRequestV2 {
262
259
  }
263
260
 
264
261
  async #assignAttributes(action, resbody, status, error) {
265
- if (this.log) {
266
- console.log("assignAttributes resbody:", resbody)
267
- console.log("assignAttributes error:", error)
268
- console.log("assignAttributes status:", status)
269
- console.log("assignAttributes action:", action)
270
- }
262
+
271
263
  if (this.context.tdcache) {
272
264
  if (action.assignResultTo && resbody) {
273
- if (this.log) { console.log("assign assignResultTo:", resbody); }
274
265
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignResultTo, resbody);
275
266
  }
276
267
  if (action.assignErrorTo && error) {
277
- if (this.log) { console.log("assign assignResultTo:", error); }
278
268
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
279
269
  }
280
270
  if (action.assignStatusTo && status) {
281
- if (this.log) { console.log("assign assignStatusTo:", status); }
282
271
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
283
272
  }
284
- // Debug log
285
- if (this.log) {
286
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
287
- for (const [key, value] of Object.entries(all_parameters)) {
288
- if (this.log) { console.log("(webRequest) request parameter:", key, "value:", value, "type:", typeof value) }
289
- }
290
- }
291
273
  }
292
274
  }
293
275
 
294
276
  #myrequest(options, callback) {
295
277
  try {
296
- if (this.log) {
297
- console.log("API URL:", options.url);
298
- //console.log("** Options:", JSON.stringify(options));
299
- // Stringify "options". FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
300
- let cache = [];
301
- let str_Options = JSON.stringify(options, function (key, value) { // try to use a separate function
302
- if (typeof value === 'object' && value != null) {
303
- if (cache.indexOf(value) !== -1) {
304
- return;
305
- }
306
- cache.push(value);
307
- }
308
- return value;
309
- });
310
- console.log("** Options:", str_Options);
311
- }
312
278
  let axios_options = {
313
279
  url: options.url,
314
280
  method: options.method,
@@ -322,9 +288,6 @@ class DirWebRequestV2 {
322
288
  if (options.json !== null) {
323
289
  axios_options.data = options.json
324
290
  }
325
- // if (this.log) {
326
- // console.log("axios_options:", JSON.stringify(axios_options));
327
- // }
328
291
  if (options.url.startsWith("https:")) {
329
292
  const httpsAgent = new https.Agent({
330
293
  rejectUnauthorized: false,
@@ -334,20 +297,12 @@ class DirWebRequestV2 {
334
297
 
335
298
  axios(axios_options)
336
299
  .then((res) => {
337
- if (this.log) {
338
- console.log("Success Response:", res);
339
- console.log("Response for url:", options.url);
340
- console.log("Response headers:\n", JSON.stringify(res.headers));
341
- }
342
300
  if (callback) {
343
301
  callback(null, res);
344
302
  }
345
303
  })
346
304
  .catch((err) => {
347
305
  if (this.log) {
348
- if (err.response) {
349
- console.log("Error Response data:", err.response.data);
350
- }
351
306
  // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
352
307
  let cache = [];
353
308
  let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
@@ -359,9 +314,8 @@ class DirWebRequestV2 {
359
314
  }
360
315
  return value;
361
316
  });
362
- console.error("(DirWebRequestv2) An error occurred: ", error_log);
317
+ winston.error("(DirWebRequestv2) An error occurred: ", error_log);
363
318
  // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
364
- // console.error("An error occurred:", JSON.stringify(err));
365
319
  }
366
320
  if (callback) {
367
321
  let status = 1000;
@@ -398,7 +352,7 @@ class DirWebRequestV2 {
398
352
  });
399
353
  }
400
354
  catch (error) {
401
- console.error("Error:", error);
355
+ winston.error("DirWebRequestV2 Error:", error);
402
356
  }
403
357
  }
404
358
 
@@ -407,20 +361,11 @@ class DirWebRequestV2 {
407
361
  if (!action.settings) {
408
362
  return timeout;
409
363
  }
410
- // console.log("default timeout:", timeout);
411
- // console.log("action.settings:", action.settings);
412
- // console.log("action.settings.timeout:", action.settings.timeout);
413
- // console.log("typeof action.settings.timeout:", typeof action.settings.timeout);
414
- // console.log("action.settings.timeout > min", action.settings.timeout > min)
415
- // console.log("action.settings.timeout < max", action.settings.timeout < max)
416
-
417
364
  if (action.settings.timeout) {
418
365
  if ((typeof action.settings.timeout === "number") && action.settings.timeout > min && action.settings.timeout < max) {
419
366
  timeout = Math.round(action.settings.timeout)
420
- // console.log("new timeout:", timeout);
421
367
  }
422
368
  }
423
- // console.log("returning timeout:", timeout);
424
369
  return timeout
425
370
  }
426
371
 
@@ -1,7 +1,7 @@
1
1
  let axios = require('axios');
2
2
  let https = require("https");
3
3
  const { Filler } = require('../Filler');
4
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
5
5
  const { DirIntent } = require('./DirIntent');
6
6
 
7
7
  class DirWebRequestV2 {
@@ -1,6 +1,6 @@
1
1
  const { Filler } = require('../Filler');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
- const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
+ const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
5
 
6
6
  class DirWebResponse {
@@ -18,12 +18,13 @@ class DirWebResponse {
18
18
  }
19
19
 
20
20
  execute(directive, callback) {
21
+ winston.debug("Execute WebResponse directive: ", directive);
21
22
  let action;
22
23
  if (directive.action) {
23
24
  action = directive.action;
24
25
  }
25
26
  else {
26
- console.error("Incorrect directive (no action provided):", directive);
27
+ winston.debug("DirWebResponse Incorrect directive: ", directive);
27
28
  callback();
28
29
  return;
29
30
  }
@@ -34,22 +35,20 @@ class DirWebResponse {
34
35
  }
35
36
 
36
37
  async go(action, callback) {
37
- if (this.log) {
38
- console.log("(DirWebResponse) action:", action);
39
- }
38
+ winston.debug("DirWebResponse action: ", action);
40
39
 
41
40
  let requestAttributes = null;
41
+ let status = null;
42
42
  if (this.tdcache) {
43
43
  requestAttributes =
44
44
  await TiledeskChatbot.allParametersStatic(this.tdcache, this.requestId);
45
45
  const filler = new Filler();
46
46
 
47
47
  try {
48
- let status = action.status;
49
- status = filler.fill(status, requestAttributes);
48
+ status = filler.fill(action.status, requestAttributes);
50
49
  }
51
50
  catch(e) {
52
- console.error(e)
51
+ winston.error("DirWebResponse Error: ", e)
53
52
  }
54
53
 
55
54
  }
@@ -64,12 +63,10 @@ class DirWebResponse {
64
63
 
65
64
  try {
66
65
  this.tdcache.publish(topic, JSON.stringify(webResponse));
67
- if (this.log) {
68
- console.log("(DirWebResponse) Published webresponse to topic:", topic);
69
- }
66
+ winston.verbose("DirWebResponse Published webresponse to topic: " + topic);
70
67
  }
71
68
  catch(e) {
72
- console.error(e)
69
+ winston.error("DirWebResponse Error: ", e)
73
70
  }
74
71
 
75
72
  callback();
@@ -87,7 +84,7 @@ class DirWebResponse {
87
84
  resolve(json);
88
85
  }
89
86
  catch (err) {
90
- if (this.log) { console.error("Error parsing webRequest jsonBody:", jsonBody, err) };
87
+ winston.error("Error parsing webRequest jsonBody: " + JSON.stringify(jsonBody) + "\nError: " + JSON.stringify(err));
91
88
  reject("Error parsing jsonBody");
92
89
  }
93
90
  }
@@ -1,5 +1,7 @@
1
1
  const axios = require("axios").default;
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
+ const httpUtils = require("../../utils/HttpUtils");
4
+ const winston = require('../../utils/winston');
3
5
 
4
6
  let whatsapp_api_url;
5
7
 
@@ -15,13 +17,13 @@ class DirWhatsappByAttribute {
15
17
  }
16
18
 
17
19
  execute(directive, callback) {
18
- console.log("\n\nwhatsapp by attribtues action (execute) - directive: ", directive);
20
+ winston.verbose("Execute WhatsappByAttribute 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("DirWhatsappByAttribute Incorrect directive: ", directive);
25
27
  callback();
26
28
  return;
27
29
  }
@@ -31,10 +33,7 @@ class DirWhatsappByAttribute {
31
33
  }
32
34
 
33
35
  async go(action, callback) {
34
-
35
- if (this.log) {
36
- console.log("whatsapp by attributes action: ", JSON.stringify(action))
37
- }
36
+ winston.debug("(DirWhatsappByAttribute) Action: ", action);
38
37
 
39
38
  const whatsapp_api_url_pre = process.env.WHATSAPP_ENDPOINT;
40
39
 
@@ -43,20 +42,20 @@ class DirWhatsappByAttribute {
43
42
  } else {
44
43
  whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
45
44
  }
46
- console.log("DirWhatsappByAttribute whatsapp_api_url: ", whatsapp_api_url);
45
+ winston.debug("(DirWhatsappByAttribute) whatsapp_api_url: " + whatsapp_api_url);
47
46
 
48
47
  if (!action.attributeName) {
49
- console.error("DirWhatsappByAttribute attributeName is mandatory")
48
+ winston.error("(DirWhatsappByAttribute) attributeName is mandatory")
50
49
  callback();
51
50
  return;
52
51
  }
53
- if (this.log) { console.log("DirWhatsappByAttribute attributeName: ", action.attributeName )};
52
+ winston.debug("(DirWhatsappByAttribute) attributeName: " + action.attributeName )
54
53
 
55
54
  const attribute_value = await TiledeskChatbot.getParameterStatic(this.context.tdcache, this.context.requestId, action.attributeName)
56
- if (this.log) { console.log("attribute_value:", JSON.stringify(attribute_value)); }
55
+ winston.debug("(DirWhatsappByAttribute) attribute_value:", attribute_value);
57
56
 
58
57
  if (attribute_value == null) {
59
- console.error("DirWhatsappByAttribute attribute_value is undefined");
58
+ winston.error("(DirWhatsappByAttribute) attribute_value is undefined");
60
59
  callback();
61
60
  return;
62
61
  }
@@ -73,7 +72,7 @@ class DirWhatsappByAttribute {
73
72
  }
74
73
 
75
74
  return new Promise((resolve, reject) => {
76
- DirWhatsappByAttribute.myrequest(
75
+ httpUtils.request(
77
76
  HTTPREQUEST,
78
77
  function (err, resbody) {
79
78
  if (err) {
@@ -86,41 +85,13 @@ class DirWhatsappByAttribute {
86
85
  if (callback) {
87
86
  callback(null, resbody);
88
87
  }
89
- console.log("(tybot) broadcast sent: ", resbody);
88
+ winston.debug("(DirWhatsappByAttribute) broadcast sent: ", resbody);
90
89
  resolve(resbody);
91
90
  }
92
91
  }, true);
93
92
  })
94
93
 
95
94
  }
96
-
97
- // HTTP REQUEST
98
- static async myrequest(options, callback, log) {
99
- console.log("my request execution")
100
- return await axios({
101
- url: options.url,
102
- method: options.method,
103
- data: options.json,
104
- params: options.params,
105
- headers: options.headers
106
- }).then((res) => {
107
- if (res && res.status == 200 && res.data) {
108
- if (callback) {
109
- callback(null, res.data);
110
- }
111
- }
112
- else {
113
- if (callback) {
114
- callback(TiledeskClient.getErr({ message: "Response status not 200" }, options, res), null, null);
115
- }
116
- }
117
- }).catch((err) => {
118
- console.error("(tybot request) An error occured: ", err);
119
- if (callback) {
120
- callback(err, null, null);
121
- }
122
- })
123
- }
124
95
  }
125
96
 
126
97
  module.exports = { DirWhatsappByAttribute }
@@ -74,13 +74,10 @@ class Directives {
74
74
  // static CONDITION = "condition"; // DEPRECATED
75
75
 
76
76
  static actionToDirective(action) {
77
- // console.log("actionToDirective:", action);
78
77
  let directive = {
79
78
  name: action["_tdActionType"],
80
79
  action: action
81
80
  }
82
- // delete directive.action["_tdActionType"];
83
- // console.log("Directive out:", directive);
84
81
  return directive;
85
82
  }
86
83
  }