@tiledesk/tiledesk-tybot-connector 2.0.19 → 2.0.20
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/TdCache.js +16 -2
- package/index.js +8 -3
- package/package.json +1 -1
package/TdCache.js
CHANGED
|
@@ -149,9 +149,23 @@ class TdCache {
|
|
|
149
149
|
})
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
async unsubscribe(topic
|
|
153
|
-
|
|
152
|
+
async unsubscribe(topic) {
|
|
153
|
+
if (!this.subscriberClient) {
|
|
154
|
+
winston.warn("Redis subscriberClient not initialized, cannot unsubscribe.");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const result = await this.subscriberClient.unsubscribe(topic);
|
|
160
|
+
winston.debug(`Unsubscribed from topic "${topic}". Current subscription count: ${result}`);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
winston.error(`Error unsubscribing from topic "${topic}":`, err);
|
|
163
|
+
}
|
|
154
164
|
}
|
|
165
|
+
|
|
166
|
+
// async unsubscribe(topic, listener) {
|
|
167
|
+
// await this.subscriberClient.unsubscribe(topic, listener);
|
|
168
|
+
// }
|
|
155
169
|
|
|
156
170
|
// subscribe(key, callback) {
|
|
157
171
|
// this.redis_sub.subscribe(key, (message) => {
|
package/index.js
CHANGED
|
@@ -13,6 +13,8 @@ const { TiledeskChatbotConst } = require('./engine/TiledeskChatbotConst.js');
|
|
|
13
13
|
const { IntentsMachineFactory } = require('./engine/IntentsMachineFactory.js');
|
|
14
14
|
const { v4: uuidv4 } = require('uuid');
|
|
15
15
|
let axios = require('axios');
|
|
16
|
+
const { customAlphabet } = require('nanoid');
|
|
17
|
+
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);
|
|
16
18
|
// let parser = require('accept-language-parser');
|
|
17
19
|
|
|
18
20
|
router.use(bodyParser.json({limit: '50mb'}));
|
|
@@ -393,6 +395,8 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
393
395
|
const token = body.token;
|
|
394
396
|
delete body.async;
|
|
395
397
|
delete body.token;
|
|
398
|
+
|
|
399
|
+
let draft = req.body.draft || false;
|
|
396
400
|
|
|
397
401
|
// invoke block
|
|
398
402
|
// unique ID for each execution
|
|
@@ -402,7 +406,6 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
402
406
|
} else {
|
|
403
407
|
const execution_id = uuidv4().replace(/-/g, '');
|
|
404
408
|
request_id = "automation-request-" + project_id + "-" + execution_id;
|
|
405
|
-
|
|
406
409
|
}
|
|
407
410
|
const command = "/#" + block_id;
|
|
408
411
|
let message = {
|
|
@@ -411,7 +414,8 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
411
414
|
text: command,
|
|
412
415
|
id_project: project_id,
|
|
413
416
|
request: {
|
|
414
|
-
request_id: request_id
|
|
417
|
+
request_id: request_id,
|
|
418
|
+
draft: draft
|
|
415
419
|
},
|
|
416
420
|
attributes: {
|
|
417
421
|
payload: body
|
|
@@ -432,13 +436,14 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
432
436
|
} else {
|
|
433
437
|
|
|
434
438
|
winston.verbose("Sync webhook. Subscribe and await for reply...")
|
|
439
|
+
let uniqueid = nanoid();
|
|
435
440
|
const topic = `/webhooks/${request_id}`;
|
|
436
441
|
|
|
437
442
|
try {
|
|
438
443
|
|
|
439
444
|
const listener = async (message, topic) => {
|
|
440
445
|
winston.debug("Web response is: " + JSON.stringify(message) + " for topic " + topic);
|
|
441
|
-
await tdcache.unsubscribe(topic
|
|
446
|
+
await tdcache.unsubscribe(topic);
|
|
442
447
|
|
|
443
448
|
let json = JSON.parse(message);
|
|
444
449
|
let status = json.status ? json.status : 200;
|