@tiledesk/tiledesk-server 2.3.73 → 2.3.74
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/event/botEvent.js +13 -1
- package/middleware/passport.js +34 -7
- package/package.json +2 -2
- package/pubmodules/cache/mongoose-cachegoose-fn.js +38 -19
- package/services/BotSubscriptionNotifier.js +14 -1
- package/services/faqBotHandler.js +1 -1
- package/services/faqBotSupport.js +1 -1
- package/utils/sendMessageUtil.js +2 -2
package/event/botEvent.js
CHANGED
|
@@ -4,6 +4,8 @@ const Faq_kb = require('../models/faq_kb');
|
|
|
4
4
|
var winston = require('../config/winston');
|
|
5
5
|
|
|
6
6
|
class BotEvent extends EventEmitter {}
|
|
7
|
+
const cacheUtil = require("../utils/cacheUtil");
|
|
8
|
+
const cacheEnabler = require("../services/cacheEnabler");
|
|
7
9
|
|
|
8
10
|
const botEvent = new BotEvent();
|
|
9
11
|
|
|
@@ -108,7 +110,17 @@ messageEvent.on('message.create', function(message) {
|
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
|
|
111
|
-
Faq_kb.findById(botId)
|
|
113
|
+
let qbot = Faq_kb.findById(botId); //TODO add cache_bot_here
|
|
114
|
+
|
|
115
|
+
if (cacheEnabler.faq_kb) {
|
|
116
|
+
qbot.cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId)
|
|
117
|
+
winston.debug('faq_kb cache enabled');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
qbot.exec(function(err, bot) {
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
112
124
|
if (err) {
|
|
113
125
|
winston.error('Error getting object.', err);
|
|
114
126
|
return 0;
|
package/middleware/passport.js
CHANGED
|
@@ -18,7 +18,7 @@ var UserUtil = require('../utils/userUtil');
|
|
|
18
18
|
var jwt = require('jsonwebtoken');
|
|
19
19
|
const url = require('url');
|
|
20
20
|
var cacheUtil = require('../utils/cacheUtil');
|
|
21
|
-
|
|
21
|
+
var cacheEnabler = require("../services/cacheEnabler");
|
|
22
22
|
|
|
23
23
|
const MaskData = require("maskdata");
|
|
24
24
|
|
|
@@ -114,8 +114,18 @@ module.exports = function(passport) {
|
|
|
114
114
|
return done(null, null);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
winston.debug("bot id: "+ AudienceId );
|
|
118
|
-
Faq_kb.findById(AudienceId).select('+secret')
|
|
117
|
+
winston.debug("bot id AudienceId: "+ AudienceId );
|
|
118
|
+
let qbot = Faq_kb.findById(AudienceId).select('+secret');
|
|
119
|
+
|
|
120
|
+
if (cacheEnabler.faq_kb) {
|
|
121
|
+
let id_project = decoded.id_project;
|
|
122
|
+
winston.debug("decoded.id_project:"+decoded.id_project);
|
|
123
|
+
qbot.cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+AudienceId+":secret")
|
|
124
|
+
winston.debug('faq_kb AudienceId cache enabled');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
qbot.exec(function (err, faq_kb){ //TODO add cache_bot_here
|
|
119
129
|
if (err) {
|
|
120
130
|
winston.error("auth Faq_kb err: ", {error: err, decoded:decoded} );
|
|
121
131
|
return done(null, null);
|
|
@@ -247,7 +257,18 @@ module.exports = function(passport) {
|
|
|
247
257
|
|
|
248
258
|
if (subject == "bot") {
|
|
249
259
|
winston.debug("Passport JWT bot");
|
|
250
|
-
|
|
260
|
+
|
|
261
|
+
let qbot = Faq_kb.findOne({_id: identifier}); //TODO add cache_bot_here
|
|
262
|
+
|
|
263
|
+
if (cacheEnabler.faq_kb) {
|
|
264
|
+
let id_project = jwt_payload.id_project;
|
|
265
|
+
winston.debug("jwt_payload.id_project:"+jwt_payload.id_project);
|
|
266
|
+
qbot.cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+identifier)
|
|
267
|
+
winston.debug('faq_kb cache enabled');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
qbot.exec(function(err, faq_kb) {
|
|
271
|
+
|
|
251
272
|
if (err) {
|
|
252
273
|
winston.error("Passport JWT bot err", err);
|
|
253
274
|
return done(err, false);
|
|
@@ -326,9 +347,15 @@ module.exports = function(passport) {
|
|
|
326
347
|
|
|
327
348
|
} else {
|
|
328
349
|
winston.debug("Passport JWT generic user");
|
|
329
|
-
User.findOne({_id: identifier, status: 100})
|
|
350
|
+
let quser = User.findOne({_id: identifier, status: 100}) //TODO user_cache_here
|
|
330
351
|
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+identifier)
|
|
331
|
-
|
|
352
|
+
|
|
353
|
+
if (cacheEnabler.user) {
|
|
354
|
+
quser.cache(cacheUtil.defaultTTL, "users:id:"+identifier)
|
|
355
|
+
winston.debug('user cache enabled');
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
quser.exec(function(err, user) {
|
|
332
359
|
if (err) {
|
|
333
360
|
winston.error("Passport JWT generic err ", err);
|
|
334
361
|
return done(err, false);
|
|
@@ -358,7 +385,7 @@ module.exports = function(passport) {
|
|
|
358
385
|
var email = userid.toLowerCase();
|
|
359
386
|
winston.debug("email lowercase: " + email);
|
|
360
387
|
|
|
361
|
-
User.findOne({ email: email, status: 100}, 'email firstname lastname password emailverified id')
|
|
388
|
+
User.findOne({ email: email, status: 100}, 'email firstname lastname password emailverified id') //TODO user_cache_here. NOT used frequently. ma attento select. ATTENTO QUI NN USEREI LA SELECT altrimenti con JWT ho tuttto USER mentre con basich auth solo aluni campi
|
|
362
389
|
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:email:"+email)
|
|
363
390
|
.exec(function (err, user) {
|
|
364
391
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-server",
|
|
3
3
|
"description": "The Tiledesk server module",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.74",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node ./bin/www",
|
|
7
7
|
"pretest": "mongodb-runner start",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.33",
|
|
44
44
|
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
|
45
45
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
|
46
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.1.
|
|
46
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.1.50",
|
|
47
47
|
"@tiledesk/tiledesk-dialogflow-connector": "^1.8.3",
|
|
48
48
|
"app-root-path": "^3.0.0",
|
|
49
49
|
"bcrypt-nodejs": "0.0.3",
|
|
@@ -201,12 +201,13 @@
|
|
|
201
201
|
winston.verbose("Created cache for user.signup",{err:err});
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
204
|
+
// NOT IN USE (TESTED)
|
|
205
|
+
// var key = "users:email:"+user.email;
|
|
206
|
+
// winston.verbose("Creating cache for user.signup with key: " + key);
|
|
207
|
+
// client.set(key, user, cacheUtil.defaultTTL, (err, reply) => {
|
|
208
|
+
// winston.debug("Created cache for user.signup",reply);
|
|
209
|
+
// winston.verbose("Created cache for user.signup",{err:err});
|
|
210
|
+
// });
|
|
210
211
|
});
|
|
211
212
|
});
|
|
212
213
|
|
|
@@ -222,12 +223,13 @@
|
|
|
222
223
|
winston.verbose("Updated cache for user.update",{err:err});
|
|
223
224
|
});
|
|
224
225
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
226
|
+
// NOT IN USE (TESTED)
|
|
227
|
+
// var key = "users:email:"+user.email;
|
|
228
|
+
// winston.verbose("Updating cache for user.update with key: " + key);
|
|
229
|
+
// client.set(key, user, cacheUtil.defaultTTL, (err, reply) => {
|
|
230
|
+
// winston.debug("Updated cache for user.update",reply);
|
|
231
|
+
// winston.verbose("Updated cache for user.update",{err:err});
|
|
232
|
+
// });
|
|
231
233
|
});
|
|
232
234
|
});
|
|
233
235
|
|
|
@@ -242,12 +244,13 @@
|
|
|
242
244
|
winston.verbose("Deleted cache for user.delete",{err:err});
|
|
243
245
|
});
|
|
244
246
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
});
|
|
247
|
+
// NOT IN USE (TESTED)
|
|
248
|
+
// var key = "users:email:"+user.email;
|
|
249
|
+
// winston.verbose("Deleting cache for user.delete with key: " + key);
|
|
250
|
+
// client.del(key, (err, reply) => {
|
|
251
|
+
// winston.debug("Deleted cache for user.delete",reply);
|
|
252
|
+
// winston.verbose("Deleted cache for user.delete",{err:err});
|
|
253
|
+
// });
|
|
251
254
|
});
|
|
252
255
|
});
|
|
253
256
|
|
|
@@ -413,6 +416,14 @@
|
|
|
413
416
|
winston.verbose("Created cache for faq_kb.update",{err:err});
|
|
414
417
|
});
|
|
415
418
|
|
|
419
|
+
|
|
420
|
+
key = faq_kb.id_project+":faq_kbs:id:"+faq_kb._id+":secret";
|
|
421
|
+
winston.verbose("Deleting cache for faq_kb.update secret with key: " + key);
|
|
422
|
+
client.del(key, function (err, reply) { //tested
|
|
423
|
+
winston.debug("Deleted cache for faq_kb.update secret",reply);
|
|
424
|
+
winston.verbose("Deleted cache for faq_kb.update secret",{err:err});
|
|
425
|
+
});
|
|
426
|
+
|
|
416
427
|
// TODO invalidate widgets here
|
|
417
428
|
winston.verbose("Deleting widgets cache for faqbot.update");
|
|
418
429
|
invalidateWidgets(client, faq_kb.id_project); //TESTED
|
|
@@ -420,7 +431,7 @@
|
|
|
420
431
|
});
|
|
421
432
|
|
|
422
433
|
|
|
423
|
-
botEvent.on("faqbot.delete", function(faq_kb) {
|
|
434
|
+
botEvent.on("faqbot.delete", function(faq_kb) { //LOGIC deletion for chatbot is used
|
|
424
435
|
setImmediate(() => {
|
|
425
436
|
var key = faq_kb.id_project+":faq_kbs:id:"+faq_kb._id;
|
|
426
437
|
winston.verbose("Deleting cache for faqbot.delete with key: " + key);
|
|
@@ -429,6 +440,14 @@
|
|
|
429
440
|
winston.verbose("Deleted cache for faqbot.delete",{err:err});
|
|
430
441
|
});
|
|
431
442
|
|
|
443
|
+
|
|
444
|
+
key = faq_kb.id_project+":faq_kbs:id:"+faq_kb._id+":secret";
|
|
445
|
+
winston.verbose("Deleting cache for faq_kb.delete secret with key: " + key);
|
|
446
|
+
client.del(key, function (err, reply) {
|
|
447
|
+
winston.debug("Deleted cache for faq_kb.delete secret",reply);
|
|
448
|
+
winston.verbose("Deleted cache for faq_kb.delete secret",{err:err});
|
|
449
|
+
});
|
|
450
|
+
|
|
432
451
|
// TODO invalidate widgets here
|
|
433
452
|
winston.verbose("Deleting widgets cache for faqbot.delete");
|
|
434
453
|
invalidateWidgets(client, faq_kb.id_project); //tested
|
|
@@ -11,6 +11,9 @@ var request = require('retry-request', {
|
|
|
11
11
|
var webhook_origin = process.env.WEBHOOK_ORIGIN || "http://localhost:3000";
|
|
12
12
|
winston.debug("webhook_origin: "+webhook_origin);
|
|
13
13
|
|
|
14
|
+
var cacheUtil = require('../utils/cacheUtil');
|
|
15
|
+
var cacheEnabler = require("../services/cacheEnabler");
|
|
16
|
+
|
|
14
17
|
class BotSubscriptionNotifier {
|
|
15
18
|
|
|
16
19
|
|
|
@@ -76,7 +79,17 @@ class BotSubscriptionNotifier {
|
|
|
76
79
|
//modify to async
|
|
77
80
|
botEvent.on('bot.message.received.notify.external', function(botNotification) {
|
|
78
81
|
var bot = botNotification.bot;
|
|
79
|
-
|
|
82
|
+
winston.debug('getting botWithSecret');
|
|
83
|
+
let qbot = Faq_kb.findById(bot._id).select('+secret')
|
|
84
|
+
|
|
85
|
+
if (cacheEnabler.faq_kb) {
|
|
86
|
+
let id_project = bot.id_project;
|
|
87
|
+
winston.debug("id_project.id_project:"+id_project);
|
|
88
|
+
qbot.cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+bot._id+":secret")
|
|
89
|
+
winston.debug('faq_kb BotSubscriptionNotifier cache enabled');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
qbot.exec(function (err, botWithSecret){ //TODO add cache_bot_here????
|
|
80
93
|
if (err) {
|
|
81
94
|
winston.debug('Error getting botWithSecret', err);
|
|
82
95
|
}
|
|
@@ -86,7 +86,7 @@ class FaqBotHandler {
|
|
|
86
86
|
winston.debug("message.text "+ message.text);
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
Faq_kb.findById(botId)
|
|
89
|
+
Faq_kb.findById(botId) //TODO add cache_bot_NOT_here it's internal bot that is deprecated-> skip caching
|
|
90
90
|
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId)
|
|
91
91
|
.exec(function(err, faq_kb) {
|
|
92
92
|
if (err) {
|
|
@@ -126,7 +126,7 @@ class FaqBotSupport {
|
|
|
126
126
|
return resolve(messageReply);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
var botWithSecret = await Faq_kb.findById(bot._id).select('+secret').exec();
|
|
129
|
+
var botWithSecret = await Faq_kb.findById(bot._id).select('+secret').exec(); //TODO add cache_bot_nOT_here?? it's internal bot that is deprecated-> skip caching
|
|
130
130
|
|
|
131
131
|
var signOptions = {
|
|
132
132
|
issuer: 'https://tiledesk.com',
|
package/utils/sendMessageUtil.js
CHANGED
|
@@ -22,14 +22,14 @@ async send(sender, senderFullname, recipient, text, id_project, createdBy, attri
|
|
|
22
22
|
var id = sender.replace("bot_",""); // botprefix
|
|
23
23
|
winston.debug("bot id: "+id);
|
|
24
24
|
sender = id; //change sender removing bot_
|
|
25
|
-
var bot = await Faq_kb.findById(id)
|
|
25
|
+
var bot = await Faq_kb.findById(id) //TODO add cache_bot_here non sembra scattare.. dove viene usato?
|
|
26
26
|
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+id)
|
|
27
27
|
.exec();
|
|
28
28
|
winston.debug("bot",bot);
|
|
29
29
|
senderFullname = bot.name;
|
|
30
30
|
} else {
|
|
31
31
|
winston.debug("user id: "+sender);
|
|
32
|
-
var user = await User.findById(sender)
|
|
32
|
+
var user = await User.findById(sender) //TODO user_cache_here
|
|
33
33
|
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+sender) //user_cache
|
|
34
34
|
.exec()
|
|
35
35
|
winston.debug("user", user);
|