@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
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,13 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
+
# v0.2.132
|
|
21
|
+
- Added support for external API_ENDPOINT
|
|
22
|
+
- Removed logs
|
|
23
|
+
|
|
24
|
+
# v0.2.131-rc2
|
|
25
|
+
- changed API_URL with API_ENDPOINT
|
|
26
|
+
|
|
20
27
|
# v0.2.131
|
|
21
28
|
- added: AUDIO_RECORD vxml action as reply_v2 actionType
|
|
22
29
|
- added: DirAddTags action
|
package/index.js
CHANGED
|
@@ -30,7 +30,7 @@ const { DirectivesChatbotPlug } = require('./tiledeskChatbotPlugs/DirectivesChat
|
|
|
30
30
|
let mongoose = require('mongoose');
|
|
31
31
|
// const { Directives } = require('./tiledeskChatbotPlugs/directives/Directives.js');
|
|
32
32
|
const { TiledeskChatbotUtil } = require('./models/TiledeskChatbotUtil.js'); //require('@tiledesk/tiledesk-chatbot-util');
|
|
33
|
-
let
|
|
33
|
+
let API_ENDPOINT = null;
|
|
34
34
|
let staticBots;
|
|
35
35
|
|
|
36
36
|
router.post('/ext/:botid', async (req, res) => {
|
|
@@ -160,7 +160,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
160
160
|
botId: botId,
|
|
161
161
|
bot: bot,
|
|
162
162
|
token: token,
|
|
163
|
-
APIURL:
|
|
163
|
+
APIURL: API_ENDPOINT,
|
|
164
164
|
APIKEY: "___",
|
|
165
165
|
tdcache: tdcache,
|
|
166
166
|
requestId: requestId,
|
|
@@ -206,7 +206,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
206
206
|
directives: directives,
|
|
207
207
|
chatbot: chatbot,
|
|
208
208
|
supportRequest: message.request,
|
|
209
|
-
|
|
209
|
+
API_ENDPOINT: API_ENDPOINT,
|
|
210
210
|
TILEBOT_ENDPOINT:process.env.TYBOT_ENDPOINT,
|
|
211
211
|
token: token,
|
|
212
212
|
log: log,
|
|
@@ -232,7 +232,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
232
232
|
reply.attributes.splits = true;
|
|
233
233
|
reply.attributes.markbot = true;
|
|
234
234
|
reply.attributes.fillParams = true;
|
|
235
|
-
let extEndpoint = `${
|
|
235
|
+
let extEndpoint = `${API_ENDPOINT}/modules/tilebot/`;
|
|
236
236
|
if (process.env.TYBOT_ENDPOINT) {
|
|
237
237
|
extEndpoint = `${process.env.TYBOT_ENDPOINT}`;
|
|
238
238
|
}
|
|
@@ -264,7 +264,7 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
264
264
|
const tdclient = new TiledeskClient({
|
|
265
265
|
projectId: projectId,
|
|
266
266
|
token: token,
|
|
267
|
-
APIURL:
|
|
267
|
+
APIURL: API_ENDPOINT,
|
|
268
268
|
APIKEY: "___",
|
|
269
269
|
log: false
|
|
270
270
|
});
|
|
@@ -309,10 +309,10 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
309
309
|
}
|
|
310
310
|
if (log) {
|
|
311
311
|
console.log("/ext request....", JSON.stringify(request));
|
|
312
|
-
console.log("/ext
|
|
312
|
+
console.log("/ext API_ENDPOINT....", API_ENDPOINT);
|
|
313
313
|
console.log("/ext process.env.TYBOT_ENDPOINT....", process.env.TYBOT_ENDPOINT);
|
|
314
314
|
}
|
|
315
|
-
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request,
|
|
315
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT:process.env.TYBOT_ENDPOINT, token: token, log: log, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT, cache: tdcache});
|
|
316
316
|
// let directivesPlug = null;
|
|
317
317
|
// PIPELINE-EXT
|
|
318
318
|
// if (log) {console.log("answer to process:", JSON.stringify(answer));}
|
|
@@ -542,7 +542,7 @@ router.post('/echobot', (req, res) => {
|
|
|
542
542
|
const tdclient = new TiledeskClient({
|
|
543
543
|
projectId: projectId,
|
|
544
544
|
token: token,
|
|
545
|
-
APIURL:
|
|
545
|
+
APIURL: API_ENDPOINT,
|
|
546
546
|
APIKEY: "___",
|
|
547
547
|
log: false
|
|
548
548
|
});
|
|
@@ -619,8 +619,8 @@ async function startApp(settings, completionCallback) {
|
|
|
619
619
|
throw new Error("settings.API_ENDPOINT is mandatory id no settings.bots.");
|
|
620
620
|
}
|
|
621
621
|
else {
|
|
622
|
-
|
|
623
|
-
console.log("(Tilebot) settings.API_ENDPOINT:",
|
|
622
|
+
API_ENDPOINT = settings.API_ENDPOINT;
|
|
623
|
+
console.log("(Tilebot) settings.API_ENDPOINT:", API_ENDPOINT);
|
|
624
624
|
}
|
|
625
625
|
|
|
626
626
|
if (settings.REDIS_HOST && settings.REDIS_PORT) {
|
|
@@ -730,7 +730,7 @@ async function checkRequest(request_id, id_project) {
|
|
|
730
730
|
function sendMessageToBot(TILEBOT_ENDPOINT, message, botId, callback) {
|
|
731
731
|
// const jwt_token = this.fixToken(token);
|
|
732
732
|
if (!TILEBOT_ENDPOINT) {
|
|
733
|
-
TILEBOT_ENDPOINT = `${
|
|
733
|
+
TILEBOT_ENDPOINT = `${API_ENDPOINT}/modules/tilebot`
|
|
734
734
|
}
|
|
735
735
|
const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
|
|
736
736
|
console.log("sendMessageToBot URL", url);
|
|
@@ -516,10 +516,13 @@ class TiledeskChatbotUtil {
|
|
|
516
516
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
|
|
517
517
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
518
518
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
519
|
+
/**
|
|
520
|
+
* RefactoringCheck: can this be deleted?
|
|
521
|
+
*/
|
|
522
|
+
// if (process.env.TILEDESK_API) {
|
|
523
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
|
|
524
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
525
|
+
// }
|
|
523
526
|
|
|
524
527
|
if (process.env.API_URL) {
|
|
525
528
|
await chatbot.addParameter(TiledeskChatbotConst.API_BASE_URL, process.env.API_URL);
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
2
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
3
3
|
const { DirDeflectToHelpCenter } = require('./directives/DirDeflectToHelpCenter');
|
|
4
|
-
// const { DirOfflineHours } = require('./directives/DirOfflineHours'); // DEPRECATED
|
|
5
4
|
const { DirMoveToAgent } = require('./directives/DirMoveToAgent');
|
|
6
5
|
const { DirMessage } = require('./directives/DirMessage');
|
|
7
6
|
const { DirWait } = require('./directives/DirWait');
|
|
@@ -65,7 +64,7 @@ class DirectivesChatbotPlug {
|
|
|
65
64
|
|
|
66
65
|
constructor(config) {
|
|
67
66
|
this.supportRequest = config.supportRequest;
|
|
68
|
-
this.
|
|
67
|
+
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
69
68
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
70
69
|
this.token = config.token;
|
|
71
70
|
this.log = config.log;
|
|
@@ -125,7 +124,7 @@ class DirectivesChatbotPlug {
|
|
|
125
124
|
// console.log("supportRequest is:", JSON.stringify(supportRequest))
|
|
126
125
|
|
|
127
126
|
const token = this.token;
|
|
128
|
-
const
|
|
127
|
+
const API_ENDPOINT = this.API_ENDPOINT;
|
|
129
128
|
const TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
130
129
|
|
|
131
130
|
// const requestId = supportRequest.request_id
|
|
@@ -142,7 +141,7 @@ class DirectivesChatbotPlug {
|
|
|
142
141
|
tdclient = new TiledeskClient({
|
|
143
142
|
projectId: projectId,
|
|
144
143
|
token: token,
|
|
145
|
-
APIURL:
|
|
144
|
+
APIURL: API_ENDPOINT,
|
|
146
145
|
APIKEY: "___",
|
|
147
146
|
log: this.log
|
|
148
147
|
});
|
|
@@ -159,11 +158,10 @@ class DirectivesChatbotPlug {
|
|
|
159
158
|
supportRequest: supportRequest,
|
|
160
159
|
reply: this.reply,
|
|
161
160
|
requestId: supportRequest.request_id,
|
|
162
|
-
|
|
161
|
+
API_ENDPOINT: API_ENDPOINT,
|
|
163
162
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
164
163
|
departmentId: depId,
|
|
165
164
|
tdcache: tdcache,
|
|
166
|
-
tdclient: tdclient,
|
|
167
165
|
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT,
|
|
168
166
|
log: this.log
|
|
169
167
|
}
|
|
@@ -768,7 +766,7 @@ class DirectivesChatbotPlug {
|
|
|
768
766
|
}
|
|
769
767
|
const supportRequest = this.supportRequest;
|
|
770
768
|
const token = this.token;
|
|
771
|
-
const
|
|
769
|
+
const API_ENDPOINT = this.API_ENDPOINT;
|
|
772
770
|
// const requestId = supportRequest.request_id
|
|
773
771
|
// let depId;
|
|
774
772
|
// if (supportRequest.department && supportRequest.department._id) {
|
|
@@ -778,7 +776,7 @@ class DirectivesChatbotPlug {
|
|
|
778
776
|
const tdclient = new TiledeskClient({
|
|
779
777
|
projectId: projectId,
|
|
780
778
|
token: token,
|
|
781
|
-
APIURL:
|
|
779
|
+
APIURL: API_ENDPOINT,
|
|
782
780
|
APIKEY: "___",
|
|
783
781
|
log: false
|
|
784
782
|
});
|
|
@@ -8,6 +8,7 @@ const { TiledeskChatbotUtil } = require("../../models/TiledeskChatbotUtil");
|
|
|
8
8
|
const req = require("express/lib/request");
|
|
9
9
|
const { rejects } = require("assert");
|
|
10
10
|
const { update } = require("../../models/faq");
|
|
11
|
+
const { TiledeskClient } = require("@tiledesk/tiledesk-client");
|
|
11
12
|
require('dotenv').config();
|
|
12
13
|
|
|
13
14
|
class DirAddTags {
|
|
@@ -20,10 +21,16 @@ class DirAddTags {
|
|
|
20
21
|
this.chatbot = this.context.chatbot;
|
|
21
22
|
this.tdcache = this.context.tdcache;
|
|
22
23
|
this.requestId = this.context.requestId;
|
|
23
|
-
this.
|
|
24
|
-
// this.intentDir = new DirIntent(context);
|
|
24
|
+
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
25
25
|
this.log = context.log;
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
this.tdClient = new TiledeskClient({
|
|
28
|
+
projectId: this.context.projectId,
|
|
29
|
+
token: this.context.token,
|
|
30
|
+
APIURL: this.API_ENDPOINT,
|
|
31
|
+
APIKEY: "___",
|
|
32
|
+
log: this.log
|
|
33
|
+
});
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
execute(directive, callback) {
|
|
@@ -77,12 +84,6 @@ class DirAddTags {
|
|
|
77
84
|
console.log("(DirAddTags) tags: ", filled_tags);
|
|
78
85
|
}
|
|
79
86
|
|
|
80
|
-
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
81
|
-
if (this.log) {
|
|
82
|
-
console.log("(DirAddTags) server_base_url ", server_base_url);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
87
|
// let request = await this.tdClient.getRequestById(this.requestId);
|
|
87
88
|
// if (this.log) { console.log('(DirAddTags) request detail: ', request) }
|
|
88
89
|
// if(!request){
|
|
@@ -91,7 +92,6 @@ class DirAddTags {
|
|
|
91
92
|
// return;
|
|
92
93
|
// }
|
|
93
94
|
|
|
94
|
-
|
|
95
95
|
/** use case: CONVERSATION */
|
|
96
96
|
if(target === 'request'){
|
|
97
97
|
|
|
@@ -99,7 +99,7 @@ class DirAddTags {
|
|
|
99
99
|
|
|
100
100
|
if(action.pushToList){
|
|
101
101
|
newTags.forEach(async (tag) => {
|
|
102
|
-
let tags = await this.addNewTag(
|
|
102
|
+
let tags = await this.addNewTag(tag)
|
|
103
103
|
if(!tags){
|
|
104
104
|
callback();
|
|
105
105
|
return;
|
|
@@ -108,7 +108,7 @@ class DirAddTags {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
if (this.log) { console.log('(DirAddTags) UPDATE request with newTags', newTags) }
|
|
111
|
-
let updatedRequest = await this.updateRequestWithTags(
|
|
111
|
+
let updatedRequest = await this.updateRequestWithTags(newTags)
|
|
112
112
|
if(!updatedRequest){
|
|
113
113
|
callback();
|
|
114
114
|
return;
|
|
@@ -130,7 +130,7 @@ class DirAddTags {
|
|
|
130
130
|
|
|
131
131
|
if(action.pushToList){
|
|
132
132
|
newTags.forEach(async (tag) => {
|
|
133
|
-
let tags = await this.addNewTag(
|
|
133
|
+
let tags = await this.addNewTag(tag)
|
|
134
134
|
if(!tags){
|
|
135
135
|
callback();
|
|
136
136
|
return;
|
|
@@ -139,7 +139,7 @@ class DirAddTags {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
if (this.log) { console.log('(DirAddTags) UPDATE lead with newTags', newTags) }
|
|
142
|
-
let updatedLead = await this.updateLeadWithTags(
|
|
142
|
+
let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
|
|
143
143
|
if(!updatedLead){
|
|
144
144
|
callback();
|
|
145
145
|
return;
|
|
@@ -273,10 +273,10 @@ class DirAddTags {
|
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
async addNewTag(
|
|
276
|
+
async addNewTag(tag){
|
|
277
277
|
return new Promise((resolve, rejects)=> {
|
|
278
278
|
const HTTPREQUEST = {
|
|
279
|
-
url:
|
|
279
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/tags",
|
|
280
280
|
headers: {
|
|
281
281
|
'Content-Type': 'application/json',
|
|
282
282
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -305,7 +305,7 @@ class DirAddTags {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
|
|
308
|
-
async updateRequestWithTags(
|
|
308
|
+
async updateRequestWithTags(tags) {
|
|
309
309
|
return new Promise((resolve) => {
|
|
310
310
|
let json = []
|
|
311
311
|
let filteredTags = tags.map((tag) => ({tag: tag, color: '#f0806f'}))
|
|
@@ -314,7 +314,7 @@ class DirAddTags {
|
|
|
314
314
|
console.log('(httprequest) DirAddTags updateRequestWithTags tags--> ', json)
|
|
315
315
|
}
|
|
316
316
|
const HTTPREQUEST = {
|
|
317
|
-
url:
|
|
317
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + '/tag',
|
|
318
318
|
headers: {
|
|
319
319
|
'Content-Type': 'application/json',
|
|
320
320
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -340,10 +340,10 @@ class DirAddTags {
|
|
|
340
340
|
})
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
async updateLeadWithTags(
|
|
343
|
+
async updateLeadWithTags(lead_id, tags) {
|
|
344
344
|
return new Promise((resolve) => {
|
|
345
345
|
const HTTPREQUEST = {
|
|
346
|
-
url:
|
|
346
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/leads/" + lead_id + '/tag',
|
|
347
347
|
headers: {
|
|
348
348
|
'Content-Type': 'application/json',
|
|
349
349
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -15,6 +15,7 @@ class DirAskGPT {
|
|
|
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
|
|
|
@@ -88,17 +89,13 @@ class DirAskGPT {
|
|
|
88
89
|
const filler = new Filler();
|
|
89
90
|
const filled_question = filler.fill(action.question, requestVariables);
|
|
90
91
|
|
|
91
|
-
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
92
92
|
const kb_endpoint = process.env.KB_ENDPOINT;
|
|
93
|
-
if (this.log) {
|
|
94
|
-
console.log("DirAskGPT ApiEndpoint URL: ", server_base_url);
|
|
95
|
-
console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint);
|
|
96
|
-
}
|
|
93
|
+
if (this.log) { console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint); }
|
|
97
94
|
|
|
98
|
-
let key = await this.getKeyFromIntegrations(
|
|
95
|
+
let key = await this.getKeyFromIntegrations();
|
|
99
96
|
if (!key) {
|
|
100
97
|
if (this.log) { console.log("DirAskGPT - Key not found in Integrations. Searching in kb settings..."); }
|
|
101
|
-
key = await this.getKeyFromKbSettings(
|
|
98
|
+
key = await this.getKeyFromKbSettings();
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
if (!key) {
|
|
@@ -120,7 +117,7 @@ class DirAskGPT {
|
|
|
120
117
|
}
|
|
121
118
|
|
|
122
119
|
if (publicKey === true) {
|
|
123
|
-
let keep_going = await this.checkQuoteAvailability(
|
|
120
|
+
let keep_going = await this.checkQuoteAvailability();
|
|
124
121
|
if (keep_going === false) {
|
|
125
122
|
if (this.log) { console.log("DirAskGPT - Quota exceeded for tokens. Skip the action")}
|
|
126
123
|
callback();
|
|
@@ -167,7 +164,7 @@ class DirAskGPT {
|
|
|
167
164
|
|
|
168
165
|
// if (publicKey === true) {
|
|
169
166
|
// let token_usage = resbody.usage.total_tokens;
|
|
170
|
-
// this.updateQuote(
|
|
167
|
+
// this.updateQuote(token_usage);
|
|
171
168
|
// }
|
|
172
169
|
|
|
173
170
|
if (trueIntent) {
|
|
@@ -305,11 +302,11 @@ class DirAskGPT {
|
|
|
305
302
|
});
|
|
306
303
|
}
|
|
307
304
|
|
|
308
|
-
async getKeyFromIntegrations(
|
|
305
|
+
async getKeyFromIntegrations() {
|
|
309
306
|
return new Promise((resolve) => {
|
|
310
307
|
|
|
311
308
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
312
|
-
url:
|
|
309
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
313
310
|
headers: {
|
|
314
311
|
'Content-Type': 'application/json',
|
|
315
312
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -337,11 +334,11 @@ class DirAskGPT {
|
|
|
337
334
|
})
|
|
338
335
|
}
|
|
339
336
|
|
|
340
|
-
async getKeyFromKbSettings(
|
|
337
|
+
async getKeyFromKbSettings() {
|
|
341
338
|
return new Promise((resolve) => {
|
|
342
339
|
|
|
343
340
|
const KB_HTTPREQUEST = {
|
|
344
|
-
url:
|
|
341
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
|
|
345
342
|
headers: {
|
|
346
343
|
'Content-Type': 'application/json',
|
|
347
344
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -19,6 +19,7 @@ class DirAskGPTV2 {
|
|
|
19
19
|
this.tdcache = this.context.tdcache;
|
|
20
20
|
this.requestId = this.context.requestId;
|
|
21
21
|
this.intentDir = new DirIntent(context);
|
|
22
|
+
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
22
23
|
this.log = context.log;
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -136,18 +137,13 @@ class DirAskGPTV2 {
|
|
|
136
137
|
if (this.log) { console.log("DirAskGPT transcript ", transcript) }
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
140
140
|
const kb_endpoint = process.env.KB_ENDPOINT_QA
|
|
141
|
-
|
|
142
|
-
if (this.log) {
|
|
143
|
-
console.log("DirAskGPT ApiEndpoint URL: ", server_base_url);
|
|
144
|
-
console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint);
|
|
145
|
-
}
|
|
141
|
+
if (this.log) { console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint); }
|
|
146
142
|
|
|
147
|
-
let key = await this.getKeyFromIntegrations(
|
|
143
|
+
let key = await this.getKeyFromIntegrations();
|
|
148
144
|
if (!key) {
|
|
149
145
|
if (this.log) { console.log("DirAskGPT - Key not found in Integrations. Searching in kb settings..."); }
|
|
150
|
-
key = await this.getKeyFromKbSettings(
|
|
146
|
+
key = await this.getKeyFromKbSettings();
|
|
151
147
|
}
|
|
152
148
|
|
|
153
149
|
if (!key) {
|
|
@@ -169,7 +165,7 @@ class DirAskGPTV2 {
|
|
|
169
165
|
}
|
|
170
166
|
|
|
171
167
|
if (publicKey === true) {
|
|
172
|
-
let keep_going = await this.checkQuoteAvailability(
|
|
168
|
+
let keep_going = await this.checkQuoteAvailability();
|
|
173
169
|
if (keep_going === false) {
|
|
174
170
|
if (this.log) { console.log("DirAskGPT - Quota exceeded for tokens. Skip the action")}
|
|
175
171
|
await this.chatbot.addParameter("flowError", "AskGPT Error: tokens quota exceeded");
|
|
@@ -183,12 +179,11 @@ class DirAskGPTV2 {
|
|
|
183
179
|
if (action.namespaceAsName) {
|
|
184
180
|
// Namespace could be an attribute
|
|
185
181
|
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
186
|
-
|
|
187
|
-
ns = await this.getNamespace(server_base_url, filled_namespace, null);
|
|
182
|
+
ns = await this.getNamespace(filled_namespace, null);
|
|
188
183
|
namespace = ns.id;
|
|
189
184
|
if (this.log) { console.log("DirAskGPT - Retrieved namespace id from name ", namespace); }
|
|
190
185
|
} else {
|
|
191
|
-
ns = await this.getNamespace(
|
|
186
|
+
ns = await this.getNamespace(null, namespace);
|
|
192
187
|
}
|
|
193
188
|
|
|
194
189
|
if (ns.engine) {
|
|
@@ -242,7 +237,6 @@ class DirAskGPTV2 {
|
|
|
242
237
|
if (this.log) { console.log("DirAskGPT json:", json); }
|
|
243
238
|
|
|
244
239
|
const HTTPREQUEST = {
|
|
245
|
-
// url: server_base_url + "/" + this.context.projectId + "/kb/qa",
|
|
246
240
|
url: kb_endpoint + "/qa",
|
|
247
241
|
headers: {
|
|
248
242
|
'Content-Type': 'application/json',
|
|
@@ -284,7 +278,7 @@ class DirAskGPTV2 {
|
|
|
284
278
|
tokens: resbody.prompt_token_size,
|
|
285
279
|
model: json.model
|
|
286
280
|
}
|
|
287
|
-
this.updateQuote(
|
|
281
|
+
this.updateQuote(tokens_usage);
|
|
288
282
|
}
|
|
289
283
|
|
|
290
284
|
if (trueIntent) {
|
|
@@ -420,11 +414,11 @@ class DirAskGPTV2 {
|
|
|
420
414
|
});
|
|
421
415
|
}
|
|
422
416
|
|
|
423
|
-
async getKeyFromIntegrations(
|
|
417
|
+
async getKeyFromIntegrations() {
|
|
424
418
|
return new Promise((resolve) => {
|
|
425
419
|
|
|
426
420
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
427
|
-
url:
|
|
421
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
428
422
|
headers: {
|
|
429
423
|
'Content-Type': 'application/json',
|
|
430
424
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -452,11 +446,11 @@ class DirAskGPTV2 {
|
|
|
452
446
|
})
|
|
453
447
|
}
|
|
454
448
|
|
|
455
|
-
async getKeyFromKbSettings(
|
|
449
|
+
async getKeyFromKbSettings() {
|
|
456
450
|
return new Promise((resolve) => {
|
|
457
451
|
|
|
458
452
|
const KB_HTTPREQUEST = {
|
|
459
|
-
url:
|
|
453
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
|
|
460
454
|
headers: {
|
|
461
455
|
'Content-Type': 'application/json',
|
|
462
456
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -482,11 +476,11 @@ class DirAskGPTV2 {
|
|
|
482
476
|
})
|
|
483
477
|
}
|
|
484
478
|
|
|
485
|
-
async checkQuoteAvailability(
|
|
479
|
+
async checkQuoteAvailability() {
|
|
486
480
|
return new Promise((resolve) => {
|
|
487
481
|
|
|
488
482
|
const HTTPREQUEST = {
|
|
489
|
-
url:
|
|
483
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
|
|
490
484
|
headers: {
|
|
491
485
|
'Content-Type': 'application/json',
|
|
492
486
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -512,11 +506,11 @@ class DirAskGPTV2 {
|
|
|
512
506
|
})
|
|
513
507
|
}
|
|
514
508
|
|
|
515
|
-
async updateQuote(
|
|
509
|
+
async updateQuote(tokens_usage) {
|
|
516
510
|
return new Promise((resolve) => {
|
|
517
511
|
|
|
518
512
|
const HTTPREQUEST = {
|
|
519
|
-
url:
|
|
513
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
|
|
520
514
|
headers: {
|
|
521
515
|
'Content-Type': 'application/json',
|
|
522
516
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -588,10 +582,10 @@ class DirAskGPTV2 {
|
|
|
588
582
|
return objectTranscript;
|
|
589
583
|
}
|
|
590
584
|
|
|
591
|
-
async getNamespace(
|
|
585
|
+
async getNamespace(name, id) {
|
|
592
586
|
return new Promise((resolve) => {
|
|
593
587
|
const HTTPREQUEST = {
|
|
594
|
-
url:
|
|
588
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kb/namespace/all",
|
|
595
589
|
headers: {
|
|
596
590
|
'Content-Type': 'application/json',
|
|
597
591
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -633,39 +627,6 @@ class DirAskGPTV2 {
|
|
|
633
627
|
})
|
|
634
628
|
}
|
|
635
629
|
|
|
636
|
-
// async getNamespaceIdFromName(server_base_url, name) {
|
|
637
|
-
// return new Promise((resolve) => {
|
|
638
|
-
|
|
639
|
-
// const HTTPREQUEST = {
|
|
640
|
-
// url: server_base_url + "/" + this.context.projectId + "/kb/namespace/all",
|
|
641
|
-
// headers: {
|
|
642
|
-
// 'Content-Type': 'application/json',
|
|
643
|
-
// 'Authorization': 'JWT ' + this.context.token
|
|
644
|
-
// },
|
|
645
|
-
// method: "GET"
|
|
646
|
-
// }
|
|
647
|
-
// if (this.log) { console.log("DirAskGPT get all namespaces HTTPREQUEST", HTTPREQUEST); }
|
|
648
|
-
|
|
649
|
-
// this.#myrequest(
|
|
650
|
-
// HTTPREQUEST, async (err, namespaces) => {
|
|
651
|
-
// if (err) {
|
|
652
|
-
// console.error("(httprequest) DirAskGPT get all namespaces err: ", err);
|
|
653
|
-
// resolve(null)
|
|
654
|
-
// } else {
|
|
655
|
-
// if (this.log) { console.log("(httprequest) DirAskGPT get all namespaces resbody: ", namespaces); }
|
|
656
|
-
|
|
657
|
-
// let namespace = namespaces.find(n => n.name === name);
|
|
658
|
-
// let namespace_id = namespace.id;
|
|
659
|
-
|
|
660
|
-
// resolve(namespace_id);
|
|
661
|
-
// }
|
|
662
|
-
// }
|
|
663
|
-
// )
|
|
664
|
-
// })
|
|
665
|
-
|
|
666
|
-
// }
|
|
667
|
-
|
|
668
|
-
|
|
669
630
|
}
|
|
670
631
|
|
|
671
632
|
module.exports = { DirAskGPTV2 }
|
|
@@ -10,17 +10,6 @@ class DirAssign {
|
|
|
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
13
|
this.log = context.log;
|
|
25
14
|
}
|
|
26
15
|
|
|
@@ -9,27 +9,17 @@ 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
|
-
// });
|
|
31
12
|
this.log = context.log;
|
|
32
13
|
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
|
+
});
|
|
33
23
|
}
|
|
34
24
|
|
|
35
25
|
async execute(directive, callback) {
|
|
@@ -77,7 +67,7 @@ class DirAssignFromFunction {
|
|
|
77
67
|
async invoke(functionName, callback) {
|
|
78
68
|
switch (functionName) {
|
|
79
69
|
case "openNow":
|
|
80
|
-
this.
|
|
70
|
+
this.tdClient.openNow((err, result) => {
|
|
81
71
|
if (this.log) {console.log("openNow():", result);}
|
|
82
72
|
if (err) {
|
|
83
73
|
callback(err);
|
|
@@ -91,7 +81,7 @@ class DirAssignFromFunction {
|
|
|
91
81
|
});
|
|
92
82
|
break;
|
|
93
83
|
case "availableAgents":
|
|
94
|
-
this.
|
|
84
|
+
this.tdClient.getProjectAvailableAgents((err, agents) => {
|
|
95
85
|
if (this.log) {console.log("Agents on 'open'", agents);}
|
|
96
86
|
if (err || !agents) {
|
|
97
87
|
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;
|
|
14
13
|
this.tdcache = context.tdcache;
|
|
15
14
|
this.requestId = context.requestId;
|
|
16
15
|
this.intentDir = new DirIntent(context);
|
|
16
|
+
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
17
17
|
this.log = context.log;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -264,8 +264,7 @@ class DirAssistant {
|
|
|
264
264
|
return process.env.TEST_OPENAI_APIKEY
|
|
265
265
|
}
|
|
266
266
|
else {
|
|
267
|
-
|
|
268
|
-
return await this.getKeyFromIntegrations(server_base_url);
|
|
267
|
+
return await this.getKeyFromIntegrations();
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
270
|
|
|
@@ -496,11 +495,11 @@ class DirAssistant {
|
|
|
496
495
|
});
|
|
497
496
|
}
|
|
498
497
|
|
|
499
|
-
async getKeyFromIntegrations(
|
|
498
|
+
async getKeyFromIntegrations() {
|
|
500
499
|
return new Promise((resolve) => {
|
|
501
500
|
|
|
502
501
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
503
|
-
url:
|
|
502
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
504
503
|
headers: {
|
|
505
504
|
'Content-Type': 'application/json',
|
|
506
505
|
'Authorization': 'JWT ' + this.context.token
|