@tiledesk/tiledesk-tybot-connector 0.2.138-rc6 → 0.2.138
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 +3 -2
- package/TdCache.js +197 -82
- package/TdCache_v4.js +146 -0
- package/index.js +0 -1
- package/models/TiledeskChatbotUtil.js +1 -1
- package/package.json +2 -2
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirMessage.js +3 -1
- package/TdCache_v3.js +0 -261
package/CHANGELOG.md
CHANGED
|
@@ -17,8 +17,9 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
-
# v0.2.138
|
|
21
|
-
-
|
|
20
|
+
# v0.2.138
|
|
21
|
+
- Bug-fixed: hiddenMessage not blocked
|
|
22
|
+
- Bug-fixed: DirAskGPTV2 has hardcoded engine
|
|
22
23
|
|
|
23
24
|
# v0.2.138-rc1
|
|
24
25
|
- Updated redis to 4.7.0
|
package/TdCache.js
CHANGED
|
@@ -3,63 +3,38 @@ const redis = require('redis');
|
|
|
3
3
|
class TdCache {
|
|
4
4
|
|
|
5
5
|
constructor(config) {
|
|
6
|
-
console.log("TdCache config: ", config);
|
|
7
6
|
this.redis_host = config.host;
|
|
8
7
|
this.redis_port = config.port;
|
|
9
8
|
this.redis_password = config.password;
|
|
10
|
-
console.log("TdCache this.redis_host: ", this.redis_host);
|
|
11
|
-
console.log("TdCache this.redis_port: ", this.redis_port);
|
|
12
|
-
console.log("TdCache this.redis_password: ", this.redis_password);
|
|
13
9
|
this.client = null;
|
|
14
|
-
this.redis_sub = null;
|
|
15
10
|
}
|
|
16
11
|
|
|
17
12
|
async connect(callback) {
|
|
18
|
-
|
|
13
|
+
// client = redis.createClient();
|
|
19
14
|
return new Promise( async (resolve, reject) => {
|
|
20
|
-
/**
|
|
21
|
-
* Connect redis client
|
|
22
|
-
*/
|
|
23
15
|
this.client = redis.createClient(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
{
|
|
17
|
+
host: this.redis_host,
|
|
18
|
+
port: this.redis_port,
|
|
19
|
+
password: this.redis_password
|
|
20
|
+
});
|
|
28
21
|
this.client.on('error', err => {
|
|
29
22
|
reject(err);
|
|
30
23
|
if (callback) {
|
|
31
24
|
callback(err);
|
|
32
25
|
}
|
|
33
26
|
});
|
|
27
|
+
// this.client.on('connect', function() {
|
|
28
|
+
// console.log('Redis Connected!');
|
|
29
|
+
// });
|
|
34
30
|
this.client.on('ready',function() {
|
|
31
|
+
// console.log("connected")
|
|
35
32
|
resolve();
|
|
36
33
|
if (callback) {
|
|
37
34
|
callback();
|
|
38
35
|
}
|
|
36
|
+
//console.log("Redis is ready.");
|
|
39
37
|
});
|
|
40
|
-
await this.client.connect();
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Connect redis subscription client
|
|
44
|
-
*/
|
|
45
|
-
this.redis_sub = redis.createClient(
|
|
46
|
-
{
|
|
47
|
-
url: `redis://${this.redis_host}:${this.redis_port}`,
|
|
48
|
-
password: this.redis_password
|
|
49
|
-
});
|
|
50
|
-
this.redis_sub.on('error', err => {
|
|
51
|
-
reject(err);
|
|
52
|
-
if (callback) {
|
|
53
|
-
callback(err);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
this.redis_sub.on('ready',function() {
|
|
57
|
-
resolve();
|
|
58
|
-
if (callback) {
|
|
59
|
-
callback();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
await this.redis_sub.connect();
|
|
63
38
|
});
|
|
64
39
|
}
|
|
65
40
|
|
|
@@ -68,59 +43,202 @@ class TdCache {
|
|
|
68
43
|
if (!options) {
|
|
69
44
|
options = {EX: 86400}
|
|
70
45
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
});
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
async incr(key) {
|
|
78
|
-
|
|
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
|
+
});
|
|
79
110
|
}
|
|
80
111
|
|
|
81
112
|
async hset(dict_key, key, value, options) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
});
|
|
93
146
|
}
|
|
94
147
|
|
|
95
|
-
async hdel(dict_key, key) {
|
|
96
|
-
|
|
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
|
+
});
|
|
97
180
|
}
|
|
98
181
|
|
|
99
182
|
async setJSON(key, value, options) {
|
|
100
|
-
if (!value) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (!options) {
|
|
104
|
-
options = {EX: 86400}
|
|
105
|
-
}
|
|
106
183
|
const _string = JSON.stringify(value);
|
|
107
184
|
return await this.set(key, _string, options);
|
|
108
185
|
}
|
|
109
186
|
|
|
110
|
-
async get(key) {
|
|
111
|
-
|
|
112
|
-
return
|
|
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
|
+
});
|
|
113
202
|
}
|
|
114
203
|
|
|
115
|
-
async hgetall(dict_key) {
|
|
116
|
-
|
|
117
|
-
return
|
|
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
|
+
});
|
|
118
222
|
}
|
|
119
223
|
|
|
120
|
-
async hget(dict_key, key) {
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
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
|
+
});
|
|
124
242
|
}
|
|
125
243
|
|
|
126
244
|
async getJSON(key, callback) {
|
|
@@ -128,19 +246,16 @@ class TdCache {
|
|
|
128
246
|
return JSON.parse(value);
|
|
129
247
|
}
|
|
130
248
|
|
|
131
|
-
async del(key) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
})
|
|
137
258
|
}
|
|
138
|
-
|
|
139
|
-
// subscribe(key, callback) {
|
|
140
|
-
// this.redis_sub.subscribe(key, (message) => {
|
|
141
|
-
// callback(message);
|
|
142
|
-
// });
|
|
143
|
-
// }
|
|
144
259
|
}
|
|
145
260
|
|
|
146
261
|
module.exports = { TdCache };
|
package/TdCache_v4.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const redis = require('redis');
|
|
2
|
+
|
|
3
|
+
class TdCache {
|
|
4
|
+
|
|
5
|
+
constructor(config) {
|
|
6
|
+
console.log("TdCache config: ", config);
|
|
7
|
+
this.redis_host = config.host;
|
|
8
|
+
this.redis_port = config.port;
|
|
9
|
+
this.redis_password = config.password;
|
|
10
|
+
console.log("TdCache this.redis_host: ", this.redis_host);
|
|
11
|
+
console.log("TdCache this.redis_port: ", this.redis_port);
|
|
12
|
+
console.log("TdCache this.redis_password: ", this.redis_password);
|
|
13
|
+
this.client = null;
|
|
14
|
+
this.redis_sub = null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async connect(callback) {
|
|
18
|
+
|
|
19
|
+
return new Promise( async (resolve, reject) => {
|
|
20
|
+
/**
|
|
21
|
+
* Connect redis client
|
|
22
|
+
*/
|
|
23
|
+
this.client = redis.createClient(
|
|
24
|
+
{
|
|
25
|
+
url: `redis://${this.redis_host}:${this.redis_port}`,
|
|
26
|
+
password: this.redis_password
|
|
27
|
+
});
|
|
28
|
+
this.client.on('error', err => {
|
|
29
|
+
reject(err);
|
|
30
|
+
if (callback) {
|
|
31
|
+
callback(err);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
this.client.on('ready',function() {
|
|
35
|
+
resolve();
|
|
36
|
+
if (callback) {
|
|
37
|
+
callback();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await this.client.connect();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Connect redis subscription client
|
|
44
|
+
*/
|
|
45
|
+
this.redis_sub = redis.createClient(
|
|
46
|
+
{
|
|
47
|
+
url: `redis://${this.redis_host}:${this.redis_port}`,
|
|
48
|
+
password: this.redis_password
|
|
49
|
+
});
|
|
50
|
+
this.redis_sub.on('error', err => {
|
|
51
|
+
reject(err);
|
|
52
|
+
if (callback) {
|
|
53
|
+
callback(err);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
this.redis_sub.on('ready',function() {
|
|
57
|
+
resolve();
|
|
58
|
+
if (callback) {
|
|
59
|
+
callback();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
await this.redis_sub.connect();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async set(key, value, options) {
|
|
67
|
+
//console.log("setting key value", key, value)
|
|
68
|
+
if (!options) {
|
|
69
|
+
options = {EX: 86400}
|
|
70
|
+
}
|
|
71
|
+
await this.client.set(
|
|
72
|
+
key,
|
|
73
|
+
value,
|
|
74
|
+
options);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async incr(key) {
|
|
78
|
+
await this.client.incr(key);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async hset(dict_key, key, value, options) {
|
|
82
|
+
if (!value) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!options) {
|
|
86
|
+
options = {EX: 86400}
|
|
87
|
+
}
|
|
88
|
+
await this.client.HSET(
|
|
89
|
+
dict_key,
|
|
90
|
+
key,
|
|
91
|
+
value,
|
|
92
|
+
options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async hdel(dict_key, key) {
|
|
96
|
+
await this.client.HDEL(dict_key, key);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async setJSON(key, value, options) {
|
|
100
|
+
if (!value) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!options) {
|
|
104
|
+
options = {EX: 86400}
|
|
105
|
+
}
|
|
106
|
+
const _string = JSON.stringify(value);
|
|
107
|
+
return await this.set(key, _string, options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async get(key) {
|
|
111
|
+
const value = await this.client.GET(key);
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async hgetall(dict_key) {
|
|
116
|
+
const all = await this.client.HGETALL(dict_key);
|
|
117
|
+
return all;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async hget(dict_key, key) {
|
|
121
|
+
// console.log("hgetting dics", dict_key);
|
|
122
|
+
const value = await this.client.HGET(dict_key, key);
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async getJSON(key, callback) {
|
|
127
|
+
const value = await this.get(key);
|
|
128
|
+
return JSON.parse(value);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async del(key) {
|
|
132
|
+
await this.client.del(key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async publish(key, value) {
|
|
136
|
+
await this.redis_sub.publish(key, value);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// subscribe(key, callback) {
|
|
140
|
+
// this.redis_sub.subscribe(key, (message) => {
|
|
141
|
+
// callback(message);
|
|
142
|
+
// });
|
|
143
|
+
// }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = { TdCache };
|
package/index.js
CHANGED
|
@@ -609,7 +609,6 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
|
|
|
609
609
|
|
|
610
610
|
async function startApp(settings, completionCallback) {
|
|
611
611
|
console.log("Starting Tilebot...");
|
|
612
|
-
// console.log("Starting Tilebot with Settings:", settings);
|
|
613
612
|
if (settings.bots) { // static bots data source
|
|
614
613
|
staticBots = settings.bots;
|
|
615
614
|
}
|
|
@@ -699,6 +699,7 @@ class TiledeskChatbotUtil {
|
|
|
699
699
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
|
|
700
700
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.attributes.departmentName);
|
|
701
701
|
}
|
|
702
|
+
|
|
702
703
|
if (message.attributes) {
|
|
703
704
|
if (chatbot.log) {console.log("Ok message.attributes", JSON.stringify(message.attributes));}
|
|
704
705
|
// if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > Ok message.attributes", JSON.stringify(message.attributes));}
|
|
@@ -919,7 +920,6 @@ class TiledeskChatbotUtil {
|
|
|
919
920
|
}
|
|
920
921
|
|
|
921
922
|
/**
|
|
922
|
-
* DEPRECATED
|
|
923
923
|
* A stub to get the request parameters, hosted by tilebot on:
|
|
924
924
|
* /${TILEBOT_ROUTE}/ext/parameters/requests/${requestId}?all
|
|
925
925
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.2.138
|
|
3
|
+
"version": "0.2.138",
|
|
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": "^
|
|
32
|
+
"redis": "^3.1.2",
|
|
33
33
|
"uuid": "^3.3.3",
|
|
34
34
|
"vm2": "^3.9.13"
|
|
35
35
|
},
|
|
@@ -624,10 +624,10 @@ class DirAskGPTV2 {
|
|
|
624
624
|
return new Promise((resolve) => {
|
|
625
625
|
let engine = {
|
|
626
626
|
name: "pinecone",
|
|
627
|
-
type:
|
|
627
|
+
type: process.env.PINECONE_TYPE,
|
|
628
628
|
apikey: "",
|
|
629
629
|
vector_size: 1536,
|
|
630
|
-
index_name:
|
|
630
|
+
index_name: process.env.PINECONE_INDEX
|
|
631
631
|
}
|
|
632
632
|
resolve(engine);
|
|
633
633
|
})
|
|
@@ -26,6 +26,7 @@ class DirMessage {
|
|
|
26
26
|
this.token = context.token;
|
|
27
27
|
this.log = this.context.log;
|
|
28
28
|
this.supportRequest = this.context.supportRequest
|
|
29
|
+
this.hMessage = false
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
execute(directive, callback) {
|
|
@@ -70,6 +71,7 @@ class DirMessage {
|
|
|
70
71
|
}
|
|
71
72
|
if (directive.name === Directives.HMESSAGE) {
|
|
72
73
|
action.attributes.subtype = "info";
|
|
74
|
+
this.hMessage = true;
|
|
73
75
|
}
|
|
74
76
|
// if (directive.name === Directives.HMESSAGE) {
|
|
75
77
|
// action.sender = "tiledesk";
|
|
@@ -95,7 +97,7 @@ class DirMessage {
|
|
|
95
97
|
const message = action;
|
|
96
98
|
if (this.log) {console.log("Message to extEndpoint:", JSON.stringify(message))};
|
|
97
99
|
|
|
98
|
-
if(this.supportRequest && !this.supportRequest.draft){
|
|
100
|
+
if(this.hMessage && this.supportRequest && !this.supportRequest.draft){
|
|
99
101
|
callback();
|
|
100
102
|
return;
|
|
101
103
|
}
|
package/TdCache_v3.js
DELETED
|
@@ -1,261 +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
|
-
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
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
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
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
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
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
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
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async setJSON(key, value, options) {
|
|
183
|
-
const _string = JSON.stringify(value);
|
|
184
|
-
return await this.set(key, _string, options);
|
|
185
|
-
}
|
|
186
|
-
|
|
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
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
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
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
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
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async getJSON(key, callback) {
|
|
245
|
-
const value = await this.get(key);
|
|
246
|
-
return JSON.parse(value);
|
|
247
|
-
}
|
|
248
|
-
|
|
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
|
-
})
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
module.exports = { TdCache };
|