@tiledesk/tiledesk-server 2.3.109 → 2.3.110
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/routes/faq_kb.js +2 -1
- package/routes/request.js +36 -0
- package/services/departmentService.js +22 -0
- package/services/requestService.js +9 -3
- package/websocket/webSocketServer.js +10 -2
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.110",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -43,8 +43,8 @@
|
|
43
43
|
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
44
44
|
"@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
|
45
45
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
46
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.1.
|
47
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.
|
46
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.1.66",
|
47
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.40",
|
48
48
|
"amqplib": "^0.5.5",
|
49
49
|
"app-root-path": "^3.0.0",
|
50
50
|
"bcrypt-nodejs": "0.0.3",
|
package/routes/faq_kb.js
CHANGED
@@ -19,7 +19,8 @@ let chatbot_templates_api_url = process.env.CHATBOT_TEMPLATES_API_URL
|
|
19
19
|
router.post('/', function (req, res) {
|
20
20
|
winston.debug('create BOT ', req.body);
|
21
21
|
//create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template)
|
22
|
-
faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined, req.body.language, req.body.template, req.body.mainCategory, req.body.intentsEngine).then(function (savedFaq_kb) {
|
22
|
+
//faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined, req.body.language, req.body.template, req.body.mainCategory, req.body.intentsEngine).then(function (savedFaq_kb) {
|
23
|
+
faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, req.body.webhook_url, req.body.webhook_enabled, req.body.language, req.body.template, req.body.mainCategory, req.body.intentsEngine, req.body.attributes).then(function (savedFaq_kb) {
|
23
24
|
res.json(savedFaq_kb);
|
24
25
|
});
|
25
26
|
|
package/routes/request.js
CHANGED
@@ -6,6 +6,7 @@ var Schema = mongoose.Schema,
|
|
6
6
|
ObjectId = Schema.ObjectId;
|
7
7
|
var moment = require('moment');
|
8
8
|
var requestService = require('../services/requestService');
|
9
|
+
var departmentService = require('../services/departmentService');
|
9
10
|
var winston = require('../config/winston');
|
10
11
|
const requestEvent = require('../event/requestEvent');
|
11
12
|
var Subscription = require("../models/subscription");
|
@@ -454,6 +455,40 @@ router.put('/:requestid/departments', function (req, res) {
|
|
454
455
|
});
|
455
456
|
|
456
457
|
|
458
|
+
router.put('/:requestid/agent', async (req, res) => {
|
459
|
+
winston.debug(req.body);
|
460
|
+
//route(request_id, departmentid, id_project) {
|
461
|
+
|
462
|
+
|
463
|
+
var request = await Request.findOne({"request_id":req.params.requestid, id_project:req.projectid})
|
464
|
+
.exec();
|
465
|
+
|
466
|
+
if (!request) {
|
467
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
468
|
+
}
|
469
|
+
|
470
|
+
var departmentid = request.department;
|
471
|
+
winston.debug("departmentid before: "+ departmentid);
|
472
|
+
|
473
|
+
if (!departmentid) {
|
474
|
+
var defaultDepartment = await departmentService.getDefaultDepartment(req.projectid);
|
475
|
+
winston.debug("defaultDepartment: ", defaultDepartment);
|
476
|
+
departmentid = defaultDepartment.id;
|
477
|
+
}
|
478
|
+
winston.debug("departmentid after: "+ departmentid);
|
479
|
+
|
480
|
+
requestService.route(req.params.requestid, departmentid, req.projectid, true, undefined).then(function(updatedRequest) {
|
481
|
+
|
482
|
+
winston.debug("department changed", updatedRequest);
|
483
|
+
|
484
|
+
return res.json(updatedRequest);
|
485
|
+
}).catch(function(error) {
|
486
|
+
winston.error('Error changing the department.', error)
|
487
|
+
return res.status(500).send({ success: false, msg: 'Error changing the department.' });
|
488
|
+
})
|
489
|
+
|
490
|
+
|
491
|
+
});
|
457
492
|
|
458
493
|
// router.post('/:requestid/attributes', function (req, res) {
|
459
494
|
// winston.debug(req.body);
|
@@ -692,6 +727,7 @@ router.delete('/:requestid', function (req, res) {
|
|
692
727
|
winston.verbose('Messages deleted for the recipient: '+ req.params.requestid );
|
693
728
|
});
|
694
729
|
|
730
|
+
|
695
731
|
Request.remove({ request_id: req.params.requestid }, function (err, request) {
|
696
732
|
if (err) {
|
697
733
|
winston.error('--- > ERROR ', err);
|
@@ -548,7 +548,29 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
548
548
|
|
549
549
|
|
550
550
|
|
551
|
+
getDefaultDepartment(projectid) {
|
552
|
+
return new Promise(function (resolve, reject) {
|
553
|
+
let query = { default: true, id_project: projectid };
|
554
|
+
winston.debug('query ', query)
|
555
|
+
// console.log('query', query);
|
556
|
+
return Department.findOne(query).exec(function (err, department) {
|
557
|
+
// return Department.findOne(query).exec().then(function (department) {
|
551
558
|
|
559
|
+
if (err) {
|
560
|
+
winston.error('-- > 1 DEPT FIND BY ID ERR ', err)
|
561
|
+
return reject(err);
|
562
|
+
}
|
563
|
+
// console.log("department", department);
|
564
|
+
if (!department) {
|
565
|
+
winston.error("Department not found for projectid: "+ projectid +" for query: ", query, context);
|
566
|
+
return reject({ success: false, msg: 'Department not found for projectid: '+ projectid +' for query: ' + JSON.stringify(query) });
|
567
|
+
}
|
568
|
+
winston.debug('department ', department);
|
569
|
+
|
570
|
+
return resolve(department);
|
571
|
+
});
|
572
|
+
});
|
573
|
+
}
|
552
574
|
|
553
575
|
getRandomAvailableOperator(project_users_available) {
|
554
576
|
|
@@ -399,8 +399,16 @@ class RequestService {
|
|
399
399
|
winston.error(err);
|
400
400
|
return reject(err);
|
401
401
|
}
|
402
|
-
|
402
|
+
|
403
403
|
winston.debug("here reroute1 ");
|
404
|
+
|
405
|
+
// Cannot read property 'toString' of undefined at /usr/src/app/services/requestService.js:404:61 at /usr/src/app/node_modules/cachegoose/out/extend-query.js:44:13 at Command.cb [as callback] (/usr/src/app/node_modules/cacheman-redis/node/index.js:142:9) at normal_reply (/usr/src/app/node_modules/redis/index.js:655:21) at RedisClient.return_reply (/usr/src/app/node_modules/redis/index.js:753:9) at JavascriptRedisParser.returnReply (/usr/src/app/node_modules/redis/index.js:138:18) at JavascriptRedisParser.execute (/usr/src/app/node_modules/redis-parser/lib/parser.js:544:14) at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:219:27) at Socket.emit (events.js:314:20) at addChunk (_stream_readable.js:297:12) at readableAddChunk (_stream_readable.js:272:9) at Socket.Readable.push (_stream_readable.js:213:10) at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {"date":"Tue Mar 21 2023 18:45:47 GMT+0000 (Coordinated Unive
|
406
|
+
if (request.department === undefined) {
|
407
|
+
winston.error("Request with request_id " + request_id + " has empty department. So I can't reroute");
|
408
|
+
return reject("Request with request_id " + request_id + " has empty department. So I can't reroute");
|
409
|
+
}
|
410
|
+
|
411
|
+
|
404
412
|
return that.route(request_id, request.department.toString(), id_project, nobot).then(function(routedRequest){
|
405
413
|
|
406
414
|
var endDate = new Date();
|
@@ -525,7 +533,6 @@ class RequestService {
|
|
525
533
|
|
526
534
|
agents = result.agents;
|
527
535
|
|
528
|
-
|
529
536
|
if (status == 50) {
|
530
537
|
// skip assignment
|
531
538
|
if (participants.length == 0 ) {
|
@@ -630,7 +637,6 @@ class RequestService {
|
|
630
637
|
auto_close: auto_close,
|
631
638
|
followers: followers
|
632
639
|
});
|
633
|
-
|
634
640
|
|
635
641
|
winston.debug('newRequest.',newRequest);
|
636
642
|
|
@@ -636,7 +636,10 @@ class WebSocketServer {
|
|
636
636
|
|
637
637
|
if (request.preflight===false) {
|
638
638
|
|
639
|
-
|
639
|
+
//TODO ATTENTION change value by reference requestJSON.snapshot
|
640
|
+
let requestJSON = Object.assign({}, request);
|
641
|
+
// var requestJSON = request;
|
642
|
+
|
640
643
|
if (request.toObject) {
|
641
644
|
requestJSON = request.toObject();
|
642
645
|
}
|
@@ -659,6 +662,7 @@ class WebSocketServer {
|
|
659
662
|
snapshotAgents.snapshot.agents.forEach(a => {
|
660
663
|
agentsnew.push({id_user: a.id_user})
|
661
664
|
});
|
665
|
+
//TODO ATTENTION change value by reference requestJSON.snapshot.agents. but it's fixed with line 640
|
662
666
|
requestJSON.snapshot.agents = agentsnew;
|
663
667
|
}
|
664
668
|
winston.debug('requestJSON',requestJSON);
|
@@ -685,7 +689,10 @@ class WebSocketServer {
|
|
685
689
|
winston.debug('requestEvent websocket server: '+requestUpdateKey, request);
|
686
690
|
if (request.preflight===false && request.status > requestConstants.TEMP) {
|
687
691
|
|
688
|
-
|
692
|
+
//TODO ATTENTION change value by reference requestJSON.snapshot
|
693
|
+
let requestJSON = Object.assign({}, request);
|
694
|
+
// var requestJSON = request;
|
695
|
+
|
689
696
|
if (request.toObject) {
|
690
697
|
requestJSON = request.toObject();
|
691
698
|
}
|
@@ -706,6 +713,7 @@ class WebSocketServer {
|
|
706
713
|
snapshotAgents.snapshot.agents.forEach(a => {
|
707
714
|
agentsnew.push({id_user: a.id_user})
|
708
715
|
});
|
716
|
+
//TODO ATTENTION change value by reference requestJSON.snapshot.agents . fixed with line 693
|
709
717
|
requestJSON.snapshot.agents = agentsnew;
|
710
718
|
}
|
711
719
|
winston.debug('requestJSON',requestJSON);
|