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