@tiledesk/tiledesk-tybot-connector 0.2.601-rc1 → 0.3.0
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 +378 -1
- package/ExtApi.js +6 -6
- package/TdCache copy.js +242 -0
- package/TdCache.js +81 -176
- package/TdCache_v3.js +261 -0
- package/TiledeskExpression.js +7 -3
- package/index.js +290 -43
- package/logs/app.log +279 -0
- package/models/IntentsMachineFactory.js +5 -2
- package/models/MockBotsDataSource.js +19 -11
- package/models/TiledeskChatbot.js +97 -79
- package/models/TiledeskChatbotConst.js +12 -17
- package/models/TiledeskChatbotUtil.js +353 -109
- package/models/TiledeskIntentsMachine.js +1 -1
- package/models/faqKbService.js +1 -1
- package/package.json +7 -6
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +172 -106
- package/tiledeskChatbotPlugs/Filler.js +13 -2
- package/tiledeskChatbotPlugs/TildeskContextForCodeOrchestrator.js +8 -0
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +13 -7
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +374 -0
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +476 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +16 -19
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +221 -34
- package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -11
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +11 -21
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +728 -0
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +353 -0
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +3 -30
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +22 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +16 -3
- package/tiledeskChatbotPlugs/directives/DirCode.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -26
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +183 -0
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +121 -0
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +11 -1
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +15 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +17 -6
- package/tiledeskChatbotPlugs/directives/DirForm.js +12 -2
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +83 -38
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +4 -7
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +14 -27
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +278 -0
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +147 -51
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +125 -0
- package/tiledeskChatbotPlugs/directives/DirIntent.js +8 -36
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +5 -26
- package/tiledeskChatbotPlugs/directives/DirMessage.js +19 -17
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +136 -0
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +20 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +59 -0
- package/tiledeskChatbotPlugs/directives/DirQapla.js +6 -9
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +17 -7
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +17 -7
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +11 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +135 -21
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +163 -0
- package/tiledeskChatbotPlugs/directives/DirReply.js +42 -9
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +347 -0
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +13 -23
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +247 -0
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +202 -15
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +13 -4
- package/tiledeskChatbotPlugs/directives/DirWait.js +21 -4
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +166 -103
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +2 -60
- package/tiledeskChatbotPlugs/directives/Directives.js +16 -1
- /package/tiledeskChatbotPlugs/directives/{DirOfflineHours.js → DEPRECATED_DirOfflineHours.js} +0 -0
|
@@ -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) {
|
|
@@ -281,18 +278,18 @@ class DirQapla {
|
|
|
281
278
|
}
|
|
282
279
|
})
|
|
283
280
|
.catch((error) => {
|
|
284
|
-
|
|
281
|
+
console.error("(DirQapla) Axios error: ", JSON.stringify(error));
|
|
285
282
|
if (callback) {
|
|
286
283
|
callback(error, null);
|
|
287
284
|
}
|
|
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
|
|
@@ -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) {
|
|
@@ -78,16 +88,16 @@ class DirRandomReply {
|
|
|
78
88
|
message.attributes = {}
|
|
79
89
|
}
|
|
80
90
|
// Reserved names: userEmail, userFullname
|
|
81
|
-
if (requestVariables['userEmail']) {
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (requestVariables['userFullname']) {
|
|
85
|
-
|
|
86
|
-
}
|
|
91
|
+
// if (requestVariables['userEmail']) {
|
|
92
|
+
// message.attributes.updateUserEmail = requestVariables['userEmail'];
|
|
93
|
+
// }
|
|
94
|
+
// if (requestVariables['userFullname']) {
|
|
95
|
+
// message.attributes.updateUserFullname = requestVariables['userFullname'];
|
|
96
|
+
// }
|
|
87
97
|
}
|
|
88
98
|
// send!
|
|
89
99
|
if (this.log) {console.log("Reply:", JSON.stringify(message))};
|
|
90
|
-
this.
|
|
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(
|
|
5
|
-
if (!
|
|
6
|
-
throw new Error('
|
|
5
|
+
constructor(context) {
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error('context object is mandatory.');
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
this.
|
|
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
|
-
|
|
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.
|
|
54
|
+
this.tdClient.replaceBotByName(this.requestId, botName, () => {
|
|
46
55
|
callback();
|
|
47
56
|
});
|
|
48
57
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
1
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
2
3
|
const { Filler } = require('../Filler');
|
|
3
4
|
|
|
5
|
+
const axios = require("axios").default;
|
|
6
|
+
let https = require("https");
|
|
7
|
+
|
|
4
8
|
class DirReplaceBotV2 {
|
|
5
9
|
|
|
6
10
|
constructor(context) {
|
|
@@ -8,9 +12,17 @@ class DirReplaceBotV2 {
|
|
|
8
12
|
throw new Error('context object is mandatory.');
|
|
9
13
|
}
|
|
10
14
|
this.context = context;
|
|
11
|
-
this.tdclient = context.tdclient;
|
|
12
15
|
this.requestId = context.requestId;
|
|
13
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
|
+
});
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
execute(directive, callback) {
|
|
@@ -43,30 +55,132 @@ class DirReplaceBotV2 {
|
|
|
43
55
|
);
|
|
44
56
|
const filler = new Filler();
|
|
45
57
|
botName = filler.fill(botName, variables);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
|
|
59
|
+
let data = {};
|
|
60
|
+
if (action.nameAsSlug && action.nameAsSlug === true) {
|
|
61
|
+
data.slug = botName;
|
|
62
|
+
} else {
|
|
63
|
+
data.name = botName;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const HTTPREQUEST = {
|
|
67
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + "/replace",
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
'Authorization': 'JWT ' + this.context.token
|
|
71
|
+
},
|
|
72
|
+
json: data,
|
|
73
|
+
method: 'PUT'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.#myrequest(
|
|
77
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
78
|
+
if (err) {
|
|
79
|
+
console.log("DirReplaceBot error: ", err);
|
|
80
|
+
if (callback) {
|
|
81
|
+
callback();
|
|
82
|
+
return;
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
|
|
86
|
+
if (this.log) { console.log("DirReplaceBot replace resbody: ", resbody) };
|
|
87
|
+
if (blockName) {
|
|
88
|
+
if (this.log) { console.log("Sending hidden /start message to bot in dept"); }
|
|
89
|
+
const message = {
|
|
90
|
+
type: "text",
|
|
91
|
+
text: "/" + blockName,
|
|
92
|
+
attributes: {
|
|
93
|
+
subtype: "info"
|
|
61
94
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
95
|
+
}
|
|
96
|
+
this.tdClient.sendSupportMessage(
|
|
97
|
+
this.requestId,
|
|
98
|
+
message, (err) => {
|
|
99
|
+
if (err) {
|
|
100
|
+
console.error("Error sending hidden message:", err.message);
|
|
101
|
+
}
|
|
102
|
+
if (this.log) { console.log("Hidden message sent."); }
|
|
103
|
+
callback();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
callback();
|
|
108
|
+
}
|
|
68
109
|
}
|
|
69
|
-
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
// this.tdClient.replaceBotByName(this.requestId, botName, () => {
|
|
113
|
+
// if (blockName) {
|
|
114
|
+
// if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
115
|
+
// const message = {
|
|
116
|
+
// type: "text",
|
|
117
|
+
// text: "/" + blockName,
|
|
118
|
+
// attributes : {
|
|
119
|
+
// subtype: "info"
|
|
120
|
+
// }
|
|
121
|
+
// }
|
|
122
|
+
// this.tdClient.sendSupportMessage(
|
|
123
|
+
// this.requestId,
|
|
124
|
+
// message, (err) => {
|
|
125
|
+
// if (err) {
|
|
126
|
+
// console.error("Error sending hidden message:", err.message);
|
|
127
|
+
// }
|
|
128
|
+
// if (this.log) {console.log("Hidden message sent.");}
|
|
129
|
+
// callback();
|
|
130
|
+
// });
|
|
131
|
+
// }
|
|
132
|
+
// else {
|
|
133
|
+
// callback();
|
|
134
|
+
// }
|
|
135
|
+
// });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#myrequest(options, callback) {
|
|
139
|
+
if (this.log) {
|
|
140
|
+
console.log("API URL:", options.url);
|
|
141
|
+
console.log("** Options:", JSON.stringify(options));
|
|
142
|
+
}
|
|
143
|
+
let axios_options = {
|
|
144
|
+
url: options.url,
|
|
145
|
+
method: options.method,
|
|
146
|
+
params: options.params,
|
|
147
|
+
headers: options.headers
|
|
148
|
+
}
|
|
149
|
+
if (options.json !== null) {
|
|
150
|
+
axios_options.data = options.json
|
|
151
|
+
}
|
|
152
|
+
if (this.log) {
|
|
153
|
+
console.log("axios_options:", JSON.stringify(axios_options));
|
|
154
|
+
}
|
|
155
|
+
if (options.url.startsWith("https:")) {
|
|
156
|
+
const httpsAgent = new https.Agent({
|
|
157
|
+
rejectUnauthorized: false,
|
|
158
|
+
});
|
|
159
|
+
axios_options.httpsAgent = httpsAgent;
|
|
160
|
+
}
|
|
161
|
+
axios(axios_options)
|
|
162
|
+
.then((res) => {
|
|
163
|
+
if (this.log) {
|
|
164
|
+
console.log("Response for url:", options.url);
|
|
165
|
+
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
166
|
+
}
|
|
167
|
+
if (res && res.status == 200 && res.data) {
|
|
168
|
+
if (callback) {
|
|
169
|
+
callback(null, res.data);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (callback) {
|
|
174
|
+
callback(new Error("Response status is not 200"), null);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
.catch((error) => {
|
|
179
|
+
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
180
|
+
if (callback) {
|
|
181
|
+
callback(error, null);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
70
184
|
}
|
|
71
185
|
}
|
|
72
186
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
2
|
+
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
|
+
const { Filler } = require('../Filler');
|
|
4
|
+
|
|
5
|
+
const axios = require("axios").default;
|
|
6
|
+
let https = require("https");
|
|
7
|
+
|
|
8
|
+
class DirReplaceBotV3 {
|
|
9
|
+
|
|
10
|
+
constructor(context) {
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('context object is mandatory.');
|
|
13
|
+
}
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.requestId = context.requestId;
|
|
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
|
+
}
|
|
27
|
+
|
|
28
|
+
execute(directive, callback) {
|
|
29
|
+
if (this.log) {console.log("Replacing bot");}
|
|
30
|
+
let action;
|
|
31
|
+
if (directive.action) {
|
|
32
|
+
action = directive.action;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.error("DirReplaceBot Incorrect directive: ", JSON.stringify(directive));
|
|
36
|
+
callback();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.go(action, () => {
|
|
40
|
+
callback();
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async go(action, callback) {
|
|
45
|
+
let botId = action.botId;
|
|
46
|
+
let botSlug = action.botSlug;
|
|
47
|
+
let useSlug = action.useSlug;
|
|
48
|
+
let blockName = action.blockName;
|
|
49
|
+
let variables = null;
|
|
50
|
+
variables =
|
|
51
|
+
await TiledeskChatbot.allParametersStatic(
|
|
52
|
+
this.context.tdcache, this.context.requestId
|
|
53
|
+
);
|
|
54
|
+
const filler = new Filler();
|
|
55
|
+
//botId = filler.fill(botId, variables);
|
|
56
|
+
botSlug = filler.fill(botSlug, variables);
|
|
57
|
+
blockName = filler.fill(blockName, variables);
|
|
58
|
+
|
|
59
|
+
let data = {};
|
|
60
|
+
if (useSlug && useSlug === true) {
|
|
61
|
+
data.slug = botSlug;
|
|
62
|
+
} else {
|
|
63
|
+
data.id = botId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const HTTPREQUEST = {
|
|
67
|
+
url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + "/replace",
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
'Authorization': 'JWT ' + this.context.token
|
|
71
|
+
},
|
|
72
|
+
json: data,
|
|
73
|
+
method: 'PUT'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.#myrequest(
|
|
77
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
78
|
+
if (err) {
|
|
79
|
+
console.log("DirReplaceBot error: ", err);
|
|
80
|
+
if (callback) {
|
|
81
|
+
callback();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (this.log) { console.log("DirReplaceBot replace resbody: ", resbody) };
|
|
87
|
+
if (blockName) {
|
|
88
|
+
if (this.log) { console.log("Sending hidden /start message to bot in dept"); }
|
|
89
|
+
const message = {
|
|
90
|
+
type: "text",
|
|
91
|
+
text: "/" + blockName,
|
|
92
|
+
attributes: {
|
|
93
|
+
subtype: "info"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.tdClient.sendSupportMessage(
|
|
97
|
+
this.requestId,
|
|
98
|
+
message, (err) => {
|
|
99
|
+
if (err) {
|
|
100
|
+
console.error("Error sending hidden message:", err.message);
|
|
101
|
+
}
|
|
102
|
+
if (this.log) { console.log("Hidden message sent."); }
|
|
103
|
+
callback();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
callback();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#myrequest(options, callback) {
|
|
114
|
+
if (this.log) {
|
|
115
|
+
console.log("API URL:", options.url);
|
|
116
|
+
console.log("** Options:", JSON.stringify(options));
|
|
117
|
+
}
|
|
118
|
+
let axios_options = {
|
|
119
|
+
url: options.url,
|
|
120
|
+
method: options.method,
|
|
121
|
+
params: options.params,
|
|
122
|
+
headers: options.headers
|
|
123
|
+
}
|
|
124
|
+
if (options.json !== null) {
|
|
125
|
+
axios_options.data = options.json
|
|
126
|
+
}
|
|
127
|
+
if (this.log) {
|
|
128
|
+
console.log("axios_options:", JSON.stringify(axios_options));
|
|
129
|
+
}
|
|
130
|
+
if (options.url.startsWith("https:")) {
|
|
131
|
+
const httpsAgent = new https.Agent({
|
|
132
|
+
rejectUnauthorized: false,
|
|
133
|
+
});
|
|
134
|
+
axios_options.httpsAgent = httpsAgent;
|
|
135
|
+
}
|
|
136
|
+
axios(axios_options)
|
|
137
|
+
.then((res) => {
|
|
138
|
+
if (this.log) {
|
|
139
|
+
console.log("Response for url:", options.url);
|
|
140
|
+
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
141
|
+
}
|
|
142
|
+
if (res && res.status == 200 && res.data) {
|
|
143
|
+
if (callback) {
|
|
144
|
+
callback(null, res.data);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
if (callback) {
|
|
149
|
+
callback(new Error("Response status is not 200"), null);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
.catch((error) => {
|
|
154
|
+
console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
|
|
155
|
+
if (callback) {
|
|
156
|
+
callback(error, null);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = { DirReplaceBotV3 };
|
|
@@ -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) {
|
|
@@ -77,6 +87,12 @@ class DirReply {
|
|
|
77
87
|
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
|
|
78
88
|
if (this.log) {console.log("command filled:", command.message.text);}
|
|
79
89
|
}
|
|
90
|
+
if (command.type === 'settings' && command.settings) {
|
|
91
|
+
Object.keys(command.settings).forEach(k => {
|
|
92
|
+
command.settings[k] = filler.fill(command.settings[k], requestAttributes)
|
|
93
|
+
if (this.log) {console.log("settings command filled:", command.settings[k]);}
|
|
94
|
+
})
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
}
|
|
@@ -94,16 +110,32 @@ class DirReply {
|
|
|
94
110
|
message.attributes = {}
|
|
95
111
|
}
|
|
96
112
|
// Reserved names: userEmail, userFullname
|
|
97
|
-
if (requestAttributes['userEmail']) {
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
if (requestAttributes['userFullname']) {
|
|
101
|
-
|
|
102
|
-
}
|
|
113
|
+
// if (requestAttributes['userEmail']) {
|
|
114
|
+
// message.attributes.updateUserEmail = requestAttributes['userEmail'];
|
|
115
|
+
// }
|
|
116
|
+
// if (requestAttributes['userFullname']) {
|
|
117
|
+
// message.attributes.updateUserFullname = requestAttributes['userFullname'];
|
|
118
|
+
// }
|
|
103
119
|
// intent_info
|
|
104
120
|
if (this.context.reply && this.context.reply.attributes && this.context.reply.attributes.intent_info) {
|
|
105
121
|
message.attributes.intentName = this.context.reply.attributes.intent_info.intent_name;
|
|
106
122
|
}
|
|
123
|
+
// userFlowAttributes
|
|
124
|
+
let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
|
|
125
|
+
if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
|
|
126
|
+
if (userFlowAttributes) {
|
|
127
|
+
message.attributes["flowAttributes"] = {};
|
|
128
|
+
for (const [key, value] of Object.entries(userFlowAttributes)) {
|
|
129
|
+
try {
|
|
130
|
+
if(typeof value === 'string' && value.length <= 1000){
|
|
131
|
+
message.attributes["flowAttributes"][key] = value;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch(err) {
|
|
135
|
+
console.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
107
139
|
}
|
|
108
140
|
// send!
|
|
109
141
|
let cleanMessage = message;
|
|
@@ -113,18 +145,19 @@ class DirReply {
|
|
|
113
145
|
// callback(); // cancel reply operation
|
|
114
146
|
// return;
|
|
115
147
|
// }
|
|
116
|
-
|
|
148
|
+
|
|
117
149
|
cleanMessage.senderFullname = this.context.chatbot.bot.name;
|
|
118
150
|
if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
|
|
119
151
|
await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
|
|
120
|
-
|
|
152
|
+
// console.log("sending message!", cleanMessage);
|
|
153
|
+
this.tdClient.sendSupportMessage(
|
|
121
154
|
this.requestId,
|
|
122
155
|
cleanMessage,
|
|
123
156
|
(err) => {
|
|
124
157
|
if (err) {
|
|
125
158
|
console.error("Error sending reply:", err);
|
|
126
159
|
}
|
|
127
|
-
if (this.log) {console.log("Reply message sent");}
|
|
160
|
+
if (this.log) {console.log("Reply message sent:", JSON.stringify(cleanMessage));}
|
|
128
161
|
const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
|
|
129
162
|
// console.log("got total delay:", delay)
|
|
130
163
|
if (delay > 0 && delay <= 30000) { // prevent long delays
|