@tiledesk/tiledesk-tybot-connector 0.2.120 → 0.2.122
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 +8 -1
- package/ExtApi.js +1 -1
- package/index.js +6 -6
- package/models/TiledeskChatbot.js +1 -1
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +12 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -174
- package/tiledeskChatbotPlugs/directives/DirIntent.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -17,7 +17,14 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
-
# v0.2.
|
|
20
|
+
# v0.2.122 -> test
|
|
21
|
+
- fixed check if (!this.validWebhookURL(this.webhookurl)) {... on WebhookChatbotPlug.js with return
|
|
22
|
+
- removed logs, err => JSON.stringify(err)
|
|
23
|
+
|
|
24
|
+
# v0.2.121 -> test
|
|
25
|
+
- added check if (!this.validWebhookURL(this.webhookurl)) {... on WebhookChatbotPlug.js
|
|
26
|
+
|
|
27
|
+
# v0.2.120 -> prod
|
|
21
28
|
- removed check in go() - it is already in execute() - on SetAttributeV2: if (!action) {...}
|
|
22
29
|
- merged Whatsapp Action
|
|
23
30
|
- updated "@tiledesk/tiledesk-client": "^0.10.13"
|
package/ExtApi.js
CHANGED
package/index.js
CHANGED
|
@@ -182,7 +182,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
182
182
|
reply = await chatbot.replyToMessage(message);
|
|
183
183
|
}
|
|
184
184
|
catch(err) {
|
|
185
|
-
console.error("An error occurred replying to message:", JSON.stringify(message), "\nError:", err );
|
|
185
|
+
console.error("(tybotRoute) An error occurred replying to message:", JSON.stringify(message), "\nError:", err );
|
|
186
186
|
}
|
|
187
187
|
if (!reply) {
|
|
188
188
|
reply = {
|
|
@@ -569,8 +569,8 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
569
569
|
const bot_id = req.params['bot_id'];
|
|
570
570
|
const block_id = req.params['block_id'];
|
|
571
571
|
const body = req.body;
|
|
572
|
-
console.log('/block/:project_id/:bot_id/:block_id:', project_id, "/", bot_id, "/", block_id);
|
|
573
|
-
console.log('/block/:project_id/:bot_id/:block_id.body', body);
|
|
572
|
+
// console.log('/block/:project_id/:bot_id/:block_id:', project_id, "/", bot_id, "/", block_id);
|
|
573
|
+
// console.log('/block/:project_id/:bot_id/:block_id.body', body);
|
|
574
574
|
|
|
575
575
|
// invoke block
|
|
576
576
|
// unique ID for each execution
|
|
@@ -588,11 +588,11 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
588
588
|
"attributes": {
|
|
589
589
|
"payload": body
|
|
590
590
|
}
|
|
591
|
-
}
|
|
591
|
+
}
|
|
592
592
|
}
|
|
593
593
|
console.log("sendMessageToBot()...");
|
|
594
594
|
sendMessageToBot(process.env.TYBOT_ENDPOINT, request, bot_id, async () => {
|
|
595
|
-
console.log("Async webhook message sent:\n", request);
|
|
595
|
+
// console.log("Async webhook message sent:\n", request);
|
|
596
596
|
res.status(200).send({"success":true});
|
|
597
597
|
return;
|
|
598
598
|
});
|
|
@@ -785,7 +785,7 @@ function myrequest(options, callback, log) {
|
|
|
785
785
|
}
|
|
786
786
|
})
|
|
787
787
|
.catch((error) => {
|
|
788
|
-
console.error("An error occurred:", error);
|
|
788
|
+
console.error("(tybotRoute index) An error occurred:", JSON.stringify(error), "url:", options.url);
|
|
789
789
|
if (callback) {
|
|
790
790
|
callback(error, null, null);
|
|
791
791
|
}
|
|
@@ -267,7 +267,7 @@ class TiledeskChatbot {
|
|
|
267
267
|
if (this.log) {console.log("got faq by EXACT MATCH", faqs);}
|
|
268
268
|
}
|
|
269
269
|
catch (error) {
|
|
270
|
-
console.error("An error occurred during exact match:", error);
|
|
270
|
+
console.error("(TiledeskChatbot) An error occurred during exact match:", JSON.stringify(error));
|
|
271
271
|
}
|
|
272
272
|
if (faqs && faqs.length > 0 && faqs[0].answer) {
|
|
273
273
|
if (this.log) {console.log("EXACT MATCH OR ACTION FAQ:", faqs[0]);}
|
package/package.json
CHANGED
|
@@ -22,6 +22,11 @@ class WebhookChatbotPlug {
|
|
|
22
22
|
if (answer.attributes && answer.attributes.webhook && answer.attributes.webhook === true) {
|
|
23
23
|
if (this.log) {console.log("EXECUTING WEBHOOK URL!", this.webhookurl);}
|
|
24
24
|
if (this.log) {console.log("EXECUTING WEBHOOK ON CONTEXT:", JSON.stringify(context));}
|
|
25
|
+
if (!this.validWebhookURL(this.webhookurl)) {
|
|
26
|
+
if (this.log) {console.error("(WebhookChatbotPlug) Error. Invalid webhook URL:", this.webhookurl, "on context:", JSON.stringify(context));}
|
|
27
|
+
pipeline.nextplug();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
25
30
|
this.execWebhook(answer, context, this.webhookurl, (err, message_from_webhook) => {
|
|
26
31
|
if (this.log) {console.log("message_from_webhook:", message_from_webhook);}
|
|
27
32
|
if (err) {
|
|
@@ -67,6 +72,13 @@ class WebhookChatbotPlug {
|
|
|
67
72
|
if (this.log) {console.log("Start processing webhook...");}
|
|
68
73
|
}
|
|
69
74
|
|
|
75
|
+
validWebhookURL(webhookurl) {
|
|
76
|
+
if (!webhookurl) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
execWebhook(reply_message, context, webhookurl, callback) {
|
|
71
83
|
if (this.log) {
|
|
72
84
|
console.log("WEBHOOK. on context", JSON.stringify(context));
|
|
@@ -191,7 +191,7 @@ class DirConnectBlock {
|
|
|
191
191
|
}
|
|
192
192
|
})
|
|
193
193
|
.catch( (error) => {
|
|
194
|
-
console.error("An error occurred:", error);
|
|
194
|
+
console.error("An error occurred:", JSON.stringify(error), "url:", options.url);
|
|
195
195
|
if (callback) {
|
|
196
196
|
callback(error, null, null);
|
|
197
197
|
}
|
|
@@ -110,7 +110,6 @@ class DirIfOnlineAgentsV2 {
|
|
|
110
110
|
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all | getProjectAvailableAgents(null, true)"); }
|
|
111
111
|
agents = await this.getProjectAvailableAgents(null, true);
|
|
112
112
|
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
113
|
-
console.log("(DirIfOnlineAgents) agents:", agents);
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
if (agents && agents.length > 0) {
|
|
@@ -154,7 +153,7 @@ class DirIfOnlineAgentsV2 {
|
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
catch(err) {
|
|
157
|
-
console.error("(DirIfOnlineAgents) An error occurred:"
|
|
156
|
+
console.error("(DirIfOnlineAgents) An error occurred:" + err);
|
|
158
157
|
this.chatbot.addParameter("flowError", "(If online Agents) An error occurred: " + err);
|
|
159
158
|
callback();
|
|
160
159
|
}
|
|
@@ -209,178 +208,6 @@ class DirIfOnlineAgentsV2 {
|
|
|
209
208
|
|
|
210
209
|
}
|
|
211
210
|
|
|
212
|
-
// async getDepartmentAvailableAgents(depId) {
|
|
213
|
-
// return new Promise( (resolve, reject) => {
|
|
214
|
-
// this.tdclient.getDepartment(depId, async (error, dep) => {
|
|
215
|
-
// if (error) {
|
|
216
|
-
// reject(error);
|
|
217
|
-
// }
|
|
218
|
-
// else {
|
|
219
|
-
// if (this.log) {console.log("(DirIfOnlineAgents) got department:", JSON.stringify(dep)); }
|
|
220
|
-
// const groupId = dep.id_group;
|
|
221
|
-
// if (this.log) {console.log("(DirIfOnlineAgents) department.groupId:", groupId); }
|
|
222
|
-
// try {
|
|
223
|
-
// if (groupId) {
|
|
224
|
-
// const group = await this.getGroup(groupId);
|
|
225
|
-
// if (this.log) { console.log("(DirIfOnlineAgents) got group info:", group); }
|
|
226
|
-
// if (group) {
|
|
227
|
-
// if (group.members) {
|
|
228
|
-
// if (this.log) { console.log("(DirIfOnlineAgents) group members ids:", group.members);}
|
|
229
|
-
// // let group_members = await getTeammates(group.members);
|
|
230
|
-
// // console.log("group members details:", group_members);
|
|
231
|
-
// let all_teammates = await this.getAllTeammates();
|
|
232
|
-
// if (this.log) { console.log("(DirIfOnlineAgents) all teammates:", all_teammates); }
|
|
233
|
-
// if (all_teammates && all_teammates.length > 0){
|
|
234
|
-
// // [
|
|
235
|
-
// // {
|
|
236
|
-
// // "user_available": false,
|
|
237
|
-
// // ...
|
|
238
|
-
// // "id_user": {
|
|
239
|
-
// // "status": 100,
|
|
240
|
-
// // "email": "michele@tiledesk.com",
|
|
241
|
-
// // "firstname": "Michele",
|
|
242
|
-
// // "lastname": "Pomposo",
|
|
243
|
-
// // ...
|
|
244
|
-
// // },
|
|
245
|
-
// // "role": "admin",
|
|
246
|
-
// // "tags": [],
|
|
247
|
-
// // "presence": {
|
|
248
|
-
// // "status": "offline",
|
|
249
|
-
// // "changedAt": "2023-11-16T12:37:31.990Z"
|
|
250
|
-
// // },
|
|
251
|
-
// // "isBusy": false
|
|
252
|
-
// // }, ... ]
|
|
253
|
-
// // filter on availability
|
|
254
|
-
// console.log("(DirIfOnlineAgents) filtering available agents for group:", groupId);
|
|
255
|
-
// let available_agents = [];
|
|
256
|
-
// all_teammates.forEach((agent) => {
|
|
257
|
-
// if (this.log) { console.log("Checking teammate:", agent.id_user._id, "(", agent.id_user.email ,") Available:", agent.user_available, ") with members:",group.members ); }
|
|
258
|
-
// if (agent.user_available === true && group.members.includes(agent.id_user._id)) {
|
|
259
|
-
// console.log("Adding teammate:", agent.id_user._id);
|
|
260
|
-
// available_agents.push(agent);
|
|
261
|
-
// }
|
|
262
|
-
// });
|
|
263
|
-
// if (this.log) { console.log("(DirIfOnlineAgents) available agents in group:", available_agents); }
|
|
264
|
-
// resolve(available_agents);
|
|
265
|
-
// }
|
|
266
|
-
// }
|
|
267
|
-
// else {
|
|
268
|
-
// this.chatbot.addParameter("flowError", "(If online Agents) Empty group:" + groupId);
|
|
269
|
-
// resolve([]);
|
|
270
|
-
// }
|
|
271
|
-
// }
|
|
272
|
-
// else {
|
|
273
|
-
// this.chatbot.addParameter("flowError", "(If online Agents) Error: no group for groupId:" + groupId);
|
|
274
|
-
// resolve([]);
|
|
275
|
-
// }
|
|
276
|
-
// }
|
|
277
|
-
// else {
|
|
278
|
-
// // no group => assigned to all teammates
|
|
279
|
-
// const agents = await this.getProjectAvailableAgents(true);
|
|
280
|
-
// resolve(agents);
|
|
281
|
-
// }
|
|
282
|
-
// }
|
|
283
|
-
// catch(error) {
|
|
284
|
-
// console.error("(DirIfOnlineAgents) Error:", error);
|
|
285
|
-
// reject(error);
|
|
286
|
-
// }
|
|
287
|
-
// }
|
|
288
|
-
// });
|
|
289
|
-
// });
|
|
290
|
-
// }
|
|
291
|
-
|
|
292
|
-
// async getGroup(groupId, callback) {
|
|
293
|
-
// return new Promise ( (resolve, reject) => {
|
|
294
|
-
// const URL = `${this.context.TILEDESK_APIURL}/${this.context.projectId}/groups/${groupId}`
|
|
295
|
-
// const HTTPREQUEST = {
|
|
296
|
-
// url: URL,
|
|
297
|
-
// headers: {
|
|
298
|
-
// 'Content-Type' : 'application/json',
|
|
299
|
-
// 'Authorization': this.fixToken(this.context.token)
|
|
300
|
-
// },
|
|
301
|
-
// method: 'GET',
|
|
302
|
-
// httpsOptions: this.httpsOptions
|
|
303
|
-
// };
|
|
304
|
-
// this.#myrequest(
|
|
305
|
-
// HTTPREQUEST,
|
|
306
|
-
// function(err, resbody) {
|
|
307
|
-
// if (err) {
|
|
308
|
-
// reject(err);
|
|
309
|
-
// if (callback) {
|
|
310
|
-
// callback(err);
|
|
311
|
-
// }
|
|
312
|
-
// }
|
|
313
|
-
// else {
|
|
314
|
-
// // {
|
|
315
|
-
// // "members": [
|
|
316
|
-
// // "62b317986993970035f0697e",
|
|
317
|
-
// // "5aaa99024c3b110014b478f0"
|
|
318
|
-
// // ],
|
|
319
|
-
// // "_id": "65ddec23fd8dc3003295cdd7",
|
|
320
|
-
// // "name": "Sales",
|
|
321
|
-
// // "trashed": false,
|
|
322
|
-
// // "id_project": "65203e12f8c0cf002cf4110b",
|
|
323
|
-
// // "createdBy": "5e09d16d4d36110017506d7f",
|
|
324
|
-
// // "createdAt": "2024-02-27T14:05:23.373Z",
|
|
325
|
-
// // "updatedAt": "2024-02-27T14:05:29.137Z",
|
|
326
|
-
// // "__v": 0
|
|
327
|
-
// // }
|
|
328
|
-
// resolve(resbody);
|
|
329
|
-
// if (callback) {
|
|
330
|
-
// callback(null, resbody);
|
|
331
|
-
// }
|
|
332
|
-
// }
|
|
333
|
-
// }, this.log
|
|
334
|
-
// );
|
|
335
|
-
// });
|
|
336
|
-
// }
|
|
337
|
-
|
|
338
|
-
// async getAllTeammates(members, callback) {
|
|
339
|
-
// return new Promise ( (resolve, reject) => {
|
|
340
|
-
// const URL = `${this.context.TILEDESK_APIURL}/${this.context.projectId}/project_users`
|
|
341
|
-
// const HTTPREQUEST = {
|
|
342
|
-
// url: URL,
|
|
343
|
-
// headers: {
|
|
344
|
-
// 'Content-Type' : 'application/json',
|
|
345
|
-
// 'Authorization': this.fixToken(this.context.token)
|
|
346
|
-
// },
|
|
347
|
-
// method: 'GET',
|
|
348
|
-
// httpsOptions: this.httpsOptions
|
|
349
|
-
// };
|
|
350
|
-
// this.#myrequest(
|
|
351
|
-
// HTTPREQUEST,
|
|
352
|
-
// function(err, resbody) {
|
|
353
|
-
// if (err) {
|
|
354
|
-
// reject(err);
|
|
355
|
-
// if (callback) {
|
|
356
|
-
// callback(err);
|
|
357
|
-
// }
|
|
358
|
-
// }
|
|
359
|
-
// else {
|
|
360
|
-
// // {
|
|
361
|
-
// // "members": [
|
|
362
|
-
// // "62b317986993970035f0697e",
|
|
363
|
-
// // "5aaa99024c3b110014b478f0"
|
|
364
|
-
// // ],
|
|
365
|
-
// // "_id": "65ddec23fd8dc3003295cdd7",
|
|
366
|
-
// // "name": "Sales",
|
|
367
|
-
// // "trashed": false,
|
|
368
|
-
// // "id_project": "65203e12f8c0cf002cf4110b",
|
|
369
|
-
// // "createdBy": "5e09d16d4d36110017506d7f",
|
|
370
|
-
// // "createdAt": "2024-02-27T14:05:23.373Z",
|
|
371
|
-
// // "updatedAt": "2024-02-27T14:05:29.137Z",
|
|
372
|
-
// // "__v": 0
|
|
373
|
-
// // }
|
|
374
|
-
// resolve(resbody);
|
|
375
|
-
// if (callback) {
|
|
376
|
-
// callback(null, resbody);
|
|
377
|
-
// }
|
|
378
|
-
// }
|
|
379
|
-
// }, this.log
|
|
380
|
-
// );
|
|
381
|
-
// });
|
|
382
|
-
// }
|
|
383
|
-
|
|
384
211
|
#myrequest(options, callback) {
|
|
385
212
|
if (this.log) {
|
|
386
213
|
console.log("API URL:", options.url);
|
|
@@ -225,7 +225,7 @@ class DirIntent {
|
|
|
225
225
|
}
|
|
226
226
|
})
|
|
227
227
|
.catch( (error) => {
|
|
228
|
-
console.error("An error occurred:", error);
|
|
228
|
+
console.error("(DirIntent) An error occurred:", JSON.stringify(error), "url:", options.url);
|
|
229
229
|
if (callback) {
|
|
230
230
|
callback(error, null, null);
|
|
231
231
|
}
|