@tiledesk/tiledesk-tybot-connector 2.0.18 → 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 CHANGED
@@ -149,9 +149,23 @@ class TdCache {
149
149
  })
150
150
  }
151
151
 
152
- async unsubscribe(topic, listener) {
153
- await this.subscriberClient.unsubscribe(topic, listener);
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, listener);
446
+ await tdcache.unsubscribe(topic);
442
447
 
443
448
  let json = JSON.parse(message);
444
449
  let status = json.status ? json.status : 200;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "@tiledesk/tiledesk-chatbot-client": "^0.5.30",
16
16
  "@tiledesk/tiledesk-chatbot-util": "^0.8.39",
17
17
  "@tiledesk/tiledesk-client": "^0.10.13",
18
- "@tiledesk/tiledesk-multi-worker": "^0.3.1",
18
+ "@tiledesk/tiledesk-multi-worker": "^0.3.2",
19
19
  "accept-language-parser": "^1.5.0",
20
20
  "app-root-path": "^3.1.0",
21
21
  "axios": "^1.7.7",
@@ -42,6 +42,7 @@ class DirIntent {
42
42
  const intentName = action.intentName;
43
43
  const projectId = this.supportRequest.id_project;
44
44
  const requestId = this.supportRequest.request_id;
45
+ const draft = this.supportRequest.draft;
45
46
  const botId = this.supportRequest.bot_id;
46
47
  let intent_command;
47
48
  if (intentName) {
@@ -63,7 +64,8 @@ class DirIntent {
63
64
  "id_project": projectId,
64
65
  "request": {
65
66
  "request_id": requestId,
66
- "id_project": projectId
67
+ "id_project": projectId,
68
+ "draft": draft
67
69
  }
68
70
  },
69
71
  "token": this.token