@tiledesk/tiledesk-tybot-connector 0.2.131-rc1 → 0.2.131-rc3
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 +3 -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 +11 -17
- 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 +0 -18
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -26
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +1 -13
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +5 -8
- 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 +0 -24
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -29
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +0 -24
- 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/DirQapla.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -20
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +2 -60
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,9 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
+
# v0.2.131-rc2
|
|
21
|
+
- changed API_URL with API_ENDPOINT
|
|
22
|
+
|
|
20
23
|
# v0.2.131-rc1
|
|
21
24
|
- added: AUDIO_RECORD vxml action as reply_v2 actionType
|
|
22
25
|
- 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);
|
|
@@ -517,10 +517,13 @@ class TiledeskChatbotUtil {
|
|
|
517
517
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
|
|
518
518
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
519
519
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
520
|
+
/**
|
|
521
|
+
* RefactoringCheck: can this be deleted?
|
|
522
|
+
*/
|
|
523
|
+
// if (process.env.TILEDESK_API) {
|
|
524
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
|
|
525
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
526
|
+
// }
|
|
524
527
|
|
|
525
528
|
if (process.env.API_URL) {
|
|
526
529
|
await chatbot.addParameter(TiledeskChatbotConst.API_BASE_URL, process.env.API_URL);
|
package/package.json
CHANGED
|
@@ -65,7 +65,7 @@ class DirectivesChatbotPlug {
|
|
|
65
65
|
|
|
66
66
|
constructor(config) {
|
|
67
67
|
this.supportRequest = config.supportRequest;
|
|
68
|
-
this.
|
|
68
|
+
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
69
69
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
70
70
|
this.token = config.token;
|
|
71
71
|
this.log = config.log;
|
|
@@ -125,7 +125,7 @@ class DirectivesChatbotPlug {
|
|
|
125
125
|
// console.log("supportRequest is:", JSON.stringify(supportRequest))
|
|
126
126
|
|
|
127
127
|
const token = this.token;
|
|
128
|
-
const
|
|
128
|
+
const API_ENDPOINT = this.API_ENDPOINT;
|
|
129
129
|
const TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
130
130
|
|
|
131
131
|
// const requestId = supportRequest.request_id
|
|
@@ -142,7 +142,7 @@ class DirectivesChatbotPlug {
|
|
|
142
142
|
tdclient = new TiledeskClient({
|
|
143
143
|
projectId: projectId,
|
|
144
144
|
token: token,
|
|
145
|
-
APIURL:
|
|
145
|
+
APIURL: API_ENDPOINT,
|
|
146
146
|
APIKEY: "___",
|
|
147
147
|
log: this.log
|
|
148
148
|
});
|
|
@@ -159,7 +159,7 @@ class DirectivesChatbotPlug {
|
|
|
159
159
|
supportRequest: supportRequest,
|
|
160
160
|
reply: this.reply,
|
|
161
161
|
requestId: supportRequest.request_id,
|
|
162
|
-
|
|
162
|
+
API_ENDPOINT: API_ENDPOINT,
|
|
163
163
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
164
164
|
departmentId: depId,
|
|
165
165
|
tdcache: tdcache,
|
|
@@ -720,14 +720,12 @@ class DirectivesChatbotPlug {
|
|
|
720
720
|
});
|
|
721
721
|
}
|
|
722
722
|
else if (directive_name === Directives.CLEAR_TRANSCRIPT) {
|
|
723
|
-
console.log("...CLEAR_TRANSCRIPT");
|
|
724
723
|
new DirClearTranscript(context).execute(directive, async () => {
|
|
725
724
|
let next_dir = await this.nextDirective(this.directives);
|
|
726
725
|
this.process(next_dir);
|
|
727
726
|
});
|
|
728
727
|
}
|
|
729
728
|
else if (directive_name === Directives.MOVE_TO_UNASSIGNED) {
|
|
730
|
-
console.log("...MOVE_TO_UNASSIGNED");
|
|
731
729
|
new DirMoveToUnassigned(context).execute(directive, async () => {
|
|
732
730
|
let next_dir = await this.nextDirective(this.directives);
|
|
733
731
|
this.process(next_dir);
|
|
@@ -770,7 +768,7 @@ class DirectivesChatbotPlug {
|
|
|
770
768
|
}
|
|
771
769
|
const supportRequest = this.supportRequest;
|
|
772
770
|
const token = this.token;
|
|
773
|
-
const
|
|
771
|
+
const API_ENDPOINT = this.API_ENDPOINT;
|
|
774
772
|
// const requestId = supportRequest.request_id
|
|
775
773
|
// let depId;
|
|
776
774
|
// if (supportRequest.department && supportRequest.department._id) {
|
|
@@ -780,7 +778,7 @@ class DirectivesChatbotPlug {
|
|
|
780
778
|
const tdclient = new TiledeskClient({
|
|
781
779
|
projectId: projectId,
|
|
782
780
|
token: token,
|
|
783
|
-
APIURL:
|
|
781
|
+
APIURL: API_ENDPOINT,
|
|
784
782
|
APIKEY: "___",
|
|
785
783
|
log: false
|
|
786
784
|
});
|
|
@@ -21,6 +21,7 @@ class DirAddTags {
|
|
|
21
21
|
this.tdcache = this.context.tdcache;
|
|
22
22
|
this.requestId = this.context.requestId;
|
|
23
23
|
this.tdClient = this.context.tdclient;
|
|
24
|
+
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
24
25
|
// this.intentDir = new DirIntent(context);
|
|
25
26
|
this.log = context.log;
|
|
26
27
|
// this.log = true;
|
|
@@ -77,12 +78,6 @@ class DirAddTags {
|
|
|
77
78
|
console.log("(DirAddTags) tags: ", filled_tags);
|
|
78
79
|
}
|
|
79
80
|
|
|
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
81
|
// let request = await this.tdClient.getRequestById(this.requestId);
|
|
87
82
|
// if (this.log) { console.log('(DirAddTags) request detail: ', request) }
|
|
88
83
|
// if(!request){
|
|
@@ -91,7 +86,6 @@ class DirAddTags {
|
|
|
91
86
|
// return;
|
|
92
87
|
// }
|
|
93
88
|
|
|
94
|
-
|
|
95
89
|
/** use case: CONVERSATION */
|
|
96
90
|
if(target === 'request'){
|
|
97
91
|
|
|
@@ -99,7 +93,7 @@ class DirAddTags {
|
|
|
99
93
|
|
|
100
94
|
if(action.pushToList){
|
|
101
95
|
newTags.forEach(async (tag) => {
|
|
102
|
-
let tags = await this.addNewTag(
|
|
96
|
+
let tags = await this.addNewTag(tag)
|
|
103
97
|
if(!tags){
|
|
104
98
|
callback();
|
|
105
99
|
return;
|
|
@@ -108,7 +102,7 @@ class DirAddTags {
|
|
|
108
102
|
}
|
|
109
103
|
|
|
110
104
|
if (this.log) { console.log('(DirAddTags) UPDATE request with newTags', newTags) }
|
|
111
|
-
let updatedRequest = await this.updateRequestWithTags(
|
|
105
|
+
let updatedRequest = await this.updateRequestWithTags(newTags)
|
|
112
106
|
if(!updatedRequest){
|
|
113
107
|
callback();
|
|
114
108
|
return;
|
|
@@ -130,7 +124,7 @@ class DirAddTags {
|
|
|
130
124
|
|
|
131
125
|
if(action.pushToList){
|
|
132
126
|
newTags.forEach(async (tag) => {
|
|
133
|
-
let tags = await this.addNewTag(
|
|
127
|
+
let tags = await this.addNewTag(tag)
|
|
134
128
|
if(!tags){
|
|
135
129
|
callback();
|
|
136
130
|
return;
|
|
@@ -139,7 +133,7 @@ class DirAddTags {
|
|
|
139
133
|
}
|
|
140
134
|
|
|
141
135
|
if (this.log) { console.log('(DirAddTags) UPDATE lead with newTags', newTags) }
|
|
142
|
-
let updatedLead = await this.updateLeadWithTags(
|
|
136
|
+
let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
|
|
143
137
|
if(!updatedLead){
|
|
144
138
|
callback();
|
|
145
139
|
return;
|
|
@@ -273,10 +267,10 @@ class DirAddTags {
|
|
|
273
267
|
});
|
|
274
268
|
}
|
|
275
269
|
|
|
276
|
-
async addNewTag(
|
|
270
|
+
async addNewTag(tag){
|
|
277
271
|
return new Promise((resolve, rejects)=> {
|
|
278
272
|
const HTTPREQUEST = {
|
|
279
|
-
url:
|
|
273
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/tags",
|
|
280
274
|
headers: {
|
|
281
275
|
'Content-Type': 'application/json',
|
|
282
276
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -305,7 +299,7 @@ class DirAddTags {
|
|
|
305
299
|
}
|
|
306
300
|
|
|
307
301
|
|
|
308
|
-
async updateRequestWithTags(
|
|
302
|
+
async updateRequestWithTags(tags) {
|
|
309
303
|
return new Promise((resolve) => {
|
|
310
304
|
let json = []
|
|
311
305
|
let filteredTags = tags.map((tag) => ({tag: tag, color: '#f0806f'}))
|
|
@@ -314,7 +308,7 @@ class DirAddTags {
|
|
|
314
308
|
console.log('(httprequest) DirAddTags updateRequestWithTags tags--> ', json)
|
|
315
309
|
}
|
|
316
310
|
const HTTPREQUEST = {
|
|
317
|
-
url:
|
|
311
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + '/tag',
|
|
318
312
|
headers: {
|
|
319
313
|
'Content-Type': 'application/json',
|
|
320
314
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -340,10 +334,10 @@ class DirAddTags {
|
|
|
340
334
|
})
|
|
341
335
|
}
|
|
342
336
|
|
|
343
|
-
async updateLeadWithTags(
|
|
337
|
+
async updateLeadWithTags(lead_id, tags) {
|
|
344
338
|
return new Promise((resolve) => {
|
|
345
339
|
const HTTPREQUEST = {
|
|
346
|
-
url:
|
|
340
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/leads/" + lead_id + '/tag',
|
|
347
341
|
headers: {
|
|
348
342
|
'Content-Type': 'application/json',
|
|
349
343
|
'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,25 +9,7 @@ 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
12
|
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
13
|
this.log = context.log;
|
|
32
14
|
this.tdcache = context.tdcache;
|
|
33
15
|
}
|
|
@@ -14,6 +14,7 @@ class DirAssistant {
|
|
|
14
14
|
this.tdcache = context.tdcache;
|
|
15
15
|
this.requestId = context.requestId;
|
|
16
16
|
this.intentDir = new DirIntent(context);
|
|
17
|
+
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
17
18
|
this.log = context.log;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -264,8 +265,7 @@ class DirAssistant {
|
|
|
264
265
|
return process.env.TEST_OPENAI_APIKEY
|
|
265
266
|
}
|
|
266
267
|
else {
|
|
267
|
-
|
|
268
|
-
return await this.getKeyFromIntegrations(server_base_url);
|
|
268
|
+
return await this.getKeyFromIntegrations();
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
@@ -496,11 +496,11 @@ class DirAssistant {
|
|
|
496
496
|
});
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
async getKeyFromIntegrations(
|
|
499
|
+
async getKeyFromIntegrations() {
|
|
500
500
|
return new Promise((resolve) => {
|
|
501
501
|
|
|
502
502
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
503
|
-
url:
|
|
503
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
|
|
504
504
|
headers: {
|
|
505
505
|
'Content-Type': 'application/json',
|
|
506
506
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -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
|