@tiledesk/tiledesk-server 2.4.39 → 2.4.41
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/app.js +2 -2
- package/channels/chat21/chat21Handler.js +9 -4
- package/event/botEvent.js +1 -1
- package/jobs.js +29 -3
- package/jobsManager.js +20 -3
- package/package.json +2 -2
- package/pubmodules/activities/activityArchiver.js +12 -2
- package/pubmodules/emailNotification/requestNotification.js +6 -6
- package/pubmodules/pubModulesManager.js +3 -1
- package/pubmodules/queue/reconnect.js +7 -4
- package/routes/faq.js +69 -47
- package/routes/faq_kb.js +0 -1
- package/routes/users-util.js +1 -1
- package/services/BotSubscriptionNotifier.js +1 -1
package/app.js
CHANGED
|
@@ -147,9 +147,9 @@ var subscriptionNotifierQueued = require('./services/subscriptionNotifierQueued'
|
|
|
147
147
|
|
|
148
148
|
|
|
149
149
|
var botSubscriptionNotifier = require('./services/BotSubscriptionNotifier');
|
|
150
|
-
|
|
150
|
+
botSubscriptionNotifier.start(); //queued but disabled
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
botEvent.listen(); //queued but disabled
|
|
153
153
|
|
|
154
154
|
var trainingService = require('./services/trainingService');
|
|
155
155
|
trainingService.start();
|
|
@@ -85,6 +85,8 @@ class Chat21Handler {
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
|
|
88
|
+
// chat21Handler on worker is loaded with stadard events like request.create and NOT request.create.queue because it is used internally by the worker when the request is closed by ChatUnhandledRequestScheduler
|
|
89
|
+
|
|
88
90
|
// su projectUser create e update
|
|
89
91
|
authEvent.on('user.signup', function(userData) {
|
|
90
92
|
var firstName = userData.savedUser.firstname;
|
|
@@ -258,7 +260,7 @@ class Chat21Handler {
|
|
|
258
260
|
});
|
|
259
261
|
});
|
|
260
262
|
|
|
261
|
-
|
|
263
|
+
// chat21Handler on worker is loaded with stadard events like request.create and NOT request.create.queue because it is used internally by the worker when the request is closed by ChatUnhandledRequestScheduler
|
|
262
264
|
messageEvent.on('message.sending', function(message) {
|
|
263
265
|
|
|
264
266
|
// setImmediate(() => {
|
|
@@ -358,7 +360,7 @@ class Chat21Handler {
|
|
|
358
360
|
return chat21.messages.sendToGroup(message.senderFullname, message.recipient,
|
|
359
361
|
recipient_fullname, message.text, message.sender, attributes, message.type, message.metadata, timestamp)
|
|
360
362
|
.then(function(data){
|
|
361
|
-
winston.verbose("Chat21Sender sendToGroup sent: "+ JSON.stringify(data));
|
|
363
|
+
winston.verbose("Chat21Sender sendToGroup sent: "+ JSON.stringify(data) + " for text message " + message.text);
|
|
362
364
|
|
|
363
365
|
|
|
364
366
|
// chat21.conversations.stopTyping(message.recipient,message.sender);
|
|
@@ -520,6 +522,8 @@ class Chat21Handler {
|
|
|
520
522
|
// });
|
|
521
523
|
// });
|
|
522
524
|
|
|
525
|
+
|
|
526
|
+
// chat21Handler on worker is loaded with stadard events like request.create and NOT request.create.queue because it is used internally by the worker when the request is closed by ChatUnhandledRequestScheduler
|
|
523
527
|
requestEvent.on('request.create', function(request) {
|
|
524
528
|
|
|
525
529
|
winston.debug("chat21Handler requestEvent request.create called" , request);
|
|
@@ -632,9 +636,10 @@ class Chat21Handler {
|
|
|
632
636
|
});
|
|
633
637
|
|
|
634
638
|
|
|
635
|
-
|
|
636
|
-
requestEvent.on('request.close', function(request) {
|
|
639
|
+
// chat21Handler on worker is loaded with stadard events like request.create and NOT request.create.queue because it is used internally by the worker when the request is closed by ChatUnhandledRequestScheduler
|
|
637
640
|
|
|
641
|
+
requestEvent.on('request.close', function(request) { //request.close event here noqueued
|
|
642
|
+
winston.debug("request.close event here 8")
|
|
638
643
|
winston.debug("chat21Handler requestEvent request.close called" , request);
|
|
639
644
|
|
|
640
645
|
setImmediate(() => {
|
package/event/botEvent.js
CHANGED
|
@@ -26,7 +26,7 @@ class BotEvent extends EventEmitter {
|
|
|
26
26
|
messageCreateKey = 'message.create.queue';
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
winston.info("Listening
|
|
29
|
+
winston.info("Listening " + messageCreateKey + " event for Chatbot messages");
|
|
30
30
|
|
|
31
31
|
messageEvent.on(messageCreateKey, function(message) {
|
|
32
32
|
|
package/jobs.js
CHANGED
|
@@ -26,6 +26,7 @@ var subscriptionNotifierQueued = require('./services/subscriptionNotifierQueued'
|
|
|
26
26
|
var botSubscriptionNotifier = require('./services/BotSubscriptionNotifier');
|
|
27
27
|
|
|
28
28
|
const botEvent = require('./event/botEvent');
|
|
29
|
+
var channelManager = require('./channels/channelManager');
|
|
29
30
|
|
|
30
31
|
require('./services/mongoose-cache-fn')(mongoose);
|
|
31
32
|
|
|
@@ -58,11 +59,27 @@ winston.info("Mongoose connection done on host: "+mongoose.connection.host + " o
|
|
|
58
59
|
async function main()
|
|
59
60
|
{
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
////************* LOAD QUEUE ************ //
|
|
63
|
+
require('./pubmodules/cache').cachegoose(mongoose);
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
////************* LOAD CONCIERGE BOT ************ //
|
|
67
|
+
require('./pubmodules/rules/appRules').start();
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// require('./pubmodules/trigger/rulesTrigger').listen(); request.close trigger event is not triggered by anyone now?
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
//************* LOAD QUEUE ************ //
|
|
74
|
+
require('./pubmodules/queue');
|
|
64
75
|
// require('@tiledesk-ent/tiledesk-server-queue');
|
|
65
76
|
|
|
77
|
+
//************* LOAD CHAT21 ************ //
|
|
78
|
+
channelManager.listen(); // chat21Handler is loaded with stadard events like request.create and NOT request.create.queue because it is used internally by the worker when the request is closed by ChatUnhandledRequestScheduler
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
66
83
|
let jobsManager = new JobsManager(undefined, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier);
|
|
67
84
|
|
|
68
85
|
jobsManager.listen();
|
|
@@ -76,6 +93,15 @@ async function main()
|
|
|
76
93
|
jobsManager.listenActivityArchiver(activityArchiver);
|
|
77
94
|
|
|
78
95
|
|
|
96
|
+
// let routingQueue = require('./pubmodules/routing-queue').listener; //ci sono altri eventi che nn gestisco in queue request.participants.join etc
|
|
97
|
+
// winston.info("routingQueue1");
|
|
98
|
+
// jobsManager.listenRoutingQueue(routingQueue);
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
let scheduler = require('./pubmodules/scheduler');
|
|
103
|
+
jobsManager.listenScheduler(scheduler);
|
|
104
|
+
|
|
79
105
|
|
|
80
106
|
winston.info("Jobs started");
|
|
81
107
|
|
package/jobsManager.js
CHANGED
|
@@ -27,12 +27,13 @@ class JobsManager {
|
|
|
27
27
|
return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listeners");
|
|
28
28
|
}
|
|
29
29
|
this.geoService.listen();
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
// this.botEvent.listen(); // disabled
|
|
31
32
|
|
|
32
33
|
// this.subscriptionNotifier.start();
|
|
33
34
|
this.subscriptionNotifierQueued.start();
|
|
34
35
|
|
|
35
|
-
this.botSubscriptionNotifier.start();
|
|
36
|
+
// this.botSubscriptionNotifier.start(); // disabled
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
listenEmailNotification(emailNotification) {
|
|
@@ -44,7 +45,23 @@ class JobsManager {
|
|
|
44
45
|
this.emailNotification.requestNotification.listen();
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
// listenRoutingQueue(routingQueue) {
|
|
49
|
+
// winston.info("JobsManager routingQueue started");
|
|
50
|
+
// if ( this.jobWorkerEnabled == true) {
|
|
51
|
+
// return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for routingQueue");
|
|
52
|
+
// }
|
|
53
|
+
// this.routingQueue = routingQueue;
|
|
54
|
+
// this.routingQueue.listen();
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
listenScheduler(scheduler) {
|
|
58
|
+
winston.info("JobsManager scheduler started");
|
|
59
|
+
if ( this.jobWorkerEnabled == true) {
|
|
60
|
+
return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for scheduler");
|
|
61
|
+
}
|
|
62
|
+
this.scheduler = scheduler;
|
|
63
|
+
this.scheduler.taskRunner.start();
|
|
64
|
+
}
|
|
48
65
|
|
|
49
66
|
listenActivityArchiver(activityArchiver) {
|
|
50
67
|
winston.info("JobsManager listenActivityArchiver started");
|
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.4.
|
|
4
|
+
"version": "2.4.41",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node ./bin/www",
|
|
7
7
|
"pretest": "mongodb-runner start",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@tiledesk/tiledesk-messenger-connector": "0.1.9",
|
|
46
46
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
|
47
47
|
"@tiledesk/tiledesk-tybot-connector": "^0.1.89",
|
|
48
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.
|
|
48
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.51",
|
|
49
49
|
"amqplib": "^0.5.5",
|
|
50
50
|
"app-root-path": "^3.0.0",
|
|
51
51
|
"bcrypt-nodejs": "0.0.3",
|
|
@@ -42,6 +42,7 @@ class ActivityArchiver {
|
|
|
42
42
|
activityEvent.on('lead.download.csv', this.save);
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
|
+
// works only if worker is disabled
|
|
45
46
|
var authProjectUserInvitePendingKey = 'project_user.invite.pending'; //Don't work if job_worker enabled because queue.worker is disabled
|
|
46
47
|
// if (authEvent.queueEnabled) { //queue not supported.
|
|
47
48
|
// authProjectUserInvitePendingKey = 'project_user.invite.pending.queue';
|
|
@@ -63,6 +64,10 @@ class ActivityArchiver {
|
|
|
63
64
|
|
|
64
65
|
});
|
|
65
66
|
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// works only if worker is disabled
|
|
66
71
|
var authProjectUserInviteKey = 'project_user.invite'; //Don't work if job_worker enabled because queue.worker is disabled
|
|
67
72
|
// if (authEvent.queueEnabled) { //queue not supported
|
|
68
73
|
// authProjectUserInviteKey = 'project_user.invite.queue';
|
|
@@ -84,6 +89,9 @@ class ActivityArchiver {
|
|
|
84
89
|
|
|
85
90
|
});
|
|
86
91
|
});
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
87
95
|
|
|
88
96
|
// verified with queue
|
|
89
97
|
var authProjectUserUpdateKey = 'project_user.update';
|
|
@@ -125,7 +133,7 @@ class ActivityArchiver {
|
|
|
125
133
|
|
|
126
134
|
});
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
// works only if worker is disabled
|
|
129
137
|
var authProjectUserDeleteKey = 'project_user.delete'; //Don't work if job_worker enabled because queue.worker is disabled
|
|
130
138
|
// if (authEvent.queueEnabled) { //queue not supported
|
|
131
139
|
// authProjectUserDeleteKey = 'project_user.delete.queue';
|
|
@@ -147,8 +155,10 @@ class ActivityArchiver {
|
|
|
147
155
|
|
|
148
156
|
});
|
|
149
157
|
});
|
|
150
|
-
|
|
151
158
|
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
// disabled why? performance?
|
|
152
162
|
// var authUserSignineKey = 'user.signin';
|
|
153
163
|
// // if (authEvent.queueEnabled) { //queue not supported
|
|
154
164
|
// // authUserSignineKey = 'user.signin.queue';
|
|
@@ -83,14 +83,14 @@ listen() {
|
|
|
83
83
|
|
|
84
84
|
//messages sent from admins or agents to requester
|
|
85
85
|
if (message.sender != message.request.lead.lead_id) {
|
|
86
|
-
winston.
|
|
86
|
+
winston.debug("sending sendToUserEmailChannelEmail for EMAIL or FORM channel");
|
|
87
87
|
|
|
88
88
|
//send email notification to requester (send also to followers)
|
|
89
89
|
return that.sendToUserEmailChannelEmail(message.id_project, message);
|
|
90
90
|
} else { //messages sent from requester to agents or admins
|
|
91
91
|
|
|
92
92
|
if (message.text != message.request.first_text) {
|
|
93
|
-
winston.
|
|
93
|
+
winston.debug("sending sendToAgentEmailChannelEmail for EMAIL or FORM channel");
|
|
94
94
|
|
|
95
95
|
//send email notification to admins and agents(send also to followers)
|
|
96
96
|
return that.sendToAgentEmailChannelEmail(message.id_project, message);
|
|
@@ -140,7 +140,7 @@ listen() {
|
|
|
140
140
|
|
|
141
141
|
/*
|
|
142
142
|
if (request && (request.channel.name===ChannelConstants.EMAIL || request.channel.name===ChannelConstants.FORM )) {
|
|
143
|
-
winston.
|
|
143
|
+
winston.debug("sending sendEmailChannelTakingNotification for EMAIL or FORM channel");
|
|
144
144
|
that.sendEmailChannelTakingNotification(request.id_project, request)
|
|
145
145
|
}
|
|
146
146
|
*/
|
|
@@ -190,7 +190,7 @@ listen() {
|
|
|
190
190
|
if (requestEvent.queueEnabled) {
|
|
191
191
|
requestCloseExtendedKey = 'request.close.extended.queue';
|
|
192
192
|
}
|
|
193
|
-
winston.debug('RequestNotification requestCloseExtendedKey: ' + requestCloseExtendedKey);
|
|
193
|
+
winston.debug('RequestNotification requestCloseExtendedKey: ' + requestCloseExtendedKey); //request.close event here queued under job
|
|
194
194
|
requestEvent.on(requestCloseExtendedKey, function(data) {
|
|
195
195
|
winston.debug('requestEvent.on(requestCloseExtendedKey ' + requestCloseExtendedKey);
|
|
196
196
|
setImmediate(() => {
|
|
@@ -563,7 +563,7 @@ sendToAgentEmailChannelEmail(projectid, message) {
|
|
|
563
563
|
if (!user) {
|
|
564
564
|
winston.warn("User not found", userid);
|
|
565
565
|
} else {
|
|
566
|
-
winston.
|
|
566
|
+
winston.debug("Sending sendNewPooledMessageNotification to user with email: "+ user.email);
|
|
567
567
|
if (user.emailverified) {
|
|
568
568
|
emailService.sendNewPooledMessageEmailNotification(user.email, savedRequest, project, message);
|
|
569
569
|
}else {
|
|
@@ -997,7 +997,7 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
997
997
|
if (!user) {
|
|
998
998
|
winston.warn("User not found", savedRequest.participants[0]);
|
|
999
999
|
} else {
|
|
1000
|
-
winston.
|
|
1000
|
+
winston.debug("Sending sendNewAssignedRequestNotification to user with email", user.email);
|
|
1001
1001
|
// if (user.emailverified) { enable it? send anyway to improve engagment for new account
|
|
1002
1002
|
|
|
1003
1003
|
|
|
@@ -493,7 +493,8 @@ class PubModulesManager {
|
|
|
493
493
|
|
|
494
494
|
if (this.scheduler) {
|
|
495
495
|
try {
|
|
496
|
-
this.scheduler.taskRunner.start();
|
|
496
|
+
// this.scheduler.taskRunner.start();
|
|
497
|
+
this.jobsManager.listenScheduler(this.scheduler);
|
|
497
498
|
winston.info("PubModulesManager scheduler started.");
|
|
498
499
|
} catch(err) {
|
|
499
500
|
winston.info("PubModulesManager error starting scheduler module", err);
|
|
@@ -515,6 +516,7 @@ class PubModulesManager {
|
|
|
515
516
|
if (this.routingQueue) {
|
|
516
517
|
try {
|
|
517
518
|
this.routingQueue.listen();
|
|
519
|
+
// this.jobsManager.listenRoutingQueue(this.routingQueue);
|
|
518
520
|
winston.info("PubModulesManager routingQueue started");
|
|
519
521
|
} catch(err) {
|
|
520
522
|
winston.info("PubModulesManager error starting routingQueue module", err);
|
|
@@ -17,7 +17,9 @@ var url = process.env.CLOUDAMQP_URL + "?heartbeat=60" || "amqp://localhost";
|
|
|
17
17
|
// attento devi aggiornare configMap di PRE E PROD
|
|
18
18
|
// var url = process.env.AMQP_URL + "?heartbeat=60" || "amqp://localhost?heartbeat=60";
|
|
19
19
|
|
|
20
|
+
// var durable = true;
|
|
20
21
|
var durable = false;
|
|
22
|
+
|
|
21
23
|
// if (process.env.ENABLE_DURABLE_QUEUE == false || process.env.ENABLE_DURABLE_QUEUE == "false") {
|
|
22
24
|
// durable = false;
|
|
23
25
|
// }
|
|
@@ -67,10 +69,10 @@ function whenConnected() {
|
|
|
67
69
|
winston.info("JobsManager jobWorkerEnabled: "+ jobWorkerEnabled);
|
|
68
70
|
|
|
69
71
|
if (jobWorkerEnabled == false) {
|
|
70
|
-
winston.info("Queue Reconnect
|
|
72
|
+
winston.info("Queue Reconnect starts queue worker (queue observer)");
|
|
71
73
|
startWorker();
|
|
72
74
|
} else {
|
|
73
|
-
winston.info("Queue Reconnect without worker because external worker is enabled");
|
|
75
|
+
winston.info("Queue Reconnect without queue worker (queue observer) because external worker is enabled");
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
}
|
|
@@ -328,9 +330,10 @@ function listen() {
|
|
|
328
330
|
});
|
|
329
331
|
});
|
|
330
332
|
|
|
331
|
-
|
|
333
|
+
// winston.debug("sub to reconnect request.close");
|
|
332
334
|
requestEvent.on('request.close', function(request) {
|
|
333
335
|
setImmediate(() => {
|
|
336
|
+
winston.debug("reconnect request.close");
|
|
334
337
|
publish(exchange, "request_close", Buffer.from(JSON.stringify(request)));
|
|
335
338
|
});
|
|
336
339
|
});
|
|
@@ -395,6 +398,6 @@ if (process.env.QUEUE_ENABLED === "true") {
|
|
|
395
398
|
leadEvent.queueEnabled = true;
|
|
396
399
|
listen();
|
|
397
400
|
start();
|
|
398
|
-
winston.info("Queue enabled.
|
|
401
|
+
winston.info("Queue enabled. endpoint: " + url );
|
|
399
402
|
}
|
|
400
403
|
|
package/routes/faq.js
CHANGED
|
@@ -10,6 +10,7 @@ const faqEvent = require('../event/faqBotEvent')
|
|
|
10
10
|
|
|
11
11
|
var parsecsv = require("fast-csv");
|
|
12
12
|
const botEvent = require('../event/botEvent');
|
|
13
|
+
const uuidv4 = require('uuid/v4');
|
|
13
14
|
csv = require('csv-express');
|
|
14
15
|
csv.separator = ';';
|
|
15
16
|
|
|
@@ -21,10 +22,10 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
|
21
22
|
winston.debug(' -> FILE ', req.file);
|
|
22
23
|
|
|
23
24
|
var id_faq_kb = req.body.id_faq_kb;
|
|
24
|
-
winston.debug('id_faq_kb: '+id_faq_kb);
|
|
25
|
+
winston.debug('id_faq_kb: ' + id_faq_kb);
|
|
25
26
|
|
|
26
27
|
var delimiter = req.body.delimiter || ";";
|
|
27
|
-
winston.debug('delimiter: '+delimiter);
|
|
28
|
+
winston.debug('delimiter: ' + delimiter);
|
|
28
29
|
|
|
29
30
|
var csv = req.file.buffer.toString('utf8');
|
|
30
31
|
// winston.debug(' -> CSV STRING ', csv);
|
|
@@ -32,10 +33,10 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
|
32
33
|
// res.json({ success: true, msg: 'Importing CSV...' });
|
|
33
34
|
|
|
34
35
|
// PARSE CSV
|
|
35
|
-
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
Faq_kb.findById(id_faq_kb).exec(function (err, faq_kb) {
|
|
39
40
|
if (err) {
|
|
40
41
|
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
|
41
42
|
}
|
|
@@ -44,18 +45,43 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
|
44
45
|
}
|
|
45
46
|
winston.debug('faq_kb ', faq_kb.toJSON());
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
// getFaqKbKeyById(req.body.id_faq_kb, function (remote_faqkb_key) {
|
|
48
49
|
|
|
49
50
|
parsecsv.parseString(csv, { headers: false, delimiter: delimiter })
|
|
50
51
|
.on("data", function (data) {
|
|
51
52
|
winston.debug('PARSED CSV ', data);
|
|
52
53
|
|
|
53
54
|
var question = data[0]
|
|
54
|
-
var answer = data[1]
|
|
55
|
+
//var answer = data[1]
|
|
55
56
|
var intent_id = data[2];
|
|
56
57
|
var intent_display_name = data[3];
|
|
57
58
|
var webhook_enabled = data[4];
|
|
58
59
|
|
|
60
|
+
|
|
61
|
+
var actions = [
|
|
62
|
+
{
|
|
63
|
+
_tdActionType: "reply",
|
|
64
|
+
_tdActionId: uuidv4(),
|
|
65
|
+
text: data[1],
|
|
66
|
+
attributes: {
|
|
67
|
+
commands: [
|
|
68
|
+
{
|
|
69
|
+
type: "wait",
|
|
70
|
+
time: 500
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "message",
|
|
74
|
+
message: {
|
|
75
|
+
type: "text",
|
|
76
|
+
text: data[1]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
|
|
59
85
|
var webhook_enabled_boolean = false;
|
|
60
86
|
if (webhook_enabled) {
|
|
61
87
|
webhook_enabled_boolean = (webhook_enabled == 'true');
|
|
@@ -67,8 +93,9 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
|
67
93
|
var newFaq = new Faq({
|
|
68
94
|
id_faq_kb: id_faq_kb,
|
|
69
95
|
question: question,
|
|
70
|
-
answer: answer,
|
|
71
|
-
|
|
96
|
+
//answer: answer,
|
|
97
|
+
actions: actions,
|
|
98
|
+
intent_id: intent_id,
|
|
72
99
|
intent_display_name: intent_display_name,
|
|
73
100
|
webhook_enabled: webhook_enabled_boolean,
|
|
74
101
|
language: faq_kb.language,
|
|
@@ -85,7 +112,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
|
85
112
|
} else {
|
|
86
113
|
faqBotEvent.emit('faq.create', savedFaq);
|
|
87
114
|
}
|
|
88
|
-
|
|
115
|
+
|
|
89
116
|
});
|
|
90
117
|
})
|
|
91
118
|
.on("end", function () {
|
|
@@ -105,7 +132,7 @@ router.post('/', function (req, res) {
|
|
|
105
132
|
|
|
106
133
|
winston.debug(req.body);
|
|
107
134
|
|
|
108
|
-
Faq_kb.findById(req.body.id_faq_kb).exec(function(err, faq_kb) {
|
|
135
|
+
Faq_kb.findById(req.body.id_faq_kb).exec(function (err, faq_kb) {
|
|
109
136
|
if (err) {
|
|
110
137
|
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
|
111
138
|
}
|
|
@@ -148,7 +175,7 @@ router.post('/', function (req, res) {
|
|
|
148
175
|
} else {
|
|
149
176
|
winston.debug('--- > ERROR ', err)
|
|
150
177
|
return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
|
151
|
-
}
|
|
178
|
+
}
|
|
152
179
|
}
|
|
153
180
|
winston.debug('1. ID OF THE NEW FAQ CREATED ', savedFaq._id)
|
|
154
181
|
winston.debug('1. QUESTION OF THE NEW FAQ CREATED ', savedFaq.question)
|
|
@@ -160,14 +187,13 @@ router.post('/', function (req, res) {
|
|
|
160
187
|
|
|
161
188
|
res.json(savedFaq);
|
|
162
189
|
|
|
163
|
-
|
|
190
|
+
|
|
164
191
|
});
|
|
165
192
|
});
|
|
166
193
|
});
|
|
167
194
|
|
|
168
195
|
router.patch('/:faqid/attributes', function (req, res) {
|
|
169
196
|
let data = req.body;
|
|
170
|
-
console.log("data: ", data);
|
|
171
197
|
|
|
172
198
|
Faq.findById(req.params.faqid, function (err, updatedFaq) {
|
|
173
199
|
if (err) {
|
|
@@ -180,22 +206,18 @@ router.patch('/:faqid/attributes', function (req, res) {
|
|
|
180
206
|
}
|
|
181
207
|
|
|
182
208
|
if (!updatedFaq.attributes) {
|
|
183
|
-
console.log("empty attributes");
|
|
184
209
|
winston.debug("empty attributes");
|
|
185
210
|
updatedFaq.attributes = {};
|
|
186
211
|
}
|
|
187
212
|
|
|
188
213
|
winston.debug("updatedFaq attributes", updatedFaq.attributes);
|
|
189
214
|
|
|
190
|
-
Object.keys(data).forEach(function(key) {
|
|
215
|
+
Object.keys(data).forEach(function (key) {
|
|
191
216
|
var val = data[key];
|
|
192
217
|
winston.debug("data attributes" + key + " " + val);
|
|
193
218
|
updatedFaq.attributes[key] = val;
|
|
194
219
|
})
|
|
195
220
|
|
|
196
|
-
console.log("updatedFaq: ", updatedFaq);
|
|
197
|
-
console.log("updatedFaq attributes: ", updatedFaq.attributes);
|
|
198
|
-
|
|
199
221
|
winston.debug("updatedBot attributes", updatedFaq.attributes)
|
|
200
222
|
|
|
201
223
|
updatedFaq.markModified('attributes');
|
|
@@ -207,8 +229,6 @@ router.patch('/:faqid/attributes', function (req, res) {
|
|
|
207
229
|
return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
|
208
230
|
}
|
|
209
231
|
|
|
210
|
-
console.log("saved faq attributes", savedFaq.toObject());
|
|
211
|
-
|
|
212
232
|
winston.verbose("saved faq attributes", savedFaq.toObject());
|
|
213
233
|
faqBotEvent.emit('faq.update', savedFaq);
|
|
214
234
|
res.json(savedFaq);
|
|
@@ -221,38 +241,38 @@ router.put('/:faqid', function (req, res) {
|
|
|
221
241
|
winston.debug('UPDATE FAQ ', req.body);
|
|
222
242
|
|
|
223
243
|
var update = {};
|
|
224
|
-
|
|
225
|
-
if (req.body.intent!=undefined) {
|
|
244
|
+
|
|
245
|
+
if (req.body.intent != undefined) {
|
|
226
246
|
update.intent = req.body.intent;
|
|
227
247
|
}
|
|
228
|
-
if (req.body.question!=undefined) {
|
|
248
|
+
if (req.body.question != undefined) {
|
|
229
249
|
update.question = req.body.question;
|
|
230
250
|
}
|
|
231
|
-
if (req.body.answer!=undefined) {
|
|
251
|
+
if (req.body.answer != undefined) {
|
|
232
252
|
update.answer = req.body.answer;
|
|
233
253
|
}
|
|
234
|
-
if (req.body.topic!=undefined) {
|
|
254
|
+
if (req.body.topic != undefined) {
|
|
235
255
|
update.topic = req.body.topic;
|
|
236
256
|
}
|
|
237
|
-
if (req.body.status!=undefined) {
|
|
257
|
+
if (req.body.status != undefined) {
|
|
238
258
|
update.status = req.body.status;
|
|
239
259
|
}
|
|
240
|
-
if (req.body.language!=undefined) {
|
|
260
|
+
if (req.body.language != undefined) {
|
|
241
261
|
update.language = req.body.language;
|
|
242
262
|
}
|
|
243
|
-
if (req.body.intent_display_name!=undefined) {
|
|
263
|
+
if (req.body.intent_display_name != undefined) {
|
|
244
264
|
update.intent_display_name = req.body.intent_display_name;
|
|
245
265
|
}
|
|
246
|
-
if (req.body.webhook_enabled!=undefined) {
|
|
266
|
+
if (req.body.webhook_enabled != undefined) {
|
|
247
267
|
update.webhook_enabled = req.body.webhook_enabled;
|
|
248
268
|
}
|
|
249
|
-
if (req.body.enabled!=undefined) {
|
|
269
|
+
if (req.body.enabled != undefined) {
|
|
250
270
|
update.enabled = req.body.enabled;
|
|
251
271
|
}
|
|
252
|
-
if (req.body.reply!=undefined) {
|
|
272
|
+
if (req.body.reply != undefined) {
|
|
253
273
|
update.reply = req.body.reply;
|
|
254
274
|
}
|
|
255
|
-
if (req.body.form!=undefined) {
|
|
275
|
+
if (req.body.form != undefined) {
|
|
256
276
|
update.form = req.body.form;
|
|
257
277
|
}
|
|
258
278
|
if (req.body.actions != undefined) {
|
|
@@ -266,7 +286,7 @@ router.put('/:faqid', function (req, res) {
|
|
|
266
286
|
if (err) {
|
|
267
287
|
if (err.code == 11000) {
|
|
268
288
|
return res.status(409).send({ success: false, msg: 'Duplicate intent_display_name.' });
|
|
269
|
-
}else {
|
|
289
|
+
} else {
|
|
270
290
|
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
|
271
291
|
}
|
|
272
292
|
}
|
|
@@ -315,16 +335,18 @@ router.get('/csv', function (req, res) {
|
|
|
315
335
|
|
|
316
336
|
winston.debug('EXPORT FAQS TO CSV QUERY', query);
|
|
317
337
|
|
|
318
|
-
|
|
338
|
+
Faq.find(query, 'question answer intent_id intent_display_name webhook_enabled -_id').lean().exec(function (err, faqs) {
|
|
319
339
|
if (err) {
|
|
320
340
|
winston.debug('EXPORT FAQS TO CSV ERR', err)
|
|
321
341
|
return (err)
|
|
322
342
|
};
|
|
323
343
|
var csv = [];
|
|
324
|
-
faqs.forEach(function(element) {
|
|
325
|
-
var row = {
|
|
344
|
+
faqs.forEach(function (element) {
|
|
345
|
+
var row = {
|
|
346
|
+
question: element.question, answer: element.answer,
|
|
326
347
|
intent_id: element.intent_id, intent_display_name: element.intent_display_name,
|
|
327
|
-
webhook_enabled: element.webhook_enabled || false
|
|
348
|
+
webhook_enabled: element.webhook_enabled || false
|
|
349
|
+
}
|
|
328
350
|
csv.push(row);
|
|
329
351
|
});
|
|
330
352
|
winston.debug('EXPORT FAQ TO CSV FAQS', csv)
|
|
@@ -363,9 +385,9 @@ router.get('/', function (req, res, next) {
|
|
|
363
385
|
|
|
364
386
|
var limit = 3000; // Number of request per page
|
|
365
387
|
|
|
366
|
-
if (req.query.limit) {
|
|
388
|
+
if (req.query.limit) {
|
|
367
389
|
limit = parseInt(req.query.limit);
|
|
368
|
-
winston.debug('faq ROUTE - limit: '+limit);
|
|
390
|
+
winston.debug('faq ROUTE - limit: ' + limit);
|
|
369
391
|
}
|
|
370
392
|
|
|
371
393
|
var page = 0;
|
|
@@ -388,15 +410,15 @@ router.get('/', function (req, res, next) {
|
|
|
388
410
|
}
|
|
389
411
|
|
|
390
412
|
if (req.query.intent_display_name) {
|
|
391
|
-
query.intent_display_name=req.query.intent_display_name
|
|
413
|
+
query.intent_display_name = req.query.intent_display_name
|
|
392
414
|
}
|
|
393
|
-
|
|
415
|
+
|
|
394
416
|
|
|
395
417
|
winston.debug("GET FAQ query", query);
|
|
396
418
|
|
|
397
419
|
// query.$text = {"$search": "question"};
|
|
398
420
|
|
|
399
|
-
// TODO ORDER BY SCORE
|
|
421
|
+
// TODO ORDER BY SCORE
|
|
400
422
|
// return Faq.find(query, {score: { $meta: "textScore" } })
|
|
401
423
|
// .sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
|
|
402
424
|
|
|
@@ -404,11 +426,11 @@ router.get('/', function (req, res, next) {
|
|
|
404
426
|
// return Faq.search('a closer', (err, result) => {
|
|
405
427
|
// console.log("result: ", result);
|
|
406
428
|
// })
|
|
407
|
-
|
|
429
|
+
|
|
408
430
|
return Faq.find(query).
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
431
|
+
skip(skip).limit(limit).
|
|
432
|
+
populate({ path: 'faq_kb' })//, match: { trashed: { $in: [null, false] } }}).
|
|
433
|
+
.exec(function (err, faq) {
|
|
412
434
|
winston.debug("GET FAQ ", faq);
|
|
413
435
|
|
|
414
436
|
if (err) {
|
|
@@ -420,7 +442,7 @@ router.get('/', function (req, res, next) {
|
|
|
420
442
|
|
|
421
443
|
});
|
|
422
444
|
|
|
423
|
-
|
|
445
|
+
|
|
424
446
|
});
|
|
425
447
|
|
|
426
448
|
|
package/routes/faq_kb.js
CHANGED
|
@@ -363,7 +363,6 @@ router.put('/:faq_kbid/language/:language', (req, res) => {
|
|
|
363
363
|
botEvent.emit('faqbot.update', updatedFaq_kb);
|
|
364
364
|
return res.status(500).send({ success: false, msg: 'Error updating multiple object.' });
|
|
365
365
|
}
|
|
366
|
-
console.log("updateMany intents result: ", result)
|
|
367
366
|
return res.status(200).send(updatedFaq_kb)
|
|
368
367
|
})
|
|
369
368
|
|
package/routes/users-util.js
CHANGED
|
@@ -21,7 +21,7 @@ router.get('/:userid', function (req, res) {
|
|
|
21
21
|
return res.status(404).send({ success: false, msg: 'User id not found' });
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
User.findById(userid, 'firstname lastname _id', function (err, user) {
|
|
24
|
+
User.findById(userid, 'firstname lastname _id public_website public_email description', function (err, user) {
|
|
25
25
|
if (err) {
|
|
26
26
|
winston.error('Error getting object.',err);
|
|
27
27
|
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
|
@@ -19,7 +19,7 @@ class BotSubscriptionNotifier {
|
|
|
19
19
|
|
|
20
20
|
notify(bot,botWithSecret, payload) {
|
|
21
21
|
|
|
22
|
-
winston.
|
|
22
|
+
winston.debug("BotSubscriptionNotifier bot", bot.toObject());
|
|
23
23
|
winston.debug("BotSubscriptionNotifier payload", payload );
|
|
24
24
|
|
|
25
25
|
var url = bot.url;
|