@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,11 +1,14 @@
|
|
|
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
|
-
const { TiledeskChatbotConst } = require("../../
|
|
7
|
-
const { TiledeskChatbotUtil } = require("../../
|
|
6
|
+
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
7
|
+
const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
8
8
|
require('dotenv').config();
|
|
9
|
+
const winston = require('../../utils/winston');
|
|
10
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
11
|
+
const integrationService = require("../../services/IntegrationService");
|
|
9
12
|
|
|
10
13
|
class DirGptTask {
|
|
11
14
|
|
|
@@ -17,19 +20,21 @@ class DirGptTask {
|
|
|
17
20
|
this.chatbot = this.context.chatbot;
|
|
18
21
|
this.tdcache = this.context.tdcache;
|
|
19
22
|
this.requestId = this.context.requestId;
|
|
23
|
+
this.projectId = this.context.projectId;
|
|
24
|
+
this.token = this.context.token;
|
|
20
25
|
this.intentDir = new DirIntent(context);
|
|
21
26
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
22
27
|
this.log = context.log;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
execute(directive, callback) {
|
|
26
|
-
|
|
31
|
+
winston.verbose("Execute GptTask directive");
|
|
27
32
|
let action;
|
|
28
33
|
if (directive.action) {
|
|
29
34
|
action = directive.action;
|
|
30
35
|
}
|
|
31
36
|
else {
|
|
32
|
-
|
|
37
|
+
winston.warn("DirGptTask Incorrect directive: ", directive);
|
|
33
38
|
callback();
|
|
34
39
|
return;
|
|
35
40
|
}
|
|
@@ -39,9 +44,9 @@ class DirGptTask {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
async go(action, callback) {
|
|
42
|
-
|
|
47
|
+
winston.debug("(DirGptTask) Action: ", action);
|
|
43
48
|
if (!this.tdcache) {
|
|
44
|
-
|
|
49
|
+
winston.error("(DirGptTask) Error: tdcache is mandatory");
|
|
45
50
|
callback();
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
@@ -53,19 +58,17 @@ class DirGptTask {
|
|
|
53
58
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
54
59
|
let transcript;
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
console.log("DirGptTask falseIntentAttributes", falseIntentAttributes)
|
|
61
|
-
}
|
|
61
|
+
winston.debug("(DirGptTask) trueIntent " + trueIntent)
|
|
62
|
+
winston.debug("(DirGptTask) falseIntent " + falseIntent)
|
|
63
|
+
winston.debug("(DirGptTask) trueIntentAttributes " + trueIntentAttributes)
|
|
64
|
+
winston.debug("(DirGptTask) falseIntentAttributes " + falseIntentAttributes)
|
|
62
65
|
|
|
63
66
|
// default value
|
|
64
67
|
let answer = "No answer.";
|
|
65
68
|
let model = "gpt-3.5-turbo";
|
|
66
69
|
|
|
67
70
|
if (!action.question || action.question === '') {
|
|
68
|
-
|
|
71
|
+
winston.debug("(DirGptTask) Error: question attribute is mandatory. Executing condition false...")
|
|
69
72
|
if (falseIntent) {
|
|
70
73
|
await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
|
|
71
74
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -93,43 +96,41 @@ class DirGptTask {
|
|
|
93
96
|
model = action.model;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.log("DirGptTask temperature: ", temperature);
|
|
99
|
-
}
|
|
99
|
+
winston.debug("(DirGptTask) max_tokens: " + max_tokens);
|
|
100
|
+
winston.debug("(DirGptTask) temperature: " + temperature);
|
|
100
101
|
|
|
101
102
|
if (action.history) {
|
|
102
103
|
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
103
104
|
this.context.tdcache,
|
|
104
105
|
this.context.requestId,
|
|
105
106
|
TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
|
|
106
|
-
|
|
107
|
+
winston.debug("(DirGptTask) transcript string: " + transcript_string)
|
|
107
108
|
|
|
108
109
|
if (transcript_string) {
|
|
109
110
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
110
|
-
|
|
111
|
+
winston.debug("(DirGptTask) transcript: ", transcript)
|
|
111
112
|
} else {
|
|
112
|
-
|
|
113
|
+
winston.debug("(DirGptTask) transcript_string is undefined. Skip JSON translation for chat history");
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
117
|
-
|
|
118
|
+
winston.debug("(DirGptTask) openai_url " + openai_url);
|
|
118
119
|
|
|
119
|
-
let key = await
|
|
120
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
120
121
|
if (!key) {
|
|
121
|
-
|
|
122
|
+
winston.debug("(DirGptTask) - Key not found in Integrations. Searching in kb settings...");
|
|
122
123
|
key = await this.getKeyFromKbSettings();
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
if (!key) {
|
|
126
|
-
|
|
127
|
+
winston.debug("(DirGptTask) - Retrieve public gptkey")
|
|
127
128
|
key = process.env.GPTKEY;
|
|
128
129
|
publicKey = true;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
if (!key) {
|
|
132
|
-
|
|
133
|
+
winston.error("(DirGptTask) gptkey is mandatory");
|
|
133
134
|
await this.#assignAttributes(action, answer);
|
|
134
135
|
if (falseIntent) {
|
|
135
136
|
await this.chatbot.addParameter("flowError", "GPT Error: gpt apikey is undefined");
|
|
@@ -144,7 +145,7 @@ class DirGptTask {
|
|
|
144
145
|
if (publicKey === true) {
|
|
145
146
|
let keep_going = await this.checkQuoteAvailability();
|
|
146
147
|
if (keep_going === false) {
|
|
147
|
-
|
|
148
|
+
|
|
148
149
|
await this.chatbot.addParameter("flowError", "GPT Error: tokens quota exceeded");
|
|
149
150
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
150
151
|
callback();
|
|
@@ -183,7 +184,7 @@ class DirGptTask {
|
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
|
|
186
|
-
|
|
187
|
+
winston.debug("(DirGptTask) json: ", json)
|
|
187
188
|
|
|
188
189
|
const HTTPREQUEST = {
|
|
189
190
|
url: openai_url,
|
|
@@ -194,14 +195,13 @@ class DirGptTask {
|
|
|
194
195
|
json: json,
|
|
195
196
|
method: 'POST'
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
-
|
|
198
|
+
winston.debug("(DirGptTask) HttpRequest: ", HTTPREQUEST);
|
|
199
|
+
|
|
200
|
+
httpUtils.request(
|
|
199
201
|
HTTPREQUEST, async (err, resbody) => {
|
|
200
202
|
if (err) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
console.error("(httprequest) DirGptTask openai err:", err.response?.data?.error?.message);
|
|
204
|
-
}
|
|
203
|
+
winston.debug("(DirGptTask) openai err: ", err);
|
|
204
|
+
winston.debug("(DirGptTask) openai err: " + err.response?.data?.error?.message);
|
|
205
205
|
await this.#assignAttributes(action, answer);
|
|
206
206
|
if (falseIntent) {
|
|
207
207
|
await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
|
|
@@ -212,7 +212,7 @@ class DirGptTask {
|
|
|
212
212
|
callback();
|
|
213
213
|
return;
|
|
214
214
|
} else {
|
|
215
|
-
|
|
215
|
+
winston.debug("(DirGptTask) resbody: ", resbody);
|
|
216
216
|
answer = resbody.choices[0].message.content;
|
|
217
217
|
|
|
218
218
|
if (action.formatType === 'json_object' || action.formatType === undefined || action.formatType === null) {
|
|
@@ -274,7 +274,7 @@ class DirGptTask {
|
|
|
274
274
|
})
|
|
275
275
|
}
|
|
276
276
|
else {
|
|
277
|
-
|
|
277
|
+
winston.debug("(DirGptTask) No trueIntentDirective specified");
|
|
278
278
|
if (callback) {
|
|
279
279
|
callback();
|
|
280
280
|
}
|
|
@@ -289,7 +289,7 @@ class DirGptTask {
|
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
291
|
else {
|
|
292
|
-
|
|
292
|
+
winston.debug("(DirGptTask) No falseIntentDirective specified");
|
|
293
293
|
if (callback) {
|
|
294
294
|
callback();
|
|
295
295
|
}
|
|
@@ -298,103 +298,16 @@ class DirGptTask {
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
async #assignAttributes(action, answer) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
301
|
+
winston.debug("(DirGptTask) assignAttributes action: ", action)
|
|
302
|
+
winston.debug("(DirGptTask) assignAttributes answer: " + answer)
|
|
303
|
+
|
|
305
304
|
if (this.context.tdcache) {
|
|
306
305
|
if (action.assignReplyTo && answer) {
|
|
307
306
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
308
307
|
}
|
|
309
|
-
// Debug log
|
|
310
|
-
if (this.log) {
|
|
311
|
-
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
312
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
313
|
-
if (this.log) { console.log("(gpttask) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
308
|
}
|
|
317
309
|
}
|
|
318
310
|
|
|
319
|
-
#myrequest(options, callback) {
|
|
320
|
-
if (this.log) {
|
|
321
|
-
console.log("API URL:", options.url);
|
|
322
|
-
console.log("** Options:", JSON.stringify(options));
|
|
323
|
-
}
|
|
324
|
-
let axios_options = {
|
|
325
|
-
url: options.url,
|
|
326
|
-
method: options.method,
|
|
327
|
-
params: options.params,
|
|
328
|
-
headers: options.headers
|
|
329
|
-
}
|
|
330
|
-
if (options.json !== null) {
|
|
331
|
-
axios_options.data = options.json
|
|
332
|
-
}
|
|
333
|
-
if (this.log) {
|
|
334
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
335
|
-
}
|
|
336
|
-
if (options.url.startsWith("https:")) {
|
|
337
|
-
const httpsAgent = new https.Agent({
|
|
338
|
-
rejectUnauthorized: false,
|
|
339
|
-
});
|
|
340
|
-
axios_options.httpsAgent = httpsAgent;
|
|
341
|
-
}
|
|
342
|
-
axios(axios_options)
|
|
343
|
-
.then((res) => {
|
|
344
|
-
if (this.log) {
|
|
345
|
-
console.log("Response for url:", options.url);
|
|
346
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
347
|
-
}
|
|
348
|
-
if (res && res.status == 200 && res.data) {
|
|
349
|
-
if (callback) {
|
|
350
|
-
callback(null, res.data);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
if (callback) {
|
|
355
|
-
callback(new Error("Response status is not 200"), null);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
})
|
|
359
|
-
.catch((error) => {
|
|
360
|
-
console.error("(DirGptTask) Axios error: ", JSON.stringify(error));
|
|
361
|
-
if (callback) {
|
|
362
|
-
callback(error, null);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
async getKeyFromIntegrations() {
|
|
368
|
-
return new Promise((resolve) => {
|
|
369
|
-
|
|
370
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
371
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
372
|
-
headers: {
|
|
373
|
-
'Content-Type': 'application/json',
|
|
374
|
-
'Authorization': 'JWT ' + this.context.token
|
|
375
|
-
},
|
|
376
|
-
method: "GET"
|
|
377
|
-
}
|
|
378
|
-
if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
379
|
-
|
|
380
|
-
this.#myrequest(
|
|
381
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
382
|
-
if (err) {
|
|
383
|
-
resolve(null);
|
|
384
|
-
} else {
|
|
385
|
-
|
|
386
|
-
if (integration &&
|
|
387
|
-
integration.value) {
|
|
388
|
-
resolve(integration.value.apikey)
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
resolve(null)
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
})
|
|
395
|
-
})
|
|
396
|
-
}
|
|
397
|
-
|
|
398
311
|
async getKeyFromKbSettings() {
|
|
399
312
|
return new Promise((resolve) => {
|
|
400
313
|
|
|
@@ -406,15 +319,12 @@ class DirGptTask {
|
|
|
406
319
|
},
|
|
407
320
|
method: "GET"
|
|
408
321
|
}
|
|
409
|
-
|
|
322
|
+
winston.debug("(DirGptTask) KB HttpRequest ", KB_HTTPREQUEST);
|
|
410
323
|
|
|
411
|
-
|
|
324
|
+
httpUtils.request(
|
|
412
325
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
413
326
|
if (err) {
|
|
414
|
-
|
|
415
|
-
if (this.log) {
|
|
416
|
-
console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
|
|
417
|
-
}
|
|
327
|
+
winston.error("(DirGptTask) Get KnowledgeBase err:", err.message);
|
|
418
328
|
resolve(null);
|
|
419
329
|
} else {
|
|
420
330
|
if (!resbody.gptkey) {
|
|
@@ -439,9 +349,9 @@ class DirGptTask {
|
|
|
439
349
|
},
|
|
440
350
|
method: "GET"
|
|
441
351
|
}
|
|
442
|
-
|
|
352
|
+
winston.debug("(DirGptTask) check quote availability HttpRequest ", HTTPREQUEST);
|
|
443
353
|
|
|
444
|
-
|
|
354
|
+
httpUtils.request(
|
|
445
355
|
HTTPREQUEST, async (err, resbody) => {
|
|
446
356
|
if (err) {
|
|
447
357
|
resolve(true)
|
|
@@ -469,15 +379,15 @@ class DirGptTask {
|
|
|
469
379
|
json: tokens_usage,
|
|
470
380
|
method: "POST"
|
|
471
381
|
}
|
|
472
|
-
|
|
382
|
+
winston.debug("(DirGptTask) update quote HttpRequest ", HTTPREQUEST);
|
|
473
383
|
|
|
474
|
-
|
|
384
|
+
httpUtils.request(
|
|
475
385
|
HTTPREQUEST, async (err, resbody) => {
|
|
476
386
|
if (err) {
|
|
477
|
-
|
|
387
|
+
winston.debug("(DirGptTask) Increment tokens quote err: ", err);
|
|
478
388
|
reject(false)
|
|
479
389
|
} else {
|
|
480
|
-
|
|
390
|
+
winston.debug("(DirGptTask) Increment token quote resbody: ", resbody);
|
|
481
391
|
resolve(true);
|
|
482
392
|
}
|
|
483
393
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
6
7
|
require('dotenv').config();
|
|
7
8
|
|
|
8
9
|
class DirGptTask {
|
|
@@ -98,8 +99,8 @@ class DirGptTask {
|
|
|
98
99
|
method: "GET"
|
|
99
100
|
}
|
|
100
101
|
if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
|
|
103
|
+
httpUtils.request(
|
|
103
104
|
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
104
105
|
if (err) {
|
|
105
106
|
if (callback) {
|
|
@@ -133,7 +134,7 @@ class DirGptTask {
|
|
|
133
134
|
}
|
|
134
135
|
if (this.log) { console.log("DirGptTask KB_HTTPREQUEST", KB_HTTPREQUEST); }
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
httpUtils.request(
|
|
137
138
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
138
139
|
if (err) {
|
|
139
140
|
if (callback) {
|
|
@@ -199,7 +200,7 @@ class DirGptTask {
|
|
|
199
200
|
method: 'POST'
|
|
200
201
|
}
|
|
201
202
|
if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
|
|
202
|
-
|
|
203
|
+
httpUtils.request(
|
|
203
204
|
HTTPREQUEST, async (err, resbody) => {
|
|
204
205
|
if (err) {
|
|
205
206
|
if (this.log) {
|
|
@@ -267,7 +268,7 @@ class DirGptTask {
|
|
|
267
268
|
method: 'POST'
|
|
268
269
|
}
|
|
269
270
|
if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
|
|
270
|
-
|
|
271
|
+
httpUtils.request(
|
|
271
272
|
HTTPREQUEST, async (err, resbody) => {
|
|
272
273
|
if (err) {
|
|
273
274
|
if (this.log) {
|
|
@@ -381,53 +382,7 @@ class DirGptTask {
|
|
|
381
382
|
}
|
|
382
383
|
}
|
|
383
384
|
}
|
|
384
|
-
|
|
385
|
-
#myrequest(options, callback) {
|
|
386
|
-
if (this.log) {
|
|
387
|
-
console.log("API URL:", options.url);
|
|
388
|
-
console.log("** Options:", JSON.stringify(options));
|
|
389
|
-
}
|
|
390
|
-
let axios_options = {
|
|
391
|
-
url: options.url,
|
|
392
|
-
method: options.method,
|
|
393
|
-
params: options.params,
|
|
394
|
-
headers: options.headers
|
|
395
|
-
}
|
|
396
|
-
if (options.json !== null) {
|
|
397
|
-
axios_options.data = options.json
|
|
398
|
-
}
|
|
399
|
-
if (this.log) {
|
|
400
|
-
console.log("axios_options:", JSON.stringify(axios_options));
|
|
401
|
-
}
|
|
402
|
-
if (options.url.startsWith("https:")) {
|
|
403
|
-
const httpsAgent = new https.Agent({
|
|
404
|
-
rejectUnauthorized: false,
|
|
405
|
-
});
|
|
406
|
-
axios_options.httpsAgent = httpsAgent;
|
|
407
|
-
}
|
|
408
|
-
axios(axios_options)
|
|
409
|
-
.then((res) => {
|
|
410
|
-
if (this.log) {
|
|
411
|
-
console.log("Response for url:", options.url);
|
|
412
|
-
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
413
|
-
}
|
|
414
|
-
if (res && res.status == 200 && res.data) {
|
|
415
|
-
if (callback) {
|
|
416
|
-
callback(null, res.data);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
if (callback) {
|
|
421
|
-
callback(new Error("Response status is not 200"), null);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
})
|
|
425
|
-
.catch((error) => {
|
|
426
|
-
if (callback) {
|
|
427
|
-
callback(error, null);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
385
|
+
|
|
431
386
|
}
|
|
432
387
|
|
|
433
388
|
module.exports = { DirGptTask }
|