@tiledesk/tiledesk-tybot-connector 0.5.0-rc2 → 0.5.1-rc1
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 +7 -0
- package/ExtApi.js +2 -71
- package/Logger.js +32 -5
- package/{models → engine}/IntentsMachineFactory.js +1 -1
- package/{models → engine}/MongodbBotsDataSource.js +2 -2
- package/{models → engine}/MongodbIntentsMachine.js +1 -1
- package/{models → engine}/TiledeskChatbot.js +3 -1
- package/{models → engine}/TiledeskIntentsMachine.js +1 -2
- package/{models → engine/mock}/MockBotsDataSource.js +1 -2
- package/index.js +23 -111
- package/logs/app.log +3041 -4469
- package/logs/app3.log +2822 -0
- package/logs/app4.log +46163 -0
- package/logs/app5.log +33173 -0
- package/models/faq.js +2 -5
- package/package.json +1 -1
- package/{TiledeskServices → services}/AIService.js +4 -3
- package/{models/faqKbService.js → services/FaqKbService.js} +1 -1
- 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 +2 -3
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -1
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +8 -42
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +9 -74
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +14 -83
- package/tiledeskChatbotPlugs/directives/DirAssign.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +13 -106
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +5 -34
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirClose.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirCode.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +3 -72
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +5 -33
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirForm.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +13 -76
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +5 -34
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +3 -39
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -38
- package/tiledeskChatbotPlugs/directives/DirIntent.js +2 -77
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +3 -72
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirQapla.js +7 -72
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -38
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +3 -39
- package/tiledeskChatbotPlugs/directives/DirReply.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +3 -29
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +3 -38
- package/tiledeskChatbotPlugs/directives/DirWait.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +32 -22
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +23 -64
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +3 -29
- package/utils/HttpUtils.js +128 -0
- package/{models → utils}/TiledeskChatbotUtil.js +8 -50
- package/TiledeskServices/utils.js +0 -99
- /package/{models → engine}/IntentForm.js +0 -0
- /package/{models → engine}/TiledeskChatbotConst.js +0 -0
- /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
- /package/{models → engine/mock}/MockTdCache.js +0 -0
|
@@ -1,10 +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')
|
|
7
|
+
const winston = require('../../utils/winston');
|
|
8
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
9
|
+
const integrationService = require("../../services/IntegrationService");
|
|
8
10
|
|
|
9
11
|
class DirAskGPT {
|
|
10
12
|
|
|
@@ -15,6 +17,8 @@ class DirAskGPT {
|
|
|
15
17
|
this.context = context;
|
|
16
18
|
this.tdcache = this.context.tdcache;
|
|
17
19
|
this.requestId = this.context.requestId;
|
|
20
|
+
this.projectId = this.context.projectId;
|
|
21
|
+
this.token = this.context.token;
|
|
18
22
|
this.intentDir = new DirIntent(context);
|
|
19
23
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
20
24
|
this.log = context.log;
|
|
@@ -91,7 +95,7 @@ class DirAskGPT {
|
|
|
91
95
|
const kb_endpoint = process.env.KB_ENDPOINT;
|
|
92
96
|
winston.verbose("DirAskGPT KbEndpoint URL: ", kb_endpoint);
|
|
93
97
|
|
|
94
|
-
let key = await
|
|
98
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
95
99
|
if (!key) {
|
|
96
100
|
winston.debug("(DirAskGPT) - Key not found in Integrations. Searching in kb settings...");
|
|
97
101
|
key = await this.getKeyFromKbSettings();
|
|
@@ -138,7 +142,7 @@ class DirAskGPT {
|
|
|
138
142
|
}
|
|
139
143
|
winston.debug("(DirAskGPT) HttpRequest", HTTPREQUEST);
|
|
140
144
|
|
|
141
|
-
|
|
145
|
+
httpUtils.request(
|
|
142
146
|
HTTPREQUEST, async (err, resbody) => {
|
|
143
147
|
|
|
144
148
|
winston.debug("(DirAskGPT) resbody:", resbody);
|
|
@@ -240,75 +244,6 @@ class DirAskGPT {
|
|
|
240
244
|
}
|
|
241
245
|
}
|
|
242
246
|
|
|
243
|
-
#myrequest(options, callback) {
|
|
244
|
-
let axios_options = {
|
|
245
|
-
url: options.url,
|
|
246
|
-
method: options.method,
|
|
247
|
-
params: options.params,
|
|
248
|
-
headers: options.headers
|
|
249
|
-
}
|
|
250
|
-
if (options.json !== null) {
|
|
251
|
-
axios_options.data = options.json
|
|
252
|
-
}
|
|
253
|
-
if (options.url.startsWith("https:")) {
|
|
254
|
-
const httpsAgent = new https.Agent({
|
|
255
|
-
rejectUnauthorized: false,
|
|
256
|
-
});
|
|
257
|
-
axios_options.httpsAgent = httpsAgent;
|
|
258
|
-
}
|
|
259
|
-
axios(axios_options)
|
|
260
|
-
.then((res) => {
|
|
261
|
-
if (res && res.status == 200 && res.data) {
|
|
262
|
-
if (callback) {
|
|
263
|
-
callback(null, res.data);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
if (callback) {
|
|
268
|
-
callback(new Error("Response status is not 200"), null);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
})
|
|
272
|
-
.catch((error) => {
|
|
273
|
-
winston.error("(DirAskGPT) Axios error: ", error.response.data);
|
|
274
|
-
if (callback) {
|
|
275
|
-
callback(error, null);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async getKeyFromIntegrations() {
|
|
281
|
-
return new Promise((resolve) => {
|
|
282
|
-
|
|
283
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
284
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
285
|
-
headers: {
|
|
286
|
-
'Content-Type': 'application/json',
|
|
287
|
-
'Authorization': 'JWT ' + this.context.token
|
|
288
|
-
},
|
|
289
|
-
method: "GET"
|
|
290
|
-
}
|
|
291
|
-
winston.debug("(DirAskGPT) Integrations HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
292
|
-
|
|
293
|
-
this.#myrequest(
|
|
294
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
295
|
-
if (err) {
|
|
296
|
-
if (this.log) { winston.error("DirAskGPT Get integrations error ", err); }
|
|
297
|
-
resolve(null);
|
|
298
|
-
} else {
|
|
299
|
-
|
|
300
|
-
if (integration &&
|
|
301
|
-
integration.value) {
|
|
302
|
-
resolve(integration.value.apikey)
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
resolve(null)
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
})
|
|
309
|
-
})
|
|
310
|
-
}
|
|
311
|
-
|
|
312
247
|
async getKeyFromKbSettings() {
|
|
313
248
|
return new Promise((resolve) => {
|
|
314
249
|
|
|
@@ -322,7 +257,7 @@ class DirAskGPT {
|
|
|
322
257
|
}
|
|
323
258
|
winston.debug("(DirAskGPT) KB HttpRequest ", KB_HTTPREQUEST);
|
|
324
259
|
|
|
325
|
-
|
|
260
|
+
httpUtils.request(
|
|
326
261
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
327
262
|
if (err) {
|
|
328
263
|
winston.error("DirAskGPT Get kb settings error ", err?.response?.data);
|
|
@@ -1,13 +1,15 @@
|
|
|
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
|
const assert = require("assert");
|
|
9
9
|
require('dotenv').config();
|
|
10
10
|
const winston = require('../../utils/winston');
|
|
11
|
+
const httpUtils = require("../../utils/HttpUtils");
|
|
12
|
+
const integrationService = require("../../services/IntegrationService");
|
|
11
13
|
|
|
12
14
|
class DirAskGPTV2 {
|
|
13
15
|
|
|
@@ -19,6 +21,8 @@ class DirAskGPTV2 {
|
|
|
19
21
|
this.chatbot = context.chatbot;
|
|
20
22
|
this.tdcache = this.context.tdcache;
|
|
21
23
|
this.requestId = this.context.requestId;
|
|
24
|
+
this.projectId = this.context.projectId;
|
|
25
|
+
this.token = this.context.token;
|
|
22
26
|
this.intentDir = new DirIntent(context);
|
|
23
27
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
24
28
|
this.log = context.log;
|
|
@@ -137,14 +141,14 @@ class DirAskGPTV2 {
|
|
|
137
141
|
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
138
142
|
winston.debug("DirAskGPTV2 transcript ", transcript)
|
|
139
143
|
} else {
|
|
140
|
-
winston.
|
|
144
|
+
winston.verbose("DirAskGPT transcript_string is undefined. Skip JSON translation for chat history")
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
const kb_endpoint = process.env.KB_ENDPOINT_QA
|
|
145
149
|
winston.verbose("DirAskGPTV2 KbEndpoint URL: " + kb_endpoint);
|
|
146
150
|
|
|
147
|
-
let key = await
|
|
151
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
148
152
|
if (!key) {
|
|
149
153
|
winston.verbose("DirAskGPTV2 - Key not found in Integrations. Searching in kb settings...");
|
|
150
154
|
key = await this.getKeyFromKbSettings();
|
|
@@ -264,7 +268,7 @@ class DirAskGPTV2 {
|
|
|
264
268
|
}
|
|
265
269
|
winston.debug("DirAskGPTV2 HttpRequest: ", HTTPREQUEST);
|
|
266
270
|
|
|
267
|
-
|
|
271
|
+
httpUtils.request(
|
|
268
272
|
HTTPREQUEST, async (err, resbody) => {
|
|
269
273
|
|
|
270
274
|
if (err) {
|
|
@@ -367,79 +371,6 @@ class DirAskGPTV2 {
|
|
|
367
371
|
}
|
|
368
372
|
}
|
|
369
373
|
|
|
370
|
-
#myrequest(options, callback) {
|
|
371
|
-
winston.debug("DirAskGPTV2 API URL:", options.url);
|
|
372
|
-
winston.debug("DirAskGPTV2 Options:", options);
|
|
373
|
-
let axios_options = {
|
|
374
|
-
url: options.url,
|
|
375
|
-
method: options.method,
|
|
376
|
-
params: options.params,
|
|
377
|
-
headers: options.headers
|
|
378
|
-
}
|
|
379
|
-
if (options.json !== null) {
|
|
380
|
-
axios_options.data = options.json
|
|
381
|
-
}
|
|
382
|
-
if (options.url.startsWith("https:")) {
|
|
383
|
-
const httpsAgent = new https.Agent({
|
|
384
|
-
rejectUnauthorized: false,
|
|
385
|
-
});
|
|
386
|
-
axios_options.httpsAgent = httpsAgent;
|
|
387
|
-
}
|
|
388
|
-
axios(axios_options)
|
|
389
|
-
.then((res) => {
|
|
390
|
-
winston.debug("DirAskGPTV2 Response for url: " + options.url);
|
|
391
|
-
winston.debug("DirAskGPTV2 Response headers: \n", res.headers);
|
|
392
|
-
if (res && res.status == 200 && res.data) {
|
|
393
|
-
if (callback) {
|
|
394
|
-
callback(null, res.data);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
if (callback) {
|
|
399
|
-
callback(new Error("Response status is not 200"), null);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
})
|
|
403
|
-
.catch((error) => {
|
|
404
|
-
winston.error("DirAskGPTV2 Axios error: ", error.response.data);
|
|
405
|
-
if (callback) {
|
|
406
|
-
callback(error, null);
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
async getKeyFromIntegrations() {
|
|
412
|
-
return new Promise((resolve) => {
|
|
413
|
-
|
|
414
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
415
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
416
|
-
headers: {
|
|
417
|
-
'Content-Type': 'application/json',
|
|
418
|
-
'Authorization': 'JWT ' + this.context.token
|
|
419
|
-
},
|
|
420
|
-
method: "GET"
|
|
421
|
-
}
|
|
422
|
-
winston.debug("DirAskGPTV2 Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
423
|
-
|
|
424
|
-
this.#myrequest(
|
|
425
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
426
|
-
if (err) {
|
|
427
|
-
winston.error("DirAskGPTV2 Get integrations error ", err);
|
|
428
|
-
resolve(null);
|
|
429
|
-
} else {
|
|
430
|
-
|
|
431
|
-
if (integration &&
|
|
432
|
-
integration.value) {
|
|
433
|
-
resolve(integration.value.apikey)
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
resolve(null)
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
})
|
|
440
|
-
})
|
|
441
|
-
}
|
|
442
|
-
|
|
443
374
|
async getKeyFromKbSettings() {
|
|
444
375
|
return new Promise((resolve) => {
|
|
445
376
|
|
|
@@ -453,7 +384,7 @@ class DirAskGPTV2 {
|
|
|
453
384
|
}
|
|
454
385
|
winston.debug("DirAskGPTV2 KB HttpRequest", KB_HTTPREQUEST);
|
|
455
386
|
|
|
456
|
-
|
|
387
|
+
httpUtils.request(
|
|
457
388
|
KB_HTTPREQUEST, async (err, resbody) => {
|
|
458
389
|
if (err) {
|
|
459
390
|
winston.error("DirAskGPTV2 Get kb settings error ", err?.response?.data);
|
|
@@ -483,7 +414,7 @@ class DirAskGPTV2 {
|
|
|
483
414
|
}
|
|
484
415
|
winston.debug("DirAskGPTV2 check quote availability HttpRequest", HTTPREQUEST);
|
|
485
416
|
|
|
486
|
-
|
|
417
|
+
httpUtils.request(
|
|
487
418
|
HTTPREQUEST, async (err, resbody) => {
|
|
488
419
|
if (err) {
|
|
489
420
|
winston.error("DirAskGPTV2 Check quote availability err: ", err);
|
|
@@ -514,7 +445,7 @@ class DirAskGPTV2 {
|
|
|
514
445
|
}
|
|
515
446
|
winston.debug("DirAskGPTV2 update quote HttpRequest ", HTTPREQUEST);
|
|
516
447
|
|
|
517
|
-
|
|
448
|
+
httpUtils.request(
|
|
518
449
|
HTTPREQUEST, async (err, resbody) => {
|
|
519
450
|
if (err) {
|
|
520
451
|
winston.error("DirAskGPTV2 Increment tokens quote err: ", err);
|
|
@@ -586,7 +517,7 @@ class DirAskGPTV2 {
|
|
|
586
517
|
method: "GET"
|
|
587
518
|
}
|
|
588
519
|
winston.debug("DirAskGPTV2 get all namespaces HttpRequest", HTTPREQUEST);
|
|
589
|
-
|
|
520
|
+
httpUtils.request(
|
|
590
521
|
HTTPREQUEST, async (err, namespaces) => {
|
|
591
522
|
if (err) {
|
|
592
523
|
winston.error("DirAskGPTV2 get all namespaces err: ", err);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { TiledeskChatbot } = require('../../
|
|
1
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
2
2
|
const { TiledeskExpression } = require('../../TiledeskExpression');
|
|
3
3
|
const ms = require('minimist-string');
|
|
4
4
|
const { Filler } = require('../Filler');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
2
|
const ms = require('minimist-string');
|
|
3
|
-
const { TiledeskChatbot } = require('../../
|
|
3
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot.js');
|
|
4
4
|
const winston = require('../../utils/winston')
|
|
5
5
|
|
|
6
6
|
class DirAssignFromFunction {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
let axios = require('axios');
|
|
2
2
|
let https = require("https");
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
|
-
const { TiledeskChatbot } = require('../../
|
|
4
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
5
5
|
const { DirIntent } = require('./DirIntent');
|
|
6
6
|
const winston = require('../../utils/winston')
|
|
7
|
+
const httpUtils = require('../../utils/HttpUtils');
|
|
8
|
+
const integrationService = require('../../services/IntegrationService');
|
|
7
9
|
|
|
8
10
|
class DirAssistant {
|
|
9
11
|
constructor(context) {
|
|
@@ -13,6 +15,8 @@ class DirAssistant {
|
|
|
13
15
|
this.context = context;
|
|
14
16
|
this.tdcache = context.tdcache;
|
|
15
17
|
this.requestId = context.requestId;
|
|
18
|
+
this.projectId = this.context.projectId;
|
|
19
|
+
this.token = this.context.token;
|
|
16
20
|
this.intentDir = new DirIntent(context);
|
|
17
21
|
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
18
22
|
this.log = context.log;
|
|
@@ -260,7 +264,7 @@ class DirAssistant {
|
|
|
260
264
|
return process.env.TEST_OPENAI_APIKEY
|
|
261
265
|
}
|
|
262
266
|
else {
|
|
263
|
-
return await
|
|
267
|
+
return await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
|
|
264
268
|
}
|
|
265
269
|
}
|
|
266
270
|
|
|
@@ -280,7 +284,7 @@ class DirAssistant {
|
|
|
280
284
|
timeout: this.timeout
|
|
281
285
|
};
|
|
282
286
|
winston.debug("(DirAssistant) DirAssistant HttpRequest", HTTPREQUEST);
|
|
283
|
-
|
|
287
|
+
httpUtils.request(
|
|
284
288
|
HTTPREQUEST, async (err, res) => {
|
|
285
289
|
let status = res.status;
|
|
286
290
|
if (err) {
|
|
@@ -340,7 +344,7 @@ class DirAssistant {
|
|
|
340
344
|
timeout: this.timeout
|
|
341
345
|
};
|
|
342
346
|
winston.debug("(DirAssistant) HttpRequest: ", HTTPREQUEST);
|
|
343
|
-
|
|
347
|
+
httpUtils.request(
|
|
344
348
|
HTTPREQUEST, async (err, res) => {
|
|
345
349
|
let status = res.status;
|
|
346
350
|
if (err) {
|
|
@@ -401,7 +405,7 @@ class DirAssistant {
|
|
|
401
405
|
timeout: this.timeout
|
|
402
406
|
};
|
|
403
407
|
winston.debug("(DirAssistant) HttpRequest: ", HTTPREQUEST);
|
|
404
|
-
|
|
408
|
+
httpUtils.request(
|
|
405
409
|
HTTPREQUEST, async (err, res) => {
|
|
406
410
|
if (err) {
|
|
407
411
|
winston.error("(DirAssistant) error: ", err);
|
|
@@ -409,6 +413,7 @@ class DirAssistant {
|
|
|
409
413
|
}
|
|
410
414
|
else if(res?.status >= 200 && res?.status <= 299) {
|
|
411
415
|
winston.debug("(DirAddTags) got response data: ", res.data);
|
|
416
|
+
// let return_body = res.data;
|
|
412
417
|
resolve(res.data);
|
|
413
418
|
}
|
|
414
419
|
else {
|
|
@@ -435,7 +440,7 @@ class DirAssistant {
|
|
|
435
440
|
timeout: this.timeout
|
|
436
441
|
};
|
|
437
442
|
winston.debug("(DirAssistant) HttpRequest: ", HTTPREQUEST);
|
|
438
|
-
|
|
443
|
+
httpUtils.request(
|
|
439
444
|
HTTPREQUEST, async (err, res) => {
|
|
440
445
|
if (err) {
|
|
441
446
|
winston.error("(DirAssistant) error: ", err);
|
|
@@ -443,6 +448,7 @@ class DirAssistant {
|
|
|
443
448
|
}
|
|
444
449
|
else if(res?.status >= 200 && res?.status <= 299) {
|
|
445
450
|
winston.debug("(DirAddTags) got response data: ", res.data);
|
|
451
|
+
// let return_body = res.data;
|
|
446
452
|
resolve(res.data);
|
|
447
453
|
}
|
|
448
454
|
else {
|
|
@@ -469,7 +475,7 @@ class DirAssistant {
|
|
|
469
475
|
timeout: this.timeout
|
|
470
476
|
};
|
|
471
477
|
winston.debug("(DirAssistant) HttpRequest: ", HTTPREQUEST);
|
|
472
|
-
|
|
478
|
+
httpUtils.request(
|
|
473
479
|
HTTPREQUEST, async (err, res) => {
|
|
474
480
|
if (err) {
|
|
475
481
|
winston.error("(DirAssistant) error: ", err);
|
|
@@ -488,105 +494,6 @@ class DirAssistant {
|
|
|
488
494
|
);
|
|
489
495
|
});
|
|
490
496
|
}
|
|
491
|
-
|
|
492
|
-
async getKeyFromIntegrations() {
|
|
493
|
-
return new Promise((resolve) => {
|
|
494
|
-
|
|
495
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
496
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
497
|
-
headers: {
|
|
498
|
-
'Content-Type': 'application/json',
|
|
499
|
-
'Authorization': 'JWT ' + this.context.token
|
|
500
|
-
},
|
|
501
|
-
method: "GET"
|
|
502
|
-
}
|
|
503
|
-
winston.debug("(DirAssistant) Integrations HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
504
|
-
|
|
505
|
-
this.#myrequest(
|
|
506
|
-
INTEGRATIONS_HTTPREQUEST, async (err, res) => {
|
|
507
|
-
if (err) {
|
|
508
|
-
resolve(null);
|
|
509
|
-
} else {
|
|
510
|
-
let integration = res.data;
|
|
511
|
-
if (integration &&
|
|
512
|
-
integration.value) {
|
|
513
|
-
resolve(integration.value.apikey)
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
resolve(null)
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
})
|
|
520
|
-
})
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
#myrequest(options, callback) {
|
|
524
|
-
try {
|
|
525
|
-
let axios_options = {
|
|
526
|
-
url: options.url,
|
|
527
|
-
method: options.method,
|
|
528
|
-
params: options.params,
|
|
529
|
-
headers: options.headers,
|
|
530
|
-
timeout: options.timeout
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
if (options.json !== null) {
|
|
534
|
-
axios_options.data = options.json
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
if (options.url.startsWith("https:")) {
|
|
538
|
-
const httpsAgent = new https.Agent({
|
|
539
|
-
rejectUnauthorized: false,
|
|
540
|
-
});
|
|
541
|
-
axios_options.httpsAgent = httpsAgent;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
axios(axios_options)
|
|
545
|
-
.then((res) => {
|
|
546
|
-
if (callback) {
|
|
547
|
-
callback(null, res);
|
|
548
|
-
}
|
|
549
|
-
})
|
|
550
|
-
.catch( (err) => {
|
|
551
|
-
if (callback) {
|
|
552
|
-
let status = 1000;
|
|
553
|
-
let cache = [];
|
|
554
|
-
let str_error = JSON.stringify(err, function(key, value) { // try to use a separate function
|
|
555
|
-
if (typeof value === 'object' && value != null) {
|
|
556
|
-
if (cache.indexOf(value) !== -1) {
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
cache.push(value);
|
|
560
|
-
}
|
|
561
|
-
return value;
|
|
562
|
-
});
|
|
563
|
-
let error = JSON.parse(str_error) // "status" disappears without this trick
|
|
564
|
-
let errorMessage = JSON.stringify(error);
|
|
565
|
-
if (error.status) {
|
|
566
|
-
status = error.status;
|
|
567
|
-
}
|
|
568
|
-
if (error.message) {
|
|
569
|
-
errorMessage = error.message;
|
|
570
|
-
}
|
|
571
|
-
let data = null;
|
|
572
|
-
if (err.response) {
|
|
573
|
-
data = err.response.data;
|
|
574
|
-
}
|
|
575
|
-
callback(
|
|
576
|
-
{
|
|
577
|
-
status: status,
|
|
578
|
-
data: data,
|
|
579
|
-
error: errorMessage
|
|
580
|
-
}, data
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
catch(error) {
|
|
586
|
-
winston.error("(DirAssistant) Axios error: ", error);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
497
|
}
|
|
591
498
|
|
|
592
499
|
|
|
@@ -1,10 +1,11 @@
|
|
|
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
|
const { DirIntent } = require("./DirIntent");
|
|
5
5
|
let https = require("https");
|
|
6
6
|
require('dotenv').config();
|
|
7
7
|
const winston = require('../../utils/winston');
|
|
8
|
+
const integrationService = require("../../services/IntegrationService");
|
|
8
9
|
|
|
9
10
|
class DirBrevo {
|
|
10
11
|
|
|
@@ -15,6 +16,8 @@ class DirBrevo {
|
|
|
15
16
|
this.context = context;
|
|
16
17
|
this.tdcache = this.context.tdcache;
|
|
17
18
|
this.requestId = this.context.requestId;
|
|
19
|
+
this.projectId = this.context.projectId;
|
|
20
|
+
this.token = this.context.token;
|
|
18
21
|
this.intentDir = new DirIntent(context);
|
|
19
22
|
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
20
23
|
this.log = context.log;
|
|
@@ -74,7 +77,7 @@ class DirBrevo {
|
|
|
74
77
|
const brevo_base_url = process.env.BREVO_ENDPOINT || "https://api.brevo.com/v3"
|
|
75
78
|
winston.debug("(DirBrevo) brevo_base_url: " + brevo_base_url);
|
|
76
79
|
|
|
77
|
-
let key = await
|
|
80
|
+
let key = await integrationService.getKeyFromIntegrations(this.projectId, 'Brevo', this.token);
|
|
78
81
|
winston.debug("(DirBrevo) key: ", key)
|
|
79
82
|
if (!key) {
|
|
80
83
|
winston.debug("(DirBrevo) - Key not found in Integrations.");
|
|
@@ -285,38 +288,6 @@ class DirBrevo {
|
|
|
285
288
|
}
|
|
286
289
|
}
|
|
287
290
|
}
|
|
288
|
-
|
|
289
|
-
async getKeyFromIntegrations() {
|
|
290
|
-
return new Promise((resolve) => {
|
|
291
|
-
|
|
292
|
-
const INTEGRATIONS_HTTPREQUEST = {
|
|
293
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/Brevo",
|
|
294
|
-
headers: {
|
|
295
|
-
'Content-Type': 'application/json',
|
|
296
|
-
'Authorization': 'JWT ' + this.context.token
|
|
297
|
-
},
|
|
298
|
-
method: "GET"
|
|
299
|
-
}
|
|
300
|
-
winston.debug("(DirBrevo) Inteegration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
|
|
301
|
-
|
|
302
|
-
this.#myrequest(
|
|
303
|
-
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
304
|
-
if (err) {
|
|
305
|
-
resolve(null);
|
|
306
|
-
} else {
|
|
307
|
-
|
|
308
|
-
if (integration &&
|
|
309
|
-
integration.value) {
|
|
310
|
-
resolve(integration.value.apikey)
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
resolve(null)
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
})
|
|
317
|
-
})
|
|
318
|
-
}
|
|
319
|
-
|
|
320
291
|
}
|
|
321
292
|
|
|
322
293
|
module.exports = { DirBrevo }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { Filler } = require('../Filler');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
3
|
const { DirIntent } = require('./DirIntent');
|
|
4
4
|
const winston = require('../../utils/winston');
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
3
|
-
const { TiledeskChatbotConst } = require("../../
|
|
3
|
+
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
4
4
|
const winston = require('../../utils/winston');
|
|
5
5
|
|
|
6
6
|
class DirClose {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { TiledeskChatbot } = require('../../
|
|
1
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
2
2
|
const { TiledeskExpression } = require('../../TiledeskExpression');
|
|
3
3
|
const { TiledeskRequestVariables } = require('../TiledeskRequestVariables');
|
|
4
4
|
const winston = require('../../utils/winston');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { DirIntent } = require('./DirIntent');
|
|
2
|
-
const { TiledeskChatbot } = require('../../
|
|
2
|
+
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
3
|
const { TiledeskExpression } = require('../../TiledeskExpression');
|
|
4
4
|
const ms = require('minimist-string');
|
|
5
5
|
const winston = require('../../utils/winston');
|