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