@tiledesk/tiledesk-tybot-connector 0.2.134 → 0.2.135

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
@@ -17,6 +17,11 @@ available on:
17
17
  - Added flowError on JSONCondition when result = null
18
18
  - Added fix on Filler -->
19
19
 
20
+ # v0.2.135
21
+ - Updated to redis 4.7.0 + Tdcache.js
22
+ - Disabled close_directive_test.js - DirClose directive - too old, not passing
23
+ - Disabled conversation-gpt_assistant_test.js
24
+
20
25
  # v0.2.134
21
26
  - Added filter for mweb on hidden messages
22
27
 
package/TdCache.js CHANGED
@@ -7,6 +7,7 @@ class TdCache {
7
7
  this.redis_port = config.port;
8
8
  this.redis_password = config.password;
9
9
  this.client = null;
10
+ this.redis_sub = null;
10
11
  }
11
12
 
12
13
  async connect(callback) {
@@ -24,17 +25,22 @@ class TdCache {
24
25
  callback(err);
25
26
  }
26
27
  });
27
- // this.client.on('connect', function() {
28
- // console.log('Redis Connected!');
29
- // });
30
28
  this.client.on('ready',function() {
31
- // console.log("connected")
32
29
  resolve();
33
30
  if (callback) {
34
31
  callback();
35
32
  }
36
33
  //console.log("Redis is ready.");
37
34
  });
35
+ await this.client.connect();
36
+ this.redis_sub = redis.createClient(
37
+ {
38
+ host: this.redis_host,
39
+ port: this.redis_port,
40
+ password: this.redis_password
41
+ });
42
+ // console.log("redis is:", this.redis_sub)
43
+ await this.redis_sub.connect();
38
44
  });
39
45
  }
40
46
 
@@ -43,202 +49,59 @@ class TdCache {
43
49
  if (!options) {
44
50
  options = {EX: 86400}
45
51
  }
46
- return new Promise( async (resolve, reject) => {
47
- if (options && options.EX) {
48
- //console.log("expires:", options.EX)
49
- try {
50
- this.client.set(
51
- key,
52
- value,
53
- 'EX', options.EX,
54
- (err) => {
55
- if (err) {
56
- reject(err);
57
- }
58
- else {
59
- return resolve();
60
- }
61
- }
62
- );
63
- }
64
- catch(error) {
65
- reject(error)
66
- }
67
- }
68
- else {
69
- try {
70
- //console.log("setting here...key", key, value)
71
- await this.client.set(
72
- key,
73
- value,
74
- (err) => {
75
- if (err) {
76
- reject(err);
77
- }
78
- else {
79
- return resolve();
80
- }
81
- }
82
- );
83
- }
84
- catch(error) {
85
- console.error("TdCache Error:", error);
86
- reject(error)
87
- }
88
- }
89
- // if (options && options.callback) {
90
- // options.callback();
91
- // }
92
- //console.log("resolving...", key);
93
- // return resolve();
94
- });
52
+ await this.client.set(
53
+ key,
54
+ value,
55
+ options);
95
56
  }
96
57
 
97
58
  async incr(key) {
98
- // console.log("incr key:", key)
99
- return new Promise( async (resolve, reject) => {
100
- try {
101
- // console.log("incr here...key", key)
102
- await this.client.incr(key);
103
- }
104
- catch(error) {
105
- console.error("Error on incr:", error);
106
- reject(error)
107
- }
108
- return resolve();
109
- });
59
+ await this.client.incr(key);
110
60
  }
111
61
 
112
62
  async hset(dict_key, key, value, options) {
113
- //console.log("hsetting dict_key key value", dict_key, key, value)
114
- return new Promise( async (resolve, reject) => {
115
- if (options && options.EX) {
116
- //console.log("expires:", options.EX)
117
- try {
118
- await this.client.hset(
119
- dict_key,
120
- key,
121
- value,
122
- 'EX', options.EX);
123
- }
124
- catch(error) {
125
- reject(error)
126
- }
127
- }
128
- else {
129
- try {
130
- //console.log("setting here...key", key, value)
131
- await this.client.hset(
132
- dict_key,
133
- key,
134
- value);
135
- }
136
- catch(error) {
137
- console.error("Error", error);
138
- reject(error)
139
- }
140
- }
141
- if (options && options.callback) {
142
- options.callback();
143
- }
144
- return resolve();
145
- });
63
+ if (!value) {
64
+ return;
65
+ }
66
+ if (!options) {
67
+ options = {EX: 86400}
68
+ }
69
+ await this.client.HSET(
70
+ dict_key,
71
+ key,
72
+ value,
73
+ options);
146
74
  }
147
75
 
148
- async hdel(dict_key, key, options) {
149
- //console.log("hsetting dict_key key value", dict_key, key, value)
150
- return new Promise( async (resolve, reject) => {
151
- if (options && options.EX) {
152
- //console.log("expires:", options.EX)
153
- try {
154
- await this.client.hdel(
155
- dict_key,
156
- key,
157
- 'EX', options.EX);
158
- }
159
- catch(error) {
160
- reject(error)
161
- }
162
- }
163
- else {
164
- try {
165
- //console.log("setting here...key", key, value)
166
- await this.client.hdel(
167
- dict_key,
168
- key);
169
- }
170
- catch(error) {
171
- console.error("Error", error);
172
- reject(error);
173
- }
174
- }
175
- if (options && options.callback) {
176
- options.callback();
177
- }
178
- return resolve();
179
- });
76
+ async hdel(dict_key, key) {
77
+ await this.client.HDEL(dict_key, key);
180
78
  }
181
79
 
182
80
  async setJSON(key, value, options) {
81
+ if (!value) {
82
+ return;
83
+ }
84
+ if (!options) {
85
+ options = {EX: 86400}
86
+ }
183
87
  const _string = JSON.stringify(value);
184
88
  return await this.set(key, _string, options);
185
89
  }
186
90
 
187
- async get(key, callback) {
188
- //console.log("getting key", key)
189
- return new Promise( async (resolve, reject) => {
190
- this.client.get(key, (err, value) => {
191
- if (err) {
192
- reject(err);
193
- }
194
- else {
195
- if (callback) {
196
- callback(value);
197
- }
198
- return resolve(value);
199
- }
200
- });
201
- });
91
+ async get(key) {
92
+ const value = await this.client.GET(key);
93
+ return value;
202
94
  }
203
95
 
204
- async hgetall(dict_key, callback) {
205
- //console.log("hgetting dics", dict_key);
206
- return new Promise( async (resolve, reject) => {
207
- this.client.hgetall(dict_key, (err, value) => {
208
- if (err) {
209
- reject(err);
210
- if (callback) {
211
- callback(err, null);
212
- }
213
- }
214
- else {
215
- if (callback) {
216
- callback(null, value);
217
- }
218
- resolve(value);
219
- }
220
- });
221
- });
96
+ async hgetall(dict_key) {
97
+ const all = await this.client.HGETALL(dict_key);
98
+ return all;
222
99
  }
223
100
 
224
- async hget(dict_key, key, callback) {
225
- //console.log("hgetting dics", dict_key);
226
- return new Promise( async (resolve, reject) => {
227
- this.client.hget(dict_key, key, (err, value) => {
228
- if (err) {
229
- reject(err);
230
- if (callback) {
231
- callback(err, null);
232
- }
233
- }
234
- else {
235
- if (callback) {
236
- callback(null, value);
237
- }
238
- resolve(value);
239
- }
240
- });
241
- });
101
+ async hget(dict_key, key) {
102
+ // console.log("hgetting dics", dict_key);
103
+ const value = await this.client.HGET(dict_key, key);
104
+ return value;
242
105
  }
243
106
 
244
107
  async getJSON(key, callback) {
@@ -246,16 +109,19 @@ class TdCache {
246
109
  return JSON.parse(value);
247
110
  }
248
111
 
249
- async del(key, callback) {
250
- return new Promise( async (resolve, reject) => {
251
- this.client.del(key, () => {
252
- if (callback) {
253
- callback();
254
- }
255
- return resolve();
256
- });
257
- })
112
+ async del(key) {
113
+ await this.client.del(key);
114
+ }
115
+
116
+ async publish(key, value) {
117
+ await this.redis_sub.publish(key, value);
258
118
  }
119
+
120
+ // subscribe(key, callback) {
121
+ // this.redis_sub.subscribe(key, (message) => {
122
+ // callback(message);
123
+ // });
124
+ // }
259
125
  }
260
126
 
261
127
  module.exports = { TdCache };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.134",
3
+ "version": "0.2.135",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  "mongoose": "^6.3.5",
30
30
  "multer": "^1.4.5-lts.1",
31
31
  "nanoid": "^3.1.25",
32
- "redis": "^3.1.2",
32
+ "redis": "^4.7.0",
33
33
  "uuid": "^3.3.3",
34
34
  "vm2": "^3.9.13"
35
35
  },
@@ -178,7 +178,7 @@ class DirectivesChatbotPlug {
178
178
  async nextDirective(directives) {
179
179
  if (this.log) {console.log("....nextDirective() checkStep():");}
180
180
  const go_on = await TiledeskChatbot.checkStep(
181
- this.context.tdcache, this.context.requestId, this.chatbot.MAX_STEPS, this.chatbot.MAX_EXECUTION_TIME, this.log
181
+ this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME, this.log
182
182
  );
183
183
  // const current_step = await TiledeskChatbot.currentStep(this.context.tdcache, this.context.requestId);
184
184
  // if (this.log) {console.log("........nextDirective() currentStep:", current_step);}