@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.
- package/ExtApi.js +4 -83
- package/ExtUtil.js +0 -1
- package/Logger.js +105 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/{models → engine}/IntentForm.js +30 -44
- package/{models → engine}/IntentsMachineFactory.js +5 -4
- package/{models → engine}/MongodbBotsDataSource.js +31 -55
- package/{models → engine}/MongodbIntentsMachine.js +6 -5
- package/{models → engine}/TiledeskChatbot.js +82 -259
- package/{models → engine}/TiledeskChatbotConst.js +9 -0
- package/{models → engine}/TiledeskIntentsMachine.js +5 -15
- package/{models → engine/mock}/MockBotsDataSource.js +3 -19
- package/{models → engine/mock}/MockTdCache.js +0 -9
- package/index.js +103 -380
- package/logs/app.log +12723 -277
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +31686 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +5 -2
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
- package/{models/faqService.js → services/FaqService.js} +4 -3
- package/services/IntegrationService.js +43 -0
- package/services/TilebotService.js +47 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
- package/tiledeskChatbotPlugs/Filler.js +0 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
- package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
- package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
- package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
- package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +164 -234
- package/utils/winston.js +42 -0
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require("../../
|
|
2
|
+
const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
let https = require("https");
|
|
5
5
|
const { DirIntent } = require("./DirIntent");
|
|
6
6
|
require('dotenv').config();
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
9
|
+
const integrationService = require("../../services/IntegrationService");
|
|
7
10
|
|
|
8
11
|
class DirQapla {
|
|
9
12
|
|
|
@@ -14,19 +17,21 @@ class DirQapla {
|
|
|
14
17
|
this.context = context;
|
|
15
18
|
this.tdcache = this.context.tdcache;
|
|
16
19
|
this.requestId = this.context.requestId;
|
|
20
|
+
this.projectId = this.context.projectId;
|
|
21
|
+
this.token = this.context.token;
|
|
17
22
|
this.intentDir = new DirIntent(context);
|
|
18
23
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
19
24
|
this.log = context.log;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
execute(directive, callback) {
|
|
23
|
-
|
|
28
|
+
winston.verbose("Execute Qapla directive");
|
|
24
29
|
let action;
|
|
25
30
|
if (directive.action) {
|
|
26
31
|
action = directive.action;
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
|
-
|
|
34
|
+
winston.warn("DirQapla Incorrect directive: ", directive);
|
|
30
35
|
callback();
|
|
31
36
|
return;
|
|
32
37
|
}
|
|
@@ -36,9 +41,9 @@ class DirQapla {
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
async go(action, callback) {
|
|
39
|
-
|
|
44
|
+
winston.debug("(DirQapla) Action: ", action);
|
|
40
45
|
if (!this.tdcache) {
|
|
41
|
-
|
|
46
|
+
winston.error("(DirQapla) Error: tdcache is mandatory");
|
|
42
47
|
callback();
|
|
43
48
|
return;
|
|
44
49
|
}
|
|
@@ -48,12 +53,10 @@ class DirQapla {
|
|
|
48
53
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
49
54
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.log("DirQapla falseIntentAttributes", falseIntentAttributes)
|
|
56
|
-
}
|
|
56
|
+
winston.debug("(DirQapla) trueIntent " + trueIntent)
|
|
57
|
+
winston.debug("(DirQapla) falseIntent " + falseIntent)
|
|
58
|
+
winston.debug("(DirQapla) trueIntentAttributes " + trueIntentAttributes)
|
|
59
|
+
winston.debug("(DirQapla) falseIntentAttributes " + falseIntentAttributes)
|
|
57
60
|
|
|
58
61
|
// Set default values
|
|
59
62
|
let status = null;
|
|
@@ -68,10 +71,9 @@ class DirQapla {
|
|
|
68
71
|
|
|
69
72
|
const filler = new Filler();
|
|
70
73
|
const tracking_number = filler.fill(action.trackingNumber, requestVariables);
|
|
71
|
-
if (this.log) { console.log("DirQapla tracking number: ", tracking_number); }
|
|
72
74
|
|
|
73
75
|
if (!tracking_number || tracking_number === '') {
|
|
74
|
-
|
|
76
|
+
winston.debug("(DirQapla) Error: tracking number is undefined or null or empty string");
|
|
75
77
|
error = "Tracking number is not defined";
|
|
76
78
|
await this.#assignAttributes(action, status, result, error);
|
|
77
79
|
if (falseIntent) {
|
|
@@ -84,17 +86,17 @@ class DirQapla {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
const qapla_base_url = process.env.QAPLA_ENDPOINT || "https://api.qapla.it/1.2"
|
|
87
|
-
|
|
89
|
+
winston.debug("(DirQapla) DirQapla qapla_base_url: " + qapla_base_url);
|
|
88
90
|
|
|
89
91
|
let key = action.apiKey;
|
|
90
92
|
|
|
91
93
|
if (!key) {
|
|
92
|
-
|
|
93
|
-
key = await
|
|
94
|
+
winston.debug("(DirQapla) DirQapla - Key not found into action. Searching in integrations...");
|
|
95
|
+
key = await integrationService.getKeyFromIntegrations(this.projectId, 'qapla', this.token);
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
if (!key) {
|
|
97
|
-
|
|
99
|
+
winston.debug("(DirQapla) Error: api key is mandatory");
|
|
98
100
|
error = "Invalid or empty ApiKey";
|
|
99
101
|
await this.#assignAttributes(action, status, result, error);
|
|
100
102
|
if (falseIntent) {
|
|
@@ -117,16 +119,13 @@ class DirQapla {
|
|
|
117
119
|
},
|
|
118
120
|
method: "GET"
|
|
119
121
|
}
|
|
120
|
-
|
|
122
|
+
winston.debug("(DirQapla) HttpRequest ", QAPLA_HTTPREQUEST);
|
|
121
123
|
|
|
122
|
-
|
|
124
|
+
httpUtils.request(
|
|
123
125
|
QAPLA_HTTPREQUEST, async (err, resbody) => {
|
|
124
126
|
if (err) {
|
|
125
127
|
if (callback) {
|
|
126
|
-
|
|
127
|
-
if (this.log) {
|
|
128
|
-
console.error("(httprequest) DirQapla getShipment full err:", err);
|
|
129
|
-
}
|
|
128
|
+
winston.debug("(DirQapla) getShipment err: " + err.message);
|
|
130
129
|
error = "Unable to get shipment";
|
|
131
130
|
await this.#assignAttributes(action, status, result, error);
|
|
132
131
|
if (falseIntent) {
|
|
@@ -138,7 +137,7 @@ class DirQapla {
|
|
|
138
137
|
return;
|
|
139
138
|
}
|
|
140
139
|
} else if (callback) {
|
|
141
|
-
|
|
140
|
+
winston.debug("(DirQapla) getShipment resbody: ", resbody);
|
|
142
141
|
|
|
143
142
|
if (resbody.getShipment &&
|
|
144
143
|
resbody.getShipment.shipments &&
|
|
@@ -186,7 +185,7 @@ class DirQapla {
|
|
|
186
185
|
})
|
|
187
186
|
}
|
|
188
187
|
else {
|
|
189
|
-
|
|
188
|
+
winston.debug("(DirQapla) No trueIntentDirective specified");
|
|
190
189
|
if (callback) {
|
|
191
190
|
callback();
|
|
192
191
|
}
|
|
@@ -201,7 +200,7 @@ class DirQapla {
|
|
|
201
200
|
});
|
|
202
201
|
}
|
|
203
202
|
else {
|
|
204
|
-
|
|
203
|
+
winston.debug("(DirQapla)No falseIntentDirective specified");
|
|
205
204
|
if (callback) {
|
|
206
205
|
callback();
|
|
207
206
|
}
|
|
@@ -210,12 +209,7 @@ class DirQapla {
|
|
|
210
209
|
}
|
|
211
210
|
|
|
212
211
|
async #assignAttributes(action, status, result, error) {
|
|
213
|
-
|
|
214
|
-
console.log("DirQapla assignAttributes action:", action)
|
|
215
|
-
console.log("DirQapla assignAttributes status:", status)
|
|
216
|
-
console.log("DirQapla assignAttributes result:", result)
|
|
217
|
-
console.log("DirQapla assignAttributes error:", error)
|
|
218
|
-
}
|
|
212
|
+
|
|
219
213
|
if (this.context.tdcache) {
|
|
220
214
|
if (action.assignStatusTo) {
|
|
221
215
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
|
|
@@ -226,96 +220,8 @@ class DirQapla {
|
|
|
226
220
|
if (action.assignErrorTo) {
|
|
227
221
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
|
|
228
222
|
}
|
|
229
|
-
|
|
230
|
-
// Debug log
|
|
231
|
-
if (this.log) {
|
|
232
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
233
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
234
|
-
if (this.log) { console.log("DirQapla request parameter:", key, "value:", value, "type:", typeof value) }
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
#myrequest(options, callback) {
|
|
241
|
-
if (this.log) {
|
|
242
|
-
console.log("API URL:", options.url);
|
|
243
|
-
console.log("** Options:", JSON.stringify(options));
|
|
244
223
|
}
|
|
245
|
-
let axios_options = {
|
|
246
|
-
url: options.url,
|
|
247
|
-
method: options.method,
|
|
248
|
-
params: options.params,
|
|
249
|
-
headers: options.headers
|
|
250
|
-
}
|
|
251
|
-
if (options.json !== null) {
|
|
252
|
-
axios_options.data = options.json
|
|
253
|
-
}
|
|
254
|
-
if (this.log) {
|
|
255
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
256
|
-
}
|
|
257
|
-
if (options.url.startsWith("https:")) {
|
|
258
|
-
const httpsAgent = new https.Agent({
|
|
259
|
-
rejectUnauthorized: false,
|
|
260
|
-
});
|
|
261
|
-
axios_options.httpsAgent = httpsAgent;
|
|
262
|
-
}
|
|
263
|
-
axios(axios_options)
|
|
264
|
-
.then((res) => {
|
|
265
|
-
if (this.log) {
|
|
266
|
-
console.log("Response for url:", options.url);
|
|
267
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
268
|
-
}
|
|
269
|
-
if (res && res.status == 200 && res.data) {
|
|
270
|
-
if (callback) {
|
|
271
|
-
callback(null, res.data);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
if (callback) {
|
|
276
|
-
callback(new Error("Response status is not 200"), null);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
.catch((error) => {
|
|
281
|
-
console.error("(DirQapla) Axios error: ", JSON.stringify(error));
|
|
282
|
-
if (callback) {
|
|
283
|
-
callback(error, null);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
224
|
}
|
|
287
|
-
|
|
288
|
-
async getKeyFromIntegrations() {
|
|
289
|
-
return new Promise((resolve) => {
|
|
290
|
-
|
|
291
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
292
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/qapla",
|
|
293
|
-
headers: {
|
|
294
|
-
'Content-Type': 'application/json',
|
|
295
|
-
'Authorization': 'JWT ' + this.context.token
|
|
296
|
-
},
|
|
297
|
-
method: "GET"
|
|
298
|
-
}
|
|
299
|
-
if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
300
|
-
|
|
301
|
-
this.#myrequest(
|
|
302
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
303
|
-
if (err) {
|
|
304
|
-
resolve(null);
|
|
305
|
-
} else {
|
|
306
|
-
|
|
307
|
-
if (integration &&
|
|
308
|
-
integration.value) {
|
|
309
|
-
resolve(integration.value.apikey)
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
resolve(null)
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
})
|
|
316
|
-
})
|
|
317
|
-
}
|
|
318
|
-
|
|
319
225
|
}
|
|
320
226
|
|
|
321
227
|
module.exports = { DirQapla }
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const { Filler } = require('../Filler');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
3
|
-
const { TiledeskChatbotUtil } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
+
const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
|
|
4
4
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
5
|
+
const winston = require('../../utils/winston');
|
|
5
6
|
|
|
6
7
|
class DirRandomReply {
|
|
7
8
|
|
|
@@ -27,18 +28,17 @@ class DirRandomReply {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
execute(directive, callback) {
|
|
30
|
-
|
|
31
|
+
winston.verbose("Execute RandomReply directive");
|
|
31
32
|
let action;
|
|
32
33
|
if (directive.action) {
|
|
33
34
|
action = directive.action;
|
|
34
|
-
// console.log("got action:", JSON.stringify(action));
|
|
35
35
|
if (!action.attributes) {
|
|
36
36
|
action.attributes = {}
|
|
37
37
|
}
|
|
38
38
|
action.attributes.fillParams = true;
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
|
-
|
|
41
|
+
winston.warn("DirRandomReply Incorrect directive: ", directive);
|
|
42
42
|
callback();
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
@@ -48,6 +48,7 @@ class DirRandomReply {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async go(action, callback) {
|
|
51
|
+
winston.debug("(DirRandomReply) Action: ", action);
|
|
51
52
|
const message = action;
|
|
52
53
|
// fill
|
|
53
54
|
let requestVariables = null;
|
|
@@ -56,28 +57,19 @@ class DirRandomReply {
|
|
|
56
57
|
await TiledeskChatbot.allParametersStatic(
|
|
57
58
|
this.tdcache, this.requestId
|
|
58
59
|
);
|
|
59
|
-
|
|
60
|
-
for (const [key, value] of Object.entries(requestVariables)) {
|
|
61
|
-
const value_type = typeof value;
|
|
62
|
-
if (this.log) {console.log("(DirReply) request parameter:", key, "value:", value, "type:", value_type)}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
60
|
+
|
|
65
61
|
const filler = new Filler();
|
|
66
62
|
// fill text attribute
|
|
67
63
|
message.text = filler.fill(message.text, requestVariables);
|
|
68
|
-
|
|
64
|
+
winston.debug("(DirRandomReply) filling commands. Message: ", message);
|
|
69
65
|
if (message.attributes && message.attributes.commands) {
|
|
70
66
|
const rnd_commands = TiledeskChatbotUtil.chooseRandomReply(message);
|
|
71
67
|
message.attributes.commands = rnd_commands;
|
|
72
|
-
if (this.log) {console.log("filling commands'. commands found.");}
|
|
73
68
|
let commands = message.attributes.commands;
|
|
74
|
-
if (this.log) {console.log("commands:", JSON.stringify(commands), commands.length);}
|
|
75
69
|
if (commands.length > 0) {
|
|
76
|
-
if (this.log) {console.log("commands' found");}
|
|
77
70
|
for (let i = 0; i < commands.length; i++) {
|
|
78
71
|
if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
|
|
79
72
|
commands[i].message.text = filler.fill(commands[i].message.text, requestVariables);
|
|
80
|
-
if (this.log) {console.log("command filled:", commands[i].message.text);}
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
75
|
}
|
|
@@ -96,15 +88,15 @@ class DirRandomReply {
|
|
|
96
88
|
// }
|
|
97
89
|
}
|
|
98
90
|
// send!
|
|
99
|
-
|
|
91
|
+
winston.debug("(DirRandomReply) Reply:", message);
|
|
100
92
|
this.tdClient.sendSupportMessage(
|
|
101
93
|
this.requestId,
|
|
102
94
|
message,
|
|
103
95
|
(err) => {
|
|
104
96
|
if (err) {
|
|
105
|
-
|
|
97
|
+
winston.debug("(DirRandomReply) Error sending reply: " + err.message);
|
|
106
98
|
}
|
|
107
|
-
|
|
99
|
+
winston.debug("(DirRandomReply) Reply message sent.")
|
|
108
100
|
callback();
|
|
109
101
|
});
|
|
110
102
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
2
|
+
const winston = require('../../utils/winston');
|
|
2
3
|
|
|
3
4
|
class DirRemoveCurrentBot {
|
|
4
5
|
|
|
@@ -21,6 +22,7 @@ class DirRemoveCurrentBot {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
execute(directive, callback) {
|
|
25
|
+
winston.verbose("Execute RemoveCurrentBot directive");
|
|
24
26
|
let action;
|
|
25
27
|
if (directive.action) {
|
|
26
28
|
action = directive.action;
|
|
@@ -29,6 +31,7 @@ class DirRemoveCurrentBot {
|
|
|
29
31
|
action = {};
|
|
30
32
|
}
|
|
31
33
|
else {
|
|
34
|
+
winston.warn("DirRemoveCurrentBot Incorrect directive: ", directive);
|
|
32
35
|
callback();
|
|
33
36
|
}
|
|
34
37
|
this.go(action, () => {
|
|
@@ -37,6 +40,7 @@ class DirRemoveCurrentBot {
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
go(action, callback) {
|
|
43
|
+
winston.debug("(RemoveCurrentBot) Action: ", action);
|
|
40
44
|
this.tdClient.removeCurrentBot(this.requestId, (err) => {
|
|
41
45
|
callback();
|
|
42
46
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
|
+
const winston = require('../../utils/winston');
|
|
4
5
|
|
|
5
6
|
class DirReplaceBot {
|
|
6
7
|
|
|
@@ -23,7 +24,7 @@ class DirReplaceBot {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
execute(directive, callback) {
|
|
26
|
-
|
|
27
|
+
winston.verbose("Execute ReplaceBot directive");
|
|
27
28
|
let action;
|
|
28
29
|
if (directive.action) {
|
|
29
30
|
action = directive.action;
|
|
@@ -35,6 +36,7 @@ class DirReplaceBot {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
39
|
+
winston.warn("DirReplaceBot Incorrect directive: ", directive);
|
|
38
40
|
callback();
|
|
39
41
|
}
|
|
40
42
|
this.go(action, () => {
|
|
@@ -43,6 +45,7 @@ class DirReplaceBot {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async go(action, callback) {
|
|
48
|
+
winston.debug("(DirReplaceBot) Action: ", action);
|
|
46
49
|
let botName = action.botName;
|
|
47
50
|
let variables = null;
|
|
48
51
|
variables =
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
4
|
|
|
5
5
|
const axios = require("axios").default;
|
|
6
6
|
let https = require("https");
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const httpUtils = require('../../utils/HttpUtils');
|
|
7
9
|
|
|
8
10
|
class DirReplaceBotV2 {
|
|
9
11
|
|
|
@@ -26,7 +28,7 @@ class DirReplaceBotV2 {
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
execute(directive, callback) {
|
|
29
|
-
|
|
31
|
+
winston.verbose("Execute ReplaceBotV2 directive");
|
|
30
32
|
let action;
|
|
31
33
|
if (directive.action) {
|
|
32
34
|
action = directive.action;
|
|
@@ -38,6 +40,7 @@ class DirReplaceBotV2 {
|
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
else {
|
|
43
|
+
winston.warn("DirReplaceBotV2 Incorrect directive: ", directive);
|
|
41
44
|
callback();
|
|
42
45
|
}
|
|
43
46
|
this.go(action, () => {
|
|
@@ -46,6 +49,7 @@ class DirReplaceBotV2 {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
async go(action, callback) {
|
|
52
|
+
winston.debug("(DirReplaceBotV2) Action: ", action);
|
|
49
53
|
let botName = action.botName;
|
|
50
54
|
let blockName = action.blockName;
|
|
51
55
|
let variables = null;
|
|
@@ -73,19 +77,19 @@ class DirReplaceBotV2 {
|
|
|
73
77
|
method: 'PUT'
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
|
|
80
|
+
httpUtils.request(
|
|
77
81
|
HTTPREQUEST, async (err, resbody) => {
|
|
78
82
|
if (err) {
|
|
79
|
-
|
|
83
|
+
winston.error("(DirReplaceBotV2) DirReplaceBot error: ", err);
|
|
80
84
|
if (callback) {
|
|
81
85
|
callback();
|
|
82
86
|
return;
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
winston.debug("(DirReplaceBotV2) replace resbody: ", resbody)
|
|
87
91
|
if (blockName) {
|
|
88
|
-
|
|
92
|
+
winston.debug("(DirReplaceBotV2) Sending hidden /start message to bot in dept");
|
|
89
93
|
const message = {
|
|
90
94
|
type: "text",
|
|
91
95
|
text: "/" + blockName,
|
|
@@ -97,9 +101,8 @@ class DirReplaceBotV2 {
|
|
|
97
101
|
this.requestId,
|
|
98
102
|
message, (err) => {
|
|
99
103
|
if (err) {
|
|
100
|
-
|
|
104
|
+
winston.debug("(DirReplaceBotV2) Error sending hidden message: " + err.message);
|
|
101
105
|
}
|
|
102
|
-
if (this.log) { console.log("Hidden message sent."); }
|
|
103
106
|
callback();
|
|
104
107
|
});
|
|
105
108
|
}
|
|
@@ -111,7 +114,6 @@ class DirReplaceBotV2 {
|
|
|
111
114
|
|
|
112
115
|
// this.tdClient.replaceBotByName(this.requestId, botName, () => {
|
|
113
116
|
// if (blockName) {
|
|
114
|
-
// if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
115
117
|
// const message = {
|
|
116
118
|
// type: "text",
|
|
117
119
|
// text: "/" + blockName,
|
|
@@ -123,9 +125,8 @@ class DirReplaceBotV2 {
|
|
|
123
125
|
// this.requestId,
|
|
124
126
|
// message, (err) => {
|
|
125
127
|
// if (err) {
|
|
126
|
-
//
|
|
128
|
+
// winston.error("Error sending hidden message:", err.message);
|
|
127
129
|
// }
|
|
128
|
-
// if (this.log) {console.log("Hidden message sent.");}
|
|
129
130
|
// callback();
|
|
130
131
|
// });
|
|
131
132
|
// }
|
|
@@ -135,53 +136,6 @@ class DirReplaceBotV2 {
|
|
|
135
136
|
// });
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
#myrequest(options, callback) {
|
|
139
|
-
if (this.log) {
|
|
140
|
-
console.log("API URL:", options.url);
|
|
141
|
-
console.log("** Options:", JSON.stringify(options));
|
|
142
|
-
}
|
|
143
|
-
let axios_options = {
|
|
144
|
-
url: options.url,
|
|
145
|
-
method: options.method,
|
|
146
|
-
params: options.params,
|
|
147
|
-
headers: options.headers
|
|
148
|
-
}
|
|
149
|
-
if (options.json !== null) {
|
|
150
|
-
axios_options.data = options.json
|
|
151
|
-
}
|
|
152
|
-
if (this.log) {
|
|
153
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
154
|
-
}
|
|
155
|
-
if (options.url.startsWith("https:")) {
|
|
156
|
-
const httpsAgent = new https.Agent({
|
|
157
|
-
rejectUnauthorized: false,
|
|
158
|
-
});
|
|
159
|
-
axios_options.httpsAgent = httpsAgent;
|
|
160
|
-
}
|
|
161
|
-
axios(axios_options)
|
|
162
|
-
.then((res) => {
|
|
163
|
-
if (this.log) {
|
|
164
|
-
console.log("Response for url:", options.url);
|
|
165
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
166
|
-
}
|
|
167
|
-
if (res && res.status == 200 && res.data) {
|
|
168
|
-
if (callback) {
|
|
169
|
-
callback(null, res.data);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
if (callback) {
|
|
174
|
-
callback(new Error("Response status is not 200"), null);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
.catch((error) => {
|
|
179
|
-
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
180
|
-
if (callback) {
|
|
181
|
-
callback(error, null);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
139
|
}
|
|
186
140
|
|
|
187
141
|
module.exports = { DirReplaceBotV2 };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
4
|
|
|
5
5
|
const axios = require("axios").default;
|
|
6
6
|
let https = require("https");
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const httpUtils = require('../../utils/HttpUtils');
|
|
7
9
|
|
|
8
10
|
class DirReplaceBotV3 {
|
|
9
11
|
|
|
@@ -26,13 +28,13 @@ class DirReplaceBotV3 {
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
execute(directive, callback) {
|
|
29
|
-
|
|
31
|
+
winston.verbose("Execute ReplaceBotV3 directive");
|
|
30
32
|
let action;
|
|
31
33
|
if (directive.action) {
|
|
32
34
|
action = directive.action;
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
|
-
|
|
37
|
+
winston.warn("DirReplaceBotV3 Incorrect directive: ", directive);
|
|
36
38
|
callback();
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
@@ -42,6 +44,7 @@ class DirReplaceBotV3 {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async go(action, callback) {
|
|
47
|
+
winston.debug("(DirReplaceBotV3) Action: ", action);
|
|
45
48
|
let botId = action.botId;
|
|
46
49
|
let botSlug = action.botSlug;
|
|
47
50
|
let useSlug = action.useSlug;
|
|
@@ -73,19 +76,19 @@ class DirReplaceBotV3 {
|
|
|
73
76
|
method: 'PUT'
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
httpUtils.request(
|
|
77
80
|
HTTPREQUEST, async (err, resbody) => {
|
|
78
81
|
if (err) {
|
|
79
|
-
|
|
82
|
+
winston.error("(DirReplaceBotV3) error: ", err);
|
|
80
83
|
if (callback) {
|
|
81
84
|
callback();
|
|
82
85
|
return;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
winston.debug("(DirReplaceBotV3) replace resbody: ", resbody);
|
|
87
90
|
if (blockName) {
|
|
88
|
-
|
|
91
|
+
winston.debug("(DirReplaceBotV3) Sending hidden /start message to bot in dept");
|
|
89
92
|
const message = {
|
|
90
93
|
type: "text",
|
|
91
94
|
text: "/" + blockName,
|
|
@@ -97,9 +100,8 @@ class DirReplaceBotV3 {
|
|
|
97
100
|
this.requestId,
|
|
98
101
|
message, (err) => {
|
|
99
102
|
if (err) {
|
|
100
|
-
|
|
103
|
+
winston.debug("(DirReplaceBotV3) Error sending hidden message: " + err.message);
|
|
101
104
|
}
|
|
102
|
-
if (this.log) { console.log("Hidden message sent."); }
|
|
103
105
|
callback();
|
|
104
106
|
});
|
|
105
107
|
}
|
|
@@ -110,54 +112,6 @@ class DirReplaceBotV3 {
|
|
|
110
112
|
)
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
#myrequest(options, callback) {
|
|
114
|
-
if (this.log) {
|
|
115
|
-
console.log("API URL:", options.url);
|
|
116
|
-
console.log("** Options:", JSON.stringify(options));
|
|
117
|
-
}
|
|
118
|
-
let axios_options = {
|
|
119
|
-
url: options.url,
|
|
120
|
-
method: options.method,
|
|
121
|
-
params: options.params,
|
|
122
|
-
headers: options.headers
|
|
123
|
-
}
|
|
124
|
-
if (options.json !== null) {
|
|
125
|
-
axios_options.data = options.json
|
|
126
|
-
}
|
|
127
|
-
if (this.log) {
|
|
128
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
129
|
-
}
|
|
130
|
-
if (options.url.startsWith("https:")) {
|
|
131
|
-
const httpsAgent = new https.Agent({
|
|
132
|
-
rejectUnauthorized: false,
|
|
133
|
-
});
|
|
134
|
-
axios_options.httpsAgent = httpsAgent;
|
|
135
|
-
}
|
|
136
|
-
axios(axios_options)
|
|
137
|
-
.then((res) => {
|
|
138
|
-
if (this.log) {
|
|
139
|
-
console.log("Response for url:", options.url);
|
|
140
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
141
|
-
}
|
|
142
|
-
if (res && res.status == 200 && res.data) {
|
|
143
|
-
if (callback) {
|
|
144
|
-
callback(null, res.data);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
if (callback) {
|
|
149
|
-
callback(new Error("Response status is not 200"), null);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
.catch((error) => {
|
|
154
|
-
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
155
|
-
if (callback) {
|
|
156
|
-
callback(error, null);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
115
|
}
|
|
162
116
|
|
|
163
117
|
module.exports = { DirReplaceBotV3 };
|