@tiledesk/tiledesk-server 2.9.27 → 2.9.29

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,12 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.9.29
9
+ - Fixed bug: try to update non existant project user (bot)
10
+
11
+ # 2.9.28
12
+ - Updated number_assigned_request count logic (removed incr/decr)
13
+
8
14
  # 2.9.27
9
15
  - Updated tybot-connector to 0.2.107
10
16
  - Improved quotas slots
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.9.27",
4
+ "version": "2.9.29",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -2,6 +2,7 @@ const authEvent = require('../../event/authEvent');
2
2
  const requestEvent = require('../../event/requestEvent');
3
3
  var Project = require('../../models/project');
4
4
  var Project_user = require('../../models/project_user');
5
+ var Request = require('../../models/request')
5
6
  var winston = require('../../config/winston');
6
7
 
7
8
  var ProjectUserUtil = require("../../utils/project_userUtil");
@@ -34,44 +35,93 @@ class Listener {
34
35
  this.enabled = false;
35
36
  }
36
37
  winston.debug("Listener this.enabled: "+ this.enabled);
37
- }
38
+ }
38
39
 
39
40
 
40
- // db.getCollection('project_users').find({"number_assigned_requests" : {"$lt":0}}).count()
41
+ // db.getCollection('project_users').find({"number_assigned_requests" : {"$lt":0}}).count()
42
+
43
+ // New version of updateProjectUser() method.
44
+ // This will not increment or decrement the number_assigned_requests field but search the exact number of assigned conversation to the project user
45
+ updateProjectUser(id_user, id_project, operation) {
46
+ // winston.debug("Route queue updateProjectUser start operation: " + operation + "id_user " + id_user + " id_project " + id_project);
47
+
48
+ // escludi id_user che iniziano con bot_
49
+ if (id_user.startsWith('bot_')) {
50
+ return winston.warn("Chatbot is not a project_user. Skip update.")
51
+ }
52
+
53
+ return Request.countDocuments({ id_project: id_project, participantsAgents: id_user, status: { $lt: 1000 } }, (err, requestsCount) => {
54
+ winston.verbose("requestsCount for id_user: ", id_user, "and project: ", id_project, "-->", requestsCount);
55
+ if (err) {
56
+ return winston.error(err);
57
+ }
58
+
59
+ return Project_user
60
+ .findOneAndUpdate({ id_user: id_user, id_project: id_project }, { number_assigned_requests: requestsCount }, { new: true, upsert: false }, function (err, updatedPU) {
61
+ if (err) {
62
+ return winston.error(err);
63
+ }
64
+ // winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
65
+ // winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
66
+ winston.debug("Route queue number_assigned_requests updated to " + requestsCount + "for project user " + updatedPU.id);
67
+
68
+ updatedPU.populate({ path: 'id_user', select: { 'firstname': 1, 'lastname': 1 } }, function (err, updatedProject_userPopulated) {
69
+
70
+ var pu = updatedProject_userPopulated.toJSON();
71
+
72
+ return Project.findById(id_project).exec(function (err, project) {
73
+ pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
74
+ winston.debug("Route queue pu.isBusy: " + pu.isBusy);
75
+
76
+ 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
77
+
78
+
79
+ // project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
80
+ if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
81
+ authEvent.emit('project_user.update.queue', { updatedProject_userPopulated: pu, req: undefined, skipArchive: true });
82
+ }
83
+
84
+ })
85
+
86
+ });
87
+
88
+ });
89
+ })
41
90
 
91
+ }
42
92
 
43
- updateProjectUser(id_user, id_project, operation) {
44
- winston.debug("Route queue updateProjectUser start operation: " +operation+ "id_user "+ id_user + " id_project " + id_project );
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
- winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
93
+ _updateProjectUser(id_user, id_project, operation) {
94
+ winston.debug("Route queue updateProjectUser start operation: " + operation + "id_user " + id_user + " id_project " + id_project);
95
+ return Project_user
96
+ .findOneAndUpdate({ id_user: id_user, id_project: id_project }, { $inc: { 'number_assigned_requests': operation } }, { new: true, upsert: false }, function (err, updatedPU) {
97
+ if (err) {
98
+ return winston.error(err);
99
+ }
100
+ winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
101
+ winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
52
102
 
53
- updatedPU.populate({path:'id_user', select:{'firstname':1, 'lastname':1}},function (err, updatedProject_userPopulated){
103
+ updatedPU.populate({ path: 'id_user', select: { 'firstname': 1, 'lastname': 1 } }, function (err, updatedProject_userPopulated) {
54
104
 
55
- var pu = updatedProject_userPopulated.toJSON();
105
+ var pu = updatedProject_userPopulated.toJSON();
56
106
 
57
- return Project.findById(id_project).exec(function(err, project) {
58
- pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
59
- winston.debug("Route queue pu.isBusy: "+ pu.isBusy);
60
-
61
- 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
107
+ return Project.findById(id_project).exec(function (err, project) {
108
+ pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
109
+ winston.debug("Route queue pu.isBusy: " + pu.isBusy);
62
110
 
111
+ 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
63
112
 
64
- // project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
65
- if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
66
- authEvent.emit('project_user.update.queue', {updatedProject_userPopulated:pu, req: undefined, skipArchive: true});
67
- }
68
113
 
69
- })
70
-
71
- });
114
+ // project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
115
+ if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
116
+ authEvent.emit('project_user.update.queue', { updatedProject_userPopulated: pu, req: undefined, skipArchive: true });
117
+ }
72
118
 
73
- });
74
- }
119
+ })
120
+
121
+ });
122
+
123
+ });
124
+ }
75
125
 
76
126
  updateParticipatingProjectUsers(request, operation) {
77
127
  winston.debug("Route queue request.participatingAgents", request.participatingAgents);
@@ -198,27 +198,6 @@ class WebSocketServer {
198
198
  var projectId = urlSub[1];
199
199
  winston.debug('projectId: ' + projectId);
200
200
 
201
- // sponz support 65203e12f8c0cf002cf4110b
202
- // johnny support 62c3f10152dc7400352bab0d
203
- // sponz collaudo 66acec0cf7ebf80013d67974
204
- // johnny collaudo 6613ff078890fc0013ad3c3a
205
- // sponz prod 6565047fdd64fd001323f37c
206
- // mweb prod 656054000410fa00132e5dcc
207
-
208
- if (projectId === "65203e12f8c0cf002cf4110b"
209
- || projectId === "62c3f10152dc7400352bab0d"
210
- || projectId === "66acec0cf7ebf80013d67974"
211
- || projectId === "6613ff078890fc0013ad3c3a"
212
- || projectId === "6565047fdd64fd001323f37c"
213
- || projectId === "656054000410fa00132e5dcc") {
214
-
215
- console.log('WSS onSubscribeCallback - ProjectID ' + projectId);
216
- console.log("x-forwarded-for: ", req.headers['x-forwarded-for'], "remote port: ", req.socket.remotePort);
217
- console.log("remoteAddress: ", req.socket.remoteAddress)
218
- }
219
-
220
-
221
-
222
201
  let q = Project.findOne({ _id: projectId, status: 100 })
223
202
 
224
203
  if (cacheEnabler.project) {