@tiledesk/tiledesk-tybot-connector 0.2.131-rc1 → 0.2.131-rc2
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/DirAssistant.js +4 -4
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +5 -8
- 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/DirIfOpenHours.js +2 -29
- package/tiledeskChatbotPlugs/directives/DirQapla.js +5 -8
- 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 }
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -12,32 +12,8 @@ class DirIfOpenHours {
|
|
|
12
12
|
}
|
|
13
13
|
this.tdclient = context.tdclient;
|
|
14
14
|
this.context = context;
|
|
15
|
-
|
|
16
|
-
// projectId: context.projectId,
|
|
17
|
-
// token: context.token,
|
|
18
|
-
// APIURL: context.TILEDESK_APIURL,
|
|
19
|
-
// APIKEY: "___",
|
|
20
|
-
// log: context.log
|
|
21
|
-
// });
|
|
22
|
-
// let context = {
|
|
23
|
-
// projectId: projectId,
|
|
24
|
-
// token: token,
|
|
25
|
-
// requestId: supportRequest,
|
|
26
|
-
// APIURL: API_URL,
|
|
27
|
-
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
28
|
-
// departmentId: depId,
|
|
29
|
-
// log: false
|
|
30
|
-
// }
|
|
15
|
+
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
31
16
|
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
|
-
//this.log = context.log;
|
|
41
17
|
}
|
|
42
18
|
|
|
43
19
|
execute(directive, callback) {
|
|
@@ -95,10 +71,7 @@ class DirIfOpenHours {
|
|
|
95
71
|
slot_id = action.slotId;
|
|
96
72
|
}
|
|
97
73
|
|
|
98
|
-
|
|
99
|
-
if (this.log) { console.log("DirAskGPT ApiEndpoint URL: ", server_base_url); }
|
|
100
|
-
|
|
101
|
-
let isopen_url = server_base_url + "/projects/" + this.context.projectId + "/isopen";
|
|
74
|
+
let isopen_url = this.API_ENDPOINT + "/projects/" + this.context.projectId + "/isopen";
|
|
102
75
|
if (slot_id) {
|
|
103
76
|
isopen_url = isopen_url.concat("?timeSlot=" + slot_id);
|
|
104
77
|
}
|
|
@@ -15,6 +15,7 @@ class DirQapla {
|
|
|
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
|
|
|
@@ -82,18 +83,14 @@ class DirQapla {
|
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
86
86
|
const qapla_base_url = process.env.QAPLA_ENDPOINT || "https://api.qapla.it/1.2"
|
|
87
|
-
if (this.log) {
|
|
88
|
-
console.log("DirQapla server_base_url: ", qapla_base_url);
|
|
89
|
-
console.log("DirQapla qapla_base_url: ", qapla_base_url);
|
|
90
|
-
}
|
|
87
|
+
if (this.log) { console.log("DirQapla qapla_base_url: ", qapla_base_url); }
|
|
91
88
|
|
|
92
89
|
let key = action.apiKey;
|
|
93
90
|
|
|
94
91
|
if (!key) {
|
|
95
92
|
if (this.log) { console.log("DirQapla - Key not found into action. Searching in integrations..."); }
|
|
96
|
-
key = await this.getKeyFromIntegrations(
|
|
93
|
+
key = await this.getKeyFromIntegrations();
|
|
97
94
|
}
|
|
98
95
|
|
|
99
96
|
if (!key) {
|
|
@@ -288,11 +285,11 @@ class DirQapla {
|
|
|
288
285
|
});
|
|
289
286
|
}
|
|
290
287
|
|
|
291
|
-
async getKeyFromIntegrations(
|
|
288
|
+
async getKeyFromIntegrations() {
|
|
292
289
|
return new Promise((resolve) => {
|
|
293
290
|
|
|
294
291
|
const INTEGRATIONS_HTTPREQUEST = {
|
|
295
|
-
url:
|
|
292
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/qapla",
|
|
296
293
|
headers: {
|
|
297
294
|
'Content-Type': 'application/json',
|
|
298
295
|
'Authorization': 'JWT ' + this.context.token
|
|
@@ -16,6 +16,7 @@ class DirSendWhatsapp {
|
|
|
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
|
|
|
@@ -73,12 +74,11 @@ class DirSendWhatsapp {
|
|
|
73
74
|
payload.broadcast = false;
|
|
74
75
|
|
|
75
76
|
const whatsapp_api_url_pre = process.env.WHATSAPP_ENDPOINT;
|
|
76
|
-
const server_base_url = process.env.API_URL || process.env.API_ENDPOINT;
|
|
77
77
|
|
|
78
78
|
if (whatsapp_api_url_pre) {
|
|
79
79
|
whatsapp_api_url = whatsapp_api_url_pre;
|
|
80
80
|
} else {
|
|
81
|
-
whatsapp_api_url =
|
|
81
|
+
whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
|
|
82
82
|
}
|
|
83
83
|
if (this.log) { console.log("DirSendWhatsapp whatsapp_api_url: ", whatsapp_api_url); };
|
|
84
84
|
|
|
@@ -10,6 +10,7 @@ class DirWhatsappByAttribute {
|
|
|
10
10
|
throw new Error('context object is mandatory');
|
|
11
11
|
}
|
|
12
12
|
this.context = context;
|
|
13
|
+
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
13
14
|
this.log = context.log;
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -35,15 +36,12 @@ class DirWhatsappByAttribute {
|
|
|
35
36
|
console.log("whatsapp by attributes action: ", JSON.stringify(action))
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
///////////
|
|
39
|
-
|
|
40
39
|
const whatsapp_api_url_pre = process.env.WHATSAPP_ENDPOINT;
|
|
41
|
-
const server_base_url = process.env.API_URL || process.env.API_ENDPOINT;
|
|
42
40
|
|
|
43
41
|
if (whatsapp_api_url_pre) {
|
|
44
42
|
whatsapp_api_url = whatsapp_api_url_pre;
|
|
45
43
|
} else {
|
|
46
|
-
whatsapp_api_url =
|
|
44
|
+
whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
|
|
47
45
|
}
|
|
48
46
|
console.log("DirWhatsappByAttribute whatsapp_api_url: ", whatsapp_api_url);
|
|
49
47
|
|
|
@@ -94,62 +92,6 @@ class DirWhatsappByAttribute {
|
|
|
94
92
|
}, true);
|
|
95
93
|
})
|
|
96
94
|
|
|
97
|
-
|
|
98
|
-
// if (process.env.API_URL) {
|
|
99
|
-
// whatsapp_api_url = "https://tiledesk-whatsapp-connector.giovannitroisi3.repl.co/api";
|
|
100
|
-
// // whatsapp_api_url = process.env.API_URL + "/modules/whatsapp";
|
|
101
|
-
// console.log("(Tilebot) DirWhatsappByAttribute whatsapp_api_url: ", whatsapp_api_url);
|
|
102
|
-
// } else {
|
|
103
|
-
// console.error("(Tilebot) ERROR Missing whatsapp_api_url. Unable to use action WhatsApp By Attributes");
|
|
104
|
-
// callback();
|
|
105
|
-
// return;
|
|
106
|
-
// }
|
|
107
|
-
// if (action.attributeName) {
|
|
108
|
-
// if (this.log) { console.log("whatsapp attributeName:", action.attributeName); }
|
|
109
|
-
// let attribute_value = null;
|
|
110
|
-
// if (this.context.tdcache) {
|
|
111
|
-
|
|
112
|
-
// const attribute_value = await TiledeskChatbot.getParameterStatic(this.context.tdcache, this.context.requestId, action.attributeName)
|
|
113
|
-
// if (this.log) { console.log("attribute_value:", JSON.stringify(attribute_value)); }
|
|
114
|
-
|
|
115
|
-
// if (attribute_value == null) {
|
|
116
|
-
// console.error("(Tilebot) attribute_value is undefined");
|
|
117
|
-
// callback();
|
|
118
|
-
// return;
|
|
119
|
-
// }
|
|
120
|
-
|
|
121
|
-
// const URL = whatsapp_api_url + '/tiledesk/broadcast';
|
|
122
|
-
// const HTTPREQUEST = {
|
|
123
|
-
// url: URL,
|
|
124
|
-
// headers: {
|
|
125
|
-
// 'Content-Type': 'application/json',
|
|
126
|
-
|
|
127
|
-
// },
|
|
128
|
-
// json: attribute_value,
|
|
129
|
-
// method: 'POST'
|
|
130
|
-
// };
|
|
131
|
-
// let promise = new Promise((resolve, reject) => {
|
|
132
|
-
// DirWhatsappByAttribute.myrequest(
|
|
133
|
-
// HTTPREQUEST,
|
|
134
|
-
// function (err, resbody) {
|
|
135
|
-
// if (err) {
|
|
136
|
-
// if (callback) {
|
|
137
|
-
// callback(err);
|
|
138
|
-
// }
|
|
139
|
-
// reject(err);
|
|
140
|
-
// }
|
|
141
|
-
// else {
|
|
142
|
-
// if (callback) {
|
|
143
|
-
// callback(null, resbody);
|
|
144
|
-
// }
|
|
145
|
-
// console.log("(tybot) broadcast sent: ", resbody);
|
|
146
|
-
// resolve(resbody);
|
|
147
|
-
// }
|
|
148
|
-
// }, true);
|
|
149
|
-
// })
|
|
150
|
-
// return promise;
|
|
151
|
-
// }
|
|
152
|
-
// }
|
|
153
95
|
}
|
|
154
96
|
|
|
155
97
|
// HTTP REQUEST
|