@tiledesk/tiledesk-server 2.9.29 → 2.9.31

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.9.31
9
+ - Improved conversations queues management
10
+ - Added conversation status 150 (ABANDONED)
11
+
12
+ # 2.9.30
13
+ - Restore Voice and SMS modules
14
+
8
15
  # 2.9.29
9
16
  - Fixed bug: try to update non existant project user (bot)
10
17
 
@@ -1,6 +1,7 @@
1
1
  module.exports = {
2
2
  TEMP : 50,
3
3
  UNASSIGNED : 100,
4
+ ABANDONED: 150,
4
5
  ASSIGNED : 200,
5
6
  SERVED : 300,
6
7
  CLOSED: 1000
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.29",
4
+ "version": "2.9.31",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -33,11 +33,11 @@ class PubModulesManager {
33
33
  this.telegram = undefined;
34
34
  this.telegramRoute = undefined;
35
35
 
36
- // this.sms = undefined;
37
- // this.smsRoute = undefined;
36
+ this.sms = undefined;
37
+ this.smsRoute = undefined;
38
38
 
39
- // this.voice = undefined;
40
- // this.voiceRoute = undefined;
39
+ this.voice = undefined;
40
+ this.voiceRoute = undefined;
41
41
 
42
42
  this.mqttTest = undefined;
43
43
  this.mqttTestRoute = undefined;
@@ -97,14 +97,14 @@ class PubModulesManager {
97
97
  app.use('/modules/telegram', this.telegramRoute);
98
98
  winston.info("PubModulesManager telegramRoute controller loaded");
99
99
  }
100
- // if (this.smsRoute) {
101
- // app.use('/modules/sms', this.smsRoute);
102
- // winston.info("PubModulesManager smsRoute controller loaded");
103
- // }
104
- // if (this.voiceRoute) {
105
- // app.use('/modules/voice', this.voiceRoute);
106
- // winston.info("PubModulesManager voiceRoute controller loaded");
107
- // }
100
+ if (this.smsRoute) {
101
+ app.use('/modules/sms', this.smsRoute);
102
+ winston.info("PubModulesManager smsRoute controller loaded");
103
+ }
104
+ if (this.voiceRoute) {
105
+ app.use('/modules/voice', this.voiceRoute);
106
+ winston.info("PubModulesManager voiceRoute controller loaded");
107
+ }
108
108
  if (this.mqttTestRoute) {
109
109
  app.use('/modules/mqttTest', this.mqttTestRoute);
110
110
  winston.info("PubModulesManager mqttTestRoute controller loaded");
@@ -345,40 +345,40 @@ class PubModulesManager {
345
345
  }
346
346
  }
347
347
 
348
- // if (process.env.VOICE_TOKEN === process.env.VOICE_SECRET) {
349
- // try {
350
- // this.voice = require('./voice');
351
- // winston.info("this.voice: " + this.voice);
352
- // this.voice.listener.listen(config);
348
+ if (process.env.VOICE_TOKEN === process.env.VOICE_SECRET) {
349
+ try {
350
+ this.voice = require('./voice');
351
+ winston.info("this.voice: " + this.voice);
352
+ this.voice.listener.listen(config);
353
353
 
354
- // this.voiceRoute = this.voice.voiceRoute;
354
+ this.voiceRoute = this.voice.voiceRoute;
355
355
 
356
- // winston.info("PubModulesManager initialized apps (voice).")
357
- // } catch(err) {
358
- // console.log("\n Unable to start voice connector: ", err);
359
- // if (err.code == 'MODULE_NOT_FOUND') {
360
- // winston.info("PubModulesManager init apps module not found ");
361
- // } else {
362
- // winston.info("PubModulesManager error initializing init apps module", err);
363
- // }
364
- // }
365
- // }
356
+ winston.info("PubModulesManager initialized apps (voice).")
357
+ } catch(err) {
358
+ console.log("\n Unable to start voice connector: ", err);
359
+ if (err.code == 'MODULE_NOT_FOUND') {
360
+ winston.info("PubModulesManager init apps module not found ");
361
+ } else {
362
+ winston.info("PubModulesManager error initializing init apps module", err);
363
+ }
364
+ }
365
+ }
366
366
 
367
- // try {
368
- // this.sms = require('./sms');
369
- // winston.info("this.sms: " + this.sms);
370
- // this.sms.listener.listen(config);
367
+ try {
368
+ this.sms = require('./sms');
369
+ winston.info("this.sms: " + this.sms);
370
+ this.sms.listener.listen(config);
371
371
 
372
- // this.smsRoute = this.sms.smsRoute;
372
+ this.smsRoute = this.sms.smsRoute;
373
373
 
374
- // winston.info("PubModulesManager initialized apps (sms).")
375
- // } catch(err) {
376
- // if (err.code == 'MODULE_NOT_FOUND') {
377
- // winston.info("PubModulesManager init apps module not found ");
378
- // } else {
379
- // winston.info("PubModulesManager error initializing init apps module", err);
380
- // }
381
- // }
374
+ winston.info("PubModulesManager initialized apps (sms).")
375
+ } catch(err) {
376
+ if (err.code == 'MODULE_NOT_FOUND') {
377
+ winston.info("PubModulesManager init apps module not found ");
378
+ } else {
379
+ winston.info("PubModulesManager error initializing init apps module", err);
380
+ }
381
+ }
382
382
 
383
383
  try {
384
384
  this.mqttTest = require('./mqttTest');
@@ -177,7 +177,11 @@ class Listener {
177
177
  winston.debug("abandoned_by_project_usersAsArray", abandoned_by_project_usersAsArray);
178
178
 
179
179
  var available_agents_not_busy = available_agents_not_busy.filter(projectUser=> !abandoned_by_project_usersAsArray.includes(projectUser._id.toString()))
180
-
180
+
181
+ if (available_agents_not_busy.length == 0) {
182
+ res.context.request.attributes.fully_abandoned = true;
183
+ }
184
+
181
185
  winston.debug("available_agents_not_busy after: ", available_agents_not_busy );
182
186
  }
183
187
  }
@@ -50,7 +50,7 @@ class Listener {
50
50
  return winston.warn("Chatbot is not a project_user. Skip update.")
51
51
  }
52
52
 
53
- return Request.countDocuments({ id_project: id_project, participantsAgents: id_user, status: { $lt: 1000 } }, (err, requestsCount) => {
53
+ return Request.countDocuments({ id_project: id_project, participantsAgents: id_user, status: { $lt: 1000 }, draft: { $in: [null, false] } }, (err, requestsCount) => {
54
54
  winston.verbose("requestsCount for id_user: ", id_user, "and project: ", id_project, "-->", requestsCount);
55
55
  if (err) {
56
56
  return winston.error(err);
package/routes/request.js CHANGED
@@ -881,8 +881,10 @@ router.get('/', function (req, res, next) {
881
881
  winston.debug('REQUEST ROUTE - QUERY ', req.query)
882
882
 
883
883
  const DEFAULT_LIMIT = 40;
884
-
884
+
885
+ var page = 0;
885
886
  var limit = DEFAULT_LIMIT; // Number of request per page
887
+ let statusArray = [];
886
888
 
887
889
  if (req.query.limit) {
888
890
  limit = parseInt(req.query.limit);
@@ -891,9 +893,6 @@ router.get('/', function (req, res, next) {
891
893
  limit = DEFAULT_LIMIT;
892
894
  }
893
895
 
894
-
895
- var page = 0;
896
-
897
896
  if (req.query.page) {
898
897
  page = req.query.page;
899
898
  }
@@ -901,14 +900,11 @@ router.get('/', function (req, res, next) {
901
900
  var skip = page * limit;
902
901
  winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
903
902
 
904
- let statusArray = [];
905
-
906
- var query = { "id_project": req.projectid, "status": { $lt: 1000 }, preflight: false };
907
-
903
+ // Default Query
904
+ var query = { "id_project": req.projectid, "status": { $lt: 1000, $ne: 150 }, preflight: false };
908
905
 
909
906
  var projectuser = req.projectuser;
910
907
 
911
-
912
908
  if (req.user instanceof Subscription) {
913
909
  //all request
914
910
  } else if (projectuser && (projectuser.role == "owner" || projectuser.role == "admin")) {
@@ -921,7 +917,6 @@ router.get('/', function (req, res, next) {
921
917
  query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
922
918
  }
923
919
 
924
-
925
920
  if (req.query.dept_id) {
926
921
  query.department = req.query.dept_id;
927
922
  winston.debug('REQUEST ROUTE - QUERY DEPT ID', query.department);
@@ -1170,6 +1165,10 @@ router.get('/', function (req, res, next) {
1170
1165
  sortQuery[sortField] = direction;
1171
1166
  winston.debug("sort query", sortQuery);
1172
1167
 
1168
+ if (req.query.abandonded && (req.query.abandoned === true || req.query.abandoned === 'true')) {
1169
+ query["attributes.fully_abandoned"] = true
1170
+ }
1171
+
1173
1172
  if (req.query.draft && (req.query.draft === 'false' || req.query.draft === false)) {
1174
1173
  query.draft = { $in: [false, null] }
1175
1174
  }
@@ -1190,10 +1189,6 @@ router.get('/', function (req, res, next) {
1190
1189
  var q1 = Request.find(query, projection).
1191
1190
  skip(skip).limit(limit);
1192
1191
 
1193
-
1194
-
1195
-
1196
-
1197
1192
  winston.debug('REQUEST ROUTE no_populate:' + req.query.no_populate);
1198
1193
 
1199
1194
  if (req.query.no_populate != "true" && req.query.no_populate != true) {
@@ -310,6 +310,20 @@ class RequestService {
310
310
 
311
311
  winston.verbose("Request " + request.request_id + " contains already the same participants at the same request status. Routed to the same participants");
312
312
 
313
+ if (routedRequest.attributes.fully_abandoned && routedRequest.attributes.fully_abandoned === true) {
314
+ request.status = RequestConstants.ABANDONED;
315
+ request.attributes.fully_abandoned = true;
316
+ request.markModified('status');
317
+ request.markModified('attributes');
318
+ request.save((err, savedRequest) => {
319
+ if (err) {
320
+ winston.error("Error updating request with status ABANDONED ", err);
321
+ } else {
322
+ winston.verbose("Status modified in ABANDONED for request: " + savedRequest._id);
323
+ }
324
+ })
325
+ }
326
+
313
327
  if (no_populate === "true" || no_populate === true) {
314
328
  winston.debug("no_populate is true");
315
329
  return resolve(request);
@@ -310,7 +310,7 @@ class WebSocketServer {
310
310
 
311
311
  // db.getCollection('requests').find({"id_project":"5e15bef09877c800176d217f","status":{"$lt":1000},"$or":[{"agents":{"id_user":"5ddd30bff0195f0017f72c6d"}},{"participants":"5ddd30bff0195f0017f72c6d"}]})
312
312
  // pubblica dopo toni
313
- var query = { "id_project": projectId, "status": { $lt: 1000, $gt: 50 }, preflight: false, "draft": { $in: [false, null] } };
313
+ var query = { "id_project": projectId, "status": { $lt: 1000, $gt: 50, $ne: 150 }, preflight: false, "draft": { $in: [false, null] } };
314
314
  // add hasBot:false
315
315
 
316
316
  // var query = {"id_project":projectId, "status": { $lt: 1000, $gt: 50 }, $or:[ {preflight:false}, { preflight : { $exists: false } } ] };