@tiledesk/tiledesk-server 2.10.12 → 2.10.13
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -0
- package/package.json +2 -2
- package/routes/request.js +44 -33
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
+
# 2.10.13
|
9
|
+
- Updated tybot-connector to 0.2.127
|
10
|
+
- Added event on request fully abandoned
|
11
|
+
|
8
12
|
# 2.10.12
|
9
13
|
- Updated tiledesk-chatbot-template to 0.1.3
|
10
14
|
- Added check on valid mongo id
|
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.10.
|
4
|
+
"version": "2.10.13",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -48,7 +48,7 @@
|
|
48
48
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
49
49
|
"@tiledesk/tiledesk-telegram-connector": "^0.1.14",
|
50
50
|
"@tiledesk/tiledesk-train-jobworker": "^0.0.11",
|
51
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.2.
|
51
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.2.127",
|
52
52
|
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.73",
|
53
53
|
"@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.8",
|
54
54
|
"@tiledesk/tiledesk-sms-connector": "^0.1.10",
|
package/routes/request.js
CHANGED
@@ -30,6 +30,7 @@ csv.separator = ';';
|
|
30
30
|
|
31
31
|
const { check, validationResult } = require('express-validator');
|
32
32
|
const RoleConstants = require('../models/roleConstants');
|
33
|
+
const eventService = require('../pubmodules/events/eventService');
|
33
34
|
|
34
35
|
// var messageService = require('../services/messageService');
|
35
36
|
|
@@ -182,7 +183,7 @@ router.post('/',
|
|
182
183
|
|
183
184
|
winston.debug('res.json(savedRequest)');
|
184
185
|
var endTimestamp = new Date();
|
185
|
-
winston.verbose("request create end: " + (endTimestamp - startTimestamp));
|
186
|
+
winston.verbose("(Request Route) request create end: " + (endTimestamp - startTimestamp));
|
186
187
|
return res.json(savedRequest);
|
187
188
|
// });
|
188
189
|
// });
|
@@ -273,7 +274,7 @@ router.patch('/:requestid', function (req, res) {
|
|
273
274
|
|
274
275
|
|
275
276
|
|
276
|
-
winston.verbose("Request patch update", update);
|
277
|
+
winston.verbose("(Request Route) Request patch update", update);
|
277
278
|
|
278
279
|
//cacheinvalidation
|
279
280
|
return Request.findOneAndUpdate({ "request_id": req.params.requestid, "id_project": req.projectid }, { $set: update }, { new: true, upsert: false })
|
@@ -326,18 +327,18 @@ router.put('/:requestid/close', async function (req, res) {
|
|
326
327
|
})
|
327
328
|
|
328
329
|
if (!request) {
|
329
|
-
winston.verbose("Request with request_id " + request_id)
|
330
|
+
winston.verbose("(Request Route) Request with request_id " + request_id)
|
330
331
|
return res.status(404).send({ success: false, error: "Request not found"})
|
331
332
|
}
|
332
333
|
|
333
334
|
if (!request.participantsAgents.includes(req.user.id)) {
|
334
|
-
winston.verbose("Request can't be closed by a non participant. Attempt made by " + req.user.id);
|
335
|
+
winston.verbose("(Request Route) Request can't be closed by a non participant. Attempt made by " + req.user.id);
|
335
336
|
return res.status(403).send({ success: false, error: "You must be among the participants to close a conversation."})
|
336
337
|
}
|
337
338
|
}
|
338
339
|
|
339
340
|
return requestService.closeRequestByRequestId(req.params.requestid, req.projectid, false, true, closed_by, req.body.force).then(function (closedRequest) {
|
340
|
-
winston.verbose("request closed", closedRequest);
|
341
|
+
winston.verbose("(Request Route) request closed", closedRequest);
|
341
342
|
return res.json(closedRequest);
|
342
343
|
});
|
343
344
|
|
@@ -349,7 +350,7 @@ router.put('/:requestid/reopen', function (req, res) {
|
|
349
350
|
// reopenRequestByRequestId(request_id, id_project) {
|
350
351
|
return requestService.reopenRequestByRequestId(req.params.requestid, req.projectid).then(function (reopenRequest) {
|
351
352
|
|
352
|
-
winston.verbose("request reopen", reopenRequest);
|
353
|
+
winston.verbose("(Request Route) request reopen", reopenRequest);
|
353
354
|
|
354
355
|
return res.json(reopenRequest);
|
355
356
|
});
|
@@ -380,7 +381,7 @@ router.post('/:requestid/participants',
|
|
380
381
|
//addParticipantByRequestId(request_id, id_project, member)
|
381
382
|
return requestService.addParticipantByRequestId(req.params.requestid, req.projectid, req.body.member).then(function (updatedRequest) {
|
382
383
|
|
383
|
-
winston.verbose("participant added", updatedRequest);
|
384
|
+
winston.verbose("(Request Route) participant added", updatedRequest);
|
384
385
|
|
385
386
|
return res.json(updatedRequest);
|
386
387
|
});
|
@@ -420,7 +421,7 @@ router.delete('/:requestid/participants/:participantid', function (req, res) {
|
|
420
421
|
//removeParticipantByRequestId(request_id, id_project, member)
|
421
422
|
return requestService.removeParticipantByRequestId(req.params.requestid, req.projectid, req.params.participantid).then(function (updatedRequest) {
|
422
423
|
|
423
|
-
winston.verbose("participant removed", updatedRequest);
|
424
|
+
winston.verbose("(Request Route) participant removed", updatedRequest);
|
424
425
|
|
425
426
|
return res.json(updatedRequest);
|
426
427
|
});
|
@@ -451,10 +452,16 @@ router.delete('/:requestid/participants/:participantid', function (req, res) {
|
|
451
452
|
router.put('/:requestid/assign', function (req, res) {
|
452
453
|
winston.debug(req.body);
|
453
454
|
|
454
|
-
|
455
|
+
let id_project = req.projectid;
|
456
|
+
let user = req.user;
|
457
|
+
let pu;
|
458
|
+
if (req.projectuser) {
|
459
|
+
pu = req.projectuser.id;
|
460
|
+
}
|
455
461
|
|
456
|
-
//
|
457
|
-
|
462
|
+
// leggi la request se già assegnata o già chiusa (1000) esci
|
463
|
+
// cacheinvalidation
|
464
|
+
return Request.findOne({ "request_id": req.params.requestid, "id_project": id_project })
|
458
465
|
.exec(function (err, request) {
|
459
466
|
|
460
467
|
if (err) {
|
@@ -467,13 +474,17 @@ router.put('/:requestid/assign', function (req, res) {
|
|
467
474
|
}
|
468
475
|
|
469
476
|
if (request.status === RequestConstants.ASSIGNED || request.status === RequestConstants.SERVED || request.status === RequestConstants.CLOSED) {
|
470
|
-
winston.
|
477
|
+
winston.verbose('(Request Route) Request already assigned');
|
471
478
|
return res.json(request);
|
472
479
|
}
|
473
480
|
//route(request_id, departmentid, id_project) {
|
474
|
-
requestService.route(req.params.requestid, req.body.departmentid,
|
481
|
+
requestService.route(req.params.requestid, req.body.departmentid, id_project, req.body.nobot, req.body.no_populate).then(function (updatedRequest) {
|
475
482
|
|
476
|
-
winston.debug("
|
483
|
+
winston.debug("request routed ", updatedRequest);
|
484
|
+
|
485
|
+
if (updatedRequest.status === RequestConstants.ABANDONED) {
|
486
|
+
eventService.emit('request.fully_abandoned', updatedRequest, id_project, pu, user._id, undefined, user);
|
487
|
+
}
|
477
488
|
|
478
489
|
return res.json(updatedRequest);
|
479
490
|
}).catch(function (error) {
|
@@ -624,7 +635,7 @@ router.patch('/:requestid/attributes', function (req, res) {
|
|
624
635
|
winston.error("error saving request attributes", err)
|
625
636
|
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
626
637
|
}
|
627
|
-
winston.verbose(" saved request attributes", savedRequest.toObject())
|
638
|
+
winston.verbose("(Request Route) saved request attributes", savedRequest.toObject())
|
628
639
|
requestEvent.emit("request.update", savedRequest);
|
629
640
|
requestEvent.emit("request.update.comment", { comment: "ATTRIBUTES_PATCH", request: savedRequest });//Deprecated
|
630
641
|
requestEvent.emit("request.updated", { comment: "ATTRIBUTES_PATCH", request: savedRequest, patch: { attributes: data } });
|
@@ -657,7 +668,7 @@ router.post('/:requestid/notes', async function (req, res) {
|
|
657
668
|
|
658
669
|
// Check if the user is a participant
|
659
670
|
if (!request.participantsAgents.includes(req.user.id)) {
|
660
|
-
winston.verbose("Trying to add a note from a non participating agent");
|
671
|
+
winston.verbose("(Request Route) Trying to add a note from a non participating agent");
|
661
672
|
return res.status(403).send({ success: false, error: "You are not participating in the conversation"})
|
662
673
|
}
|
663
674
|
}
|
@@ -703,7 +714,7 @@ router.delete('/:requestid/notes/:noteid', async function (req, res) {
|
|
703
714
|
|
704
715
|
// Check if the user is a participant
|
705
716
|
if (!request.participantsAgents.includes(req.user.id)) {
|
706
|
-
winston.verbose("Trying to delete a note from a non participating agent");
|
717
|
+
winston.verbose("(Request Route) Trying to delete a note from a non participating agent");
|
707
718
|
return res.status(403).send({ success: false, error: "You are not participating in the conversation"})
|
708
719
|
}
|
709
720
|
}
|
@@ -773,7 +784,7 @@ router.post('/:requestid/email/send',
|
|
773
784
|
}
|
774
785
|
|
775
786
|
let newto = request.lead.email
|
776
|
-
winston.verbose("Sending an email newto " + newto);
|
787
|
+
winston.verbose("(Request Route) Sending an email newto " + newto);
|
777
788
|
|
778
789
|
//sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload)
|
779
790
|
emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined, undefined, replyto);
|
@@ -796,7 +807,7 @@ router.post('/:requestid/followers',
|
|
796
807
|
check('member').notEmpty(),
|
797
808
|
],
|
798
809
|
function (req, res) {
|
799
|
-
winston.
|
810
|
+
winston.verbose("(Request Route) followers add", req.body);
|
800
811
|
|
801
812
|
const errors = validationResult(req);
|
802
813
|
if (!errors.isEmpty()) {
|
@@ -806,7 +817,7 @@ router.post('/:requestid/followers',
|
|
806
817
|
//addParticipantByRequestId(request_id, id_project, member)
|
807
818
|
return requestService.addFollowerByRequestId(req.params.requestid, req.projectid, req.body.member).then(function (updatedRequest) {
|
808
819
|
|
809
|
-
winston.verbose("participant added", updatedRequest);
|
820
|
+
winston.verbose("(Request Route) participant added", updatedRequest);
|
810
821
|
|
811
822
|
return res.json(updatedRequest);
|
812
823
|
});
|
@@ -839,7 +850,7 @@ router.delete('/:requestid/followers/:followerid', function (req, res) {
|
|
839
850
|
//removeFollowerByRequestId(request_id, id_project, member)
|
840
851
|
return requestService.removeFollowerByRequestId(req.params.requestid, req.projectid, req.params.followerid).then(function (updatedRequest) {
|
841
852
|
|
842
|
-
winston.verbose("follower removed", updatedRequest);
|
853
|
+
winston.verbose("(Request Route) follower removed", updatedRequest);
|
843
854
|
|
844
855
|
return res.json(updatedRequest);
|
845
856
|
});
|
@@ -866,7 +877,7 @@ router.delete('/:requestid', function (req, res) {
|
|
866
877
|
if (err) {
|
867
878
|
return res.status(500).send({ success: false, msg: 'Error deleting messages.' });
|
868
879
|
}
|
869
|
-
winston.verbose('Messages deleted for the recipient: ' + req.params.requestid);
|
880
|
+
winston.verbose('(Request Route) Messages deleted for the recipient: ' + req.params.requestid);
|
870
881
|
});
|
871
882
|
|
872
883
|
|
@@ -880,7 +891,7 @@ router.delete('/:requestid', function (req, res) {
|
|
880
891
|
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
881
892
|
}
|
882
893
|
|
883
|
-
winston.verbose('Request deleted with request_id: ' + req.params.requestid);
|
894
|
+
winston.verbose('(Request Route) Request deleted with request_id: ' + req.params.requestid);
|
884
895
|
|
885
896
|
requestEvent.emit('request.delete', request);
|
886
897
|
|
@@ -928,7 +939,7 @@ router.delete('/id/:id', function (req, res) {
|
|
928
939
|
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
929
940
|
}
|
930
941
|
|
931
|
-
winston.verbose('Request deleted with id: ' + req.params.id);
|
942
|
+
winston.verbose('(Request Route) Request deleted with id: ' + req.params.id);
|
932
943
|
|
933
944
|
requestEvent.emit('request.delete', request);
|
934
945
|
|
@@ -1201,7 +1212,7 @@ router.get('/', function (req, res, next) {
|
|
1201
1212
|
} else if (req.query.duration_op === 'lt') {
|
1202
1213
|
query.duration = { $lte: duration }
|
1203
1214
|
} else {
|
1204
|
-
winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
|
1215
|
+
winston.verbose("(Request Route) Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
|
1205
1216
|
}
|
1206
1217
|
}
|
1207
1218
|
|
@@ -1217,12 +1228,12 @@ router.get('/', function (req, res, next) {
|
|
1217
1228
|
|
1218
1229
|
if (req.query.full_text) {
|
1219
1230
|
if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
|
1220
|
-
winston.verbose('fulltext projection on');
|
1231
|
+
winston.verbose('(Request Route) fulltext projection on');
|
1221
1232
|
projection = { score: { $meta: "textScore" } };
|
1222
1233
|
}
|
1223
1234
|
}
|
1224
1235
|
|
1225
|
-
winston.verbose('
|
1236
|
+
winston.verbose('(Request Route) Find request with query ', query);
|
1226
1237
|
|
1227
1238
|
var q1 = Request.find(query, projection).
|
1228
1239
|
skip(skip).limit(limit);
|
@@ -1251,7 +1262,7 @@ router.get('/', function (req, res, next) {
|
|
1251
1262
|
var q2 = Request.countDocuments(query).exec();
|
1252
1263
|
|
1253
1264
|
if (req.query.no_count && req.query.no_count == "true") {
|
1254
|
-
winston.
|
1265
|
+
winston.verbose('(Request Route) - no_count');
|
1255
1266
|
q2 = 0;
|
1256
1267
|
}
|
1257
1268
|
|
@@ -1263,16 +1274,16 @@ router.get('/', function (req, res, next) {
|
|
1263
1274
|
count: results[1],
|
1264
1275
|
requests: results[0]
|
1265
1276
|
};
|
1266
|
-
winston.debug('
|
1267
|
-
winston.debug('
|
1277
|
+
winston.debug('(Request Route) - objectToReturn ');
|
1278
|
+
winston.debug('(Request Route) - objectToReturn ', objectToReturn);
|
1268
1279
|
|
1269
1280
|
const endExecTime = new Date();
|
1270
|
-
winston.verbose('
|
1281
|
+
winston.verbose('(Request Route) - exec time: ' + (endExecTime - startExecTime));
|
1271
1282
|
|
1272
1283
|
return res.json(objectToReturn);
|
1273
1284
|
|
1274
1285
|
}).catch(function (err) {
|
1275
|
-
winston.error('
|
1286
|
+
winston.error('(Request Route) find request error ', err);
|
1276
1287
|
return res.status(500).send({ success: false, msg: 'Error getting requests.', err: err });
|
1277
1288
|
});
|
1278
1289
|
|
@@ -1824,7 +1835,7 @@ router.get('/csv', function (req, res, next) {
|
|
1824
1835
|
} else if (req.query.duration_op === 'lt') {
|
1825
1836
|
query.duration = { $lte: duration }
|
1826
1837
|
} else {
|
1827
|
-
winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
|
1838
|
+
winston.verbose("(Request Route) Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
|
1828
1839
|
}
|
1829
1840
|
}
|
1830
1841
|
|