@tiledesk/tiledesk-tybot-connector 0.2.142 → 0.2.143
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 +13 -0
- package/TdCache.js +4 -4
- package/index.js +7 -6
- package/models/TiledeskChatbot.js +2 -2
- package/models/TiledeskChatbotUtil.js +1 -1
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +0 -6
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +125 -20
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,12 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
+
# v0.2.143
|
|
21
|
+
- Changed: env var TILEBOT_ENDPOINT replaced with TILEBOT_ENDPOINT
|
|
22
|
+
|
|
23
|
+
# v0.2.142
|
|
24
|
+
- Bug-fix: action.isInfo added in DirMessage fo fix test
|
|
25
|
+
|
|
20
26
|
# v0.2.141
|
|
21
27
|
- Bug-fix: message.attributes.payload not not visible on first message
|
|
22
28
|
|
|
@@ -31,6 +37,13 @@ available on:
|
|
|
31
37
|
- Bug-fixed: hiddenMessage not blocked
|
|
32
38
|
- Bug-fixed: DirAskGPTV2 has hardcoded engine
|
|
33
39
|
|
|
40
|
+
# v0.2.138-rc8
|
|
41
|
+
- Updated redis to 4.7.0
|
|
42
|
+
- Updated tdCache
|
|
43
|
+
|
|
44
|
+
# v0.2.138-rc6
|
|
45
|
+
- First deploy external
|
|
46
|
+
|
|
34
47
|
# v0.2.138-rc1
|
|
35
48
|
- Updated redis to 4.7.0
|
|
36
49
|
- Updated tdCache
|
package/TdCache.js
CHANGED
|
@@ -21,10 +21,10 @@ class TdCache {
|
|
|
21
21
|
* Connect redis client
|
|
22
22
|
*/
|
|
23
23
|
this.client = redis.createClient(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
{
|
|
25
|
+
url: `redis://${this.redis_host}:${this.redis_port}`,
|
|
26
|
+
password: this.redis_password
|
|
27
|
+
});
|
|
28
28
|
this.client.on('error', err => {
|
|
29
29
|
reject(err);
|
|
30
30
|
if (callback) {
|
package/index.js
CHANGED
|
@@ -211,7 +211,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
211
211
|
chatbot: chatbot,
|
|
212
212
|
supportRequest: message.request,
|
|
213
213
|
API_ENDPOINT: API_ENDPOINT,
|
|
214
|
-
TILEBOT_ENDPOINT:process.env.
|
|
214
|
+
TILEBOT_ENDPOINT:process.env.TILEBOT_ENDPOINT,
|
|
215
215
|
token: token,
|
|
216
216
|
log: log,
|
|
217
217
|
// HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT,
|
|
@@ -237,8 +237,8 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
237
237
|
reply.attributes.markbot = true;
|
|
238
238
|
reply.attributes.fillParams = true;
|
|
239
239
|
let extEndpoint = `${API_ENDPOINT}/modules/tilebot/`;
|
|
240
|
-
if (process.env.
|
|
241
|
-
extEndpoint = `${process.env.
|
|
240
|
+
if (process.env.TILEBOT_ENDPOINT) {
|
|
241
|
+
extEndpoint = `${process.env.TILEBOT_ENDPOINT}`;
|
|
242
242
|
}
|
|
243
243
|
const apiext = new ExtApi({
|
|
244
244
|
ENDPOINT: extEndpoint,
|
|
@@ -314,9 +314,9 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
314
314
|
if (log) {
|
|
315
315
|
console.log("/ext request....", JSON.stringify(request));
|
|
316
316
|
console.log("/ext API_ENDPOINT....", API_ENDPOINT);
|
|
317
|
-
console.log("/ext process.env.
|
|
317
|
+
console.log("/ext process.env.TILEBOT_ENDPOINT....", process.env.TILEBOT_ENDPOINT);
|
|
318
318
|
}
|
|
319
|
-
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT:process.env.
|
|
319
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT:process.env.TILEBOT_ENDPOINT, token: token, log: log, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT, cache: tdcache});
|
|
320
320
|
// let directivesPlug = null;
|
|
321
321
|
// PIPELINE-EXT
|
|
322
322
|
// if (log) {console.log("answer to process:", JSON.stringify(answer));}
|
|
@@ -601,7 +601,7 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
601
601
|
"token": "NO-TOKEN"
|
|
602
602
|
}
|
|
603
603
|
if (this.log) {console.log("sendMessageToBot()...", JSON.stringify(request));}
|
|
604
|
-
sendMessageToBot(process.env.
|
|
604
|
+
sendMessageToBot(process.env.TILEBOT_ENDPOINT, request, bot_id, async () => {
|
|
605
605
|
res.status(200).send({"success":true});
|
|
606
606
|
return;
|
|
607
607
|
});
|
|
@@ -609,6 +609,7 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
609
609
|
|
|
610
610
|
async function startApp(settings, completionCallback) {
|
|
611
611
|
console.log("Starting Tilebot...");
|
|
612
|
+
// console.log("Starting Tilebot with Settings:", settings);
|
|
612
613
|
if (settings.bots) { // static bots data source
|
|
613
614
|
staticBots = settings.bots;
|
|
614
615
|
}
|
|
@@ -387,8 +387,8 @@ class TiledeskChatbot {
|
|
|
387
387
|
// ON THE MAIN SERVER. OTHERWISE WE USE TYBOT_ROUTE TO SPECIFY
|
|
388
388
|
// THE ALTERNATIVE ROUTE.
|
|
389
389
|
// let extEndpoint = `${this.APIURL}/modules/tilebot/`;
|
|
390
|
-
// if (process.env.
|
|
391
|
-
// extEndpoint = `${process.env.
|
|
390
|
+
// if (process.env.TILEBOT_ENDPOINT) {
|
|
391
|
+
// extEndpoint = `${process.env.TILEBOT_ENDPOINT}`;
|
|
392
392
|
// }
|
|
393
393
|
// const apiext = new ExtApi({
|
|
394
394
|
// ENDPOINT: extEndpoint,
|
|
@@ -927,7 +927,7 @@ class TiledeskChatbotUtil {
|
|
|
927
927
|
*/
|
|
928
928
|
getChatbotParameters(requestId, callback) {
|
|
929
929
|
// const jwt_token = this.fixToken(token);
|
|
930
|
-
const url = `${process.env.
|
|
930
|
+
const url = `${process.env.TILEBOT_ENDPOINT}/ext/reserved/parameters/requests/${requestId}?all`;
|
|
931
931
|
const HTTPREQUEST = {
|
|
932
932
|
url: url,
|
|
933
933
|
headers: {
|
package/package.json
CHANGED
|
@@ -2,12 +2,6 @@ let axios = require('axios');
|
|
|
2
2
|
|
|
3
3
|
class WebhookChatbotPlug {
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* @example
|
|
7
|
-
* const { DirectivesChatbotPlug } = require('./DirectivesChatbotPlug');
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
5
|
constructor(supportRequest, webhookurl, token, log) {
|
|
12
6
|
this.supportRequest = supportRequest;
|
|
13
7
|
this.webhookurl = webhookurl;
|
|
@@ -2,6 +2,9 @@ const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
|
2
2
|
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
3
3
|
const { Filler } = require('../Filler');
|
|
4
4
|
|
|
5
|
+
const axios = require("axios").default;
|
|
6
|
+
let https = require("https");
|
|
7
|
+
|
|
5
8
|
class DirReplaceBotV2 {
|
|
6
9
|
|
|
7
10
|
constructor(context) {
|
|
@@ -52,30 +55,132 @@ class DirReplaceBotV2 {
|
|
|
52
55
|
);
|
|
53
56
|
const filler = new Filler();
|
|
54
57
|
botName = filler.fill(botName, variables);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
63
83
|
}
|
|
64
84
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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"
|
|
70
94
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
}
|
|
77
109
|
}
|
|
78
|
-
|
|
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
|
+
});
|
|
79
184
|
}
|
|
80
185
|
}
|
|
81
186
|
|