@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.
- package/CHANGELOG.md +28 -0
- package/ExtApi.js +3 -13
- package/ExtUtil.js +0 -1
- package/Logger.js +86 -0
- package/TdCache.js +5 -3
- package/TiledeskClientTest.js +5 -28
- package/TiledeskExpression.js +6 -47
- package/index.js +87 -273
- package/logs/app.log +12983 -275
- package/logs/app1.log +62258 -0
- package/logs/app2.log +46280 -0
- package/logs/app3.log +28864 -0
- package/models/IntentForm.js +30 -44
- package/models/IntentsMachineFactory.js +4 -3
- package/models/MockBotsDataSource.js +1 -17
- package/models/MockTdCache.js +0 -9
- package/models/MongodbBotsDataSource.js +29 -53
- package/models/MongodbIntentsMachine.js +5 -4
- package/models/TiledeskChatbot.js +79 -258
- package/models/TiledeskChatbotConst.js +9 -0
- package/models/TiledeskChatbotUtil.js +180 -232
- package/models/TiledeskIntentsMachine.js +5 -14
- package/models/faqKbService.js +0 -1
- package/package.json +5 -2
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
- 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/WebhookChatbotPlug.js +21 -89
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
- package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
- package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
- package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
- 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 +15 -22
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
- package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
- package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
- package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
- package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
- package/utils/winston.js +42 -0
- package/TdCache copy.js +0 -242
|
@@ -4,6 +4,7 @@ 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');
|
|
7
8
|
|
|
8
9
|
class DirQapla {
|
|
9
10
|
|
|
@@ -20,13 +21,13 @@ class DirQapla {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
execute(directive, callback) {
|
|
23
|
-
|
|
24
|
+
winston.verbose("Execute Qapla directive");
|
|
24
25
|
let action;
|
|
25
26
|
if (directive.action) {
|
|
26
27
|
action = directive.action;
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
|
-
|
|
30
|
+
winston.warn("DirQapla Incorrect directive: ", directive);
|
|
30
31
|
callback();
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
@@ -36,9 +37,9 @@ class DirQapla {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
async go(action, callback) {
|
|
39
|
-
|
|
40
|
+
winston.debug("(DirQapla) Action: ", action);
|
|
40
41
|
if (!this.tdcache) {
|
|
41
|
-
|
|
42
|
+
winston.error("(DirQapla) Error: tdcache is mandatory");
|
|
42
43
|
callback();
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
@@ -48,12 +49,10 @@ class DirQapla {
|
|
|
48
49
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
49
50
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.log("DirQapla falseIntentAttributes", falseIntentAttributes)
|
|
56
|
-
}
|
|
52
|
+
winston.debug("(DirQapla) trueIntent " + trueIntent)
|
|
53
|
+
winston.debug("(DirQapla) falseIntent " + falseIntent)
|
|
54
|
+
winston.debug("(DirQapla) trueIntentAttributes " + trueIntentAttributes)
|
|
55
|
+
winston.debug("(DirQapla) falseIntentAttributes " + falseIntentAttributes)
|
|
57
56
|
|
|
58
57
|
// Set default values
|
|
59
58
|
let status = null;
|
|
@@ -68,10 +67,9 @@ class DirQapla {
|
|
|
68
67
|
|
|
69
68
|
const filler = new Filler();
|
|
70
69
|
const tracking_number = filler.fill(action.trackingNumber, requestVariables);
|
|
71
|
-
if (this.log) { console.log("DirQapla tracking number: ", tracking_number); }
|
|
72
70
|
|
|
73
71
|
if (!tracking_number || tracking_number === '') {
|
|
74
|
-
|
|
72
|
+
winston.debug("(DirQapla) Error: tracking number is undefined or null or empty string");
|
|
75
73
|
error = "Tracking number is not defined";
|
|
76
74
|
await this.#assignAttributes(action, status, result, error);
|
|
77
75
|
if (falseIntent) {
|
|
@@ -84,17 +82,17 @@ class DirQapla {
|
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
const qapla_base_url = process.env.QAPLA_ENDPOINT || "https://api.qapla.it/1.2"
|
|
87
|
-
|
|
85
|
+
winston.debug("(DirQapla) DirQapla qapla_base_url: " + qapla_base_url);
|
|
88
86
|
|
|
89
87
|
let key = action.apiKey;
|
|
90
88
|
|
|
91
89
|
if (!key) {
|
|
92
|
-
|
|
90
|
+
winston.debug("(DirQapla) DirQapla - Key not found into action. Searching in integrations...");
|
|
93
91
|
key = await this.getKeyFromIntegrations();
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
if (!key) {
|
|
97
|
-
|
|
95
|
+
winston.debug("(DirQapla) Error: api key is mandatory");
|
|
98
96
|
error = "Invalid or empty ApiKey";
|
|
99
97
|
await this.#assignAttributes(action, status, result, error);
|
|
100
98
|
if (falseIntent) {
|
|
@@ -117,16 +115,13 @@ class DirQapla {
|
|
|
117
115
|
},
|
|
118
116
|
method: "GET"
|
|
119
117
|
}
|
|
120
|
-
|
|
118
|
+
winston.debug("(DirQapla) HttpRequest ", QAPLA_HTTPREQUEST);
|
|
121
119
|
|
|
122
120
|
this.#myrequest(
|
|
123
121
|
QAPLA_HTTPREQUEST, async (err, resbody) => {
|
|
124
122
|
if (err) {
|
|
125
123
|
if (callback) {
|
|
126
|
-
|
|
127
|
-
if (this.log) {
|
|
128
|
-
console.error("(httprequest) DirQapla getShipment full err:", err);
|
|
129
|
-
}
|
|
124
|
+
winston.debug("(DirQapla) getShipment err: " + err.message);
|
|
130
125
|
error = "Unable to get shipment";
|
|
131
126
|
await this.#assignAttributes(action, status, result, error);
|
|
132
127
|
if (falseIntent) {
|
|
@@ -138,7 +133,7 @@ class DirQapla {
|
|
|
138
133
|
return;
|
|
139
134
|
}
|
|
140
135
|
} else if (callback) {
|
|
141
|
-
|
|
136
|
+
winston.debug("(DirQapla) getShipment resbody: ", resbody);
|
|
142
137
|
|
|
143
138
|
if (resbody.getShipment &&
|
|
144
139
|
resbody.getShipment.shipments &&
|
|
@@ -186,7 +181,7 @@ class DirQapla {
|
|
|
186
181
|
})
|
|
187
182
|
}
|
|
188
183
|
else {
|
|
189
|
-
|
|
184
|
+
winston.debug("(DirQapla) No trueIntentDirective specified");
|
|
190
185
|
if (callback) {
|
|
191
186
|
callback();
|
|
192
187
|
}
|
|
@@ -201,7 +196,7 @@ class DirQapla {
|
|
|
201
196
|
});
|
|
202
197
|
}
|
|
203
198
|
else {
|
|
204
|
-
|
|
199
|
+
winston.debug("(DirQapla)No falseIntentDirective specified");
|
|
205
200
|
if (callback) {
|
|
206
201
|
callback();
|
|
207
202
|
}
|
|
@@ -210,12 +205,7 @@ class DirQapla {
|
|
|
210
205
|
}
|
|
211
206
|
|
|
212
207
|
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
|
-
}
|
|
208
|
+
|
|
219
209
|
if (this.context.tdcache) {
|
|
220
210
|
if (action.assignStatusTo) {
|
|
221
211
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignStatusTo, status);
|
|
@@ -226,22 +216,10 @@ class DirQapla {
|
|
|
226
216
|
if (action.assignErrorTo) {
|
|
227
217
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignErrorTo, error);
|
|
228
218
|
}
|
|
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
219
|
}
|
|
238
220
|
}
|
|
239
221
|
|
|
240
222
|
#myrequest(options, callback) {
|
|
241
|
-
if (this.log) {
|
|
242
|
-
console.log("API URL:", options.url);
|
|
243
|
-
console.log("** Options:", JSON.stringify(options));
|
|
244
|
-
}
|
|
245
223
|
let axios_options = {
|
|
246
224
|
url: options.url,
|
|
247
225
|
method: options.method,
|
|
@@ -251,9 +229,6 @@ class DirQapla {
|
|
|
251
229
|
if (options.json !== null) {
|
|
252
230
|
axios_options.data = options.json
|
|
253
231
|
}
|
|
254
|
-
if (this.log) {
|
|
255
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
256
|
-
}
|
|
257
232
|
if (options.url.startsWith("https:")) {
|
|
258
233
|
const httpsAgent = new https.Agent({
|
|
259
234
|
rejectUnauthorized: false,
|
|
@@ -262,10 +237,6 @@ class DirQapla {
|
|
|
262
237
|
}
|
|
263
238
|
axios(axios_options)
|
|
264
239
|
.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
240
|
if (res && res.status == 200 && res.data) {
|
|
270
241
|
if (callback) {
|
|
271
242
|
callback(null, res.data);
|
|
@@ -278,7 +249,7 @@ class DirQapla {
|
|
|
278
249
|
}
|
|
279
250
|
})
|
|
280
251
|
.catch((error) => {
|
|
281
|
-
|
|
252
|
+
winston.error("(DirQapla) Axios error: ", error.response.data);
|
|
282
253
|
if (callback) {
|
|
283
254
|
callback(error, null);
|
|
284
255
|
}
|
|
@@ -296,7 +267,7 @@ class DirQapla {
|
|
|
296
267
|
},
|
|
297
268
|
method: "GET"
|
|
298
269
|
}
|
|
299
|
-
|
|
270
|
+
winston.debug("(DirQapla) Integrations HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
300
271
|
|
|
301
272
|
this.#myrequest(
|
|
302
273
|
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
@@ -2,6 +2,7 @@ const { Filler } = require('../Filler');
|
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
3
|
const { TiledeskChatbotUtil } = require('../../models/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
2
|
const { TiledeskChatbot } = require('../../models/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 =
|
|
@@ -4,6 +4,7 @@ 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');
|
|
7
8
|
|
|
8
9
|
class DirReplaceBotV2 {
|
|
9
10
|
|
|
@@ -26,7 +27,7 @@ class DirReplaceBotV2 {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
execute(directive, callback) {
|
|
29
|
-
|
|
30
|
+
winston.verbose("Execute ReplaceBotV2 directive");
|
|
30
31
|
let action;
|
|
31
32
|
if (directive.action) {
|
|
32
33
|
action = directive.action;
|
|
@@ -38,6 +39,7 @@ class DirReplaceBotV2 {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
42
|
+
winston.warn("DirReplaceBotV2 Incorrect directive: ", directive);
|
|
41
43
|
callback();
|
|
42
44
|
}
|
|
43
45
|
this.go(action, () => {
|
|
@@ -46,6 +48,7 @@ class DirReplaceBotV2 {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
async go(action, callback) {
|
|
51
|
+
winston.debug("(DirReplaceBotV2) Action: ", action);
|
|
49
52
|
let botName = action.botName;
|
|
50
53
|
let blockName = action.blockName;
|
|
51
54
|
let variables = null;
|
|
@@ -76,16 +79,16 @@ class DirReplaceBotV2 {
|
|
|
76
79
|
this.#myrequest(
|
|
77
80
|
HTTPREQUEST, async (err, resbody) => {
|
|
78
81
|
if (err) {
|
|
79
|
-
|
|
82
|
+
winston.error("(DirReplaceBotV2) DirReplaceBot error: ", err);
|
|
80
83
|
if (callback) {
|
|
81
84
|
callback();
|
|
82
85
|
return;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
winston.debug("(DirReplaceBotV2) replace resbody: ", resbody)
|
|
87
90
|
if (blockName) {
|
|
88
|
-
|
|
91
|
+
winston.debug("(DirReplaceBotV2) 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 DirReplaceBotV2 {
|
|
|
97
100
|
this.requestId,
|
|
98
101
|
message, (err) => {
|
|
99
102
|
if (err) {
|
|
100
|
-
|
|
103
|
+
winston.debug("(DirReplaceBotV2) Error sending hidden message: " + err.message);
|
|
101
104
|
}
|
|
102
|
-
if (this.log) { console.log("Hidden message sent."); }
|
|
103
105
|
callback();
|
|
104
106
|
});
|
|
105
107
|
}
|
|
@@ -111,7 +113,6 @@ class DirReplaceBotV2 {
|
|
|
111
113
|
|
|
112
114
|
// this.tdClient.replaceBotByName(this.requestId, botName, () => {
|
|
113
115
|
// if (blockName) {
|
|
114
|
-
// if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
115
116
|
// const message = {
|
|
116
117
|
// type: "text",
|
|
117
118
|
// text: "/" + blockName,
|
|
@@ -123,9 +124,8 @@ class DirReplaceBotV2 {
|
|
|
123
124
|
// this.requestId,
|
|
124
125
|
// message, (err) => {
|
|
125
126
|
// if (err) {
|
|
126
|
-
//
|
|
127
|
+
// winston.error("Error sending hidden message:", err.message);
|
|
127
128
|
// }
|
|
128
|
-
// if (this.log) {console.log("Hidden message sent.");}
|
|
129
129
|
// callback();
|
|
130
130
|
// });
|
|
131
131
|
// }
|
|
@@ -136,10 +136,6 @@ class DirReplaceBotV2 {
|
|
|
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
139
|
let axios_options = {
|
|
144
140
|
url: options.url,
|
|
145
141
|
method: options.method,
|
|
@@ -149,9 +145,6 @@ class DirReplaceBotV2 {
|
|
|
149
145
|
if (options.json !== null) {
|
|
150
146
|
axios_options.data = options.json
|
|
151
147
|
}
|
|
152
|
-
if (this.log) {
|
|
153
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
154
|
-
}
|
|
155
148
|
if (options.url.startsWith("https:")) {
|
|
156
149
|
const httpsAgent = new https.Agent({
|
|
157
150
|
rejectUnauthorized: false,
|
|
@@ -160,10 +153,6 @@ class DirReplaceBotV2 {
|
|
|
160
153
|
}
|
|
161
154
|
axios(axios_options)
|
|
162
155
|
.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
156
|
if (res && res.status == 200 && res.data) {
|
|
168
157
|
if (callback) {
|
|
169
158
|
callback(null, res.data);
|
|
@@ -176,7 +165,7 @@ class DirReplaceBotV2 {
|
|
|
176
165
|
}
|
|
177
166
|
})
|
|
178
167
|
.catch((error) => {
|
|
179
|
-
|
|
168
|
+
winston.error("(DirAskGPT) Axios error: ", error.response.data);
|
|
180
169
|
if (callback) {
|
|
181
170
|
callback(error, null);
|
|
182
171
|
}
|
|
@@ -4,6 +4,7 @@ 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');
|
|
7
8
|
|
|
8
9
|
class DirReplaceBotV3 {
|
|
9
10
|
|
|
@@ -26,13 +27,13 @@ class DirReplaceBotV3 {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
execute(directive, callback) {
|
|
29
|
-
|
|
30
|
+
winston.verbose("Execute ReplaceBotV3 directive");
|
|
30
31
|
let action;
|
|
31
32
|
if (directive.action) {
|
|
32
33
|
action = directive.action;
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
|
-
|
|
36
|
+
winston.warn("DirReplaceBotV3 Incorrect directive: ", directive);
|
|
36
37
|
callback();
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
@@ -42,6 +43,7 @@ class DirReplaceBotV3 {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
async go(action, callback) {
|
|
46
|
+
winston.debug("(DirReplaceBotV3) Action: ", action);
|
|
45
47
|
let botId = action.botId;
|
|
46
48
|
let botSlug = action.botSlug;
|
|
47
49
|
let useSlug = action.useSlug;
|
|
@@ -76,16 +78,16 @@ class DirReplaceBotV3 {
|
|
|
76
78
|
this.#myrequest(
|
|
77
79
|
HTTPREQUEST, async (err, resbody) => {
|
|
78
80
|
if (err) {
|
|
79
|
-
|
|
81
|
+
winston.error("(DirReplaceBotV3) error: ", err);
|
|
80
82
|
if (callback) {
|
|
81
83
|
callback();
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
winston.debug("(DirReplaceBotV3) replace resbody: ", resbody);
|
|
87
89
|
if (blockName) {
|
|
88
|
-
|
|
90
|
+
winston.debug("(DirReplaceBotV3) Sending hidden /start message to bot in dept");
|
|
89
91
|
const message = {
|
|
90
92
|
type: "text",
|
|
91
93
|
text: "/" + blockName,
|
|
@@ -97,9 +99,8 @@ class DirReplaceBotV3 {
|
|
|
97
99
|
this.requestId,
|
|
98
100
|
message, (err) => {
|
|
99
101
|
if (err) {
|
|
100
|
-
|
|
102
|
+
winston.debug("(DirReplaceBotV3) Error sending hidden message: " + err.message);
|
|
101
103
|
}
|
|
102
|
-
if (this.log) { console.log("Hidden message sent."); }
|
|
103
104
|
callback();
|
|
104
105
|
});
|
|
105
106
|
}
|
|
@@ -111,10 +112,6 @@ class DirReplaceBotV3 {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
#myrequest(options, callback) {
|
|
114
|
-
if (this.log) {
|
|
115
|
-
console.log("API URL:", options.url);
|
|
116
|
-
console.log("** Options:", JSON.stringify(options));
|
|
117
|
-
}
|
|
118
115
|
let axios_options = {
|
|
119
116
|
url: options.url,
|
|
120
117
|
method: options.method,
|
|
@@ -124,9 +121,6 @@ class DirReplaceBotV3 {
|
|
|
124
121
|
if (options.json !== null) {
|
|
125
122
|
axios_options.data = options.json
|
|
126
123
|
}
|
|
127
|
-
if (this.log) {
|
|
128
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
129
|
-
}
|
|
130
124
|
if (options.url.startsWith("https:")) {
|
|
131
125
|
const httpsAgent = new https.Agent({
|
|
132
126
|
rejectUnauthorized: false,
|
|
@@ -135,10 +129,6 @@ class DirReplaceBotV3 {
|
|
|
135
129
|
}
|
|
136
130
|
axios(axios_options)
|
|
137
131
|
.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
132
|
if (res && res.status == 200 && res.data) {
|
|
143
133
|
if (callback) {
|
|
144
134
|
callback(null, res.data);
|
|
@@ -151,7 +141,7 @@ class DirReplaceBotV3 {
|
|
|
151
141
|
}
|
|
152
142
|
})
|
|
153
143
|
.catch((error) => {
|
|
154
|
-
|
|
144
|
+
winston.error("(DirAskGPT) Axios error: ", error.response.data);
|
|
155
145
|
if (callback) {
|
|
156
146
|
callback(error, null);
|
|
157
147
|
}
|