@tiledesk/tiledesk-tybot-connector 0.2.131-rc4 → 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 +19 -9
  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 +1 -11
  18. package/tiledeskChatbotPlugs/directives/DirCondition.js +26 -0
  19. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +13 -1
  20. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +2 -11
  21. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +8 -5
  22. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -11
  23. package/tiledeskChatbotPlugs/directives/DirDepartment.js +2 -11
  24. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +5 -16
  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 +25 -12
  30. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +2 -12
  31. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +30 -4
  32. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +26 -12
  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 +1 -11
  38. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +1 -10
  39. package/tiledeskChatbotPlugs/directives/DirQapla.js +8 -5
  40. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +1 -11
  41. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +7 -18
  42. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +1 -10
  43. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +1 -10
  44. package/tiledeskChatbotPlugs/directives/DirReply.js +1 -11
  45. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +1 -11
  46. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +21 -11
  47. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +2 -2
  48. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +1 -10
  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
@@ -10,10 +10,10 @@ class DirAssistant {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
+ this.tdclient = context.tdclient;
13
14
  this.tdcache = context.tdcache;
14
15
  this.requestId = context.requestId;
15
16
  this.intentDir = new DirIntent(context);
16
- this.API_ENDPOINT = context.API_ENDPOINT;
17
17
  this.log = context.log;
18
18
  }
19
19
 
@@ -264,7 +264,8 @@ class DirAssistant {
264
264
  return process.env.TEST_OPENAI_APIKEY
265
265
  }
266
266
  else {
267
- return await this.getKeyFromIntegrations();
267
+ const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
268
+ return await this.getKeyFromIntegrations(server_base_url);
268
269
  }
269
270
  }
270
271
 
@@ -495,11 +496,11 @@ class DirAssistant {
495
496
  });
496
497
  }
497
498
 
498
- async getKeyFromIntegrations() {
499
+ async getKeyFromIntegrations(server_base_url) {
499
500
  return new Promise((resolve) => {
500
501
 
501
502
  const INTEGRATIONS_HTTPREQUEST = {
502
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
503
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
503
504
  headers: {
504
505
  'Content-Type': 'application/json',
505
506
  'Authorization': 'JWT ' + this.context.token
@@ -16,7 +16,6 @@ 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;
20
19
  this.log = context.log;
21
20
  }
22
21
 
@@ -72,10 +71,14 @@ class DirBrevo {
72
71
  return;
73
72
  }
74
73
 
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) { console.log("DirBrevo brevo_base_url ", brevo_base_url); }
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
+ }
77
80
 
78
- let key = await this.getKeyFromIntegrations();
81
+ let key = await this.getKeyFromIntegrations(server_base_url);
79
82
  if (this.log) { console.log('DirBrevo key Debug1: ', key) }
80
83
  // ONLY FOR DEBUG CANCELLARE!!!!!
81
84
  // if (process.env.BREVO_DEBUG == '1') {
@@ -317,11 +320,11 @@ class DirBrevo {
317
320
  }
318
321
  }
319
322
 
320
- async getKeyFromIntegrations() {
323
+ async getKeyFromIntegrations(server_base_url) {
321
324
  return new Promise((resolve) => {
322
325
 
323
326
  const INTEGRATIONS_HTTPREQUEST = {
324
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/Brevo",
327
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/Brevo",
325
328
  headers: {
326
329
  'Content-Type': 'application/json',
327
330
  'Authorization': 'JWT ' + this.context.token
@@ -7,10 +7,37 @@ class DirCaptureUserReply {
7
7
  if (!context) {
8
8
  throw new Error('context object is mandatory.');
9
9
  }
10
-
11
10
  this.context = context;
12
11
  this.reply = context.reply;
12
+ // reply = {
13
+ // actions: [
14
+ // {
15
+ // _tdActionType: 'askgpt',
16
+ // _tdActionTitle: 'gpt action',
17
+ // assignReplyTo: 'gpt_reply',
18
+ // assignSourceTo: 'gpt_source',
19
+ // kbid: 'XXX',
20
+ // trueIntent: '#SUCCESS',
21
+ // falseIntent: '#FAILURE',
22
+ // question: 'this is the question: ${last_user_message}'
23
+ // }
24
+ // ],
25
+ // attributes: {
26
+ // clienttimestamp: 1695548792706,
27
+ // intent_info: {
28
+ // intent_name: 'gpt success',
29
+ // intent_id: '00f93b97-89ee-466d-a09c-e47a18943057',
30
+ // is_fallback: false,
31
+ // confidence: undefined,
32
+ // question_payload: [Object],
33
+ // botId: 'botID',
34
+ // bot: [Object]
35
+ // },
36
+ // webhook: false
37
+ // }
38
+ // }
13
39
  this.message = context.message;
40
+ this.tdclient = context.tdclient;
14
41
  this.chatbot = context.chatbot;
15
42
  this.tdcache = context.tdcache;
16
43
  this.requestId = context.requestId;
@@ -8,6 +8,7 @@ class DirClearTranscript {
8
8
  throw new Error('context object is mandatory.');
9
9
  }
10
10
  this.context = context;
11
+ this.tdclient = context.tdclient;
11
12
  this.requestId = context.requestId;
12
13
  }
13
14
 
@@ -1,5 +1,4 @@
1
1
 
2
- const { TiledeskClient } = require("@tiledesk/tiledesk-client");
3
2
  const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
4
3
 
5
4
  class DirClose {
@@ -9,18 +8,9 @@ class DirClose {
9
8
  throw new Error('context object is mandatory.');
10
9
  }
11
10
  this.context = context;
11
+ this.tdclient = context.tdclient;
12
12
  this.requestId = context.requestId;
13
13
  this.chatbot = context.chatbot;
14
- this.API_ENDPOINT = context.API_ENDPOINT;
15
- this.log = context.log;
16
-
17
- this.tdClient = new TiledeskClient({
18
- projectId: this.context.projectId,
19
- token: this.context.token,
20
- APIURL: this.API_ENDPOINT,
21
- APIKEY: "___",
22
- log: this.log
23
- });
24
14
  }
25
15
 
26
16
  execute(directive, callback) {
@@ -10,7 +10,33 @@ class DirCondition {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
+ // let context = {
14
+ // projectId: projectId,
15
+ // token: token,
16
+ // supportRequest: supportRequest,
17
+ // requestId: supportRequest.request_id,
18
+ // TILEDESK_APIURL: API_URL,
19
+ // TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
20
+ // departmentId: depId,
21
+ // tdcache: tdcache,
22
+ // log: false
23
+ // }
24
+ // this.tdclient = new TiledeskClient({
25
+ // projectId: context.projectId,
26
+ // token: context.token,
27
+ // APIURL: context.TILEDESK_APIURL,
28
+ // APIKEY: "___",
29
+ // log: context.log
30
+ // });
13
31
  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
+ // );
14
40
  this.log = context.log;
15
41
  }
16
42
 
@@ -10,11 +10,23 @@ class DirConnectBlock {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
- this.API_ENDPOINT = context.API_ENDPOINT,
13
+ this.API_ENDPOINT = context.TILEDESK_APIURL,
14
14
  this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
15
15
  this.supportRequest = context.supportRequest;
16
16
  this.token = context.token;
17
17
  this.log = context.log;
18
+ // let context = {
19
+ // projectId: projectId,
20
+ // token: token,
21
+ // supportRequest: supportRequest,
22
+ // requestId: supportRequest.request_id,
23
+ // TILEDESK_APIURL: API_URL,
24
+ // TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
25
+ // departmentId: depId,
26
+ // tdcache: tdcache,
27
+ // tdclient: tdclient,
28
+ // log: true
29
+ // }
18
30
  }
19
31
 
20
32
  execute(directive, callback) {
@@ -3,7 +3,6 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
5
  const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
6
- const { TiledeskClient } = require('@tiledesk/tiledesk-client');
7
6
 
8
7
  class DirContactUpdate {
9
8
 
@@ -17,16 +16,8 @@ class DirContactUpdate {
17
16
  this.supportRequest = context.supportRequest;
18
17
  this.token = context.token;
19
18
  this.tdcache = context.tdcache;
20
- this.API_ENDPOINT = context.API_ENDPOINT;
19
+ this.tdclient = context.tdclient;
21
20
  this.log = context.log;
22
-
23
- this.tdClient = new TiledeskClient({
24
- projectId: this.context.projectId,
25
- token: this.context.token,
26
- APIURL: this.API_ENDPOINT,
27
- APIKEY: "___",
28
- log: this.log
29
- });
30
21
  }
31
22
 
32
23
  execute(directive, callback) {
@@ -100,7 +91,7 @@ class DirContactUpdate {
100
91
  // }
101
92
  // };
102
93
  // if (this.log) {console.log("(DirContactUpdate) sending updateLeadDataOnWidgetMessage:", updateLeadDataOnWidgetMessage); }
103
- // this.tdclient.sendSupportMessage(
94
+ // this.context.tdclient.sendSupportMessage(
104
95
  // this.requestId,
105
96
  // updateLeadDataOnWidgetMessage,
106
97
  // (err) => {
@@ -16,7 +16,6 @@ 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;
20
19
  this.log = context.log;
21
20
  }
22
21
 
@@ -70,10 +69,14 @@ class DirCustomerio {
70
69
  return;
71
70
  }
72
71
 
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) { console.log("DirCustomerio customerio_base_url: ", customerio_base_url); }
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
+ }
75
78
 
76
- let key = await this.getKeyFromIntegrations();
79
+ let key = await this.getKeyFromIntegrations(server_base_url);
77
80
  if (!key) {
78
81
  if (this.log) { console.log("DirCustomerio - Key not found in Integrations."); }
79
82
  let status = 422;
@@ -284,11 +287,11 @@ class DirCustomerio {
284
287
  }
285
288
  }
286
289
 
287
- async getKeyFromIntegrations() {
290
+ async getKeyFromIntegrations(server_base_url) {
288
291
  return new Promise((resolve) => {
289
292
 
290
293
  const INTEGRATIONS_HTTPREQUEST = {
291
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/customerio",
294
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/customerio",
292
295
  headers: {
293
296
  'Content-Type': 'application/json',
294
297
  'Authorization': 'JWT ' + this.context.token
@@ -2,7 +2,6 @@ const { HelpCenterQuery } = require('@tiledesk/helpcenter-query-client');
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot.js');
3
3
  const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
4
4
  const ms = require('minimist-string');
5
- const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
5
 
7
6
  class DirDeflectToHelpCenter {
8
7
 
@@ -11,16 +10,7 @@ class DirDeflectToHelpCenter {
11
10
  throw new Error('context object is mandatory.');
12
11
  }
13
12
  this.context = context;
14
- this.API_ENDPOINT = context.API_ENDPOINT;
15
13
  this.log = context.log;
16
-
17
- this.tdClient = new TiledeskClient({
18
- projectId: this.context.projectId,
19
- token: this.context.token,
20
- APIURL: this.API_ENDPOINT,
21
- APIKEY: "___",
22
- log: this.log
23
- });
24
14
  }
25
15
 
26
16
  async execute(directive, callback) {
@@ -142,7 +132,7 @@ class DirDeflectToHelpCenter {
142
132
  }
143
133
 
144
134
  if (this.log) {console.log("HC reply:", JSON.stringify(message))};
145
- this.tdclient.sendSupportMessage(
135
+ this.context.tdclient.sendSupportMessage(
146
136
  this.context.requestId,
147
137
  message,
148
138
  (err) => {
@@ -1,4 +1,3 @@
1
- const { TiledeskClient } = require("@tiledesk/tiledesk-client");
2
1
 
3
2
  class DirDepartment {
4
3
 
@@ -7,17 +6,9 @@ class DirDepartment {
7
6
  throw new Error('context object is mandatory.');
8
7
  }
9
8
  this.context = context;
10
- this.requestId = context.requestId;
11
- this.API_ENDPOINT = context.API_ENDPOINT;
12
9
  this.log = context.log;
13
-
14
- this.tdClient = new TiledeskClient({
15
- projectId: this.context.projectId,
16
- token: this.context.token,
17
- APIURL: this.API_ENDPOINT,
18
- APIKEY: "___",
19
- log: this.log
20
- });
10
+ this.tdclient = context.tdclient;
11
+ this.requestId = context.requestId;
21
12
  }
22
13
 
23
14
  execute(directive, callback) {
@@ -1,24 +1,13 @@
1
- const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
1
  const ms = require('minimist-string');
3
2
 
4
3
  class DirFireTiledeskEvent {
5
4
 
6
- constructor(context) {
7
- if (!context) {
8
- throw new Error('context object is mandatory.');
5
+ constructor(config) {
6
+ if (!config.tdclient) {
7
+ throw new Error('config.tdclient (TiledeskClient) object is mandatory.');
9
8
  }
10
-
11
- this.context = context;
12
- this.log = context.log;
13
-
14
- this.API_ENDPOINT = context.API_ENDPOINT;
15
- this.tdClient = new TiledeskClient({
16
- projectId: this.context.projectId,
17
- token: this.context.token,
18
- APIURL: this.API_ENDPOINT,
19
- APIKEY: "___",
20
- log: this.log
21
- });
9
+ this.tdclient = config.tdclient;
10
+ this.log = config.log;
22
11
  }
23
12
 
24
13
  execute(directive, callback) {
@@ -2,7 +2,6 @@ const { Filler } = require('../Filler');
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { DirIntent } = require('./DirIntent');
4
4
  const { IntentForm } = require('../../models/IntentForm.js');
5
- const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
5
 
7
6
  class DirForm {
8
7
  constructor(context) {
@@ -10,21 +9,12 @@ class DirForm {
10
9
  throw new Error('context object is mandatory.');
11
10
  }
12
11
  this.context = context;
12
+ this.tdclient = context.tdclient;
13
13
  this.chatbot = context.chatbot;
14
14
  this.tdcache = context.tdcache;
15
15
  this.requestId = context.requestId;
16
16
  this.intentDir = new DirIntent(context);
17
17
  this.log = context.log;
18
-
19
- this.API_ENDPOINT = context.API_ENDPOINT;
20
- this.tdClient = new TiledeskClient({
21
- projectId: this.context.projectId,
22
- token: this.context.token,
23
- APIURL: this.API_ENDPOINT,
24
- APIKEY: "___",
25
- log: this.log
26
- });
27
-
28
18
  }
29
19
 
30
20
  execute(directive, callback) {
@@ -93,7 +83,7 @@ class DirForm {
93
83
  form_reply.message.attributes.markbot = true;
94
84
  // return form_reply.message;
95
85
 
96
- this.tdclient.sendSupportMessage(
86
+ this.context.tdclient.sendSupportMessage(
97
87
  this.requestId,
98
88
  form_reply.message,
99
89
  (err) => {
@@ -18,7 +18,6 @@ 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;
22
21
  this.log = context.log;
23
22
  }
24
23
 
@@ -113,13 +112,18 @@ class DirGptTask {
113
112
  }
114
113
  }
115
114
 
115
+
116
+ const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
116
117
  const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
117
- if (this.log) { console.log("DirGptTask openai_url ", openai_url); }
118
+ if (this.log) {
119
+ console.log("DirGptTask server_base_url ", server_base_url);
120
+ console.log("DirGptTask openai_url ", openai_url);
121
+ }
118
122
 
119
- let key = await this.getKeyFromIntegrations();
123
+ let key = await this.getKeyFromIntegrations(server_base_url);
120
124
  if (!key) {
121
125
  if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
122
- key = await this.getKeyFromKbSettings();
126
+ key = await this.getKeyFromKbSettings(server_base_url);
123
127
  }
124
128
 
125
129
  if (!key) {
@@ -142,7 +146,7 @@ class DirGptTask {
142
146
  }
143
147
 
144
148
  if (publicKey === true) {
145
- let keep_going = await this.checkQuoteAvailability();
149
+ let keep_going = await this.checkQuoteAvailability(server_base_url);
146
150
  if (keep_going === false) {
147
151
  if (this.log) { console.log("DirGptTask - Quota exceeded for tokens. Skip the action")}
148
152
  await this.chatbot.addParameter("flowError", "GPT Error: tokens quota exceeded");
@@ -226,7 +230,7 @@ class DirGptTask {
226
230
  tokens: resbody.usage.total_tokens,
227
231
  model: json.model
228
232
  }
229
- this.updateQuote(tokens_usage);
233
+ this.updateQuote(server_base_url, tokens_usage);
230
234
  }
231
235
 
232
236
  if (trueIntent) {
@@ -364,11 +368,11 @@ class DirGptTask {
364
368
  });
365
369
  }
366
370
 
367
- async getKeyFromIntegrations() {
371
+ async getKeyFromIntegrations(server_base_url) {
368
372
  return new Promise((resolve) => {
369
373
 
370
374
  const INTEGRATIONS_HTTPREQUEST = {
371
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
375
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
372
376
  headers: {
373
377
  'Content-Type': 'application/json',
374
378
  'Authorization': 'JWT ' + this.context.token
@@ -395,11 +399,11 @@ class DirGptTask {
395
399
  })
396
400
  }
397
401
 
398
- async getKeyFromKbSettings() {
402
+ async getKeyFromKbSettings(server_base_url) {
399
403
  return new Promise((resolve) => {
400
404
 
401
405
  const KB_HTTPREQUEST = {
402
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
406
+ url: server_base_url + "/" + this.context.projectId + "/kbsettings",
403
407
  headers: {
404
408
  'Content-Type': 'application/json',
405
409
  'Authorization': 'JWT ' + this.context.token
@@ -428,11 +432,11 @@ class DirGptTask {
428
432
  })
429
433
  }
430
434
 
431
- async checkQuoteAvailability() {
435
+ async checkQuoteAvailability(server_base_url) {
432
436
  return new Promise((resolve) => {
433
437
 
434
438
  const HTTPREQUEST = {
435
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
439
+ url: server_base_url + "/" + this.context.projectId + "/quotes/tokens",
436
440
  headers: {
437
441
  'Content-Type': 'application/json',
438
442
  'Authorization': 'JWT ' + this.context.token
@@ -457,11 +461,11 @@ class DirGptTask {
457
461
  })
458
462
  }
459
463
 
460
- async updateQuote(tokens_usage) {
464
+ async updateQuote(server_base_url, tokens_usage) {
461
465
  return new Promise((resolve) => {
462
466
 
463
467
  const HTTPREQUEST = {
464
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
468
+ url: server_base_url + "/" + this.context.projectId + "/quotes/incr/tokens",
465
469
  headers: {
466
470
  'Content-Type': 'application/json',
467
471
  'Authorization': 'JWT ' + this.context.token
@@ -15,7 +15,6 @@ 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;
19
18
  this.log = context.log;
20
19
  }
21
20
 
@@ -86,11 +85,15 @@ class DirGptTask {
86
85
  console.log("DirGptTask temperature: ", temperature);
87
86
  }
88
87
 
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) { console.log("DirGptTask openai_url ", openai_url); }
90
+ if (this.log) {
91
+ console.log("DirGptTask server_base_url ", server_base_url);
92
+ console.log("DirGptTask openai_url ", openai_url);
93
+ }
91
94
 
92
95
  const INTEGRATIONS_HTTPREQUEST = {
93
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
96
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
94
97
  headers: {
95
98
  'Content-Type': 'application/json',
96
99
  'Authorization': 'JWT ' + this.context.token
@@ -124,7 +127,7 @@ class DirGptTask {
124
127
  if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
125
128
 
126
129
  const KB_HTTPREQUEST = {
127
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
130
+ url: server_base_url + "/" + this.context.projectId + "/kbsettings",
128
131
  headers: {
129
132
  'Content-Type': 'application/json',
130
133
  'Authorization': 'JWT ' + this.context.token
@@ -16,7 +16,6 @@ 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;
20
19
  this.log = context.log;
21
20
  }
22
21
 
@@ -72,10 +71,14 @@ class DirHubspot {
72
71
  return;
73
72
  }
74
73
 
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) { console.log("DirHubspot hubspot_base_url ", hubspot_base_url); }
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
+ }
77
80
 
78
- let key = await this.getKeyFromIntegrations();
81
+ let key = await this.getKeyFromIntegrations(server_base_url);
79
82
  if (!key) {
80
83
  if (this.log) { console.log("DirHubspot - Key not found in Integrations."); }
81
84
  if (falseIntent) {
@@ -286,11 +289,11 @@ class DirHubspot {
286
289
  }
287
290
  }
288
291
 
289
- async getKeyFromIntegrations() {
292
+ async getKeyFromIntegrations(server_base_url) {
290
293
  return new Promise((resolve) => {
291
294
 
292
295
  const INTEGRATIONS_HTTPREQUEST = {
293
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/hubspot",
296
+ url: server_base_url + "/" + this.context.projectId + "/integration/name/hubspot",
294
297
  headers: {
295
298
  'Content-Type': 'application/json',
296
299
  'Authorization': 'JWT ' + this.context.token
@@ -1,5 +1,4 @@
1
1
  // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
- const { TiledeskClient } = require('@tiledesk/tiledesk-client');
3
2
  const { DirIntent } = require('./DirIntent');
4
3
  const ms = require('minimist-string');
5
4
 
@@ -9,19 +8,33 @@ class DirIfOnlineAgents {
9
8
  if (!context) {
10
9
  throw new Error('context object is mandatory.');
11
10
  }
12
-
13
- this.context = context;
11
+ this.tdclient = context.tdclient;
12
+ // this.tdclient = new TiledeskClient({
13
+ // projectId: context.projectId,
14
+ // token: context.token,
15
+ // APIURL: context.TILEDESK_APIURL,
16
+ // APIKEY: "___",
17
+ // log: context.log
18
+ // });
19
+ // let context = {
20
+ // projectId: projectId,
21
+ // token: token,
22
+ // requestId: supportRequest,
23
+ // APIURL: API_URL,
24
+ // TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
25
+ // departmentId: depId,
26
+ // log: false
27
+ // }
14
28
  this.intentDir = new DirIntent(context);
15
- this.API_ENDPOINT = context.API_ENDPOINT;
29
+ // {
30
+ // API_ENDPOINT: context.TILEDESK_APIURL,
31
+ // TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
32
+ // supportRequest: context.supportRequest,
33
+ // token: context.token,
34
+ // log: context.log
35
+ // }
36
+ // );
16
37
  this.log = context.log;
17
-
18
- this.tdClient = new TiledeskClient({
19
- projectId: this.context.projectId,
20
- token: this.context.token,
21
- APIURL: this.API_ENDPOINT,
22
- APIKEY: "___",
23
- log: this.log
24
- });
25
38
  }
26
39
 
27
40
  execute(directive, callback) {