@tiledesk/tiledesk-tybot-connector 0.2.131-rc5 → 0.2.131
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 +2 -4
- package/TdCache.js +1 -1
- package/index.js +12 -12
- package/models/TiledeskChatbot.js +2 -3
- package/models/TiledeskChatbotUtil.js +4 -8
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +8 -6
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +20 -20
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +13 -10
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +57 -18
- package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -0
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +21 -11
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +5 -4
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +28 -1
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +2 -13
- package/tiledeskChatbotPlugs/directives/DirCondition.js +26 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +13 -1
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -12
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -11
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +5 -14
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +6 -17
- package/tiledeskChatbotPlugs/directives/DirForm.js +2 -12
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +18 -14
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +7 -4
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +27 -14
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +3 -13
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +31 -5
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +27 -13
- package/tiledeskChatbotPlugs/directives/DirIntent.js +23 -1
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +26 -0
- package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +13 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +2 -12
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +2 -11
- package/tiledeskChatbotPlugs/directives/DirQapla.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -11
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +7 -17
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +2 -11
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -12
- package/tiledeskChatbotPlugs/directives/DirReply.js +1 -11
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +1 -11
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +22 -12
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +4 -13
- package/tiledeskChatbotPlugs/directives/DirWait.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +60 -2
- /package/tiledeskChatbotPlugs/directives/{DEPRECATED_DirOfflineHours.js → DirOfflineHours.js} +0 -0
|
@@ -9,17 +9,27 @@ class DirAssignFromFunction {
|
|
|
9
9
|
throw new Error('context object is mandatory.');
|
|
10
10
|
}
|
|
11
11
|
this.context = context;
|
|
12
|
+
// let context = {
|
|
13
|
+
// projectId: projectId,
|
|
14
|
+
// token: token,
|
|
15
|
+
// supportRequest: supportRequest,
|
|
16
|
+
// requestId: supportRequest.request_id,
|
|
17
|
+
// TILEDESK_APIURL: API_URL,
|
|
18
|
+
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
19
|
+
// departmentId: depId,
|
|
20
|
+
// tdcache: tdcache,
|
|
21
|
+
// log: false
|
|
22
|
+
// }
|
|
23
|
+
this.tdclient = context.tdclient;
|
|
24
|
+
// new TiledeskClient({
|
|
25
|
+
// projectId: context.projectId,
|
|
26
|
+
// token: context.token,
|
|
27
|
+
// APIURL: context.TILEDESK_APIURL,
|
|
28
|
+
// APIKEY: "___",
|
|
29
|
+
// log: context.log
|
|
30
|
+
// });
|
|
12
31
|
this.log = context.log;
|
|
13
32
|
this.tdcache = context.tdcache;
|
|
14
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
15
|
-
|
|
16
|
-
this.tdClient = new TiledeskClient({
|
|
17
|
-
projectId: this.context.projectId,
|
|
18
|
-
token: this.context.token,
|
|
19
|
-
APIURL: this.API_ENDPOINT,
|
|
20
|
-
APIKEY: "___",
|
|
21
|
-
log: this.log
|
|
22
|
-
});
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
async execute(directive, callback) {
|
|
@@ -67,7 +77,7 @@ class DirAssignFromFunction {
|
|
|
67
77
|
async invoke(functionName, callback) {
|
|
68
78
|
switch (functionName) {
|
|
69
79
|
case "openNow":
|
|
70
|
-
this.
|
|
80
|
+
this.tdclient.openNow((err, result) => {
|
|
71
81
|
if (this.log) {console.log("openNow():", result);}
|
|
72
82
|
if (err) {
|
|
73
83
|
callback(err);
|
|
@@ -81,7 +91,7 @@ class DirAssignFromFunction {
|
|
|
81
91
|
});
|
|
82
92
|
break;
|
|
83
93
|
case "availableAgents":
|
|
84
|
-
this.
|
|
94
|
+
this.tdclient.getProjectAvailableAgents((err, agents) => {
|
|
85
95
|
if (this.log) {console.log("Agents on 'open'", agents);}
|
|
86
96
|
if (err || !agents) {
|
|
87
97
|
console.error("Error getting available agents in DirWhenAvailableAgents", err);
|
|
@@ -10,10 +10,10 @@ class DirAssistant {
|
|
|
10
10
|
throw new Error('context object is mandatory.');
|
|
11
11
|
}
|
|
12
12
|
this.context = context;
|
|
13
|
+
this.tdclient = context.tdclient;
|
|
13
14
|
this.tdcache = context.tdcache;
|
|
14
15
|
this.requestId = context.requestId;
|
|
15
16
|
this.intentDir = new DirIntent(context);
|
|
16
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
17
17
|
this.log = context.log;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -264,7 +264,8 @@ class DirAssistant {
|
|
|
264
264
|
return process.env.TEST_OPENAI_APIKEY
|
|
265
265
|
}
|
|
266
266
|
else {
|
|
267
|
-
|
|
267
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
268
|
+
return await this.getKeyFromIntegrations(server_base_url);
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
|
|
@@ -495,11 +496,11 @@ class DirAssistant {
|
|
|
495
496
|
});
|
|
496
497
|
}
|
|
497
498
|
|
|
498
|
-
async getKeyFromIntegrations() {
|
|
499
|
+
async getKeyFromIntegrations(server_base_url) {
|
|
499
500
|
return new Promise((resolve) => {
|
|
500
501
|
|
|
501
502
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
502
|
-
url:
|
|
503
|
+
url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
|
|
503
504
|
headers: {
|
|
504
505
|
'Content-Type': 'application/json',
|
|
505
506
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -16,7 +16,6 @@ class DirBrevo {
|
|
|
16
16
|
this.tdcache = this.context.tdcache;
|
|
17
17
|
this.requestId = this.context.requestId;
|
|
18
18
|
this.intentDir = new DirIntent(context);
|
|
19
|
-
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
20
19
|
this.log = context.log;
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -72,10 +71,14 @@ class DirBrevo {
|
|
|
72
71
|
return;
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
75
75
|
const brevo_base_url = process.env.BREVO_ENDPOINT || "https://api.brevo.com/v3"
|
|
76
|
-
if (this.log) {
|
|
76
|
+
if (this.log) {
|
|
77
|
+
console.log("DirBrevo server_base_url ", server_base_url);
|
|
78
|
+
console.log("DirBrevo brevo_base_url ", brevo_base_url);
|
|
79
|
+
}
|
|
77
80
|
|
|
78
|
-
let key = await this.getKeyFromIntegrations();
|
|
81
|
+
let key = await this.getKeyFromIntegrations(server_base_url);
|
|
79
82
|
if (this.log) { console.log('DirBrevo key Debug1: ', key) }
|
|
80
83
|
// ONLY FOR DEBUG CANCELLARE!!!!!
|
|
81
84
|
// if (process.env.BREVO_DEBUG == '1') {
|
|
@@ -317,11 +320,11 @@ class DirBrevo {
|
|
|
317
320
|
}
|
|
318
321
|
}
|
|
319
322
|
|
|
320
|
-
async getKeyFromIntegrations() {
|
|
323
|
+
async getKeyFromIntegrations(server_base_url) {
|
|
321
324
|
return new Promise((resolve) => {
|
|
322
325
|
|
|
323
326
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
324
|
-
url:
|
|
327
|
+
url: server_base_url + "/" + this.context.projectId + "/integration/name/Brevo",
|
|
325
328
|
headers: {
|
|
326
329
|
'Content-Type': 'application/json',
|
|
327
330
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -7,10 +7,37 @@ class DirCaptureUserReply {
|
|
|
7
7
|
if (!context) {
|
|
8
8
|
throw new Error('context object is mandatory.');
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
this.context = context;
|
|
12
11
|
this.reply = context.reply;
|
|
12
|
+
// reply = {
|
|
13
|
+
// actions: [
|
|
14
|
+
// {
|
|
15
|
+
// _tdActionType: 'askgpt',
|
|
16
|
+
// _tdActionTitle: 'gpt action',
|
|
17
|
+
// assignReplyTo: 'gpt_reply',
|
|
18
|
+
// assignSourceTo: 'gpt_source',
|
|
19
|
+
// kbid: 'XXX',
|
|
20
|
+
// trueIntent: '#SUCCESS',
|
|
21
|
+
// falseIntent: '#FAILURE',
|
|
22
|
+
// question: 'this is the question: ${last_user_message}'
|
|
23
|
+
// }
|
|
24
|
+
// ],
|
|
25
|
+
// attributes: {
|
|
26
|
+
// clienttimestamp: 1695548792706,
|
|
27
|
+
// intent_info: {
|
|
28
|
+
// intent_name: 'gpt success',
|
|
29
|
+
// intent_id: '00f93b97-89ee-466d-a09c-e47a18943057',
|
|
30
|
+
// is_fallback: false,
|
|
31
|
+
// confidence: undefined,
|
|
32
|
+
// question_payload: [Object],
|
|
33
|
+
// botId: 'botID',
|
|
34
|
+
// bot: [Object]
|
|
35
|
+
// },
|
|
36
|
+
// webhook: false
|
|
37
|
+
// }
|
|
38
|
+
// }
|
|
13
39
|
this.message = context.message;
|
|
40
|
+
this.tdclient = context.tdclient;
|
|
14
41
|
this.chatbot = context.chatbot;
|
|
15
42
|
this.tdcache = context.tdcache;
|
|
16
43
|
this.requestId = context.requestId;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
3
2
|
const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
|
|
4
3
|
|
|
5
4
|
class DirClose {
|
|
@@ -9,23 +8,13 @@ class DirClose {
|
|
|
9
8
|
throw new Error('context object is mandatory.');
|
|
10
9
|
}
|
|
11
10
|
this.context = context;
|
|
11
|
+
this.tdclient = context.tdclient;
|
|
12
12
|
this.requestId = context.requestId;
|
|
13
13
|
this.chatbot = context.chatbot;
|
|
14
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
15
|
-
this.log = context.log;
|
|
16
|
-
|
|
17
|
-
console.log("this.context.projectId: ", context)
|
|
18
|
-
this.tdClient = new TiledeskClient({
|
|
19
|
-
projectId: this.context.projectId,
|
|
20
|
-
token: this.context.token,
|
|
21
|
-
APIURL: this.API_ENDPOINT,
|
|
22
|
-
APIKEY: "___",
|
|
23
|
-
log: this.log
|
|
24
|
-
});
|
|
25
14
|
}
|
|
26
15
|
|
|
27
16
|
execute(directive, callback) {
|
|
28
|
-
this.
|
|
17
|
+
this.tdclient.closeRequest(this.requestId, async (err) => {
|
|
29
18
|
if (err) {
|
|
30
19
|
console.error("Error in 'close directive':", err);
|
|
31
20
|
}
|
|
@@ -10,7 +10,33 @@ class DirCondition {
|
|
|
10
10
|
throw new Error('context object is mandatory.');
|
|
11
11
|
}
|
|
12
12
|
this.context = context;
|
|
13
|
+
// let context = {
|
|
14
|
+
// projectId: projectId,
|
|
15
|
+
// token: token,
|
|
16
|
+
// supportRequest: supportRequest,
|
|
17
|
+
// requestId: supportRequest.request_id,
|
|
18
|
+
// TILEDESK_APIURL: API_URL,
|
|
19
|
+
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
20
|
+
// departmentId: depId,
|
|
21
|
+
// tdcache: tdcache,
|
|
22
|
+
// log: false
|
|
23
|
+
// }
|
|
24
|
+
// this.tdclient = new TiledeskClient({
|
|
25
|
+
// projectId: context.projectId,
|
|
26
|
+
// token: context.token,
|
|
27
|
+
// APIURL: context.TILEDESK_APIURL,
|
|
28
|
+
// APIKEY: "___",
|
|
29
|
+
// log: context.log
|
|
30
|
+
// });
|
|
13
31
|
this.intentDir = new DirIntent(context);
|
|
32
|
+
// {
|
|
33
|
+
// API_ENDPOINT: context.TILEDESK_APIURL,
|
|
34
|
+
// TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
35
|
+
// supportRequest: context.supportRequest,
|
|
36
|
+
// token: context.token,
|
|
37
|
+
// log: context.log
|
|
38
|
+
// }
|
|
39
|
+
// );
|
|
14
40
|
this.log = context.log;
|
|
15
41
|
}
|
|
16
42
|
|
|
@@ -10,11 +10,23 @@ class DirConnectBlock {
|
|
|
10
10
|
throw new Error('context object is mandatory.');
|
|
11
11
|
}
|
|
12
12
|
this.context = context;
|
|
13
|
-
this.API_ENDPOINT = context.
|
|
13
|
+
this.API_ENDPOINT = context.TILEDESK_APIURL,
|
|
14
14
|
this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
|
|
15
15
|
this.supportRequest = context.supportRequest;
|
|
16
16
|
this.token = context.token;
|
|
17
17
|
this.log = context.log;
|
|
18
|
+
// let context = {
|
|
19
|
+
// projectId: projectId,
|
|
20
|
+
// token: token,
|
|
21
|
+
// supportRequest: supportRequest,
|
|
22
|
+
// requestId: supportRequest.request_id,
|
|
23
|
+
// TILEDESK_APIURL: API_URL,
|
|
24
|
+
// TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
25
|
+
// departmentId: depId,
|
|
26
|
+
// tdcache: tdcache,
|
|
27
|
+
// tdclient: tdclient,
|
|
28
|
+
// log: true
|
|
29
|
+
// }
|
|
18
30
|
}
|
|
19
31
|
|
|
20
32
|
execute(directive, callback) {
|
|
@@ -3,7 +3,6 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
|
3
3
|
const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
|
|
4
4
|
let axios = require('axios');
|
|
5
5
|
const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
|
|
6
|
-
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
7
6
|
|
|
8
7
|
class DirContactUpdate {
|
|
9
8
|
|
|
@@ -17,16 +16,8 @@ class DirContactUpdate {
|
|
|
17
16
|
this.supportRequest = context.supportRequest;
|
|
18
17
|
this.token = context.token;
|
|
19
18
|
this.tdcache = context.tdcache;
|
|
20
|
-
this.
|
|
19
|
+
this.tdclient = context.tdclient;
|
|
21
20
|
this.log = context.log;
|
|
22
|
-
|
|
23
|
-
this.tdClient = new TiledeskClient({
|
|
24
|
-
projectId: this.context.projectId,
|
|
25
|
-
token: this.context.token,
|
|
26
|
-
APIURL: this.API_ENDPOINT,
|
|
27
|
-
APIKEY: "___",
|
|
28
|
-
log: this.log
|
|
29
|
-
});
|
|
30
21
|
}
|
|
31
22
|
|
|
32
23
|
execute(directive, callback) {
|
|
@@ -81,7 +72,7 @@ class DirContactUpdate {
|
|
|
81
72
|
if (this.log) {console.log("(DirContactUpdate) updating property:", key, "value:", filled_value); }
|
|
82
73
|
}
|
|
83
74
|
const leadId = requestAttributes[TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY];
|
|
84
|
-
this.
|
|
75
|
+
this.tdclient.updateLead(leadId, updateProperties, null, null, () => {
|
|
85
76
|
if (this.log) {console.log("(DirContactUpdate) Lead updated.", updateProperties);}
|
|
86
77
|
// send hidden info to update widget lead fullname only if it is a conversation!
|
|
87
78
|
if (this.log) {console.log("(DirContactUpdate) requestId:", this.requestId); }
|
|
@@ -100,7 +91,7 @@ class DirContactUpdate {
|
|
|
100
91
|
// }
|
|
101
92
|
// };
|
|
102
93
|
// if (this.log) {console.log("(DirContactUpdate) sending updateLeadDataOnWidgetMessage:", updateLeadDataOnWidgetMessage); }
|
|
103
|
-
// this.
|
|
94
|
+
// this.context.tdclient.sendSupportMessage(
|
|
104
95
|
// this.requestId,
|
|
105
96
|
// updateLeadDataOnWidgetMessage,
|
|
106
97
|
// (err) => {
|
|
@@ -16,7 +16,6 @@ class DirCustomerio {
|
|
|
16
16
|
this.tdcache = this.context.tdcache;
|
|
17
17
|
this.requestId = this.context.requestId;
|
|
18
18
|
this.intentDir = new DirIntent(context);
|
|
19
|
-
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
20
19
|
this.log = context.log;
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -70,10 +69,14 @@ class DirCustomerio {
|
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
71
|
|
|
72
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
73
73
|
const customerio_base_url = process.env.CUSTOMERIO_ENDPOINT || "https://track.customer.io/api/v1";
|
|
74
|
-
if (this.log) {
|
|
74
|
+
if (this.log) {
|
|
75
|
+
console.log("DirCustomerio server_base_url: ", server_base_url);
|
|
76
|
+
console.log("DirCustomerio customerio_base_url: ", customerio_base_url);
|
|
77
|
+
}
|
|
75
78
|
|
|
76
|
-
let key = await this.getKeyFromIntegrations();
|
|
79
|
+
let key = await this.getKeyFromIntegrations(server_base_url);
|
|
77
80
|
if (!key) {
|
|
78
81
|
if (this.log) { console.log("DirCustomerio - Key not found in Integrations."); }
|
|
79
82
|
let status = 422;
|
|
@@ -284,11 +287,11 @@ class DirCustomerio {
|
|
|
284
287
|
}
|
|
285
288
|
}
|
|
286
289
|
|
|
287
|
-
async getKeyFromIntegrations() {
|
|
290
|
+
async getKeyFromIntegrations(server_base_url) {
|
|
288
291
|
return new Promise((resolve) => {
|
|
289
292
|
|
|
290
293
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
291
|
-
url:
|
|
294
|
+
url: server_base_url + "/" + this.context.projectId + "/integration/name/customerio",
|
|
292
295
|
headers: {
|
|
293
296
|
'Content-Type': 'application/json',
|
|
294
297
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -2,7 +2,6 @@ const { HelpCenterQuery } = require('@tiledesk/helpcenter-query-client');
|
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot.js');
|
|
3
3
|
const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
|
|
4
4
|
const ms = require('minimist-string');
|
|
5
|
-
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
6
5
|
|
|
7
6
|
class DirDeflectToHelpCenter {
|
|
8
7
|
|
|
@@ -11,16 +10,7 @@ class DirDeflectToHelpCenter {
|
|
|
11
10
|
throw new Error('context object is mandatory.');
|
|
12
11
|
}
|
|
13
12
|
this.context = context;
|
|
14
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
15
13
|
this.log = context.log;
|
|
16
|
-
|
|
17
|
-
this.tdClient = new TiledeskClient({
|
|
18
|
-
projectId: this.context.projectId,
|
|
19
|
-
token: this.context.token,
|
|
20
|
-
APIURL: this.API_ENDPOINT,
|
|
21
|
-
APIKEY: "___",
|
|
22
|
-
log: this.log
|
|
23
|
-
});
|
|
24
14
|
}
|
|
25
15
|
|
|
26
16
|
async execute(directive, callback) {
|
|
@@ -142,7 +132,7 @@ class DirDeflectToHelpCenter {
|
|
|
142
132
|
}
|
|
143
133
|
|
|
144
134
|
if (this.log) {console.log("HC reply:", JSON.stringify(message))};
|
|
145
|
-
this.
|
|
135
|
+
this.context.tdclient.sendSupportMessage(
|
|
146
136
|
this.context.requestId,
|
|
147
137
|
message,
|
|
148
138
|
(err) => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
2
1
|
|
|
3
2
|
class DirDepartment {
|
|
4
3
|
|
|
@@ -7,17 +6,9 @@ class DirDepartment {
|
|
|
7
6
|
throw new Error('context object is mandatory.');
|
|
8
7
|
}
|
|
9
8
|
this.context = context;
|
|
10
|
-
this.requestId = context.requestId;
|
|
11
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
12
9
|
this.log = context.log;
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
projectId: this.context.projectId,
|
|
16
|
-
token: this.context.token,
|
|
17
|
-
APIURL: this.API_ENDPOINT,
|
|
18
|
-
APIKEY: "___",
|
|
19
|
-
log: this.log
|
|
20
|
-
});
|
|
10
|
+
this.tdclient = context.tdclient;
|
|
11
|
+
this.requestId = context.requestId;
|
|
21
12
|
}
|
|
22
13
|
|
|
23
14
|
execute(directive, callback) {
|
|
@@ -89,7 +80,7 @@ class DirDepartment {
|
|
|
89
80
|
subtype: "info"
|
|
90
81
|
}
|
|
91
82
|
}
|
|
92
|
-
this.
|
|
83
|
+
this.tdclient.sendSupportMessage(
|
|
93
84
|
this.requestId,
|
|
94
85
|
message, (err) => {
|
|
95
86
|
if (err) {
|
|
@@ -108,7 +99,7 @@ class DirDepartment {
|
|
|
108
99
|
}
|
|
109
100
|
|
|
110
101
|
moveToDepartment(requestId, depName, callback) {
|
|
111
|
-
this.
|
|
102
|
+
this.tdclient.getAllDepartments((err, deps) => {
|
|
112
103
|
if (this.log) {console.log("deps:", JSON.stringify(deps));}
|
|
113
104
|
if (err) {
|
|
114
105
|
console.error("getAllDepartments() error:", err);
|
|
@@ -125,7 +116,7 @@ class DirDepartment {
|
|
|
125
116
|
}
|
|
126
117
|
}
|
|
127
118
|
if (dep) {
|
|
128
|
-
this.
|
|
119
|
+
this.tdclient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
|
|
129
120
|
if (err) {
|
|
130
121
|
console.error("DirDepartment error:", err);
|
|
131
122
|
callback();
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
1
|
const ms = require('minimist-string');
|
|
3
2
|
|
|
4
3
|
class DirFireTiledeskEvent {
|
|
5
4
|
|
|
6
|
-
constructor(
|
|
7
|
-
if (!
|
|
8
|
-
throw new Error('
|
|
5
|
+
constructor(config) {
|
|
6
|
+
if (!config.tdclient) {
|
|
7
|
+
throw new Error('config.tdclient (TiledeskClient) object is mandatory.');
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
-
this.log = context.log;
|
|
13
|
-
|
|
14
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
15
|
-
this.tdClient = new TiledeskClient({
|
|
16
|
-
projectId: this.context.projectId,
|
|
17
|
-
token: this.context.token,
|
|
18
|
-
APIURL: this.API_ENDPOINT,
|
|
19
|
-
APIKEY: "___",
|
|
20
|
-
log: this.log
|
|
21
|
-
});
|
|
9
|
+
this.tdclient = config.tdclient;
|
|
10
|
+
this.log = config.log;
|
|
22
11
|
}
|
|
23
12
|
|
|
24
13
|
execute(directive, callback) {
|
|
@@ -29,7 +18,7 @@ class DirFireTiledeskEvent {
|
|
|
29
18
|
name: event_name,
|
|
30
19
|
attributes: params.payload
|
|
31
20
|
}
|
|
32
|
-
this.
|
|
21
|
+
this.tdclient.fireEvent(event, function(err, result) {
|
|
33
22
|
if (err) {
|
|
34
23
|
console.error("An error occurred invoking an event:", err);
|
|
35
24
|
}
|
|
@@ -2,7 +2,6 @@ const { Filler } = require('../Filler');
|
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
3
|
const { DirIntent } = require('./DirIntent');
|
|
4
4
|
const { IntentForm } = require('../../models/IntentForm.js');
|
|
5
|
-
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
6
5
|
|
|
7
6
|
class DirForm {
|
|
8
7
|
constructor(context) {
|
|
@@ -10,21 +9,12 @@ class DirForm {
|
|
|
10
9
|
throw new Error('context object is mandatory.');
|
|
11
10
|
}
|
|
12
11
|
this.context = context;
|
|
12
|
+
this.tdclient = context.tdclient;
|
|
13
13
|
this.chatbot = context.chatbot;
|
|
14
14
|
this.tdcache = context.tdcache;
|
|
15
15
|
this.requestId = context.requestId;
|
|
16
16
|
this.intentDir = new DirIntent(context);
|
|
17
17
|
this.log = context.log;
|
|
18
|
-
|
|
19
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
20
|
-
this.tdClient = new TiledeskClient({
|
|
21
|
-
projectId: this.context.projectId,
|
|
22
|
-
token: this.context.token,
|
|
23
|
-
APIURL: this.API_ENDPOINT,
|
|
24
|
-
APIKEY: "___",
|
|
25
|
-
log: this.log
|
|
26
|
-
});
|
|
27
|
-
|
|
28
18
|
}
|
|
29
19
|
|
|
30
20
|
execute(directive, callback) {
|
|
@@ -93,7 +83,7 @@ class DirForm {
|
|
|
93
83
|
form_reply.message.attributes.markbot = true;
|
|
94
84
|
// return form_reply.message;
|
|
95
85
|
|
|
96
|
-
this.
|
|
86
|
+
this.context.tdclient.sendSupportMessage(
|
|
97
87
|
this.requestId,
|
|
98
88
|
form_reply.message,
|
|
99
89
|
(err) => {
|
|
@@ -18,7 +18,6 @@ class DirGptTask {
|
|
|
18
18
|
this.tdcache = this.context.tdcache;
|
|
19
19
|
this.requestId = this.context.requestId;
|
|
20
20
|
this.intentDir = new DirIntent(context);
|
|
21
|
-
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
22
21
|
this.log = context.log;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -113,13 +112,18 @@ class DirGptTask {
|
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
115
|
+
|
|
116
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
116
117
|
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
117
|
-
if (this.log) {
|
|
118
|
+
if (this.log) {
|
|
119
|
+
console.log("DirGptTask server_base_url ", server_base_url);
|
|
120
|
+
console.log("DirGptTask openai_url ", openai_url);
|
|
121
|
+
}
|
|
118
122
|
|
|
119
|
-
let key = await this.getKeyFromIntegrations();
|
|
123
|
+
let key = await this.getKeyFromIntegrations(server_base_url);
|
|
120
124
|
if (!key) {
|
|
121
125
|
if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
|
|
122
|
-
key = await this.getKeyFromKbSettings();
|
|
126
|
+
key = await this.getKeyFromKbSettings(server_base_url);
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
if (!key) {
|
|
@@ -142,7 +146,7 @@ class DirGptTask {
|
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
if (publicKey === true) {
|
|
145
|
-
let keep_going = await this.checkQuoteAvailability();
|
|
149
|
+
let keep_going = await this.checkQuoteAvailability(server_base_url);
|
|
146
150
|
if (keep_going === false) {
|
|
147
151
|
if (this.log) { console.log("DirGptTask - Quota exceeded for tokens. Skip the action")}
|
|
148
152
|
await this.chatbot.addParameter("flowError", "GPT Error: tokens quota exceeded");
|
|
@@ -226,7 +230,7 @@ class DirGptTask {
|
|
|
226
230
|
tokens: resbody.usage.total_tokens,
|
|
227
231
|
model: json.model
|
|
228
232
|
}
|
|
229
|
-
this.updateQuote(tokens_usage);
|
|
233
|
+
this.updateQuote(server_base_url, tokens_usage);
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
if (trueIntent) {
|
|
@@ -364,11 +368,11 @@ class DirGptTask {
|
|
|
364
368
|
});
|
|
365
369
|
}
|
|
366
370
|
|
|
367
|
-
async getKeyFromIntegrations() {
|
|
371
|
+
async getKeyFromIntegrations(server_base_url) {
|
|
368
372
|
return new Promise((resolve) => {
|
|
369
373
|
|
|
370
374
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
371
|
-
url:
|
|
375
|
+
url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
|
|
372
376
|
headers: {
|
|
373
377
|
'Content-Type': 'application/json',
|
|
374
378
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -395,11 +399,11 @@ class DirGptTask {
|
|
|
395
399
|
})
|
|
396
400
|
}
|
|
397
401
|
|
|
398
|
-
async getKeyFromKbSettings() {
|
|
402
|
+
async getKeyFromKbSettings(server_base_url) {
|
|
399
403
|
return new Promise((resolve) => {
|
|
400
404
|
|
|
401
405
|
const KB_HTTPREQUEST = {
|
|
402
|
-
url:
|
|
406
|
+
url: server_base_url + "/" + this.context.projectId + "/kbsettings",
|
|
403
407
|
headers: {
|
|
404
408
|
'Content-Type': 'application/json',
|
|
405
409
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -428,11 +432,11 @@ class DirGptTask {
|
|
|
428
432
|
})
|
|
429
433
|
}
|
|
430
434
|
|
|
431
|
-
async checkQuoteAvailability() {
|
|
435
|
+
async checkQuoteAvailability(server_base_url) {
|
|
432
436
|
return new Promise((resolve) => {
|
|
433
437
|
|
|
434
438
|
const HTTPREQUEST = {
|
|
435
|
-
url:
|
|
439
|
+
url: server_base_url + "/" + this.context.projectId + "/quotes/tokens",
|
|
436
440
|
headers: {
|
|
437
441
|
'Content-Type': 'application/json',
|
|
438
442
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -457,11 +461,11 @@ class DirGptTask {
|
|
|
457
461
|
})
|
|
458
462
|
}
|
|
459
463
|
|
|
460
|
-
async updateQuote(tokens_usage) {
|
|
464
|
+
async updateQuote(server_base_url, tokens_usage) {
|
|
461
465
|
return new Promise((resolve) => {
|
|
462
466
|
|
|
463
467
|
const HTTPREQUEST = {
|
|
464
|
-
url:
|
|
468
|
+
url: server_base_url + "/" + this.context.projectId + "/quotes/incr/tokens",
|
|
465
469
|
headers: {
|
|
466
470
|
'Content-Type': 'application/json',
|
|
467
471
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -15,7 +15,6 @@ class DirGptTask {
|
|
|
15
15
|
this.tdcache = this.context.tdcache;
|
|
16
16
|
this.requestId = this.context.requestId;
|
|
17
17
|
this.intentDir = new DirIntent(context);
|
|
18
|
-
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
19
18
|
this.log = context.log;
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -86,11 +85,15 @@ class DirGptTask {
|
|
|
86
85
|
console.log("DirGptTask temperature: ", temperature);
|
|
87
86
|
}
|
|
88
87
|
|
|
88
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
89
89
|
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
90
|
-
if (this.log) {
|
|
90
|
+
if (this.log) {
|
|
91
|
+
console.log("DirGptTask server_base_url ", server_base_url);
|
|
92
|
+
console.log("DirGptTask openai_url ", openai_url);
|
|
93
|
+
}
|
|
91
94
|
|
|
92
95
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
93
|
-
url:
|
|
96
|
+
url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
|
|
94
97
|
headers: {
|
|
95
98
|
'Content-Type': 'application/json',
|
|
96
99
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -124,7 +127,7 @@ class DirGptTask {
|
|
|
124
127
|
if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
|
|
125
128
|
|
|
126
129
|
const KB_HTTPREQUEST = {
|
|
127
|
-
url:
|
|
130
|
+
url: server_base_url + "/" + this.context.projectId + "/kbsettings",
|
|
128
131
|
headers: {
|
|
129
132
|
'Content-Type': 'application/json',
|
|
130
133
|
'Authorization': 'JWT ' + this.context.token
|