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

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 (31) hide show
  1. package/package.json +1 -1
  2. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +0 -2
  3. package/tiledeskChatbotPlugs/directives/DirAddTags.js +9 -3
  4. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +11 -3
  5. package/tiledeskChatbotPlugs/directives/DirAssistant.js +0 -1
  6. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -28
  7. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +0 -1
  8. package/tiledeskChatbotPlugs/directives/DirClose.js +13 -2
  9. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +12 -3
  10. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +11 -1
  11. package/tiledeskChatbotPlugs/directives/DirDepartment.js +14 -5
  12. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +17 -6
  13. package/tiledeskChatbotPlugs/directives/DirForm.js +12 -2
  14. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +14 -3
  15. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +11 -2
  16. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +3 -2
  17. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +13 -3
  18. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +12 -2
  19. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +11 -2
  20. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -1
  21. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +17 -7
  22. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +11 -2
  23. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -3
  24. package/tiledeskChatbotPlugs/directives/DirReply.js +11 -1
  25. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +11 -1
  26. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +11 -2
  27. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +13 -4
  28. package/tiledeskChatbotPlugs/directives/DirWait.js +0 -1
  29. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
  30. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +0 -1
  31. /package/tiledeskChatbotPlugs/directives/{DirOfflineHours.js → DEPRECATED_DirOfflineHours.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.131-rc3",
3
+ "version": "0.2.131-rc5",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,6 @@
1
1
  const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
2
2
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
3
3
  const { DirDeflectToHelpCenter } = require('./directives/DirDeflectToHelpCenter');
4
- // const { DirOfflineHours } = require('./directives/DirOfflineHours'); // DEPRECATED
5
4
  const { DirMoveToAgent } = require('./directives/DirMoveToAgent');
6
5
  const { DirMessage } = require('./directives/DirMessage');
7
6
  const { DirWait } = require('./directives/DirWait');
@@ -163,7 +162,6 @@ class DirectivesChatbotPlug {
163
162
  TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
164
163
  departmentId: depId,
165
164
  tdcache: tdcache,
166
- tdclient: tdclient,
167
165
  HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT,
168
166
  log: this.log
169
167
  }
@@ -8,6 +8,7 @@ const { TiledeskChatbotUtil } = require("../../models/TiledeskChatbotUtil");
8
8
  const req = require("express/lib/request");
9
9
  const { rejects } = require("assert");
10
10
  const { update } = require("../../models/faq");
11
+ const { TiledeskClient } = require("@tiledesk/tiledesk-client");
11
12
  require('dotenv').config();
12
13
 
13
14
  class DirAddTags {
@@ -20,11 +21,16 @@ class DirAddTags {
20
21
  this.chatbot = this.context.chatbot;
21
22
  this.tdcache = this.context.tdcache;
22
23
  this.requestId = this.context.requestId;
23
- this.tdClient = this.context.tdclient;
24
24
  this.API_ENDPOINT = this.context.API_ENDPOINT;
25
- // this.intentDir = new DirIntent(context);
26
25
  this.log = context.log;
27
- // this.log = true;
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
+ });
28
34
  }
29
35
 
30
36
  execute(directive, callback) {
@@ -9,9 +9,17 @@ class DirAssignFromFunction {
9
9
  throw new Error('context object is mandatory.');
10
10
  }
11
11
  this.context = context;
12
- this.tdclient = context.tdclient;
13
12
  this.log = context.log;
14
13
  this.tdcache = context.tdcache;
14
+ this.API_ENDPOINT = context.API_ENDPOINT;
15
+
16
+ this.tdClient = new TiledeskClient({
17
+ projectId: this.context.projectId,
18
+ token: this.context.token,
19
+ APIURL: this.API_ENDPOINT,
20
+ APIKEY: "___",
21
+ log: this.log
22
+ });
15
23
  }
16
24
 
17
25
  async execute(directive, callback) {
@@ -59,7 +67,7 @@ class DirAssignFromFunction {
59
67
  async invoke(functionName, callback) {
60
68
  switch (functionName) {
61
69
  case "openNow":
62
- this.tdclient.openNow((err, result) => {
70
+ this.tdClient.openNow((err, result) => {
63
71
  if (this.log) {console.log("openNow():", result);}
64
72
  if (err) {
65
73
  callback(err);
@@ -73,7 +81,7 @@ class DirAssignFromFunction {
73
81
  });
74
82
  break;
75
83
  case "availableAgents":
76
- this.tdclient.getProjectAvailableAgents((err, agents) => {
84
+ this.tdClient.getProjectAvailableAgents((err, agents) => {
77
85
  if (this.log) {console.log("Agents on 'open'", agents);}
78
86
  if (err || !agents) {
79
87
  console.error("Error getting available agents in DirWhenAvailableAgents", err);
@@ -10,7 +10,6 @@ class DirAssistant {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
- this.tdclient = context.tdclient;
14
13
  this.tdcache = context.tdcache;
15
14
  this.requestId = context.requestId;
16
15
  this.intentDir = new DirIntent(context);
@@ -7,37 +7,10 @@ class DirCaptureUserReply {
7
7
  if (!context) {
8
8
  throw new Error('context object is mandatory.');
9
9
  }
10
+
10
11
  this.context = context;
11
12
  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
- // }
39
13
  this.message = context.message;
40
- this.tdclient = context.tdclient;
41
14
  this.chatbot = context.chatbot;
42
15
  this.tdcache = context.tdcache;
43
16
  this.requestId = context.requestId;
@@ -8,7 +8,6 @@ class DirClearTranscript {
8
8
  throw new Error('context object is mandatory.');
9
9
  }
10
10
  this.context = context;
11
- this.tdclient = context.tdclient;
12
11
  this.requestId = context.requestId;
13
12
  }
14
13
 
@@ -1,4 +1,5 @@
1
1
 
2
+ const { TiledeskClient } = require("@tiledesk/tiledesk-client");
2
3
  const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
3
4
 
4
5
  class DirClose {
@@ -8,13 +9,23 @@ class DirClose {
8
9
  throw new Error('context object is mandatory.');
9
10
  }
10
11
  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
+ console.log("this.context.projectId: ", context)
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
+ });
14
25
  }
15
26
 
16
27
  execute(directive, callback) {
17
- this.tdclient.closeRequest(this.requestId, async (err) => {
28
+ this.tdClient.closeRequest(this.requestId, async (err) => {
18
29
  if (err) {
19
30
  console.error("Error in 'close directive':", err);
20
31
  }
@@ -3,6 +3,7 @@ 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');
6
7
 
7
8
  class DirContactUpdate {
8
9
 
@@ -16,8 +17,16 @@ class DirContactUpdate {
16
17
  this.supportRequest = context.supportRequest;
17
18
  this.token = context.token;
18
19
  this.tdcache = context.tdcache;
19
- this.tdclient = context.tdclient;
20
+ this.API_ENDPOINT = context.API_ENDPOINT;
20
21
  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
+ });
21
30
  }
22
31
 
23
32
  execute(directive, callback) {
@@ -72,7 +81,7 @@ class DirContactUpdate {
72
81
  if (this.log) {console.log("(DirContactUpdate) updating property:", key, "value:", filled_value); }
73
82
  }
74
83
  const leadId = requestAttributes[TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY];
75
- this.tdclient.updateLead(leadId, updateProperties, null, null, () => {
84
+ this.tdClient.updateLead(leadId, updateProperties, null, null, () => {
76
85
  if (this.log) {console.log("(DirContactUpdate) Lead updated.", updateProperties);}
77
86
  // send hidden info to update widget lead fullname only if it is a conversation!
78
87
  if (this.log) {console.log("(DirContactUpdate) requestId:", this.requestId); }
@@ -91,7 +100,7 @@ class DirContactUpdate {
91
100
  // }
92
101
  // };
93
102
  // if (this.log) {console.log("(DirContactUpdate) sending updateLeadDataOnWidgetMessage:", updateLeadDataOnWidgetMessage); }
94
- // this.context.tdclient.sendSupportMessage(
103
+ // this.tdClient.sendSupportMessage(
95
104
  // this.requestId,
96
105
  // updateLeadDataOnWidgetMessage,
97
106
  // (err) => {
@@ -2,6 +2,7 @@ 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');
5
6
 
6
7
  class DirDeflectToHelpCenter {
7
8
 
@@ -10,7 +11,16 @@ class DirDeflectToHelpCenter {
10
11
  throw new Error('context object is mandatory.');
11
12
  }
12
13
  this.context = context;
14
+ this.API_ENDPOINT = context.API_ENDPOINT;
13
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
+ });
14
24
  }
15
25
 
16
26
  async execute(directive, callback) {
@@ -132,7 +142,7 @@ class DirDeflectToHelpCenter {
132
142
  }
133
143
 
134
144
  if (this.log) {console.log("HC reply:", JSON.stringify(message))};
135
- this.context.tdclient.sendSupportMessage(
145
+ this.tdClient.sendSupportMessage(
136
146
  this.context.requestId,
137
147
  message,
138
148
  (err) => {
@@ -1,3 +1,4 @@
1
+ const { TiledeskClient } = require("@tiledesk/tiledesk-client");
1
2
 
2
3
  class DirDepartment {
3
4
 
@@ -6,9 +7,17 @@ class DirDepartment {
6
7
  throw new Error('context object is mandatory.');
7
8
  }
8
9
  this.context = context;
9
- this.log = context.log;
10
- this.tdclient = context.tdclient;
11
10
  this.requestId = context.requestId;
11
+ this.API_ENDPOINT = context.API_ENDPOINT;
12
+ 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
+ });
12
21
  }
13
22
 
14
23
  execute(directive, callback) {
@@ -80,7 +89,7 @@ class DirDepartment {
80
89
  subtype: "info"
81
90
  }
82
91
  }
83
- this.tdclient.sendSupportMessage(
92
+ this.tdClient.sendSupportMessage(
84
93
  this.requestId,
85
94
  message, (err) => {
86
95
  if (err) {
@@ -99,7 +108,7 @@ class DirDepartment {
99
108
  }
100
109
 
101
110
  moveToDepartment(requestId, depName, callback) {
102
- this.tdclient.getAllDepartments((err, deps) => {
111
+ this.tdClient.getAllDepartments((err, deps) => {
103
112
  if (this.log) {console.log("deps:", JSON.stringify(deps));}
104
113
  if (err) {
105
114
  console.error("getAllDepartments() error:", err);
@@ -116,7 +125,7 @@ class DirDepartment {
116
125
  }
117
126
  }
118
127
  if (dep) {
119
- this.tdclient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
128
+ this.tdClient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
120
129
  if (err) {
121
130
  console.error("DirDepartment error:", err);
122
131
  callback();
@@ -1,13 +1,24 @@
1
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const ms = require('minimist-string');
2
3
 
3
4
  class DirFireTiledeskEvent {
4
5
 
5
- constructor(config) {
6
- if (!config.tdclient) {
7
- throw new Error('config.tdclient (TiledeskClient) object is mandatory.');
6
+ constructor(context) {
7
+ if (!context) {
8
+ throw new Error('context object is mandatory.');
8
9
  }
9
- this.tdclient = config.tdclient;
10
- this.log = config.log;
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
+ });
11
22
  }
12
23
 
13
24
  execute(directive, callback) {
@@ -18,7 +29,7 @@ class DirFireTiledeskEvent {
18
29
  name: event_name,
19
30
  attributes: params.payload
20
31
  }
21
- this.tdclient.fireEvent(event, function(err, result) {
32
+ this.tdClient.fireEvent(event, function(err, result) {
22
33
  if (err) {
23
34
  console.error("An error occurred invoking an event:", err);
24
35
  }
@@ -2,6 +2,7 @@ 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');
5
6
 
6
7
  class DirForm {
7
8
  constructor(context) {
@@ -9,12 +10,21 @@ class DirForm {
9
10
  throw new Error('context object is mandatory.');
10
11
  }
11
12
  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
+
18
28
  }
19
29
 
20
30
  execute(directive, callback) {
@@ -83,7 +93,7 @@ class DirForm {
83
93
  form_reply.message.attributes.markbot = true;
84
94
  // return form_reply.message;
85
95
 
86
- this.context.tdclient.sendSupportMessage(
96
+ this.tdClient.sendSupportMessage(
87
97
  this.requestId,
88
98
  form_reply.message,
89
99
  (err) => {
@@ -1,4 +1,5 @@
1
1
  // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
3
  const { DirIntent } = require('./DirIntent');
3
4
  const ms = require('minimist-string');
4
5
 
@@ -8,9 +9,19 @@ class DirIfOnlineAgents {
8
9
  if (!context) {
9
10
  throw new Error('context object is mandatory.');
10
11
  }
11
- this.tdclient = context.tdclient;
12
+
13
+ this.context = context;
12
14
  this.intentDir = new DirIntent(context);
15
+ this.API_ENDPOINT = context.API_ENDPOINT;
13
16
  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
+ });
14
25
  }
15
26
 
16
27
  execute(directive, callback) {
@@ -59,7 +70,7 @@ class DirIfOnlineAgents {
59
70
  const trueIntentAttributes = action.trueIntentAttributes;
60
71
  const falseIntentAttributes = action.falseIntentAttributes;
61
72
  let stopOnConditionMet = action.stopOnConditionMet;
62
- this.tdclient.openNow((err, result) => {
73
+ this.tdClient.openNow((err, result) => {
63
74
  if (this.log) {console.log("openNow():", result);}
64
75
  if (err) {
65
76
  console.error("IfOnlineAgents:tdclient.openNow Error:", err);
@@ -68,7 +79,7 @@ class DirIfOnlineAgents {
68
79
  }
69
80
  else {
70
81
  if (result && result.isopen) {
71
- this.tdclient.getProjectAvailableAgents((err, agents) => {
82
+ this.tdClient.getProjectAvailableAgents((err, agents) => {
72
83
  if (this.log) {console.log("Agents", agents);}
73
84
  if (err) {
74
85
  console.error("IfOnlineAgents:Error getting available agents:", err);
@@ -4,6 +4,7 @@ const { DirIntent } = require('./DirIntent');
4
4
  const axios = require("axios").default;
5
5
  let https = require("https");
6
6
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
7
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
7
8
 
8
9
  class DirIfOnlineAgentsV2 {
9
10
 
@@ -13,10 +14,18 @@ class DirIfOnlineAgentsV2 {
13
14
  }
14
15
  this.context = context;
15
16
  this.chatbot = context.chatbot;
16
- this.tdclient = context.tdclient;
17
17
  this.intentDir = new DirIntent(context);
18
18
  this.API_ENDPOINT = context.API_ENDPOINT;
19
19
  this.log = context.log;
20
+
21
+ this.tdClient = new TiledeskClient({
22
+ projectId: this.context.projectId,
23
+ token: this.context.token,
24
+ APIURL: this.API_ENDPOINT,
25
+ APIKEY: "___",
26
+ log: this.log
27
+ });
28
+
20
29
  }
21
30
 
22
31
  execute(directive, callback) {
@@ -162,7 +171,7 @@ class DirIfOnlineAgentsV2 {
162
171
 
163
172
  async openNow() {
164
173
  return new Promise( (resolve, reject) => {
165
- this.tdclient.openNow(async (err, result) => {
174
+ this.tdClient.openNow(async (err, result) => {
166
175
  if (this.log) {console.log("(DirIfOnlineAgents) openNow():", result);}
167
176
  if (err) {
168
177
  reject(err);
@@ -10,10 +10,11 @@ class DirIfOpenHours {
10
10
  if (!context) {
11
11
  throw new Error('context object is mandatory.');
12
12
  }
13
- this.tdclient = context.tdclient;
13
+
14
14
  this.context = context;
15
15
  this.API_ENDPOINT = context.API_ENDPOINT;
16
16
  this.intentDir = new DirIntent(context);
17
+ this.log = context.log;
17
18
  }
18
19
 
19
20
  execute(directive, callback) {
@@ -129,7 +130,7 @@ class DirIfOpenHours {
129
130
  }
130
131
  )
131
132
 
132
- // this.tdclient.openNow(action.slot_id, (err, result) => {
133
+ // this.tdClient.openNow(action.slot_id, (err, result) => {
133
134
  // console.log("openNow():", result);
134
135
  // if (this.log) {console.log("openNow():", result);}
135
136
  // if (err) {
@@ -1,4 +1,4 @@
1
- // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const { DirIntent } = require('./DirIntent');
3
3
  const ms = require('minimist-string');
4
4
 
@@ -8,9 +8,19 @@ class DirIfOpenHours {
8
8
  if (!context) {
9
9
  throw new Error('context object is mandatory.');
10
10
  }
11
- this.tdclient = context.tdclient;
11
+
12
+ this.context = context;
12
13
  this.intentDir = new DirIntent(context);
13
14
  this.log = context.log;
15
+
16
+ this.API_ENDPOINT = context.API_ENDPOINT;
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
+ });
14
24
  }
15
25
 
16
26
  execute(directive, callback) {
@@ -62,7 +72,7 @@ class DirIfOpenHours {
62
72
  callback();
63
73
  return;
64
74
  }
65
- this.tdclient.openNow((err, result) => {
75
+ this.tdClient.openNow((err, result) => {
66
76
  if (this.log) {console.log("openNow():", result);}
67
77
  if (err) {
68
78
  console.error("*** DirIfOpenHours Error:", err);
@@ -2,6 +2,7 @@
2
2
  const { Directives } = require('./Directives');
3
3
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
4
  const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
5
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
5
6
 
6
7
  class DirMoveToAgent {
7
8
 
@@ -10,10 +11,19 @@ class DirMoveToAgent {
10
11
  throw new Error('context object is mandatory.');
11
12
  }
12
13
  this.context = context;
13
- this.tdclient = context.tdclient;
14
14
  this.tdcache = context.tdcache;
15
15
  this.requestId = context.requestId;
16
16
  this.log = context.log;
17
+
18
+ this.API_ENDPOINT = context.API_ENDPOINT;
19
+ this.tdClient = new TiledeskClient({
20
+ projectId: this.context.projectId,
21
+ token: this.context.token,
22
+ APIURL: this.API_ENDPOINT,
23
+ APIKEY: "___",
24
+ log: this.log
25
+ });
26
+
17
27
  }
18
28
 
19
29
  execute(directive, callback) {
@@ -24,7 +34,7 @@ class DirMoveToAgent {
24
34
  }
25
35
 
26
36
  async go(action, callback) {
27
- this.tdclient.moveToAgent(this.requestId, (err) => {
37
+ this.tdClient.moveToAgent(this.requestId, (err) => {
28
38
  if (err) {
29
39
  console.error("Error moving to agent:", err);
30
40
  }
@@ -2,6 +2,7 @@
2
2
  const { Directives } = require('./Directives');
3
3
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
4
  const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
5
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
5
6
 
6
7
  class DirMoveToUnassigned {
7
8
 
@@ -10,9 +11,17 @@ class DirMoveToUnassigned {
10
11
  throw new Error('context object is mandatory.');
11
12
  }
12
13
  this.context = context;
13
- this.tdclient = context.tdclient;
14
14
  this.requestId = context.requestId;
15
15
  this.log = context.log;
16
+
17
+ this.API_ENDPOINT = context.API_ENDPOINT;
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
+ });
16
25
  }
17
26
 
18
27
  execute(directive, callback) {
@@ -36,7 +45,7 @@ class DirMoveToUnassigned {
36
45
 
37
46
  async moveToUnassigned(requestId, callback) {
38
47
  const empty_participants = [] // STATUS WILL MOVE AUTOMATICALLY TO UNASSIGNED (100)
39
- this.tdclient.updateRequestParticipants(requestId, empty_participants, (err) => {
48
+ this.tdClient.updateRequestParticipants(requestId, empty_participants, (err) => {
40
49
  if (callback) {
41
50
  callback(err);
42
51
  }
@@ -1,6 +1,7 @@
1
1
  const { Filler } = require('../Filler');
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
4
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
4
5
 
5
6
  class DirRandomReply {
6
7
 
@@ -14,6 +15,15 @@ class DirRandomReply {
14
15
  this.token = context.token;
15
16
  this.tdcache = context.tdcache;
16
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
+ });
17
27
  }
18
28
 
19
29
  execute(directive, callback) {
@@ -87,7 +97,7 @@ class DirRandomReply {
87
97
  }
88
98
  // send!
89
99
  if (this.log) {console.log("Reply:", JSON.stringify(message))};
90
- this.context.tdclient.sendSupportMessage(
100
+ this.tdClient.sendSupportMessage(
91
101
  this.requestId,
92
102
  message,
93
103
  (err) => {
@@ -1,16 +1,26 @@
1
+ const { TiledeskClient } = require("@tiledesk/tiledesk-client");
1
2
 
2
3
  class DirRemoveCurrentBot {
3
4
 
4
- constructor(config) {
5
- if (!config.tdclient) {
6
- throw new Error('tdclient (TiledeskClient) object is mandatory.');
5
+ constructor(context) {
6
+ if (!context) {
7
+ throw new Error('context object is mandatory.');
7
8
  }
8
- this.tdclient = config.tdclient;
9
- this.requestId = config.requestId;
9
+
10
+ this.context = context;
11
+ this.requestId = context.requestId;
12
+ this.API_ENDPOINT = context.API_ENDPOINT;
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
21
  }
11
22
 
12
23
  execute(directive, callback) {
13
- console.log("Remove current bot");
14
24
  let action;
15
25
  if (directive.action) {
16
26
  action = directive.action;
@@ -27,7 +37,7 @@ class DirRemoveCurrentBot {
27
37
  }
28
38
 
29
39
  go(action, callback) {
30
- tdclient.removeCurrentBot(this.requestId, (err) => {
40
+ this.tdClient.removeCurrentBot(this.requestId, (err) => {
31
41
  callback();
32
42
  });
33
43
  }
@@ -1,3 +1,4 @@
1
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
3
  const { Filler } = require('../Filler');
3
4
 
@@ -8,9 +9,17 @@ class DirReplaceBot {
8
9
  throw new Error('context object is mandatory.');
9
10
  }
10
11
  this.context = context;
11
- this.tdclient = context.tdclient;
12
12
  this.requestId = context.requestId;
13
13
  this.log = context.log;
14
+
15
+ this.API_ENDPOINT = context.API_ENDPOINT;
16
+ this.tdClient = new TiledeskClient({
17
+ projectId: this.context.projectId,
18
+ token: this.context.token,
19
+ APIURL: this.API_ENDPOINT,
20
+ APIKEY: "___",
21
+ log: this.log
22
+ });
14
23
  }
15
24
 
16
25
  execute(directive, callback) {
@@ -42,7 +51,7 @@ class DirReplaceBot {
42
51
  );
43
52
  const filler = new Filler();
44
53
  botName = filler.fill(botName, variables);
45
- this.tdclient.replaceBotByName(this.requestId, botName, () => {
54
+ this.tdClient.replaceBotByName(this.requestId, botName, () => {
46
55
  callback();
47
56
  });
48
57
  }
@@ -1,3 +1,4 @@
1
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
3
  const { Filler } = require('../Filler');
3
4
 
@@ -8,9 +9,17 @@ class DirReplaceBotV2 {
8
9
  throw new Error('context object is mandatory.');
9
10
  }
10
11
  this.context = context;
11
- this.tdclient = context.tdclient;
12
12
  this.requestId = context.requestId;
13
13
  this.log = context.log;
14
+
15
+ this.API_ENDPOINT = context.API_ENDPOINT;
16
+ this.tdClient = new TiledeskClient({
17
+ projectId: this.context.projectId,
18
+ token: this.context.token,
19
+ APIURL: this.API_ENDPOINT,
20
+ APIKEY: "___",
21
+ log: this.log
22
+ });
14
23
  }
15
24
 
16
25
  execute(directive, callback) {
@@ -43,7 +52,7 @@ class DirReplaceBotV2 {
43
52
  );
44
53
  const filler = new Filler();
45
54
  botName = filler.fill(botName, variables);
46
- this.tdclient.replaceBotByName(this.requestId, botName, () => {
55
+ this.tdClient.replaceBotByName(this.requestId, botName, () => {
47
56
  if (blockName) {
48
57
  if (this.log) {console.log("Sending hidden /start message to bot in dept");}
49
58
  const message = {
@@ -53,7 +62,7 @@ class DirReplaceBotV2 {
53
62
  subtype: "info"
54
63
  }
55
64
  }
56
- this.tdclient.sendSupportMessage(
65
+ this.tdClient.sendSupportMessage(
57
66
  this.requestId,
58
67
  message, (err) => {
59
68
  if (err) {
@@ -2,6 +2,7 @@ const { Filler } = require('../Filler');
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
5
6
 
6
7
  class DirReply {
7
8
 
@@ -15,6 +16,15 @@ class DirReply {
15
16
  this.token = context.token;
16
17
  this.tdcache = context.tdcache;
17
18
  this.log = context.log;
19
+
20
+ this.API_ENDPOINT = context.API_ENDPOINT;
21
+ this.tdClient = new TiledeskClient({
22
+ projectId: this.context.projectId,
23
+ token: this.context.token,
24
+ APIURL: this.API_ENDPOINT,
25
+ APIKEY: "___",
26
+ log: this.log
27
+ });
18
28
  }
19
29
 
20
30
  execute(directive, callback) {
@@ -130,7 +140,7 @@ class DirReply {
130
140
  if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
131
141
  await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
132
142
  // console.log("sending message!", cleanMessage);
133
- this.context.tdclient.sendSupportMessage(
143
+ this.tdClient.sendSupportMessage(
134
144
  this.requestId,
135
145
  cleanMessage,
136
146
  (err) => {
@@ -6,6 +6,7 @@ const { DirIntent } = require("./DirIntent");
6
6
  // const { defaultOptions } = require('liquidjs');
7
7
  const { DirMessageToBot } = require('./DirMessageToBot');
8
8
  const { v4: uuidv4 } = require('uuid');
9
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
9
10
 
10
11
  class DirReplyV2 {
11
12
 
@@ -23,6 +24,15 @@ class DirReplyV2 {
23
24
  this.chatbot = context.chatbot;
24
25
  this.reply = context.reply;
25
26
  this.originalMessage = context.message;
27
+
28
+ this.API_ENDPOINT = context.API_ENDPOINT;
29
+ this.tdClient = new TiledeskClient({
30
+ projectId: this.context.projectId,
31
+ token: this.context.token,
32
+ APIURL: this.API_ENDPOINT,
33
+ APIKEY: "___",
34
+ log: this.log
35
+ });
26
36
  }
27
37
 
28
38
  execute(directive, callback) {
@@ -263,7 +273,7 @@ class DirReplyV2 {
263
273
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
264
274
  if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
265
275
  await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
266
- this.context.tdclient.sendSupportMessage(
276
+ this.tdClient.sendSupportMessage(
267
277
  this.requestId,
268
278
  cleanMessage,
269
279
  (err) => {
@@ -2,6 +2,7 @@ const { param } = require('express/lib/request');
2
2
  const ms = require('minimist-string');
3
3
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
4
4
  const { Filler } = require('../Filler');
5
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
5
6
  // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
7
 
7
8
  class DirSendEmail {
@@ -11,10 +12,18 @@ class DirSendEmail {
11
12
  throw new Error('context object is mandatory.');
12
13
  }
13
14
  this.context = context;
14
- this.tdclient = context.tdclient;
15
15
  this.tdcache = context.tdcache;
16
16
  this.requestId = context.requestId;
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
+ });
18
27
  }
19
28
 
20
29
  execute(directive, callback) {
@@ -64,7 +73,7 @@ class DirSendEmail {
64
73
  replyto: reply_to
65
74
  }
66
75
  // console.log("email message:", JSON.stringify(message));
67
- const message_echo = await this.tdclient.sendEmail(message);
76
+ const message_echo = await this.tdClient.sendEmail(message);
68
77
  if (this.log) {console.log("email sent. filled_subject:", filled_subject);}
69
78
  if (this.log) {console.log("email sent. filled_text:", filled_text);}
70
79
  if (this.log) {console.log("email sent. filled_to:", filled_to);}
@@ -1,3 +1,4 @@
1
+ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
1
2
  const { Filler } = require('../Filler');
2
3
 
3
4
  class DirSetConversationTags {
@@ -8,8 +9,16 @@ class DirSetConversationTags {
8
9
  }
9
10
  this.context = context;
10
11
  this.log = context.log;
11
- this.tdclient = context.tdclient;
12
12
  this.requestId = context.requestId;
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
+ });
13
22
  }
14
23
 
15
24
  execute(directive, callback) {
@@ -72,7 +81,7 @@ class DirSetConversationTags {
72
81
  subtype: "info"
73
82
  }
74
83
  }
75
- this.tdclient.sendSupportMessage(
84
+ this.tdClient.sendSupportMessage(
76
85
  this.requestId,
77
86
  message, (err) => {
78
87
  if (err) {
@@ -91,7 +100,7 @@ class DirSetConversationTags {
91
100
  }
92
101
 
93
102
  moveToDepartment(requestId, depName, callback) {
94
- this.tdclient.getAllDepartments((err, deps) => {
103
+ this.tdClient.getAllDepartments((err, deps) => {
95
104
  if (this.log) {console.log("deps:", JSON.stringify(deps));}
96
105
  if (err) {
97
106
  console.error("getAllDepartments() error:", err);
@@ -108,7 +117,7 @@ class DirSetConversationTags {
108
117
  }
109
118
  }
110
119
  if (dep) {
111
- this.tdclient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
120
+ this.tdClient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
112
121
  if (err) {
113
122
  console.error("DirDepartment error:", err);
114
123
  callback();
@@ -8,7 +8,6 @@ class DirWait {
8
8
  throw new Error('context object is mandatory.');
9
9
  }
10
10
  this.context = context;
11
- this.tdclient = context.tdclient;
12
11
  this.chatbot = context.chatbot;
13
12
  this.tdcache = context.tdcache;
14
13
  this.requestId = context.requestId;
@@ -10,7 +10,6 @@ class DirWebRequest {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
- this.tdclient = context.tdclient;
14
13
  this.tdcache = context.tdcache;
15
14
  this.requestId = context.requestId;
16
15
  this.log = context.log;
@@ -10,7 +10,6 @@ class DirWebRequestV2 {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
- this.tdclient = context.tdclient;
14
13
  this.tdcache = context.tdcache;
15
14
  this.requestId = context.requestId;
16
15
  this.intentDir = new DirIntent(context);