@tiledesk/tiledesk-tybot-connector 0.4.2 → 0.5.0-rc1

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 CHANGED
@@ -5,6 +5,9 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ # v0.5.0-rc1
9
+ - added: ability to get 'none' as bodytype in webresponse
10
+
8
11
  # v0.4.2
9
12
  - bug-fixed: minor log fix
10
13
 
@@ -17,6 +20,19 @@ available on:
17
20
  - changed: refactoring of DIrWebRequestv2
18
21
  - bug-fixed: erro while parsing webrequestv2 body
19
22
 
23
+ # v0.3.5-rc4
24
+ - added: webhook action (same as intent one)
25
+
26
+ # v0.3.5-rc3
27
+ - bug-fixed: jsonBody parse error in web-request-v2
28
+
29
+ # v0.3.5-rc2
30
+ - bug-fixed: cannot set status of undefined reading res.status in DirAssistant
31
+
32
+ # v0.3.5-rc1
33
+ - changed: refactoring web-request-v2
34
+ - bug-fixed: jsonBody parse error in web-request-v2
35
+
20
36
  # v0.3.4
21
37
  -bug-fixed: slit is undefined in TiledeskChatbotUtils
22
38
 
@@ -26,6 +42,18 @@ available on:
26
42
  # v0.3.2
27
43
  - bug-fixed: minor improvement
28
44
 
45
+ # v0.2.153-rc9
46
+ - changed: updated tiledesk-multi-worker to 0.2.1-rc2
47
+
48
+ # v0.2.153-rc8
49
+ - added: fixToken function in TiledeskService utils class
50
+
51
+ # v0.2.153-rc4
52
+ - log added
53
+
54
+ # v0.2.153-rc3
55
+ - added: specchToText function to transcript audio file
56
+
29
57
  # v0.2.153-rc1
30
58
  - changed: context for gpt-40 and gpt-40-mini
31
59
 
package/Logger.js ADDED
@@ -0,0 +1,86 @@
1
+ let { Publisher } = require("@tiledesk/tiledesk-multi-worker");
2
+
3
+ const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
4
+ let publisher = new Publisher(AMQP_MANAGER_URL, {
5
+ debug: false,
6
+ queueName: "logs_queue",
7
+ exchange: "tiledesk-multi",
8
+ topic: "logs",
9
+ })
10
+
11
+ class Logger {
12
+
13
+ constructor(config) {
14
+
15
+ if (!config) {
16
+ throw new Error('config is mandatory');
17
+ }
18
+
19
+ if (!config.request_id) {
20
+ console.error('config.request_id is mandatory');
21
+ //throw new Error('config.request_id is mandatory');
22
+ }
23
+
24
+ this.request_id = config.request_id;
25
+ this.dev = false;
26
+ if (config.dev && config.dev === true) {
27
+ this.dev = true;
28
+ }
29
+
30
+ if (!AMQP_MANAGER_URL) {
31
+ console.error('AMQP_MANAGER_URL is undefined. Logger not available...');
32
+ return;
33
+ //throw new Error("Error starting logger: AMQP_MANAGER_URL is undefined.")
34
+ }
35
+
36
+ }
37
+
38
+ error(...args) {
39
+ let log = this.formatLog(args);
40
+ return this.base('error', log);
41
+ }
42
+
43
+ warn(...args) {
44
+ let log = this.formatLog(args);
45
+ return this.base('warn', log);
46
+ }
47
+
48
+ info(...args) {
49
+ let log = this.formatLog(args);
50
+ return this.base('info', log);
51
+ }
52
+
53
+ debug(...args) {
54
+ let log = this.formatLog(args);
55
+ return this.base('debug', log);
56
+ }
57
+
58
+ base(level, text) {
59
+ if (!this.request_id || !publisher) {
60
+ console.log("Return because request or publisher is undefined", this.request_id, publisher);
61
+ return;
62
+ }
63
+
64
+ let data = {
65
+ request_id: this.request_id,
66
+ text: text,
67
+ level: level,
68
+ timestamp: new Date(),
69
+ dev: this.dev
70
+ }
71
+
72
+ publisher.publish(data, (err, ok) => {
73
+ if (err) console.warn("publish log fail: ", err);
74
+ return;
75
+ })
76
+ }
77
+
78
+ formatLog(args) {
79
+ return args
80
+ .map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg ))
81
+ .join(" ")
82
+ }
83
+
84
+ }
85
+
86
+ module.exports = { Logger }
@@ -349,6 +349,105 @@ class TiledeskChatbotUtil {
349
349
  return all_buttons;
350
350
  }
351
351
 
352
+ static replaceJSONButtons(message, flow_attributes) {
353
+ let all_buttons = [];
354
+ if (message.attributes && message.attributes.commands) {
355
+ let commands = message.attributes.commands;
356
+ if (commands.length > 0) {
357
+ for (let i = 0; i < commands.length; i++) {
358
+ let command = commands[i];
359
+ if (command.type === 'message' && command.message) {
360
+ if (command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.json_buttons){
361
+ // console.log("command with buttons ok:")
362
+ let json_buttons_string = command.message.attributes.attachment.json_buttons;
363
+ let json_buttons = null;
364
+ let final_buttons = [];
365
+ try {
366
+ // fill buttons
367
+ const filler = new Filler();
368
+ json_buttons_string = filler.fill(json_buttons_string, flow_attributes);
369
+ console.log("json_buttons_string:", json_buttons_string);
370
+ console.log("type json_buttons_string:", typeof json_buttons_string);
371
+ try {
372
+ json_buttons = JSON.parse(json_buttons_string);
373
+ console.log("json_buttons (parsed): ", json_buttons);
374
+ } catch(err) {
375
+ console.error("Error parsing json_buttons_string: ", err)
376
+ }
377
+
378
+ console.log("after try type json_buttons: ", typeof json_buttons, json_buttons);
379
+ console.log("Array.isArray(json_buttons): ", Array.isArray(json_buttons));
380
+ if (Array.isArray(json_buttons)) {
381
+ console.log("json_buttons is array");
382
+ json_buttons.forEach(button => {
383
+ console.log("analyze button:", button);
384
+ console.log("button.value:", typeof button.value, button.value);
385
+ console.log("button.type:", typeof button.type, button.type);
386
+ console.log("button.action:", typeof button.action, button.action);
387
+ console.log("final_buttons:", final_buttons);
388
+ if (button.value && button.type === "action" && button.action) {
389
+ console.log("Case 1");
390
+ button.show_echo = true;
391
+ // console.log("pushing:", button)
392
+ final_buttons.push(button);
393
+ }
394
+ else if (button.value && button.type === "text") {
395
+ console.log("Case 2");
396
+ button.show_echo = true;
397
+ // console.log("pushing:", button)
398
+ final_buttons.push(button);
399
+ }
400
+ else if (button.value && button.type === "url" && button.link) {
401
+ console.log("Case 3");
402
+ button.show_echo = true;
403
+ // console.log("pushing:", button)
404
+ final_buttons.push(button);
405
+ }
406
+ else {
407
+ console.log("Invalid button. Skipping:", JSON.stringify(button) );
408
+ }
409
+ });
410
+ }
411
+
412
+ // "buttons": [
413
+ // {
414
+ // "type": "action",
415
+ // "value": "Button1", // obbligatorio sempre
416
+ // "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
417
+ // "show_echo": true, // lo inserisco sempre
418
+ // "alias": "button1 alias"
419
+ // },
420
+ // {
421
+ // "type": "text",
422
+ // "value": "Button2 text", // obbligatorio sempre
423
+ // "show_echo": true // lo inserisco sempre
424
+ // },
425
+ // {
426
+ // "type": "url",
427
+ // "value": "Button3 link", // obbligatorio sempre
428
+ // "link": "http://", // obbligatorio
429
+ // "show_echo": true // lo inserisco sempre
430
+ // }
431
+ // ]
432
+ }
433
+ catch(error) {
434
+ console.error("Invalid json_buttons:", error)
435
+ }
436
+ if (final_buttons && final_buttons.length > 0) {
437
+ command.message.attributes.attachment.buttons = final_buttons;
438
+ delete command.message.attributes.attachment.json_buttons;
439
+ }
440
+ else {
441
+ console.log("Invalid json buttons. Skipped:", JSON.stringify(final_buttons));
442
+ }
443
+ }
444
+ }
445
+ }
446
+ }
447
+ }
448
+ return all_buttons;
449
+ }
450
+
352
451
  static buttonByText(text, buttons) {
353
452
  if (buttons === null || text === null) {
354
453
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.4.2",
3
+ "version": "0.5.0-rc1",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,6 +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.2.1-rc2",
18
19
  "accept-language-parser": "^1.5.0",
19
20
  "axios": "^1.7.7",
20
21
  "body-parser": "^1.19.0",
@@ -774,6 +774,19 @@ class DirectivesChatbotPlug {
774
774
  }
775
775
  });
776
776
  }
777
+ else if (directive_name === Directives.WEBHOOK) {
778
+ // console.log(".....DirIntent")
779
+ new DirIntent(context).execute(directive, async (stop) => {
780
+ if (stop) {
781
+ if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
782
+ this.theend();
783
+ }
784
+ else {
785
+ let next_dir = await this.nextDirective(this.directives);
786
+ this.process(next_dir);
787
+ }
788
+ });
789
+ }
777
790
  else if (directive_name === Directives.WEB_RESPONSE) {
778
791
  new DirWebResponse(context).execute(directive, async () => {
779
792
  let next_dir = await this.nextDirective(this.directives);
@@ -71,11 +71,12 @@ class DirIntent {
71
71
  "recipient": requestId,
72
72
  "text": intent_command,
73
73
  "id_project": projectId,
74
- "request": {
75
- "request_id": requestId,
76
- "id_project": projectId
77
- // "bot_id": botId
78
- }
74
+ "request": this.supportRequest,
75
+ // "request": {
76
+ // "request_id": requestId,
77
+ // "id_project": projectId
78
+ // // "bot_id": botId
79
+ // }
79
80
  },
80
81
  "token": this.token
81
82
  }
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const { Logger } = require('../../Logger');
6
7
 
7
8
  class DirReply {
8
9
 
@@ -16,6 +17,8 @@ class DirReply {
16
17
  this.token = context.token;
17
18
  this.tdcache = context.tdcache;
18
19
  this.log = context.log;
20
+ this.supportRequest = this.context.supportRequest;
21
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
19
22
 
20
23
  this.API_ENDPOINT = context.API_ENDPOINT;
21
24
  this.tdClient = new TiledeskClient({
@@ -38,16 +41,21 @@ class DirReply {
38
41
  }
39
42
  else {
40
43
  console.error("Incorrect directive (no action provided):", directive);
44
+ this.logger.error("Incorrect directive (no action provided):", directive);
41
45
  callback();
42
46
  return;
43
47
  }
48
+ this.logger.info("Executing Action Reply ", directive.action)
49
+
44
50
  this.go(action, () => {
51
+ this.logger.info("Action Reply terminated")
45
52
  callback();
46
53
  });
47
54
  }
48
55
 
49
56
  async go(action, callback) {
50
57
  const message = action;
58
+
51
59
  // fill
52
60
  let requestAttributes = null;
53
61
  if (this.tdcache) {
@@ -55,22 +63,22 @@ class DirReply {
55
63
  await TiledeskChatbot.allParametersStatic(
56
64
  this.tdcache, this.requestId
57
65
  );
58
- if (this.log) {
59
- for (const [key, value] of Object.entries(requestAttributes)) {
60
- const value_type = typeof value;
61
- // if (this.log) {console.log("(DirReply) request parameter:", key, "value:", value, "type:", value_type)}
62
- }
63
- }
66
+
67
+ TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
68
+
64
69
  const filler = new Filler();
65
70
  // fill text attribute
66
71
  message.text = filler.fill(message.text, requestAttributes);
72
+
67
73
  if (message.metadata) {
68
74
  if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
69
75
  if (message.metadata.src) {
70
76
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
77
+ this.logger.debug("Filled metadata.src with ", message.metadata.src);
71
78
  }
72
79
  if (message.metadata.name) {
73
80
  message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
81
+ this.logger.debug("Filled metadata.name with ", message.metadata.name);
74
82
  }
75
83
  }
76
84
  if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
@@ -84,6 +92,7 @@ class DirReply {
84
92
  let command = commands[i];
85
93
  if (command.type === 'message' && command.message && command.message.text) {
86
94
  command.message.text = filler.fill(command.message.text, requestAttributes);
95
+ this.logger.debug("Filled message.text with ", command.message.text)
87
96
  TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
88
97
  if (this.log) {console.log("command filled:", command.message.text);}
89
98
  }
@@ -133,12 +142,14 @@ class DirReply {
133
142
  }
134
143
  catch(err) {
135
144
  console.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
145
+ this.logger.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
136
146
  }
137
147
  }
138
148
  }
139
149
  }
140
150
  // send!
141
151
  let cleanMessage = message;
152
+ this.logger.info("Sending reply with text ", cleanMessage.text);
142
153
  // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
143
154
  // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
144
155
  // console.log("invalid message", cleanMessage);
@@ -156,8 +167,10 @@ class DirReply {
156
167
  (err) => {
157
168
  if (err) {
158
169
  console.error("Error sending reply:", err);
170
+ this.logger.error("Error sending reply ", err.response.data);
159
171
  }
160
172
  if (this.log) {console.log("Reply message sent:", JSON.stringify(cleanMessage));}
173
+ this.logger.info("Reply message sent!", cleanMessage.text);
161
174
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
162
175
  // console.log("got total delay:", delay)
163
176
  if (delay > 0 && delay <= 30000) { // prevent long delays
@@ -79,6 +79,8 @@ class DirReplyV2 {
79
79
  }
80
80
  }
81
81
 
82
+ TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
83
+
82
84
  try {
83
85
  // lock/unlock + no-match
84
86
  // get buttons if available
@@ -34,10 +34,10 @@ class DirWebResponse {
34
34
  }
35
35
 
36
36
  async go(action, callback) {
37
- console.log("Web response...");
38
- let payload = action.payload;
39
- let status = action.status;
40
-
37
+ if (this.log) {
38
+ console.log("(DirWebResponse) action:", action);
39
+ }
40
+
41
41
  let requestAttributes = null;
42
42
  if (this.tdcache) {
43
43
  requestAttributes =
@@ -45,7 +45,7 @@ class DirWebResponse {
45
45
  const filler = new Filler();
46
46
 
47
47
  try {
48
- payload = filler.fill(payload, requestAttributes);
48
+ let status = action.status;
49
49
  status = filler.fill(status, requestAttributes);
50
50
  }
51
51
  catch(e) {
@@ -54,16 +54,19 @@ class DirWebResponse {
54
54
 
55
55
  }
56
56
 
57
+ const json = await this.getJsonFromAction(action, filler, requestAttributes)
57
58
  let webResponse = {
58
59
  status: status,
59
- payload: payload
60
+ payload: json
60
61
  }
61
62
 
62
63
  const topic = `/webhooks/${this.requestId}`;
63
64
 
64
65
  try {
65
66
  this.tdcache.publish(topic, JSON.stringify(webResponse));
66
- console.log("Published webresponse to topic:", topic);
67
+ if (this.log) {
68
+ console.log("(DirWebResponse) Published webresponse to topic:", topic);
69
+ }
67
70
  }
68
71
  catch(e) {
69
72
  console.error(e)
@@ -72,8 +75,32 @@ class DirWebResponse {
72
75
  callback();
73
76
 
74
77
  }
78
+
79
+ async getJsonFromAction(action, filler, requestAttributes) {
80
+
81
+ return new Promise( async (resolve, reject) => {
82
+
83
+ if (action.payload && action.bodyType == "json") {
84
+ let jsonBody = filler.fill(action.payload, requestAttributes);
85
+ try {
86
+ let json = JSON.parse(jsonBody);
87
+ resolve(json);
88
+ }
89
+ catch (err) {
90
+ if (this.log) { console.error("Error parsing webRequest jsonBody:", jsonBody, err) };
91
+ reject("Error parsing jsonBody");
92
+ }
93
+ }
94
+ else {
95
+ resolve(null);
96
+ }
97
+ })
98
+ }
99
+
75
100
  }
76
101
 
102
+
103
+
77
104
  /**
78
105
  * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
79
106
  * /${TILEBOT_ROUTE}/ext/${botId}
@@ -58,6 +58,7 @@ class Directives {
58
58
  static MOVE_TO_UNASSIGNED = "move_to_unassigned";
59
59
  static CONNECT_BLOCK = "connect_block";
60
60
  static ADD_TAGS = 'add_tags'
61
+ static WEBHOOK = 'webhook';
61
62
  static WEB_RESPONSE = "web_response";
62
63
 
63
64
  // static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
package/TdCache copy.js DELETED
@@ -1,242 +0,0 @@
1
- const redis = require('redis');
2
-
3
- class TdCache {
4
-
5
- constructor(config) {
6
- this.redis_host = config.host;
7
- this.redis_port = config.port;
8
- this.redis_password = config.password;
9
- this.client = null;
10
- }
11
-
12
- async connect(callback) {
13
- // client = redis.createClient();
14
- return new Promise( async (resolve, reject) => {
15
- this.client = redis.createClient(
16
- {
17
- host: this.redis_host,
18
- port: this.redis_port,
19
- password: this.redis_password
20
- });
21
- this.client.on('error', err => {
22
- reject(err);
23
- if (callback) {
24
- callback(err);
25
- }
26
- });
27
- // this.client.on('connect', function() {
28
- // console.log('Redis Connected!');
29
- // });
30
- this.client.on('ready',function() {
31
- console.log("connected")
32
- resolve();
33
- if (callback) {
34
- callback();
35
- }
36
- //console.log("Redis is ready.");
37
- });
38
- });
39
- }
40
-
41
- async set(key, value, options) {
42
- //console.log("setting key value", key, value)
43
- if (!options) {
44
- options = {EX: 86400}
45
- }
46
- return new Promise( async (resolve, reject) => {
47
- if (options && options.EX) {
48
- //console.log("expires:", options.EX)
49
- try {
50
- await this.client.set(
51
- key,
52
- value,
53
- 'EX', options.EX);
54
- }
55
- catch(error) {
56
- reject(error)
57
- }
58
- }
59
- else {
60
- try {
61
- //console.log("setting here...key", key, value)
62
- await this.client.set(
63
- key,
64
- value);
65
- }
66
- catch(error) {
67
- console.error("Error", error);
68
- reject(error)
69
- }
70
- }
71
- if (options && options.callback) {
72
- options.callback();
73
- }
74
- //console.log("resolving...", key);
75
- return resolve();
76
- });
77
- }
78
-
79
- async incr(key) {
80
- // console.log("incr key:", key)
81
- return new Promise( async (resolve, reject) => {
82
- try {
83
- // console.log("incr here...key", key)
84
- await this.client.incr(key);
85
- }
86
- catch(error) {
87
- console.error("Error on incr:", error);
88
- reject(error)
89
- }
90
- return resolve();
91
- });
92
- }
93
-
94
- async hset(dict_key, key, value, options) {
95
- //console.log("hsetting dict_key key value", dict_key, key, value)
96
- return new Promise( async (resolve, reject) => {
97
- if (options && options.EX) {
98
- //console.log("expires:", options.EX)
99
- try {
100
- await this.client.hset(
101
- dict_key,
102
- key,
103
- value,
104
- 'EX', options.EX);
105
- }
106
- catch(error) {
107
- reject(error)
108
- }
109
- }
110
- else {
111
- try {
112
- //console.log("setting here...key", key, value)
113
- await this.client.hset(
114
- dict_key,
115
- key,
116
- value);
117
- }
118
- catch(error) {
119
- console.error("Error", error);
120
- reject(error)
121
- }
122
- }
123
- if (options && options.callback) {
124
- options.callback();
125
- }
126
- return resolve();
127
- });
128
- }
129
-
130
- async hdel(dict_key, key, options) {
131
- //console.log("hsetting dict_key key value", dict_key, key, value)
132
- return new Promise( async (resolve, reject) => {
133
- if (options && options.EX) {
134
- //console.log("expires:", options.EX)
135
- try {
136
- await this.client.hdel(
137
- dict_key,
138
- key,
139
- 'EX', options.EX);
140
- }
141
- catch(error) {
142
- reject(error)
143
- }
144
- }
145
- else {
146
- try {
147
- //console.log("setting here...key", key, value)
148
- await this.client.hdel(
149
- dict_key,
150
- key);
151
- }
152
- catch(error) {
153
- console.error("Error", error);
154
- reject(error);
155
- }
156
- }
157
- if (options && options.callback) {
158
- options.callback();
159
- }
160
- return resolve();
161
- });
162
- }
163
-
164
- async setJSON(key, value, options) {
165
- const _string = JSON.stringify(value);
166
- return await this.set(key, _string, options);
167
- }
168
-
169
- async get(key, callback) {
170
- //console.log("getting key", key)
171
- return new Promise( async (resolve, reject) => {
172
- this.client.get(key, (err, value) => {
173
- if (err) {
174
- reject(err);
175
- }
176
- else {
177
- if (callback) {
178
- callback(value);
179
- }
180
- return resolve(value);
181
- }
182
- });
183
- });
184
- }
185
-
186
- async hgetall(dict_key, callback) {
187
- //console.log("hgetting dics", dict_key);
188
- return new Promise( async (resolve, reject) => {
189
- this.client.hgetall(dict_key, (err, value) => {
190
- if (err) {
191
- reject(err);
192
- if (callback) {
193
- callback(err, null);
194
- }
195
- }
196
- else {
197
- if (callback) {
198
- callback(null, value);
199
- }
200
- resolve(value);
201
- }
202
- });
203
- });
204
- }
205
-
206
- async hget(dict_key, key, callback) {
207
- //console.log("hgetting dics", dict_key);
208
- return new Promise( async (resolve, reject) => {
209
- this.client.hget(dict_key, key, (err, value) => {
210
- if (err) {
211
- reject(err);
212
- if (callback) {
213
- callback(err, null);
214
- }
215
- }
216
- else {
217
- if (callback) {
218
- callback(null, value);
219
- }
220
- resolve(value);
221
- }
222
- });
223
- });
224
- }
225
-
226
- async getJSON(key, callback) {
227
- const value = await this.get(key);
228
- return JSON.parse(value);
229
- }
230
-
231
- async del(key, callback) {
232
- return new Promise( async (resolve, reject) => {
233
- await this.client.del(key);
234
- if (callback) {
235
- callback();
236
- }
237
- return resolve();
238
- })
239
- }
240
- }
241
-
242
- module.exports = { TdCache };