@tiledesk/tiledesk-server 2.4.45 → 2.4.47

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 CHANGED
@@ -65,13 +65,15 @@ class BotEvent extends EventEmitter {
65
65
  }
66
66
 
67
67
  // qui potresti leggere anche +secret ed evitare prossima query in botNotification
68
- let qbot = Faq_kb.findById(botId); //TODO add cache_bot_here
68
+ // let qbot = Faq_kb.findById(botId); //TODO add cache_bot_here
69
+ let qbot = Faq_kb.findById(botId).select('+secret')
69
70
  //TODO unselect secret. secret is unselectable by default in the model
70
71
 
71
72
  if (cacheEnabler.faq_kb) {
72
73
  winston.debug('message.id_project+":faq_kbs:id:"+botId: '+ message.id_project+":faq_kbs:id:"+botId);
73
- qbot.cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId)
74
- winston.debug('faq_kb cache enabled');
74
+ // qbot.cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId)
75
+ qbot.cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId+":secret")
76
+ winston.debug('faq_kb cache enabled');
75
77
  }
76
78
 
77
79
  qbot.exec(function(err, bot) {
@@ -87,6 +89,7 @@ class BotEvent extends EventEmitter {
87
89
  }
88
90
 
89
91
  winston.debug("bot debug", bot);
92
+ winston.debug('bot debug secret: '+ bot.secret);
90
93
 
91
94
  if (bot) {
92
95
  if (bot.type==="internal") {
package/jobs.js CHANGED
@@ -93,9 +93,9 @@ async function main()
93
93
  jobsManager.listenActivityArchiver(activityArchiver);
94
94
 
95
95
 
96
- // let routingQueue = require('./pubmodules/routing-queue').listener; //ci sono altri eventi che nn gestisco in queue request.participants.join etc
97
- // winston.info("routingQueue1");
98
- // jobsManager.listenRoutingQueue(routingQueue);
96
+ let routingQueueQueued = require('./pubmodules/routing-queue').listenerQueued;
97
+ winston.debug("routingQueueQueued");
98
+ jobsManager.listenRoutingQueue(routingQueueQueued);
99
99
 
100
100
 
101
101
 
package/jobsManager.js CHANGED
@@ -45,14 +45,14 @@ class JobsManager {
45
45
  this.emailNotification.requestNotification.listen();
46
46
  }
47
47
 
48
- // listenRoutingQueue(routingQueue) {
49
- // winston.info("JobsManager routingQueue started");
50
- // if ( this.jobWorkerEnabled == true) {
51
- // return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for routingQueue");
52
- // }
53
- // this.routingQueue = routingQueue;
54
- // this.routingQueue.listen();
55
- // }
48
+ listenRoutingQueue(routingQueue) {
49
+ winston.info("JobsManager routingQueue started");
50
+ if ( this.jobWorkerEnabled == true) {
51
+ return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for routingQueue");
52
+ }
53
+ this.routingQueue = routingQueue;
54
+ this.routingQueue.listen();
55
+ }
56
56
 
57
57
  listenScheduler(scheduler) {
58
58
  winston.info("JobsManager scheduler started");
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.4.45",
4
+ "version": "2.4.47",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -51,6 +51,7 @@ class PubModulesManager {
51
51
  this.jobsManager = undefined;
52
52
 
53
53
  this.routingQueue = undefined;
54
+ this.routingQueueQueued = undefined;
54
55
 
55
56
  this.cache = undefined;
56
57
 
@@ -407,8 +408,11 @@ class PubModulesManager {
407
408
 
408
409
  try {
409
410
  this.routingQueue = require('./routing-queue').listener;
411
+ this.routingQueueQueued = require('./routing-queue').listenerQueued;
412
+
410
413
  // this.routingQueue.listen();
411
414
  winston.debug("this.routingQueue:"+ this.routingQueue);
415
+ winston.debug("this.routingQueueQueued:"+ this.routingQueueQueued);
412
416
 
413
417
  winston.info("PubModulesManager routing queue initialized");
414
418
  } catch(err) {
@@ -515,13 +519,21 @@ class PubModulesManager {
515
519
 
516
520
  if (this.routingQueue) {
517
521
  try {
518
- this.routingQueue.listen();
519
- // this.jobsManager.listenRoutingQueue(this.routingQueue);
522
+ this.routingQueue.listen();
520
523
  winston.info("PubModulesManager routingQueue started");
521
524
  } catch(err) {
522
525
  winston.info("PubModulesManager error starting routingQueue module", err);
523
526
  }
524
527
  }
528
+ if (this.routingQueueQueued) {
529
+ try {
530
+ // this.routingQueueQueued.listen();
531
+ this.jobsManager.listenRoutingQueue(this.routingQueueQueued);
532
+ winston.info("PubModulesManager routingQueue queued started");
533
+ } catch(err) {
534
+ winston.info("PubModulesManager error starting routingQueue queued module", err);
535
+ }
536
+ }
525
537
 
526
538
  // if (this.dialogFlow) {
527
539
  // try {
@@ -1,3 +1,5 @@
1
1
  const listener = require("./listener");
2
+ const listenerQueued = require("./listenerQueued");
2
3
 
3
- module.exports = {listener:listener };
4
+
5
+ module.exports = {listener:listener, listenerQueued: listenerQueued };
@@ -1,13 +1,7 @@
1
- const projectEvent = require('../../event/projectEvent');
2
1
  const departmentEvent = require('../../event/departmentEvent');
3
- const authEvent = require('../../event/authEvent');
4
- const requestEvent = require('../../event/requestEvent');
5
2
  var Request = require('../../models/request');
6
- var Project = require('../../models/project');
7
- var Project_user = require('../../models/project_user');
8
3
  var winston = require('../../config/winston');
9
4
 
10
- var ProjectUserUtil = require("../../utils/project_userUtil");
11
5
 
12
6
  // var request = require('retry-request', {
13
7
  // request: require('request')
@@ -55,42 +49,6 @@ class Listener {
55
49
  // };
56
50
  }
57
51
 
58
- // db.getCollection('project_users').find({"number_assigned_requests" : {"$lt":0}}).count()
59
-
60
-
61
- updateProjectUser(id_user, id_project, operation) {
62
- winston.debug("updateProjectUser start");
63
- return Project_user
64
- .findOneAndUpdate({id_user: id_user, id_project: id_project}, {$inc : {'number_assigned_requests' : operation}}, {new: true, upsert:false}, function(err, updatedPU) {
65
- if (err) {
66
- return winston.error(err);
67
- }
68
- winston.debug("number_assigned_requests +1 :" + updatedPU.id);
69
-
70
- updatedPU.populate({path:'id_user', select:{'firstname':1, 'lastname':1}},function (err, updatedProject_userPopulated){
71
-
72
- var pu = updatedProject_userPopulated.toJSON();
73
-
74
- return Project.findById(id_project).exec(function(err, project) {
75
- pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
76
- winston.debug("pu.isBusy: "+ pu.isBusy);
77
- authEvent.emit('project_user.update', {updatedProject_userPopulated:pu, req: undefined, skipArchive: true});
78
- })
79
-
80
- });
81
-
82
- });
83
- }
84
-
85
- updateParticipatingProjectUsers(request, operation) {
86
- winston.debug("request.participatingAgents", request.participatingAgents);
87
- if (request.participatingAgents.length>0) {
88
- request.participatingAgents.forEach(user => {
89
- winston.debug("request.participatingAgents user",user); //it is a user and not a project_user
90
- this.updateProjectUser(user.id, request.id_project, operation);
91
- });
92
- }
93
- }
94
52
 
95
53
  listen() {
96
54
 
@@ -101,57 +59,6 @@ class Listener {
101
59
  }
102
60
 
103
61
  var that = this;
104
-
105
- // TODO fai versione che passa anche project
106
- requestEvent.on('request.create', async (request) => {
107
- setImmediate(() => {
108
- this.updateParticipatingProjectUsers(request, +1);
109
- });
110
- });
111
-
112
- // TODO usa versione complete con project per evitare query??
113
- requestEvent.on('request.close', async (request) => {
114
- setImmediate(() => {
115
- this.updateParticipatingProjectUsers(request, -1);
116
- });
117
- });
118
-
119
-
120
- requestEvent.on('request.participants.join', async (data) => {
121
- var request = data.request;
122
- var member = data.member;
123
- setImmediate(() => {
124
- this.updateProjectUser(member, request.id_project, 1);
125
- });
126
- });
127
-
128
- requestEvent.on('request.participants.leave', async (data) => {
129
- var request = data.request;
130
- var member = data.member;
131
- setImmediate(() => {
132
- this.updateProjectUser(member, request.id_project, -1);
133
- });
134
- });
135
-
136
- requestEvent.on('request.participants.update', async (data) => {
137
- var request = data.request;
138
- var removedParticipants = data.removedParticipants;
139
- var addedParticipants = data.addedParticipants;
140
-
141
- setImmediate(() => {
142
-
143
- addedParticipants.forEach(participant => {
144
- winston.debug('addedParticipants participant', participant);
145
- this.updateProjectUser(participant, request.id_project, 1);
146
- });
147
-
148
- removedParticipants.forEach(participant => {
149
- winston.debug('removedParticipants participant', participant);
150
- this.updateProjectUser(participant, request.id_project, -1);
151
- });
152
-
153
- });
154
- });
155
62
 
156
63
  departmentEvent.on('operator.select.base2', async (res) => {
157
64
  // departmentEvent.prependListener('operator.select', async (data) => {
@@ -170,9 +77,7 @@ class Listener {
170
77
 
171
78
  }
172
79
 
173
-
174
-
175
-
80
+
176
81
 
177
82
 
178
83
 
@@ -0,0 +1,194 @@
1
+ const authEvent = require('../../event/authEvent');
2
+ const requestEvent = require('../../event/requestEvent');
3
+ var Project = require('../../models/project');
4
+ var Project_user = require('../../models/project_user');
5
+ var winston = require('../../config/winston');
6
+
7
+ var ProjectUserUtil = require("../../utils/project_userUtil");
8
+
9
+ // var request = require('retry-request', {
10
+ // request: require('request')
11
+ // });
12
+
13
+ // TODO riabilitare questo
14
+
15
+ // const ROUTE_QUEUE_ENDPOINT = process.env.ROUTE_QUEUE_ENDPOINT;
16
+ // winston.debug("ROUTE_QUEUE_ENDPOINT: " + ROUTE_QUEUE_ENDPOINT);
17
+
18
+ // if (ROUTE_QUEUE_ENDPOINT) {
19
+ // winston.info("Route queue endpoint: " + ROUTE_QUEUE_ENDPOINT);
20
+ // } else {
21
+ // winston.info("Route queue endpoint not configured");
22
+ // }
23
+
24
+
25
+
26
+
27
+ // TODO web socket is not supported with queue
28
+ class Listener {
29
+
30
+
31
+ constructor() {
32
+ this.enabled = true;
33
+ if (process.env.ROUTE_QUEUE_ENABLED=="false" || process.env.ROUTE_QUEUE_ENABLED==false) {
34
+ this.enabled = false;
35
+ }
36
+ winston.debug("Listener this.enabled: "+ this.enabled);
37
+ }
38
+
39
+
40
+ // db.getCollection('project_users').find({"number_assigned_requests" : {"$lt":0}}).count()
41
+
42
+
43
+ updateProjectUser(id_user, id_project, operation) {
44
+ winston.debug("Route queue updateProjectUser start");
45
+ return Project_user
46
+ .findOneAndUpdate({id_user: id_user, id_project: id_project}, {$inc : {'number_assigned_requests' : operation}}, {new: true, upsert:false}, function(err, updatedPU) {
47
+ if (err) {
48
+ return winston.error(err);
49
+ }
50
+ winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
51
+
52
+ updatedPU.populate({path:'id_user', select:{'firstname':1, 'lastname':1}},function (err, updatedProject_userPopulated){
53
+
54
+ var pu = updatedProject_userPopulated.toJSON();
55
+
56
+ return Project.findById(id_project).exec(function(err, project) {
57
+ pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
58
+ winston.debug("Route queue pu.isBusy: "+ pu.isBusy);
59
+
60
+ authEvent.emit('project_user.update', {updatedProject_userPopulated:pu, req: undefined, skipArchive: true}); //if queued with jobs -> websocket notification on project_user.update doesn't work??? forse si in quanto viene convertito in .pub.queue e poi rifunziiona
61
+
62
+
63
+ // project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
64
+ if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
65
+ authEvent.emit('project_user.update.queue', {updatedProject_userPopulated:pu, req: undefined, skipArchive: true});
66
+ }
67
+
68
+ })
69
+
70
+ });
71
+
72
+ });
73
+ }
74
+
75
+ updateParticipatingProjectUsers(request, operation) {
76
+ winston.debug("Route queue request.participatingAgents", request.participatingAgents);
77
+ if (request.participatingAgents.length>0) {
78
+ request.participatingAgents.forEach(user => {
79
+ winston.debug("request.participatingAgents user",user); //it is a user and not a project_user
80
+ this.updateProjectUser(user.id, request.id_project, operation);
81
+ });
82
+ }
83
+ }
84
+
85
+ listen() {
86
+
87
+ if (this.enabled==true) {
88
+ winston.info("Route queue with queue Listener listen");
89
+ } else {
90
+ return winston.info("Route queue with queue Listener disabled");
91
+ }
92
+
93
+ var that = this;
94
+
95
+ // TODO fai versione che passa anche project
96
+ var requestCreateKey = 'request.create';
97
+ if (requestEvent.queueEnabled) {
98
+ requestCreateKey = 'request.create.queue';
99
+ }
100
+ winston.debug('Route queue requestCreateKey: ' + requestCreateKey);
101
+
102
+ requestEvent.on(requestCreateKey, async (request) => {
103
+ setImmediate(() => {
104
+ winston.debug('Route queue requestCreate');
105
+ this.updateParticipatingProjectUsers(request, +1);
106
+ });
107
+ });
108
+
109
+ // TODO usa versione complete con project per evitare query??
110
+ var requestCloseKey = 'request.close'; //request.close event here queued under job
111
+ if (requestEvent.queueEnabled) {
112
+ requestCloseKey = 'request.close.queue';
113
+ }
114
+ winston.debug('Route queue requestCloseKey: ' + requestCloseKey);
115
+
116
+ requestEvent.on(requestCloseKey, async (request) => { //request.close event here noqueued
117
+ winston.debug("request.close event here 4")
118
+ setImmediate(() => {
119
+ winston.debug('Route queue requestClose');
120
+ this.updateParticipatingProjectUsers(request, -1);
121
+ });
122
+ });
123
+
124
+
125
+ var requestParticipantsJoinKey = 'request.participants.join';
126
+ if (requestEvent.queueEnabled) {
127
+ requestParticipantsJoinKey = 'request.participants.join.queue';
128
+ }
129
+ winston.debug('Route queue requestParticipantsJoinKey: ' + requestParticipantsJoinKey);
130
+
131
+ requestEvent.on(requestParticipantsJoinKey, async (data) => {
132
+ winston.debug('Route queue ParticipantsJoin');
133
+
134
+ var request = data.request;
135
+ var member = data.member;
136
+ setImmediate(() => {
137
+ this.updateProjectUser(member, request.id_project, 1);
138
+ });
139
+ });
140
+
141
+ var requestParticipantsLeaveKey = 'request.participants.leave';
142
+ if (requestEvent.queueEnabled) {
143
+ requestParticipantsLeaveKey = 'request.participants.leave.queue';
144
+ }
145
+ winston.debug('Route queue requestParticipantsLeaveKey: ' + requestParticipantsLeaveKey);
146
+
147
+ requestEvent.on(requestParticipantsLeaveKey, async (data) => {
148
+ winston.debug('Route queue ParticipantsLeave');
149
+
150
+ var request = data.request;
151
+ var member = data.member;
152
+ setImmediate(() => {
153
+ this.updateProjectUser(member, request.id_project, -1);
154
+ });
155
+ });
156
+
157
+ var requestParticipantsUpdateKey = 'request.participants.update';
158
+ if (requestEvent.queueEnabled) {
159
+ requestParticipantsUpdateKey = 'request.participants.update.queue';
160
+ }
161
+ winston.debug('Route queue requestParticipantsUpdateKey: ' + requestParticipantsUpdateKey);
162
+
163
+ requestEvent.on(requestParticipantsUpdateKey, async (data) => {
164
+ winston.debug('Route queue Participants Update');
165
+
166
+ var request = data.request;
167
+ var removedParticipants = data.removedParticipants;
168
+ var addedParticipants = data.addedParticipants;
169
+
170
+ setImmediate(() => {
171
+
172
+ addedParticipants.forEach(participant => {
173
+ winston.debug('addedParticipants participant', participant);
174
+ this.updateProjectUser(participant, request.id_project, 1);
175
+ });
176
+
177
+ removedParticipants.forEach(participant => {
178
+ winston.debug('removedParticipants participant', participant);
179
+ this.updateProjectUser(participant, request.id_project, -1);
180
+ });
181
+
182
+ });
183
+ });
184
+
185
+
186
+
187
+ }
188
+
189
+ }
190
+
191
+ var listener = new Listener();
192
+
193
+
194
+ module.exports = listener;
package/routes/auth.js CHANGED
@@ -471,10 +471,10 @@ function (req, res) {
471
471
  // Redirect the user to the Google signin page</em>
472
472
  // router.get("/google", passport.authenticate("google", { scope: ["email", "profile"] }));
473
473
  router.get("/google", function(req,res,next){
474
- winston.info("redirect_url: "+ req.query.redirect_url );
474
+ winston.debug("redirect_url: "+ req.query.redirect_url );
475
475
  req.session.redirect_url = req.query.redirect_url;
476
476
 
477
- winston.info("forced_redirect_url: "+ req.query.forced_redirect_url );
477
+ winston.debug("forced_redirect_url: "+ req.query.forced_redirect_url );
478
478
  req.session.forced_redirect_url = req.query.forced_redirect_url;
479
479
 
480
480
  // req._toParam = 'Hello';
@@ -542,7 +542,7 @@ router.get("/google/callback", passport.authenticate("google", { session: false
542
542
  url = req.session.forced_redirect_url+"?jwt=JWT "+token; //attention we use jwt= (ionic) instead token=(dashboard) for ionic
543
543
  }
544
544
 
545
- winston.info("Google Redirect: "+ url);
545
+ winston.debug("Google Redirect: "+ url);
546
546
 
547
547
  res.redirect(url);
548
548
 
package/routes/request.js CHANGED
@@ -459,7 +459,7 @@ router.put('/:requestid/agent', async (req, res) => {
459
459
  winston.debug(req.body);
460
460
  //route(request_id, departmentid, id_project) {
461
461
 
462
-
462
+
463
463
  var request = await Request.findOne({"request_id":req.params.requestid, id_project:req.projectid})
464
464
  .exec();
465
465
 
@@ -817,7 +817,7 @@ router.get('/', function (req, res, next) {
817
817
 
818
818
  if (req.user instanceof Subscription) {
819
819
  //all request
820
- } else if (projectuser && projectuser.role == "owner" || projectuser.role == "admin") {
820
+ } else if (projectuser && (projectuser.role == "owner" || projectuser.role == "admin")) {
821
821
  //all request
822
822
  // per uni mostrare solo quelle priprio quindi solo participants
823
823
  if (req.query.mine) {
@@ -1030,6 +1030,8 @@ router.get('/', function (req, res, next) {
1030
1030
  }
1031
1031
 
1032
1032
 
1033
+
1034
+
1033
1035
  var direction = -1; //-1 descending , 1 ascending
1034
1036
  if (req.query.direction) {
1035
1037
  direction = req.query.direction;
@@ -14,10 +14,13 @@ winston.debug("webhook_origin: "+webhook_origin);
14
14
  var cacheUtil = require('../utils/cacheUtil');
15
15
  var cacheEnabler = require("../services/cacheEnabler");
16
16
 
17
+
18
+
19
+
17
20
  class BotSubscriptionNotifier {
18
21
 
19
22
 
20
- notify(bot,botWithSecret, payload) {
23
+ notify(bot,secret, payload) {
21
24
 
22
25
  winston.debug("BotSubscriptionNotifier bot", bot.toObject());
23
26
  winston.debug("BotSubscriptionNotifier payload", payload );
@@ -58,7 +61,7 @@ class BotSubscriptionNotifier {
58
61
  delete botPayload.description;
59
62
  delete botPayload.attributes;
60
63
 
61
- var token = jwt.sign(botPayload, botWithSecret.secret, signOptions);
64
+ var token = jwt.sign(botPayload, secret, signOptions);
62
65
  json["token"] = token;
63
66
 
64
67
 
@@ -93,25 +96,33 @@ class BotSubscriptionNotifier {
93
96
  //modify to async
94
97
  botEvent.on('bot.message.received.notify.external', function(botNotification) {
95
98
  var bot = botNotification.bot;
96
- winston.debug('getting botWithSecret');
97
- let qbot = Faq_kb.findById(bot._id).select('+secret')
98
-
99
- if (cacheEnabler.faq_kb) {
100
- let id_project = bot.id_project;
101
- winston.debug("id_project.id_project:"+id_project);
102
- qbot.cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+bot._id+":secret")
103
- winston.debug('faq_kb BotSubscriptionNotifier cache enabled');
104
- }
105
-
106
- qbot.exec(function (err, botWithSecret){ //TODO add cache_bot_here????
107
- if (err) {
108
- winston.debug('Error getting botWithSecret', err);
109
- }
110
- botSubscriptionNotifier.notify(bot, botWithSecret, botNotification.message);
111
- });
99
+ var secret = bot.secret;
100
+ winston.debug('bot.message.received.notify.external: '+secret);
101
+
102
+ // winston.debug('getting botWithSecret');
103
+ // let qbot = Faq_kb.findById(bot._id).select('+secret')
104
+
105
+ // if (cacheEnabler.faq_kb) {
106
+ // let id_project = bot.id_project;
107
+ // winston.debug("id_project.id_project:"+id_project);
108
+ // qbot.cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+bot._id+":secret")
109
+ // winston.debug('faq_kb BotSubscriptionNotifier cache enabled');
110
+ // }
111
+
112
+ // qbot.exec(function (err, botWithSecret){ //TODO add cache_bot_here????
113
+ // if (err) {
114
+ // winston.debug('Error getting botWithSecret', err);
115
+ // }
116
+ // botSubscriptionNotifier.notify(bot, botWithSecret, botNotification.message);
117
+ // });
112
118
 
119
+ botSubscriptionNotifier.notify(bot, secret, botNotification.message);
120
+
121
+
113
122
  });
114
123
 
124
+
125
+
115
126
  winston.info('BotSubscriptionNotifier started');
116
127
 
117
128
  }