@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,7 +1,9 @@
1
1
  const axios = require("axios").default;
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { Filler } = require("../Filler");
4
4
  const { DirIntent } = require("./DirIntent");
5
+ const winston = require('../../utils/winston');
6
+ const httpUtils = require("../../utils/HttpUtils");
5
7
 
6
8
  let whatsapp_api_url;
7
9
 
@@ -21,13 +23,13 @@ class DirSendWhatsapp {
21
23
  }
22
24
 
23
25
  execute(directive, callback) {
24
- if (this.log) { console.log("DirWhatsappStatic directive: ", directive); }
26
+ winston.verbose("Execute SendWhatsapp directive");
25
27
  let action;
26
28
  if (directive.action) {
27
29
  action = directive.action;
28
30
  }
29
31
  else {
30
- console.error("Incorrect directive: ", JSON.stringify(directive));
32
+ winston.warn("DirSendWhatsapp Incorrect directive: ", directive);
31
33
  callback();
32
34
  return;
33
35
  }
@@ -38,9 +40,9 @@ class DirSendWhatsapp {
38
40
 
39
41
  async go(action, callback) {
40
42
 
41
- if (this.log) { console.log("DirWhatsappStatic action: ", JSON.stringify(action)) }
43
+ winston.debug("(DirSendWhatsapp) Action: ", action);
42
44
  if (!this.tdcache) {
43
- console.error("Error: DirAskGPT tdcache is mandatory");
45
+ winston.error("(DirSendWhatsapp) Error: tdcache is mandatory");
44
46
  callback();
45
47
  return;
46
48
  }
@@ -80,7 +82,7 @@ class DirSendWhatsapp {
80
82
  } else {
81
83
  whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
82
84
  }
83
- if (this.log) { console.log("DirSendWhatsapp whatsapp_api_url: ", whatsapp_api_url); };
85
+ winston.debug("(DirSendWhatsapp) whatsapp_api_url: " + whatsapp_api_url);
84
86
 
85
87
  const HTTPREQUEST = {
86
88
  url: whatsapp_api_url + "/tiledesk/broadcast",
@@ -91,12 +93,12 @@ class DirSendWhatsapp {
91
93
  method: 'POST'
92
94
  }
93
95
 
94
- if (this.log) { console.log("DirSendWhatsapp HTTPREQUEST: ", HTTPREQUEST); }
96
+ winston.debug("(DirSendWhatsapp) HttpRequest: ", HTTPREQUEST);
95
97
 
96
- this.#myrequest(
98
+ httpUtils.request(
97
99
  HTTPREQUEST, async (err, resbody) => {
98
100
  if (err) {
99
- console.error("DirSendWhatsapp error: ", err);
101
+ winston.error("(DirSendWhatsapp) error: ", err)
100
102
  await this.chatbot.addParameter("flowError", "SendWhatsapp Error: " + err);
101
103
  if (callback) {
102
104
  if (falseIntent) {
@@ -118,7 +120,7 @@ class DirSendWhatsapp {
118
120
  return;
119
121
  }
120
122
  } else {
121
- if (this.log) { console.log("DirSendWhatsapp unexpected resbody: ", resbody); }
123
+ winston.debug("(DirSendWhatsapp) unexpected resbody: ", resbody);
122
124
  if (callback) {
123
125
  if (falseIntent) {
124
126
  await this.#executeCondition(false, trueIntent, null, falseIntent, null);
@@ -151,7 +153,7 @@ class DirSendWhatsapp {
151
153
  })
152
154
  }
153
155
  else {
154
- if (this.log) { console.log("No trueIntentDirective specified"); }
156
+ winston.debug("(DirSendWhatsapp) No trueIntentDirective specified");
155
157
  if (callback) {
156
158
  callback();
157
159
  }
@@ -166,7 +168,7 @@ class DirSendWhatsapp {
166
168
  });
167
169
  }
168
170
  else {
169
- if (this.log) { console.log("No falseIntentDirective specified"); }
171
+ winston.debug("(DirSendWhatsapp) No falseIntentDirective specified");
170
172
  if (callback) {
171
173
  callback();
172
174
  }
@@ -209,39 +211,12 @@ class DirSendWhatsapp {
209
211
  resolve(receiver);
210
212
 
211
213
  } catch(err) {
212
- console.error("DirSendWhatsapp fillWholeReceiver error: ", err)
214
+ winston.error("(DirSendWhatsapp) fillWholeReceiver error: ", err)
213
215
  resolve(null);
214
216
  }
215
217
 
216
218
  })
217
219
  }
218
-
219
- // HTTP REQUEST
220
- async #myrequest(options, callback, log) {
221
- return await axios({
222
- url: options.url,
223
- method: options.method,
224
- data: options.json,
225
- params: options.params,
226
- headers: options.headers
227
- }).then((res) => {
228
- if (res && res.status == 200 && res.data) {
229
- if (callback) {
230
- callback(null, res.data);
231
- }
232
- }
233
- else {
234
- if (callback) {
235
- callback(TiledeskClient.getErr({ message: "Response status not 200" }, options, res), null, null);
236
- }
237
- }
238
- }).catch((err) => {
239
- console.error("(tybot request) An error occured: ", err);
240
- if (callback) {
241
- callback(err, null, null);
242
- }
243
- })
244
- }
245
220
  }
246
221
 
247
222
  module.exports = { DirSendWhatsapp }
@@ -1,9 +1,10 @@
1
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
1
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
2
2
  const { TiledeskExpression } = require('../../TiledeskExpression');
3
3
  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
  }
@@ -1,9 +1,11 @@
1
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
1
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
2
2
  const { TiledeskExpression } = require('../../TiledeskExpression');
3
3
  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');
8
+ const httpUtils = require('../../utils/HttpUtils');
7
9
 
8
10
  const schema = {
9
11
  "type": "object",
@@ -81,86 +83,66 @@ class DirSetAttributeV2 {
81
83
  }
82
84
 
83
85
  execute(directive, callback) {
86
+ winston.verbose("Execute SetAttributeV2 directive");
84
87
  let action;
85
88
  if (directive.action) {
86
89
  action = directive.action
87
90
  }
88
91
  else {
92
+ winston.warn("DirSetAttributeV2 Incorrect directive: ", directive);
89
93
  callback();
90
94
  return;
91
95
  }
92
- // console.log("go DirAssign with action:", action);
93
96
  this.go(action, () => {
94
97
  callback();
95
98
  });
96
99
  }
97
100
 
98
101
  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
- // }
102
+ winston.debug("(DirSetAttributeV2) Action: ", action);
103
+
105
104
  if (action && !action.operation) {
106
- if (this.log) {console.log("(SetAttributeV2) Error operation is mandatory");}
105
+ winston.error("(DirSetAttributeV2) Error operation is mandatory");
107
106
  callback();
107
+ return;
108
108
  }
109
109
  if (action && action.operation && action.operation.operands) {
110
- if (this.log) {console.log("(SetAttributeV2) filling in setattribute...");}
110
+ winston.debug("(DirSetAttributeV2) filling in setattribute...");
111
111
  await this.fillValues(action.operation.operands);
112
112
  }
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
113
 
116
114
  // FUN FACT: THIS TOOK A LOT OF EFFORT BUT IT WAS NEVER USED. YOU CAN SIMPLY CREATE A JSON ATTRIBUTE APPLYING
117
115
  // JSONparse FUNCTION TO AN ATTRIBUTE.
118
116
  // DEPRECATED because type = json is not available in the UI!
119
117
  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
118
  const json_value = JSON.parse(action.operation.operands[0].value);
123
- if (this.log) { console.log("(SetAttributeV2) json_value:", json_value); }
124
119
  await this.saveAttribute(action.destination, json_value);
125
120
  // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.destination, json_value);
126
121
  callback();
127
122
  return; // on json types no operations are permitted beyond assignment
128
123
  }
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
- // }
124
+ winston.debug("(DirSetAttributeV2) filled in setattribute:", action.operation);
125
+
140
126
  if (action.operation?.operators === undefined && action.operation?.operands?.length !== 1) {
141
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators === undefined && operands.length !== 1")};
127
+ winston.error("(DirSetAttributeV2) Invalid action: operators === undefined && operands.length !== 1")
142
128
  callback();
143
129
  return;
144
130
  }
145
131
  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")};
132
+ winston.error("(DirSetAttributeV2) Invalid action: operators.length !== operands.length - 1")
147
133
  callback();
148
134
  return;
149
135
  }
150
136
  // if (action && action.operation && action.operation.operands) {
151
- // console.log("filling in setattribute...");
152
137
  // await this.fillValues(action.operation.operands);
153
138
  // }
154
- // console.log("dirsetattribute, action.operation.operands:", action.operation.operands);
155
139
  try {
156
140
  const expression = TiledeskExpression.JSONOperationToExpression(action.operation?.operators, action.operation?.operands);
157
141
  const attributes = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
158
- // console.log("dirsetattribute, attributes:", attributes);
159
142
  if (attributes) {
160
143
  attributes.TiledeskMath = TiledeskMath;
161
144
  attributes.TiledeskString = TiledeskString;
162
145
  const result = new TiledeskExpression().evaluateJavascriptExpression(expression, attributes);
163
- // console.log("filling in setattribute, result:", result);
164
146
  // THE GOAL OF ATTRIBUTE-FILLING THE "DESTINATION" FIELD IS TO SUPPORT DYNAMIC ATTRIBUTES
165
147
  // (ATTRS WHOSE NAME IS UNKNOWN AD DESIGN-TIME)
166
148
  // STILL UNSUPPORTED IN UI
@@ -169,7 +151,7 @@ class DirSetAttributeV2 {
169
151
  }
170
152
  }
171
153
  catch(err) {
172
- console.error("SetAttributeV2 error:", err);
154
+ winston.error("(DirSetAttributeV2) error:", err);
173
155
  }
174
156
 
175
157
  // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, destination, result);
@@ -177,12 +159,9 @@ class DirSetAttributeV2 {
177
159
  }
178
160
 
179
161
  async saveAttribute(key, value, persist) {
180
- if (this.log) {
181
- console.log("SetAttributeV2 saving attribute:", key, value, persist);
182
- }
162
+ winston.debug("(DirSetAttributeV2) saving attribute: " + key + " " + value + " " + persist);
183
163
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
184
164
  // if (persist) {
185
- // console.log("SetAttributeV2 persisting...");
186
165
  // await this.persistOnTiledesk(destination, result);
187
166
  // }
188
167
 
@@ -216,19 +195,15 @@ class DirSetAttributeV2 {
216
195
  json: json,
217
196
  method: 'POST'
218
197
  }
219
- if (this.log) { console.log("SetAttribute. HTTPREQUEST: ", HTTPREQUEST); }
220
- this.#myrequest(
198
+ winston.debug("(DirSetAttributeV2) HttpRequest: ", HTTPREQUEST);
199
+ httpUtils.request(
221
200
  HTTPREQUEST, async (err, resbody) => {
222
201
  if (err) {
223
202
  if (this.log) {
224
- console.error("SetAttribute. persistOnTiledesk() error:", err);
203
+ winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
225
204
  }
226
- // callback();
227
- // return;
228
205
  } else {
229
- if (this.log) { console.log("SetAttribute. Attributes saved.", JSON.stringify(resbody)); }
230
- // callback();
231
- // return;
206
+ winston.debug("(DirSetAttributeV2) Attributes saved: ", resbody);
232
207
  }
233
208
  }
234
209
  );
@@ -237,13 +212,10 @@ class DirSetAttributeV2 {
237
212
 
238
213
  async fillDestination(destination) {
239
214
  if (this.tdcache) {
240
- // console.log("tdcache in setattribute...", this.tdcache);
241
215
  const requestAttributes =
242
216
  await TiledeskChatbot.allParametersStatic(this.tdcache, this.context.requestId);
243
- // console.log("requestAttributes in setattribute...", requestAttributes);
244
217
  const filler = new Filler();
245
218
  destination = filler.fill(destination, requestAttributes);
246
- // console.log("setattribute, final destination:", destination);
247
219
  }
248
220
  return destination
249
221
  }
@@ -276,27 +248,21 @@ class DirSetAttributeV2 {
276
248
  // ]
277
249
  try {
278
250
  if (this.tdcache) {
279
- // console.log("tdcache in setattribute...", this.tdcache);
280
251
  const requestAttributes =
281
252
  await TiledeskChatbot.allParametersStatic(this.tdcache, this.context.requestId);
282
- // console.log("requestAttributes in setattribute...", requestAttributes);
283
253
  const filler = new Filler();
284
254
  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
- // }
255
+ operand.value = filler.fill(operand.value, requestAttributes);
290
256
  });
291
257
  }
292
258
  }
293
259
  catch(error) {
294
- console.error("Error while filling operands:", error);
260
+ winston.error("(DirSetAttributeV2) Error while filling operands: ", error);
295
261
  }
296
262
  }
297
263
 
298
264
  convertOperandValues(operands) {
299
- console.log("Converting operands:", operands);
265
+ winston.debug("(DirSetAttributeV2) Converting operands:", operands);
300
266
  // operation: {
301
267
  // operators: ["addAsNumber", "subtractAsNumber", "divideAsNumber", "multiplyAsNumber"],
302
268
  // operands: [
@@ -309,75 +275,21 @@ class DirSetAttributeV2 {
309
275
  try {
310
276
  operands.forEach(operand => {
311
277
  if (operand.type) {
312
- console.log("Converting operands - operand.type:", operand.type.toLowerCase());
313
278
  if (operand.type.toLowerCase() === "number") {
314
- console.log("Converting operands - number");
315
279
  operand.value = Number(operand.value);
316
- console.log("new value:", operand.value);
317
- console.log("new value type:", typeof operand.value);
318
280
  }
319
281
  else if (operand.type.toLowerCase() === "json") {
320
- console.log("Converting operands - json, value =", operand.value);
321
282
  operand.value = JSON.parse(operand.value);
322
- console.log("new value:", operand.value);
323
- console.log("new value type:", typeof operand.value);
324
283
  }
325
284
  else {
326
- console.log("Converting operands - ??");
285
+ winston.warn("Converting operands - ??");
327
286
  }
328
287
  }
329
288
  });
330
289
  }
331
290
  catch(error) {
332
- console.error("Error while converting operands:", error);
333
- }
334
- }
335
-
336
- #myrequest(options, callback) {
337
- if (this.log) {
338
- console.log("API URL:", options.url);
339
- console.log("** Options:", JSON.stringify(options));
340
- }
341
- let axios_options = {
342
- url: options.url,
343
- method: options.method,
344
- params: options.params,
345
- headers: options.headers
346
- }
347
- if (options.json !== null) {
348
- axios_options.data = options.json
291
+ winston.error("(DirSetAttributeV2) Error while converting operands: ", error);
349
292
  }
350
- if (this.log) {
351
- console.log("axios_options:", JSON.stringify(axios_options));
352
- }
353
- if (options.url.startsWith("https:")) {
354
- const httpsAgent = new https.Agent({
355
- rejectUnauthorized: false,
356
- });
357
- axios_options.httpsAgent = httpsAgent;
358
- }
359
- axios(axios_options)
360
- .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
- if (res && res.status == 200 && res.data) {
366
- if (callback) {
367
- callback(null, res.data);
368
- }
369
- }
370
- else {
371
- if (callback) {
372
- callback(new Error("Response status is not 200"), null);
373
- }
374
- }
375
- })
376
- .catch((error) => {
377
- if (callback) {
378
- callback(error, null);
379
- }
380
- });
381
293
  }
382
294
 
383
295
  fixToken(token) {
@@ -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
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/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();