@tiledesk/tiledesk-tybot-connector 0.2.131-rc5 → 0.2.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +2 -4
  2. package/TdCache.js +1 -1
  3. package/index.js +12 -12
  4. package/models/TiledeskChatbot.js +2 -3
  5. package/models/TiledeskChatbotUtil.js +4 -8
  6. package/package.json +1 -1
  7. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +8 -6
  8. package/tiledeskChatbotPlugs/directives/DirAddTags.js +20 -20
  9. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +13 -10
  10. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +57 -18
  11. package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -0
  12. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +21 -11
  13. package/tiledeskChatbotPlugs/directives/DirAssistant.js +5 -4
  14. package/tiledeskChatbotPlugs/directives/DirBrevo.js +8 -5
  15. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +28 -1
  16. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -0
  17. package/tiledeskChatbotPlugs/directives/DirClose.js +2 -13
  18. package/tiledeskChatbotPlugs/directives/DirCondition.js +26 -0
  19. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +13 -1
  20. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -12
  21. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +8 -5
  22. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -11
  23. package/tiledeskChatbotPlugs/directives/DirDepartment.js +5 -14
  24. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +6 -17
  25. package/tiledeskChatbotPlugs/directives/DirForm.js +2 -12
  26. package/tiledeskChatbotPlugs/directives/DirGptTask.js +18 -14
  27. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +7 -4
  28. package/tiledeskChatbotPlugs/directives/DirHubspot.js +8 -5
  29. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +27 -14
  30. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +3 -13
  31. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +31 -5
  32. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +27 -13
  33. package/tiledeskChatbotPlugs/directives/DirIntent.js +23 -1
  34. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +26 -0
  35. package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -1
  36. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +13 -1
  37. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +2 -12
  38. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +2 -11
  39. package/tiledeskChatbotPlugs/directives/DirQapla.js +8 -5
  40. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -11
  41. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +7 -17
  42. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +2 -11
  43. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -12
  44. package/tiledeskChatbotPlugs/directives/DirReply.js +1 -11
  45. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +1 -11
  46. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +22 -12
  47. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +2 -2
  48. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +4 -13
  49. package/tiledeskChatbotPlugs/directives/DirWait.js +1 -0
  50. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -0
  51. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -0
  52. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +60 -2
  53. /package/tiledeskChatbotPlugs/directives/{DEPRECATED_DirOfflineHours.js → DirOfflineHours.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -17,12 +17,10 @@ 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
-
23
- # v0.2.131-rc1
20
+ # v0.2.131
24
21
  - added: AUDIO_RECORD vxml action as reply_v2 actionType
25
22
  - added: DirAddTags action
23
+ - externalized: process.env.CHATBOT_MAX_STEPS and process.env.CHATBOT_MAX_EXECUTION_TIME
26
24
 
27
25
  # v0.2.130
28
26
  - (TiledeskChatbotUtil) fix process.env.API_ENDPOINT => process.env.API_URL
package/TdCache.js CHANGED
@@ -28,7 +28,7 @@ class TdCache {
28
28
  // console.log('Redis Connected!');
29
29
  // });
30
30
  this.client.on('ready',function() {
31
- console.log("connected")
31
+ // console.log("connected")
32
32
  resolve();
33
33
  if (callback) {
34
34
  callback();
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 API_ENDPOINT = null;
33
+ let APIURL = 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: API_ENDPOINT,
163
+ APIURL: APIURL,
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
- API_ENDPOINT: API_ENDPOINT,
209
+ TILEDESK_API_ENDPOINT: APIURL,
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 = `${API_ENDPOINT}/modules/tilebot/`;
235
+ let extEndpoint = `${APIURL}/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: API_ENDPOINT,
267
+ APIURL: APIURL,
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 API_ENDPOINT....", API_ENDPOINT);
312
+ console.log("/ext APIURL....", APIURL);
313
313
  console.log("/ext process.env.TYBOT_ENDPOINT....", process.env.TYBOT_ENDPOINT);
314
314
  }
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});
315
+ let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, TILEDESK_API_ENDPOINT: APIURL, 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));}
@@ -332,7 +332,7 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
332
332
  tdclient.sendSupportMessage(requestId, bot_answer, (err, response) => {
333
333
  if (log) {console.log("/ext => bot_answer sent:", JSON.stringify(bot_answer));}
334
334
  if (err) {
335
- console.error("/ext => Error sending message", err);
335
+ console.error("/ext => Error sending message", JSON.stringify(err));
336
336
  }
337
337
  directivesPlug.processDirectives( () => {
338
338
  if (log) {console.log("After message - Directives executed.");}
@@ -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: API_ENDPOINT,
545
+ APIURL: APIURL,
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
- API_ENDPOINT = settings.API_ENDPOINT;
623
- console.log("(Tilebot) settings.API_ENDPOINT:", API_ENDPOINT);
622
+ APIURL = settings.API_ENDPOINT;
623
+ console.log("(Tilebot) settings.API_ENDPOINT:", APIURL);
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 = `${API_ENDPOINT}/modules/tilebot`
733
+ TILEBOT_ENDPOINT = `${APIURL}/modules/tilebot`
734
734
  }
735
735
  const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
736
736
  console.log("sendMessageToBot URL", url);
@@ -9,12 +9,11 @@ const { IntentForm } = require('./IntentForm.js');
9
9
  const { TiledeskChatbotUtil } = require('./TiledeskChatbotUtil.js');
10
10
  const { DirLockIntent } = require('../tiledeskChatbotPlugs/directives/DirLockIntent');
11
11
  const { DirUnlockIntent } = require('../tiledeskChatbotPlugs/directives/DirUnlockIntent');
12
- const { TiledeskChatbotConst } = require('./TiledeskChatbotConst.js');
13
12
 
14
13
  class TiledeskChatbot {
15
14
 
16
- static MAX_STEPS = 1000; // prod 1000;
17
- static MAX_EXECUTION_TIME = 1000 * 3600 * 8;// test // prod1000 * 3600 * 4; // 4 hours
15
+ static MAX_STEPS = process.env.CHATBOT_MAX_STEPS || 1000; // prod 1000;
16
+ static MAX_EXECUTION_TIME = process.env.CHATBOT_MAX_EXECUTION_TIME || 1000 * 3600 * 8;// test // prod1000 * 3600 * 4; // 4 hours
18
17
 
19
18
  constructor(config) {
20
19
  if (!config.botsDataSource) {
@@ -1,7 +1,6 @@
1
1
  const { TiledeskExpression } = require('../TiledeskExpression');
2
2
  const { Filler } = require('../tiledeskChatbotPlugs/Filler');
3
3
  const { TiledeskChatbotConst } = require('./TiledeskChatbotConst');
4
- const { TiledeskChatbot } = require('./TiledeskChatbot.js');
5
4
  let parser = require('accept-language-parser');
6
5
  const { Directives } = require('../tiledeskChatbotPlugs/directives/Directives.js');
7
6
  require('dotenv').config();
@@ -517,13 +516,10 @@ class TiledeskChatbotUtil {
517
516
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
518
517
  await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
519
518
  }
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
- // }
519
+ if (process.env.TILEDESK_API) {
520
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
521
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
522
+ }
527
523
 
528
524
  if (process.env.API_URL) {
529
525
  await chatbot.addParameter(TiledeskChatbotConst.API_BASE_URL, process.env.API_URL);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.131-rc5",
3
+ "version": "0.2.131",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,7 @@
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
4
5
  const { DirMoveToAgent } = require('./directives/DirMoveToAgent');
5
6
  const { DirMessage } = require('./directives/DirMessage');
6
7
  const { DirWait } = require('./directives/DirWait');
@@ -64,7 +65,7 @@ class DirectivesChatbotPlug {
64
65
 
65
66
  constructor(config) {
66
67
  this.supportRequest = config.supportRequest;
67
- this.API_ENDPOINT = config.API_ENDPOINT;
68
+ this.API_URL = config.TILEDESK_API_ENDPOINT;
68
69
  this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
69
70
  this.token = config.token;
70
71
  this.log = config.log;
@@ -124,7 +125,7 @@ class DirectivesChatbotPlug {
124
125
  // console.log("supportRequest is:", JSON.stringify(supportRequest))
125
126
 
126
127
  const token = this.token;
127
- const API_ENDPOINT = this.API_ENDPOINT;
128
+ const API_URL = this.API_URL;
128
129
  const TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
129
130
 
130
131
  // const requestId = supportRequest.request_id
@@ -141,7 +142,7 @@ class DirectivesChatbotPlug {
141
142
  tdclient = new TiledeskClient({
142
143
  projectId: projectId,
143
144
  token: token,
144
- APIURL: API_ENDPOINT,
145
+ APIURL: API_URL,
145
146
  APIKEY: "___",
146
147
  log: this.log
147
148
  });
@@ -158,10 +159,11 @@ class DirectivesChatbotPlug {
158
159
  supportRequest: supportRequest,
159
160
  reply: this.reply,
160
161
  requestId: supportRequest.request_id,
161
- API_ENDPOINT: API_ENDPOINT,
162
+ TILEDESK_APIURL: API_URL,
162
163
  TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
163
164
  departmentId: depId,
164
165
  tdcache: tdcache,
166
+ tdclient: tdclient,
165
167
  HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT,
166
168
  log: this.log
167
169
  }
@@ -766,7 +768,7 @@ class DirectivesChatbotPlug {
766
768
  }
767
769
  const supportRequest = this.supportRequest;
768
770
  const token = this.token;
769
- const API_ENDPOINT = this.API_ENDPOINT;
771
+ const API_URL = this.API_URL;
770
772
  // const requestId = supportRequest.request_id
771
773
  // let depId;
772
774
  // if (supportRequest.department && supportRequest.department._id) {
@@ -776,7 +778,7 @@ class DirectivesChatbotPlug {
776
778
  const tdclient = new TiledeskClient({
777
779
  projectId: projectId,
778
780
  token: token,
779
- APIURL: API_ENDPOINT,
781
+ APIURL: API_URL,
780
782
  APIKEY: "___",
781
783
  log: false
782
784
  });
@@ -8,7 +8,6 @@ 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");
12
11
  require('dotenv').config();
13
12
 
14
13
  class DirAddTags {
@@ -21,16 +20,10 @@ class DirAddTags {
21
20
  this.chatbot = this.context.chatbot;
22
21
  this.tdcache = this.context.tdcache;
23
22
  this.requestId = this.context.requestId;
24
- this.API_ENDPOINT = this.context.API_ENDPOINT;
23
+ this.tdClient = this.context.tdclient;
24
+ // this.intentDir = new DirIntent(context);
25
25
  this.log = context.log;
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
- });
26
+ // this.log = true;
34
27
  }
35
28
 
36
29
  execute(directive, callback) {
@@ -84,6 +77,12 @@ class DirAddTags {
84
77
  console.log("(DirAddTags) tags: ", filled_tags);
85
78
  }
86
79
 
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
+
87
86
  // let request = await this.tdClient.getRequestById(this.requestId);
88
87
  // if (this.log) { console.log('(DirAddTags) request detail: ', request) }
89
88
  // if(!request){
@@ -92,6 +91,7 @@ class DirAddTags {
92
91
  // return;
93
92
  // }
94
93
 
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(tag)
102
+ let tags = await this.addNewTag(server_base_url,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(newTags)
111
+ let updatedRequest = await this.updateRequestWithTags(server_base_url, 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(tag)
133
+ let tags = await this.addNewTag(server_base_url,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(request.lead._id, newTags)
142
+ let updatedLead = await this.updateLeadWithTags(server_base_url, 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(tag){
276
+ async addNewTag(server_base_url, tag){
277
277
  return new Promise((resolve, rejects)=> {
278
278
  const HTTPREQUEST = {
279
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/tags",
279
+ url: server_base_url + "/" + 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(tags) {
308
+ async updateRequestWithTags(server_base_url, 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: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + '/tag',
317
+ url: server_base_url + "/" + 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(lead_id, tags) {
343
+ async updateLeadWithTags(server_base_url, lead_id, tags) {
344
344
  return new Promise((resolve) => {
345
345
  const HTTPREQUEST = {
346
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/leads/" + lead_id + '/tag',
346
+ url: server_base_url + "/" + this.context.projectId + "/leads/" + lead_id + '/tag',
347
347
  headers: {
348
348
  'Content-Type': 'application/json',
349
349
  'Authorization': 'JWT ' + this.context.token
@@ -15,7 +15,6 @@ 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;
19
18
  this.log = context.log;
20
19
  }
21
20
 
@@ -89,13 +88,17 @@ class DirAskGPT {
89
88
  const filler = new Filler();
90
89
  const filled_question = filler.fill(action.question, requestVariables);
91
90
 
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) { console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint); }
93
+ if (this.log) {
94
+ console.log("DirAskGPT ApiEndpoint URL: ", server_base_url);
95
+ console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint);
96
+ }
94
97
 
95
- let key = await this.getKeyFromIntegrations();
98
+ let key = await this.getKeyFromIntegrations(server_base_url);
96
99
  if (!key) {
97
100
  if (this.log) { console.log("DirAskGPT - Key not found in Integrations. Searching in kb settings..."); }
98
- key = await this.getKeyFromKbSettings();
101
+ key = await this.getKeyFromKbSettings(server_base_url);
99
102
  }
100
103
 
101
104
  if (!key) {
@@ -117,7 +120,7 @@ class DirAskGPT {
117
120
  }
118
121
 
119
122
  if (publicKey === true) {
120
- let keep_going = await this.checkQuoteAvailability();
123
+ let keep_going = await this.checkQuoteAvailability(server_base_url);
121
124
  if (keep_going === false) {
122
125
  if (this.log) { console.log("DirAskGPT - Quota exceeded for tokens. Skip the action")}
123
126
  callback();
@@ -164,7 +167,7 @@ class DirAskGPT {
164
167
 
165
168
  // if (publicKey === true) {
166
169
  // let token_usage = resbody.usage.total_tokens;
167
- // this.updateQuote(token_usage);
170
+ // this.updateQuote(server_base_url, token_usage);
168
171
  // }
169
172
 
170
173
  if (trueIntent) {
@@ -302,11 +305,11 @@ class DirAskGPT {
302
305
  });
303
306
  }
304
307
 
305
- async getKeyFromIntegrations() {
308
+ async getKeyFromIntegrations(server_base_url) {
306
309
  return new Promise((resolve) => {
307
310
 
308
311
  const INTEGRATIONS_HTTPREQUEST = {
309
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
312
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
310
313
  headers: {
311
314
  'Content-Type': 'application/json',
312
315
  'Authorization': 'JWT ' + this.context.token
@@ -334,11 +337,11 @@ class DirAskGPT {
334
337
  })
335
338
  }
336
339
 
337
- async getKeyFromKbSettings() {
340
+ async getKeyFromKbSettings(server_base_url) {
338
341
  return new Promise((resolve) => {
339
342
 
340
343
  const KB_HTTPREQUEST = {
341
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
344
+ url: server_base_url + "/" + this.context.projectId + "/kbsettings",
342
345
  headers: {
343
346
  'Content-Type': 'application/json',
344
347
  'Authorization': 'JWT ' + this.context.token
@@ -19,7 +19,6 @@ 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;
23
22
  this.log = context.log;
24
23
  }
25
24
 
@@ -137,13 +136,18 @@ class DirAskGPTV2 {
137
136
  if (this.log) { console.log("DirAskGPT transcript ", transcript) }
138
137
  }
139
138
 
139
+ const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
140
140
  const kb_endpoint = process.env.KB_ENDPOINT_QA
141
- if (this.log) { console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint); }
141
+
142
+ if (this.log) {
143
+ console.log("DirAskGPT ApiEndpoint URL: ", server_base_url);
144
+ console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint);
145
+ }
142
146
 
143
- let key = await this.getKeyFromIntegrations();
147
+ let key = await this.getKeyFromIntegrations(server_base_url);
144
148
  if (!key) {
145
149
  if (this.log) { console.log("DirAskGPT - Key not found in Integrations. Searching in kb settings..."); }
146
- key = await this.getKeyFromKbSettings();
150
+ key = await this.getKeyFromKbSettings(server_base_url);
147
151
  }
148
152
 
149
153
  if (!key) {
@@ -165,7 +169,7 @@ class DirAskGPTV2 {
165
169
  }
166
170
 
167
171
  if (publicKey === true) {
168
- let keep_going = await this.checkQuoteAvailability();
172
+ let keep_going = await this.checkQuoteAvailability(server_base_url);
169
173
  if (keep_going === false) {
170
174
  if (this.log) { console.log("DirAskGPT - Quota exceeded for tokens. Skip the action")}
171
175
  await this.chatbot.addParameter("flowError", "AskGPT Error: tokens quota exceeded");
@@ -179,11 +183,12 @@ class DirAskGPTV2 {
179
183
  if (action.namespaceAsName) {
180
184
  // Namespace could be an attribute
181
185
  const filled_namespace = filler.fill(action.namespace, requestVariables)
182
- ns = await this.getNamespace(filled_namespace, null);
186
+ // namespace = await this.getNamespaceIdFromName(server_base_url, action.namespace)
187
+ ns = await this.getNamespace(server_base_url, filled_namespace, null);
183
188
  namespace = ns.id;
184
189
  if (this.log) { console.log("DirAskGPT - Retrieved namespace id from name ", namespace); }
185
190
  } else {
186
- ns = await this.getNamespace(null, namespace);
191
+ ns = await this.getNamespace(server_base_url, null, namespace);
187
192
  }
188
193
 
189
194
  if (ns.engine) {
@@ -237,6 +242,7 @@ class DirAskGPTV2 {
237
242
  if (this.log) { console.log("DirAskGPT json:", json); }
238
243
 
239
244
  const HTTPREQUEST = {
245
+ // url: server_base_url + "/" + this.context.projectId + "/kb/qa",
240
246
  url: kb_endpoint + "/qa",
241
247
  headers: {
242
248
  'Content-Type': 'application/json',
@@ -278,7 +284,7 @@ class DirAskGPTV2 {
278
284
  tokens: resbody.prompt_token_size,
279
285
  model: json.model
280
286
  }
281
- this.updateQuote(tokens_usage);
287
+ this.updateQuote(server_base_url, tokens_usage);
282
288
  }
283
289
 
284
290
  if (trueIntent) {
@@ -414,11 +420,11 @@ class DirAskGPTV2 {
414
420
  });
415
421
  }
416
422
 
417
- async getKeyFromIntegrations() {
423
+ async getKeyFromIntegrations(server_base_url) {
418
424
  return new Promise((resolve) => {
419
425
 
420
426
  const INTEGRATIONS_HTTPREQUEST = {
421
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
427
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
422
428
  headers: {
423
429
  'Content-Type': 'application/json',
424
430
  'Authorization': 'JWT ' + this.context.token
@@ -446,11 +452,11 @@ class DirAskGPTV2 {
446
452
  })
447
453
  }
448
454
 
449
- async getKeyFromKbSettings() {
455
+ async getKeyFromKbSettings(server_base_url) {
450
456
  return new Promise((resolve) => {
451
457
 
452
458
  const KB_HTTPREQUEST = {
453
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
459
+ url: server_base_url + "/" + this.context.projectId + "/kbsettings",
454
460
  headers: {
455
461
  'Content-Type': 'application/json',
456
462
  'Authorization': 'JWT ' + this.context.token
@@ -476,11 +482,11 @@ class DirAskGPTV2 {
476
482
  })
477
483
  }
478
484
 
479
- async checkQuoteAvailability() {
485
+ async checkQuoteAvailability(server_base_url) {
480
486
  return new Promise((resolve) => {
481
487
 
482
488
  const HTTPREQUEST = {
483
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
489
+ url: server_base_url + "/" + this.context.projectId + "/quotes/tokens",
484
490
  headers: {
485
491
  'Content-Type': 'application/json',
486
492
  'Authorization': 'JWT ' + this.context.token
@@ -506,11 +512,11 @@ class DirAskGPTV2 {
506
512
  })
507
513
  }
508
514
 
509
- async updateQuote(tokens_usage) {
515
+ async updateQuote(server_base_url, tokens_usage) {
510
516
  return new Promise((resolve) => {
511
517
 
512
518
  const HTTPREQUEST = {
513
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
519
+ url: server_base_url + "/" + this.context.projectId + "/quotes/incr/tokens",
514
520
  headers: {
515
521
  'Content-Type': 'application/json',
516
522
  'Authorization': 'JWT ' + this.context.token
@@ -582,10 +588,10 @@ class DirAskGPTV2 {
582
588
  return objectTranscript;
583
589
  }
584
590
 
585
- async getNamespace(name, id) {
591
+ async getNamespace(server_base_url, name, id) {
586
592
  return new Promise((resolve) => {
587
593
  const HTTPREQUEST = {
588
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kb/namespace/all",
594
+ url: server_base_url + "/" + this.context.projectId + "/kb/namespace/all",
589
595
  headers: {
590
596
  'Content-Type': 'application/json',
591
597
  'Authorization': 'JWT ' + this.context.token
@@ -627,6 +633,39 @@ class DirAskGPTV2 {
627
633
  })
628
634
  }
629
635
 
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
+
630
669
  }
631
670
 
632
671
  module.exports = { DirAskGPTV2 }
@@ -10,6 +10,17 @@ 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
+ // }
13
24
  this.log = context.log;
14
25
  }
15
26