@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,7 +4,7 @@ const { Filler } = require("../Filler");
4
4
  const { DirIntent } = require("./DirIntent");
5
5
  let https = require("https");
6
6
  require('dotenv').config();
7
-
7
+ const winston = require('../../utils/winston');
8
8
 
9
9
  class DirCustomerio {
10
10
 
@@ -21,13 +21,13 @@ class DirCustomerio {
21
21
  }
22
22
 
23
23
  execute(directive, callback) {
24
- if (this.log) { console.log("DirCustomerio directive: ", directive); }
24
+ winston.verbose("Execute Customerio directive");
25
25
  let action;
26
26
  if (directive.action) {
27
27
  action = directive.action;
28
28
  }
29
29
  else {
30
- console.error("DirCustomerio Incorrect directive: ", JSON.stringify(directive));
30
+ winston.warn("DirCustomerio Incorrect directive: ", directive);
31
31
  callback();
32
32
  return;
33
33
  }
@@ -37,19 +37,18 @@ class DirCustomerio {
37
37
  }
38
38
 
39
39
  async go(action, callback) {
40
- if (this.log) { console.log("DirCustomerio action:", JSON.stringify(action)); }
40
+ winston.debug("(DirCustomerio) Action: ", action);
41
41
  if (!this.tdcache) {
42
- console.error("Error: DirCustomerio tdcache is mandatory");
42
+ winston.error("(DirCustomerio) Error: tdcache is mandatory");
43
43
  callback();
44
44
  return;
45
45
  }
46
46
 
47
47
  let trueIntent = action.trueIntent;
48
48
  let falseIntent = action.falseIntent;
49
- if (this.log) {
50
- console.log("DirCustomerio trueIntent", trueIntent)
51
- console.log("DirCustomerio falseIntent", falseIntent)
52
- }
49
+
50
+ winston.debug("(DirCustomerio) trueIntent " + trueIntent)
51
+ winston.debug("(DirCustomerio) falseIntent " + falseIntent)
53
52
 
54
53
  let requestVariables = null;
55
54
  requestVariables =
@@ -59,23 +58,22 @@ class DirCustomerio {
59
58
 
60
59
  let formid = action.formid;
61
60
  let bodyParameters = action.bodyParameters;
62
- if (this.log) {
63
- console.log("DirCustomerio formid: ", formid);
64
- console.log("DirCustomerio bodyParameters: ", bodyParameters);
65
- }
61
+
62
+ winston.debug("(DirCustomerio) formid: " + formid);
63
+ winston.debug("(DirCustomerio) bodyParameters: ", bodyParameters);
66
64
 
67
65
  if (!bodyParameters || bodyParameters === '') {
68
- if (this.log) { console.error("DirCustomerio ERROR - bodyParameters is undefined or null or empty string") };
66
+ winston.debug("(DirCustomerio) Error: bodyParameters is undefined or null or empty string");
69
67
  callback();
70
68
  return;
71
69
  }
72
70
 
73
71
  const customerio_base_url = process.env.CUSTOMERIO_ENDPOINT || "https://track.customer.io/api/v1";
74
- if (this.log) { console.log("DirCustomerio customerio_base_url: ", customerio_base_url); }
72
+ winston.debug("(DirCustomerio) customerio_base_url: " + customerio_base_url);
75
73
 
76
74
  let key = await this.getKeyFromIntegrations();
77
75
  if (!key) {
78
- if (this.log) { console.log("DirCustomerio - Key not found in Integrations."); }
76
+ winston.debug("(DirCustomerio) - Key not found in Integrations.");
79
77
  let status = 422;
80
78
  let error = 'Missing customerio access token';
81
79
  await this.#assignAttributes(action, status, error);
@@ -88,11 +86,11 @@ class DirCustomerio {
88
86
 
89
87
  const filler = new Filler();
90
88
  for (const [key, value] of Object.entries(bodyParameters)) {
91
- if (this.log) { console.log("bodyParam:", key, "value:", value) }
89
+ winston.debug("(DirCustomerio) bodyParam: " + key + " value: " + value)
92
90
  let filled_value = filler.fill(value, requestVariables);
93
91
  bodyParameters[key] = filled_value;
94
92
  }
95
- if (this.log) { console.log('DirCustomerio bodyParameters filler: ', bodyParameters) }
93
+ winston.debug("(DirCustomerio) bodyParameters filler: ", bodyParameters)
96
94
 
97
95
  let json = {
98
96
  data: bodyParameters
@@ -110,16 +108,15 @@ class DirCustomerio {
110
108
  json: json,
111
109
  method: "POST"
112
110
  }
113
- if (this.log) { console.log("DirCustomerio CUSTOMERIO_HTTPREQUEST", JSON.stringify(CUSTOMERIO_HTTPREQUEST)); }
111
+ winston.debug("(DirCustomerio) HttpRequest: ", CUSTOMERIO_HTTPREQUEST);
114
112
 
115
113
  this.#myrequest(
116
114
  CUSTOMERIO_HTTPREQUEST, async (err, resbody) => {
117
115
  if (err) {
118
116
  if (callback) {
119
- if (this.log) {
120
- console.error("(httprequest) DirCustomerio err response:", err.response)
121
- console.error("(httprequest) DirCustomerio err data:", err.response.data)
122
- };
117
+ winston.debug("(DirCustomerio) err response:", err.response)
118
+ winston.debug("(DirCustomerio) err data:", err.response.data)
119
+
123
120
  let status = null;
124
121
  let error;
125
122
 
@@ -133,10 +130,9 @@ class DirCustomerio {
133
130
  error = err.response.data.meta.error;
134
131
  }
135
132
 
136
- if (this.log) {
137
- console.error("(httprequest) DirCustomerio err data status:", status);
138
- console.error("(httprequest) DirCustomerio err data error:", error);
139
- }
133
+ winston.debug("(DirCustomerio) err data status: " + status);
134
+ winston.debug("(DirCustomerio) err data error: ", error);
135
+
140
136
  await this.#assignAttributes(action, status, error);
141
137
  if (falseIntent) {
142
138
  await this.#executeCondition(false, trueIntent, null, falseIntent, null);
@@ -148,7 +144,7 @@ class DirCustomerio {
148
144
 
149
145
  }
150
146
  } else if (callback) {
151
- if (this.log) { console.log("DirCustomerio resbody: ", JSON.stringify(resbody, null, 2)); }
147
+ winston.debug("(DirCustomerio) DirCustomerio resbody: ", resbody);
152
148
 
153
149
  let status = 204;
154
150
  let error = null;
@@ -167,11 +163,9 @@ class DirCustomerio {
167
163
  }
168
164
 
169
165
  async #assignAttributes(action, status, error) {
170
- if (this.log) {
171
- console.log("DirCustomerio assignAttributes action:", action)
172
- console.log("DirCustomerio assignAttributes status:", status)
173
- console.log("DirCustomerio assignAttributes error:", error)
174
- }
166
+ winston.debug("(DirCustomerio) assignAttributes action: ", action)
167
+ winston.debug("(DirCustomerio) assignAttributes status: " + status)
168
+ winston.debug("(DirCustomerio) assignAttributes error: ", error)
175
169
  if (this.context.tdcache) {
176
170
  if (action.assignStatusTo) {
177
171
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
@@ -179,22 +173,10 @@ class DirCustomerio {
179
173
  if (action.assignErrorTo) {
180
174
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
181
175
  }
182
-
183
- // Debug log
184
- if (this.log) {
185
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
186
- for (const [key, value] of Object.entries(all_parameters)) {
187
- if (this.log) { console.log("DirCustomerio request parameter:", key, "value:", value, "type:", typeof value) }
188
- }
189
- }
190
176
  }
191
177
  }
192
178
 
193
179
  #myrequest(options, callback) {
194
- if (this.log) {
195
- console.log("** API URL:", options.url);
196
- console.log("** Options:", JSON.stringify(options));
197
- }
198
180
  let axios_options = {
199
181
  url: options.url,
200
182
  method: options.method,
@@ -204,9 +186,6 @@ class DirCustomerio {
204
186
  if (options.json !== null) {
205
187
  axios_options.data = options.json
206
188
  }
207
- if (this.log) {
208
- console.log("axios_options:", JSON.stringify(axios_options));
209
- }
210
189
  if (options.url.startsWith("https:")) {
211
190
  const httpsAgent = new https.Agent({
212
191
  rejectUnauthorized: false,
@@ -215,10 +194,6 @@ class DirCustomerio {
215
194
  }
216
195
  axios(axios_options)
217
196
  .then((res) => {
218
- if (this.log) {
219
- console.log("Response for url:", options.url);
220
- console.log("Response headers:\n", JSON.stringify(res.headers));
221
- }
222
197
  if (res && (res.status == 200 || res.status == 204) && (res.data || res.config.data)) {
223
198
  if (callback) {
224
199
  if (res.data) {
@@ -251,7 +226,6 @@ class DirCustomerio {
251
226
  if (falseIntent) {
252
227
  falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
253
228
  }
254
- if (this.log) { console.log('DirCustomerio executeCondition/result', result) }
255
229
  if (result === true) {
256
230
  if (trueIntentDirective) {
257
231
  this.intentDir.execute(trueIntentDirective, () => {
@@ -261,7 +235,7 @@ class DirCustomerio {
261
235
  });
262
236
  }
263
237
  else {
264
- if (this.log) { console.log("No trueIntentDirective specified"); }
238
+ winston.debug("(DirCustomerio) No trueIntentDirective specified");
265
239
  if (callback) {
266
240
  callback();
267
241
  }
@@ -276,7 +250,7 @@ class DirCustomerio {
276
250
  });
277
251
  }
278
252
  else {
279
- if (this.log) { console.log("No falseIntentDirective specified"); }
253
+ winston.debug("(DirCustomerio) No falseIntentDirective specified");
280
254
  if (callback) {
281
255
  callback();
282
256
  }
@@ -295,14 +269,13 @@ class DirCustomerio {
295
269
  },
296
270
  method: "GET"
297
271
  }
298
- if (this.log) { console.log("Customerio INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
272
+ winston.debug("(DirCustomerio) Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
299
273
 
300
274
  this.#myrequest(
301
275
  INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
302
276
  if (err) {
303
277
  resolve(null);
304
278
  } else {
305
- if (this.log) { console.log('Integration: ', integration); }
306
279
  if (integration &&
307
280
  integration.value) {
308
281
  resolve(integration.value.apikey)
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot.js');
3
3
  const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
4
4
  const ms = require('minimist-string');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const winston = require('../../utils/winston');
6
7
 
7
8
  class DirDeflectToHelpCenter {
8
9
 
@@ -24,6 +25,7 @@ class DirDeflectToHelpCenter {
24
25
  }
25
26
 
26
27
  async execute(directive, callback) {
28
+ winston.verbose("Execute DeflectToHelpCenter directive");
27
29
  let action;
28
30
  if (directive.action) {
29
31
  action = directive.action
@@ -60,12 +62,11 @@ class DirDeflectToHelpCenter {
60
62
  url_target = action.urlTarget;
61
63
  }
62
64
  // let message = pipeline.message;
63
- //console.log("help center message", JSON.stringify(message));
64
65
  const last_user_text = await TiledeskChatbot.getParameterStatic(
65
66
  this.context.tdcache,
66
67
  this.context.requestId,
67
68
  TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY);
68
- if (this.log) {console.log("last_user_text", last_user_text);}
69
+ winston.debug("(DirDeflectToHelpCenter) last_user_text", last_user_text);
69
70
  if (last_user_text && last_user_text.trim() !== '') {
70
71
  const helpcenter = new HelpCenterQuery({
71
72
  APIKEY: "__",
@@ -76,30 +77,29 @@ class DirDeflectToHelpCenter {
76
77
  helpcenter.APIURL = this.helpcenter_api_endpoint
77
78
  }
78
79
  if (!workspace_id) {
79
- if (this.log) {console.log("No workspaces_id. Listing all workspaces to eventually select the first");}
80
+ winston.debug("(DirDeflectToHelpCenter) No workspaces_id. Listing all workspaces to eventually select the first");
80
81
  try {
81
82
  // find/select the first workspace
82
83
  const workspaces = await helpcenter.allWorkspaces();
83
84
  if (workspaces.length > 0) {
84
85
  workspace_id = workspaces[0]._id;
85
- // console.log("First Workspace selected", workspaces[0]);
86
86
  }
87
87
  else {
88
- if (this.log) {console.log("No Workspaces found");}
88
+ winston.debug("(DirDeflectToHelpCenter) No Workspaces found");
89
89
  callback(false);
90
90
  }
91
91
  }
92
92
  catch(err) {
93
- console.error("deflectToHelpCenter Error (search workspaces):", err);
93
+ winston.error("(DirDeflectToHelpCenter) Error search workspaces: ", err);
94
94
  callback(false);
95
95
  }
96
96
  }
97
- if (this.log) {console.log("searching on workspace_id:", workspace_id);}
97
+ winston.debug("(DirDeflectToHelpCenter) searching on workspace_id: " + workspace_id);
98
98
  try {
99
99
  const results = await helpcenter.search(workspace_id, last_user_text, maxresults);
100
100
  if (results && results.length > 0) {
101
- if (this.log) {console.log("Successfully got results", JSON.stringify(results));}
102
- if (this.log) {console.log("Sending hcReply", hc_reply);}
101
+ winston.debug("(DirDeflectToHelpCenter) Successfully got results ", results);
102
+ winston.debug("(DirDeflectToHelpCenter) Sending hcReply ", hc_reply);
103
103
  // pipeline.message.text = hc_reply;
104
104
  let buttons = [];
105
105
  results.forEach(content => {
@@ -141,26 +141,26 @@ class DirDeflectToHelpCenter {
141
141
  }
142
142
  }
143
143
 
144
- if (this.log) {console.log("HC reply:", JSON.stringify(message))};
144
+ winston.debug("(DirDeflectToHelpCenter) HC reply: ", message)
145
145
  this.tdClient.sendSupportMessage(
146
146
  this.context.requestId,
147
147
  message,
148
148
  (err) => {
149
149
  if (err) {
150
- console.error("Error sending reply:", err.message);
150
+ winston.error("(DirDeflectToHelpCenter) Error sending reply: " + err.message);
151
151
  callback(false);
152
152
  }
153
- if (this.log) {console.log("Reply message sent.");}
153
+ winston.debug("(DirDeflectToHelpCenter) Reply message sent.");
154
154
  callback(true);
155
155
  });
156
156
  }
157
157
  else {
158
- if (this.log) {console.log("Nothing found in Help Center. projectId:", project_id, "workspaceId:", workspace_id);}
158
+ winston.debug("(DirDeflectToHelpCenter) Nothing found in Help Center. projectId: " + project_id + " workspaceId: " + workspace_id);
159
159
  callback(false);
160
160
  }
161
161
  }
162
162
  catch(err) {
163
- console.error("deflectToHelpCenter Error (searching results):", err);
163
+ winston.error("(DirDeflectToHelpCenter) Error (searching results): ", err);
164
164
  callback(false);
165
165
  }
166
166
  }
@@ -172,9 +172,8 @@ class DirDeflectToHelpCenter {
172
172
  parseParams(directive_parameter) {
173
173
  let workspace_id = null;
174
174
  let hc_reply = null;
175
- // console.log("ms found:", ms)
175
+
176
176
  const params = ms(directive_parameter);
177
- // console.log("ms decoded params:", params)
178
177
  if (params.w) {
179
178
  workspace_id = params.w
180
179
  }
@@ -183,16 +182,12 @@ class DirDeflectToHelpCenter {
183
182
  }
184
183
 
185
184
  if (params.m) {
186
- // console.log("_params.m:", params.m)
187
185
  //hc_reply = params.m.replaceAll("\\n", "\n");
188
186
  hc_reply = params.m.replace(/\\n/g, "\n");
189
- // console.log("hc_reply with replaced slash n regex|replaceAll", hc_reply)
190
187
  }
191
188
  if (params.message) {
192
- // console.log("_params.message:", params.message)
193
189
  //hc_reply = params.message.replaceAll("\\n", "\n");
194
190
  hc_reply = params.message.replace(/\\n/g, "\n");
195
- // console.log("hc_reply -message with replaced slash n replace(/\\n/g", hc_reply)
196
191
  }
197
192
  return {
198
193
  workspace_id: workspace_id,
@@ -2,6 +2,7 @@ const { param } = require('express/lib/request');
2
2
  const ms = require('minimist-string');
3
3
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
4
  const { Filler } = require('../Filler');
5
+ const winston = require('../../utils/winston');
5
6
 
6
7
  class DirDeleteVariable {
7
8
 
@@ -14,6 +15,7 @@ class DirDeleteVariable {
14
15
  }
15
16
 
16
17
  async execute(directive, callback) {
18
+ winston.verbose("Execute DeleteVariable directive");
17
19
  let action;
18
20
  if (directive.action) {
19
21
  action = directive.action
@@ -29,11 +31,11 @@ class DirDeleteVariable {
29
31
  }
30
32
 
31
33
  async go(action, callback) {
32
- // let variableName = action.body.variableName;
34
+ winston.debug("(DirDeleteVariable) Action: ", action);
35
+
33
36
  let variableName = action.variableName;
34
- // console.log("DirDeleteVariable:", directive);
35
37
  if (!variableName) {
36
- if (this.log) {console.log("Error deleting variable. Missing 'variableName' error. Skipping");}
38
+ winston.error("(DirDeleteVariable) deleting variable. Missing 'variableName' error. Skipping");
37
39
  if (callback) {
38
40
  callback();
39
41
  }
@@ -46,11 +48,9 @@ class DirDeleteVariable {
46
48
  await TiledeskChatbot.allParametersStatic(
47
49
  this.context.tdcache, this.context.requestId
48
50
  );
49
- // console.log("All availabe variables before deletion:", variables);
51
+
50
52
  const filler = new Filler();
51
- // console.log("delete variable name:", variableName);
52
53
  variableName = filler.fill(variableName, variables);
53
- // console.log("delete variable name (after filling):", variableName);
54
54
  await TiledeskChatbot.deleteParameterStatic(
55
55
  this.context.tdcache, this.context.requestId, variableName
56
56
  );
@@ -60,7 +60,7 @@ class DirDeleteVariable {
60
60
  }
61
61
  }
62
62
  catch(err) {
63
- console.error("DirDeleteVariable error:", err);
63
+ winston.error("(DirDeleteVariable) error: ", err);
64
64
  if (completion) {
65
65
  completion();
66
66
  }
@@ -1,4 +1,5 @@
1
1
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
2
+ const winston = require('../../utils/winston');
2
3
 
3
4
  class DirDepartment {
4
5
 
@@ -21,7 +22,7 @@ class DirDepartment {
21
22
  }
22
23
 
23
24
  execute(directive, callback) {
24
- // if (this.log) {console.log("DirDepartment:", dep_name);}
25
+ winston.verbose("Execute Department directive");
25
26
  let action;
26
27
  if (directive.action) {
27
28
  action = directive.action;
@@ -61,15 +62,15 @@ class DirDepartment {
61
62
  // }
62
63
 
63
64
  go(action, callback) {
64
- if (this.log) {console.log("Switching to department:", action.depName);}
65
+ winston.debug("(DirDepartment) Action: ", action);
65
66
  const depName = action.depName;
66
67
  this.moveToDepartment(this.requestId, depName, (deps) => {
67
68
  if (!deps) {
68
- if (this.log) {console.log("Dep not found");}
69
+ winston.warn("(DirDepartment) Dep not found");
69
70
  callback();
70
71
  return
71
72
  }
72
- if (this.log) {console.log("Switched to dept:", depName, "action:", JSON.stringify(action));}
73
+ winston.debug("(DirDepartment) Switched to dept: " + depName + " action: " + JSON.stringify(action));
73
74
  if (action.triggerBot) {
74
75
  let dep = null;
75
76
  let i;
@@ -81,7 +82,7 @@ class DirDepartment {
81
82
  }
82
83
  }
83
84
  if (dep && dep.hasBot === true && dep.id_bot) {
84
- if (this.log) {console.log("Sending hidden /start message to bot in dept");}
85
+ winston.debug("(DirDepartment) Sending hidden /start message to bot in dept");
85
86
  const message = {
86
87
  type: "text",
87
88
  text: "/start",
@@ -93,15 +94,15 @@ class DirDepartment {
93
94
  this.requestId,
94
95
  message, (err) => {
95
96
  if (err) {
96
- console.error("Error sending hidden message:", err.message);
97
+ winston.error("(DirDepartment) Error sending hidden message: " + err.message)
97
98
  }
98
- if (this.log) {console.log("Hidden message sent.");}
99
+ winston.debug("(DirDepartment) Hidden message sent.");
99
100
  callback();
100
101
  });
101
102
  }
102
103
  }
103
104
  else {
104
- if (this.log) {console.log("No action.triggerBot");}
105
+ winston.debug("(DirDepartment) No action.triggerBot");
105
106
  callback();
106
107
  }
107
108
  });
@@ -109,9 +110,9 @@ class DirDepartment {
109
110
 
110
111
  moveToDepartment(requestId, depName, callback) {
111
112
  this.tdClient.getAllDepartments((err, deps) => {
112
- if (this.log) {console.log("deps:", JSON.stringify(deps));}
113
+ winston.debug("(DirDepartment) deps: ", deps);
113
114
  if (err) {
114
- console.error("getAllDepartments() error:", err);
115
+ winston.error("(DirDepartment) getAllDepartments() error: ", err);
115
116
  callback();
116
117
  return;
117
118
  }
@@ -127,11 +128,11 @@ class DirDepartment {
127
128
  if (dep) {
128
129
  this.tdClient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
129
130
  if (err) {
130
- console.error("DirDepartment error:", err);
131
+ winston.error("(DirDepartment) updatedRequestDepartment error: ", err);
131
132
  callback();
132
133
  }
133
134
  else {
134
- if (this.log) { console.log("DirDepartment response:",JSON.stringify(res)); }
135
+ winston.debug("(DirDepartment) response: ", res);
135
136
  callback(deps);
136
137
  }
137
138
  });
@@ -1,4 +1,5 @@
1
1
  const ms = require('minimist-string');
2
+ const winston = require('../../utils/winston');
2
3
 
3
4
  // DEPRECATED
4
5
  class DirDisableInputText {
@@ -7,7 +8,7 @@ class DirDisableInputText {
7
8
  }
8
9
 
9
10
  execute(directive, pipeline, callback) {
10
- // console.log("disable input text...pipeline");
11
+ winston.verbose("Execute DisableInputText directive");
11
12
  let message = pipeline.message
12
13
  if (!message.attributes) {
13
14
  message.attributes = {}
@@ -15,10 +16,8 @@ class DirDisableInputText {
15
16
  message.attributes.disableInputMessage = true;
16
17
  if (directive.parameter) {
17
18
  const options = this.parseParams(directive.parameter);
18
- // console.log("Options", options)
19
19
  directive.options = options;
20
20
  if (options.label) {
21
- // console.log("options.label", options.label)
22
21
  message.attributes.inputMessagePlaceholder = options.label;
23
22
  }
24
23
  }
@@ -28,13 +27,10 @@ class DirDisableInputText {
28
27
  parseParams(directive_parameter) {
29
28
  let label = null;
30
29
  const params = ms(directive_parameter);
31
- // console.log("params:", params);
32
30
  if (params.l) {
33
- // console.log("_param l", params.l);
34
31
  label = params.l;
35
32
  }
36
33
  if (params.label) {
37
- // console.log("_param label", params.label);
38
34
  label = params.label;
39
35
  }
40
36
  return {
@@ -1,5 +1,6 @@
1
1
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const ms = require('minimist-string');
3
+ const winston = require('../../utils/winston');
3
4
 
4
5
  class DirFireTiledeskEvent {
5
6
 
@@ -22,6 +23,7 @@ class DirFireTiledeskEvent {
22
23
  }
23
24
 
24
25
  execute(directive, callback) {
26
+ winston.verbose("Execute FireTiledeskEvent directive");
25
27
  if (directive.parameter) {
26
28
  const params = this.parseParams(directive.parameter);
27
29
  const event_name = params.name;
@@ -31,15 +33,13 @@ class DirFireTiledeskEvent {
31
33
  }
32
34
  this.tdClient.fireEvent(event, function(err, result) {
33
35
  if (err) {
34
- console.error("An error occurred invoking an event:", err);
36
+ winston.error("(FireTiledeskEvent) An error occurred invoking an event: ", err);
35
37
  }
36
38
  callback();
37
39
  });
38
40
  }
39
41
  else {
40
- if (this.log) {
41
- console.log("DirFireTiledeskEvent: no parameter");
42
- }
42
+ winston.verbose("(DirFireTiledeskEvent) no parameter");
43
43
  callback();
44
44
  }
45
45
  }