@tiledesk/tiledesk-server 2.3.109 → 2.3.111
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/package.json +5 -4
- package/pubmodules/messenger/index.js +7 -0
- package/pubmodules/messenger/listener.js +50 -0
- package/pubmodules/pubModulesManager.js +23 -0
- 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.111",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node ./bin/www",
|
|
7
7
|
"pretest": "mongodb-runner start",
|
|
@@ -36,15 +36,16 @@
|
|
|
36
36
|
"@tiledesk-ent/tiledesk-server-enterprise": "^1.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tiledesk/tiledesk-apps": "^1.0.
|
|
39
|
+
"@tiledesk/tiledesk-apps": "^1.0.15",
|
|
40
40
|
"@tiledesk/tiledesk-chat21-app": "^1.1.7",
|
|
41
41
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.33",
|
|
42
42
|
"@tiledesk/tiledesk-dialogflow-connector": "^1.8.3",
|
|
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.67",
|
|
47
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.40",
|
|
48
|
+
"@tiledesk/tiledesk-messenger-connector": "0.1.1",
|
|
48
49
|
"amqplib": "^0.5.5",
|
|
49
50
|
"app-root-path": "^3.0.0",
|
|
50
51
|
"bcrypt-nodejs": "0.0.3",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const messenger = require("@tiledesk/tiledesk-messenger-connector");
|
|
2
|
+
var winston = require('../../config/winston');
|
|
3
|
+
var configGlobal = require('../../config/global');
|
|
4
|
+
|
|
5
|
+
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
|
6
|
+
//winston.info('Messenger apiUrl: ' + apiUrl);
|
|
7
|
+
|
|
8
|
+
class Listener {
|
|
9
|
+
|
|
10
|
+
listen(config) {
|
|
11
|
+
winston.info("Messenger Listener listen");
|
|
12
|
+
if (config.databaseUri) {
|
|
13
|
+
winston.debug("messenger config databaseUri: " + config.databaseUri);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let graph_url = process.env.META_GRAPH_URL || config.graphUrl || "https://graph.facebook.com/v14.0/"
|
|
17
|
+
winston.debug("Messenger graph_url: " + graph_url);
|
|
18
|
+
|
|
19
|
+
let log = process.env.MESSENGER_LOG || false
|
|
20
|
+
winston.debug("Messenger log: " + log);
|
|
21
|
+
|
|
22
|
+
let fb_app_id = process.env.FB_APP_ID;
|
|
23
|
+
winston.debug("Messenger fb_app_id: ", fb_app_id);
|
|
24
|
+
|
|
25
|
+
let fb_app_secret = process.env.FB_APP_SECRET;
|
|
26
|
+
winston.debug("Messenger fb_app_secret: ", fb_app_secret);
|
|
27
|
+
|
|
28
|
+
let dashboard_base_url = process.env.DASHBOARD_BASE_URL;
|
|
29
|
+
winston.debug("Messenger dashboard_base_url: ", dashboard_base_url);
|
|
30
|
+
|
|
31
|
+
messenger.startApp({
|
|
32
|
+
MONGODB_URL: config.databaseUri,
|
|
33
|
+
API_URL: apiUrl,
|
|
34
|
+
BASE_URL: apiUrl + "/modules/messenger",
|
|
35
|
+
APPS_API_URL: apiUrl + "/modules/apps",
|
|
36
|
+
FB_APP_ID: fb_app_id,
|
|
37
|
+
FB_APP_SECRET: fb_app_secret,
|
|
38
|
+
GRAPH_URL: graph_url,
|
|
39
|
+
DASHBOARD_BASE_URL: dashboard_base_url,
|
|
40
|
+
log: log
|
|
41
|
+
}, () => {
|
|
42
|
+
winston.info("Tiledesk Messenger Connector proxy server succesfully started.");
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var listener = new Listener();
|
|
49
|
+
|
|
50
|
+
module.exports = listener;
|
|
@@ -27,6 +27,9 @@ class PubModulesManager {
|
|
|
27
27
|
this.whatsapp = undefined;
|
|
28
28
|
this.whatsappRoute = undefined;
|
|
29
29
|
|
|
30
|
+
this.messenger = undefined;
|
|
31
|
+
this.messengerRoute = undefined;
|
|
32
|
+
|
|
30
33
|
this.kaleyra = undefined;
|
|
31
34
|
this.kaleyraRoute = undefined;
|
|
32
35
|
|
|
@@ -70,6 +73,10 @@ class PubModulesManager {
|
|
|
70
73
|
app.use('/modules/whatsapp', this.whatsappRoute);
|
|
71
74
|
winston.info("PubModulesManager whatsappRoute controller loaded");
|
|
72
75
|
}
|
|
76
|
+
if (this.messengerRoute) {
|
|
77
|
+
app.use('/modules/messenger', this.messengerRoute);
|
|
78
|
+
winston.info("PubModulesManager messengerRoute controller loaded");
|
|
79
|
+
}
|
|
73
80
|
if (this.kaleyraRoute) {
|
|
74
81
|
app.use('/modules/kaleyra', this.kaleyraRoute);
|
|
75
82
|
winston.info("PubModulesManager kaleyraRoute controller loaded");
|
|
@@ -269,6 +276,22 @@ class PubModulesManager {
|
|
|
269
276
|
winston.info("PubModulesManager error initializing init apps module", err);
|
|
270
277
|
}
|
|
271
278
|
}
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
this.messenger = require('./messenger');
|
|
282
|
+
winston.info("this.messenger: " + this.messenger);
|
|
283
|
+
this.messenger.listener.listen(config);
|
|
284
|
+
|
|
285
|
+
this.messengerRoute = this.messenger.messengerRoute;
|
|
286
|
+
|
|
287
|
+
winston.info("PubModulesManager initialized apps.");
|
|
288
|
+
} catch(err) {
|
|
289
|
+
if (err.code == 'MODULE_NOT_FOUND') {
|
|
290
|
+
winston.info("PubModulesManager init apps module not found ");
|
|
291
|
+
}else {
|
|
292
|
+
winston.info("PubModulesManager error initializing init apps module", err);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
272
295
|
|
|
273
296
|
try {
|
|
274
297
|
this.kaleyra = require('./kaleyra');
|
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);
|