@tiledesk/tiledesk-server 2.3.6 → 2.3.7-1.2
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/.github/workflows/docker-community-worker-push-latest.yml +23 -0
- package/.github/workflows/docker-image-tag-worker-community-tag-push.yml +22 -0
- package/CHANGELOG.md +361 -3
- package/Dockerfile-jobs +31 -0
- package/app.js +62 -69
- package/channels/chat21/chat21Handler.js +37 -6
- package/channels/chat21/chat21WebHook.js +62 -34
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/config/labels/widget.json +337 -136
- package/deploy.sh +2 -0
- package/event/messageEvent.js +110 -9
- package/jobs.js +80 -0
- package/jobsManager.js +47 -0
- package/middleware/has-role.js +10 -3
- package/middleware/ipFilter.js +220 -0
- package/middleware/passport.js +8 -2
- package/models/department.js +1 -1
- package/models/faq.js +77 -25
- package/models/faq_kb.js +19 -0
- package/models/message.js +10 -8
- package/models/project.js +10 -0
- package/models/project_user.js +10 -0
- package/models/request.js +12 -1
- package/package.json +12 -11
- package/pubmodules/activities/activityArchiver.js +216 -90
- package/pubmodules/activities/routes/activity.js +1 -1
- package/pubmodules/apps/index.js +8 -0
- package/pubmodules/apps/listener.js +27 -0
- package/pubmodules/cache/index.js +2 -0
- package/pubmodules/cache/mongoose-cachegoose-fn.js +630 -0
- package/pubmodules/canned/cannedResponse.js +4 -0
- package/pubmodules/canned/cannedResponseRoute.js +10 -5
- package/pubmodules/dialogflow/index.js +10 -0
- package/pubmodules/dialogflow/listener.js +66 -0
- package/pubmodules/emailNotification/requestNotification.js +58 -28
- package/pubmodules/events/eventRoute.js +49 -24
- package/pubmodules/messageTransformer/messageHandlebarsTransformerInterceptor.js +6 -1
- package/pubmodules/messageTransformer/messageTransformerInterceptor.js +10 -4
- package/pubmodules/pubModulesManager.js +173 -7
- package/pubmodules/queue/index.js +4 -0
- package/pubmodules/queue/reconnect.js +331 -0
- package/pubmodules/queue/reconnectFanout.js +256 -0
- package/pubmodules/rasa/listener.js +5 -5
- package/pubmodules/routing-queue/index.js +3 -0
- package/pubmodules/routing-queue/listener.js +328 -0
- package/pubmodules/rules/conciergeBot.js +2 -2
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +6 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +7 -1
- package/pubmodules/tilebot/index.js +11 -0
- package/pubmodules/tilebot/listener.js +85 -0
- package/pubmodules/trigger/rulesTrigger.js +137 -14
- package/pubmodules/trigger/start.js +5 -1
- package/pubmodules/whatsapp/index.js +7 -0
- package/pubmodules/whatsapp/listener.js +32 -0
- package/routes/auth.js +7 -2
- package/routes/campaigns.js +3 -3
- package/routes/department.js +3 -2
- package/routes/email.js +32 -2
- package/routes/faq.js +37 -2
- package/routes/faq_kb.js +496 -133
- package/routes/faqpub.js +5 -0
- package/routes/lead.js +56 -0
- package/routes/message.js +196 -14
- package/routes/messagesRoot.js +39 -0
- package/routes/project.js +76 -4
- package/routes/project_user.js +11 -1
- package/routes/project_user_test.js +19 -0
- package/routes/request.js +134 -30
- package/routes/troubleshooting.js +12 -0
- package/routes/users-util.js +39 -0
- package/routes/users.js +1 -1
- package/routes/widget.js +64 -2
- package/services/BotSubscriptionNotifier.js +5 -0
- package/services/banUserNotifier.js +86 -0
- package/services/cacheEnabler.js +56 -0
- package/services/chatbotService.js +101 -0
- package/services/departmentService.js +25 -3
- package/services/emailService.js +170 -28
- package/services/faqBotHandler.js +2 -3
- package/services/faqService.js +28 -3
- package/services/geoService.js +36 -6
- package/services/labelService.js +1 -1
- package/services/leadService.js +3 -2
- package/services/messageService.js +4 -2
- package/services/modulesManager.js +23 -76
- package/services/operatingHoursService.js +9 -4
- package/services/requestService.js +75 -39
- package/services/subscriptionNotifier.js +9 -4
- package/services/trainingService.js +106 -0
- package/template/email/assignedEmailMessage.html +21 -11
- package/template/email/assignedRequest.html +21 -11
- package/template/email/beenInvitedExistingUser.html +16 -6
- package/template/email/beenInvitedNewUser.html +16 -6
- package/template/email/emailDirect.html +130 -0
- package/template/email/newMessage.html +18 -8
- package/template/email/newMessageFollower.html +22 -12
- package/template/email/passwordChanged.html +15 -5
- package/template/email/pooledEmailMessage.html +21 -11
- package/template/email/pooledRequest.html +20 -10
- package/template/email/resetPassword.html +15 -5
- package/template/email/sendTranscript.html +7 -4
- package/template/email/ticket.html +17 -7
- package/template/email/verify.html +15 -5
- package/test/cannedRoute.js +157 -0
- package/test/chatbot-mock.js +127 -0
- package/test/example-json-intents.txt +1 -0
- package/test/example-json.txt +1 -0
- package/test/example.json +1 -0
- package/test/faqRoute.js +353 -208
- package/test/faqkbRoute.js +669 -64
- package/test/imageRoute.js +1 -1
- package/test/messageRoute.js +387 -5
- package/test/requestRoute.js +6 -6
- package/test/requestService.js +55 -4
- package/test-int/cache-project.js +90 -0
- package/test-int/cache-project_user.js +88 -0
- package/utils/UIDGenerator.js +20 -0
- package/utils/cacheUtil.js +2 -2
- package/utils/orgUtil.js +3 -3
- package/utils/promiseUtil.js +31 -0
- package/utils/recipientEmailUtil.js +66 -0
- package/utils/sendEmailUtil.js +34 -0
- package/utils/sendMessageUtil.js +1 -1
- package/utils/stringUtil.js +12 -0
- package/websocket/webSocketServer.js +33 -10
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const botEvent = require('../../event/botEvent');
|
|
2
|
+
var Faq_kb = require("../../models/faq_kb");
|
|
3
|
+
var winston = require('../../config/winston');
|
|
4
|
+
const df = require("@tiledesk/tiledesk-dialogflow-connector");
|
|
5
|
+
var configGlobal = require('../../config/global');
|
|
6
|
+
|
|
7
|
+
var port = process.env.PORT || '3000';
|
|
8
|
+
|
|
9
|
+
const BOT_DIALOGFLOW_ENDPOINT = process.env.BOT_DIALOGFLOW_ENDPOINT || "http://localhost:" + port+ "/modules/dialogflow/tdbot/";
|
|
10
|
+
winston.debug("BOT_DIALOGFLOW_ENDPOINT: " + BOT_DIALOGFLOW_ENDPOINT);
|
|
11
|
+
|
|
12
|
+
// if (BOT_DIALOGFLOW_ENDPOINT) {
|
|
13
|
+
winston.info("Dialogflow endpoint: " + BOT_DIALOGFLOW_ENDPOINT);
|
|
14
|
+
// } else {
|
|
15
|
+
// winston.info("Dialogflow endpoint not configured");
|
|
16
|
+
// }
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
|
20
|
+
winston.info('Dialogflow apiUrl: '+ apiUrl);
|
|
21
|
+
|
|
22
|
+
class Listener {
|
|
23
|
+
|
|
24
|
+
listen(config) {
|
|
25
|
+
|
|
26
|
+
winston.debug('dialogflow Listener listen');
|
|
27
|
+
|
|
28
|
+
var that = this;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
df.startApp(
|
|
32
|
+
{
|
|
33
|
+
MONGODB_URI: config.databaseUri,
|
|
34
|
+
API_ENDPOINT: apiUrl,
|
|
35
|
+
log: process.env.DIALOGFLOW_LOG
|
|
36
|
+
}, () => {
|
|
37
|
+
winston.info("Dialogflow route successfully started.");
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
botEvent.on('faqbot.create', function(bot) {
|
|
42
|
+
if (BOT_DIALOGFLOW_ENDPOINT) {
|
|
43
|
+
|
|
44
|
+
if (bot.type==="dialogflow") {
|
|
45
|
+
// bot.url = BOT_DIALOGFLOW_ENDPOINT;
|
|
46
|
+
|
|
47
|
+
Faq_kb.findByIdAndUpdate(bot.id, {"url":BOT_DIALOGFLOW_ENDPOINT}, { new: true, upsert: true }, function (err, savedFaq_kb) {
|
|
48
|
+
|
|
49
|
+
// bot.save(function (err, savedFaq_kb) {
|
|
50
|
+
if (err) {
|
|
51
|
+
return winston.error('error saving faqkb dialogflow ', err)
|
|
52
|
+
}
|
|
53
|
+
winston.verbose('Saved faqkb dialogflow', savedFaq_kb.toObject())
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var listener = new Listener();
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
module.exports = listener;
|
|
@@ -31,11 +31,25 @@ winston.debug('********* RequestNotification apiUrl: ' + apiUrl);
|
|
|
31
31
|
|
|
32
32
|
class RequestNotification {
|
|
33
33
|
|
|
34
|
+
constructor() {
|
|
35
|
+
this.enabled = true;
|
|
36
|
+
if (process.env.EMAIL_NOTIFICATION_ENABLED=="false" || process.env.EMAIL_NOTIFICATION_ENABLED==false) {
|
|
37
|
+
this.enabled = false;
|
|
38
|
+
}
|
|
39
|
+
winston.debug("RequestNotification this.enabled: "+ this.enabled);
|
|
40
|
+
}
|
|
34
41
|
|
|
35
42
|
listen() {
|
|
36
|
-
var that = this;
|
|
43
|
+
var that = this;
|
|
37
44
|
|
|
38
45
|
|
|
46
|
+
|
|
47
|
+
if (this.enabled==true) {
|
|
48
|
+
winston.info("RequestNotification listener started");
|
|
49
|
+
} else {
|
|
50
|
+
return winston.info("RequestNotification listener disabled");
|
|
51
|
+
}
|
|
52
|
+
|
|
39
53
|
|
|
40
54
|
var messageCreateKey = 'message.create';
|
|
41
55
|
if (messageEvent.queueEnabled) {
|
|
@@ -78,7 +92,7 @@ listen() {
|
|
|
78
92
|
} else {
|
|
79
93
|
winston.debug("sendUserEmail chat channel");
|
|
80
94
|
|
|
81
|
-
//TODO
|
|
95
|
+
//TODO mandare email se ultimo messaggio > X MINUTI configurato in Notification . potresti usare request.updated_at ?
|
|
82
96
|
|
|
83
97
|
|
|
84
98
|
|
|
@@ -110,7 +124,7 @@ listen() {
|
|
|
110
124
|
winston.debug('RequestNotification requestCreateKey: ' + requestCreateKey);
|
|
111
125
|
|
|
112
126
|
requestEvent.on(requestCreateKey, function(request) {
|
|
113
|
-
|
|
127
|
+
winston.debug('requestEvent.on(requestCreateKey');
|
|
114
128
|
setImmediate(() => {
|
|
115
129
|
|
|
116
130
|
/*
|
|
@@ -127,10 +141,9 @@ listen() {
|
|
|
127
141
|
|
|
128
142
|
|
|
129
143
|
var requestParticipantsUpdateKey = 'request.participants.update';
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// }
|
|
144
|
+
if (requestEvent.queueEnabled) {
|
|
145
|
+
requestParticipantsUpdateKey = 'request.participants.update.queue';
|
|
146
|
+
}
|
|
134
147
|
winston.debug('RequestNotification requestParticipantsUpdateKey: ' + requestParticipantsUpdateKey);
|
|
135
148
|
|
|
136
149
|
requestEvent.on(requestParticipantsUpdateKey, function(data) {
|
|
@@ -163,12 +176,12 @@ listen() {
|
|
|
163
176
|
// TODO Send email also for addAgent and reassign. Alessio request for pooled only?
|
|
164
177
|
|
|
165
178
|
var requestCloseExtendedKey = 'request.close.extended';
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// }
|
|
179
|
+
if (requestEvent.queueEnabled) {
|
|
180
|
+
requestCloseExtendedKey = 'request.close.extended.queue';
|
|
181
|
+
}
|
|
170
182
|
winston.debug('RequestNotification requestCloseExtendedKey: ' + requestCloseExtendedKey);
|
|
171
183
|
requestEvent.on(requestCloseExtendedKey, function(data) {
|
|
184
|
+
winston.debug('requestEvent.on(requestCloseExtendedKey ' + requestCloseExtendedKey);
|
|
172
185
|
setImmediate(() => {
|
|
173
186
|
var request = data.request;
|
|
174
187
|
var notify = data.notify;
|
|
@@ -341,7 +354,7 @@ sendToUserEmailChannelEmail(projectid, message) {
|
|
|
341
354
|
});
|
|
342
355
|
|
|
343
356
|
} catch(e) {
|
|
344
|
-
winston.error("Error sending email", {error:e, projectid:projectid, message:message});
|
|
357
|
+
winston.error("Error sending requestNotification email", {error:e, projectid:projectid, message:message});
|
|
345
358
|
}
|
|
346
359
|
}
|
|
347
360
|
|
|
@@ -356,7 +369,14 @@ async notifyFollowers(savedRequest, project, message) {
|
|
|
356
369
|
return winston.debug("not sending notifyFollowers for attributes.subtype info messages");
|
|
357
370
|
}
|
|
358
371
|
|
|
359
|
-
|
|
372
|
+
if (!savedRequest) {
|
|
373
|
+
return winston.debug("not sending notifyFollowers for direct messages");
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Cannot read property '_id' of undefined at RequestNotification.notifyFollowers (/usr/src/app/pubmodules/emailNotification/requestNotification.js:358:62) at /usr/src/app
|
|
377
|
+
// forse meglio .id
|
|
378
|
+
|
|
379
|
+
var reqWithFollowers = await Request.findById(savedRequest._id).populate('followers').exec(); // cache_attention
|
|
360
380
|
winston.debug("reqWithFollowers");
|
|
361
381
|
winston.debug("reqWithFollowers",reqWithFollowers);
|
|
362
382
|
// console.log("reqWithFollowers",reqWithFollowers);
|
|
@@ -376,7 +396,7 @@ async notifyFollowers(savedRequest, project, message) {
|
|
|
376
396
|
}
|
|
377
397
|
|
|
378
398
|
User.findOne({_id: userid , status: 100})
|
|
379
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid)
|
|
399
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid) //user_cache
|
|
380
400
|
.exec(function (err, user) {
|
|
381
401
|
if (err) {
|
|
382
402
|
// winston.debug(err);
|
|
@@ -439,7 +459,7 @@ sendToFollower(projectid, message) {
|
|
|
439
459
|
}
|
|
440
460
|
})
|
|
441
461
|
} catch (e) {
|
|
442
|
-
winston.warn("Error sending email", {error:e, projectid:projectid, message: message, savedRequest:savedRequest}); //it's better to view error email at this stage
|
|
462
|
+
winston.warn("Error sending requestNotification email", {error:e, projectid:projectid, message: message, savedRequest:savedRequest}); //it's better to view error email at this stage
|
|
443
463
|
}
|
|
444
464
|
}
|
|
445
465
|
|
|
@@ -518,7 +538,7 @@ sendToAgentEmailChannelEmail(projectid, message) {
|
|
|
518
538
|
}
|
|
519
539
|
|
|
520
540
|
User.findOne({_id: userid , status: 100})
|
|
521
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid)
|
|
541
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid) //user_cache
|
|
522
542
|
.exec(function (err, user) {
|
|
523
543
|
if (err) {
|
|
524
544
|
// winston.debug(err);
|
|
@@ -572,10 +592,10 @@ sendToAgentEmailChannelEmail(projectid, message) {
|
|
|
572
592
|
}
|
|
573
593
|
|
|
574
594
|
User.findOne({_id: assignedId, status: 100})
|
|
575
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
|
|
595
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+assignedId) //user_cache
|
|
576
596
|
.exec(function (err, user) {
|
|
577
597
|
if (err) {
|
|
578
|
-
winston.error("Error sending email to " + savedRequest.participants[0], err);
|
|
598
|
+
winston.error("Error sending requestNotification email to " + savedRequest.participants[0], err);
|
|
579
599
|
}
|
|
580
600
|
if (!user) {
|
|
581
601
|
winston.warn("User not found", savedRequest.participants[0]);
|
|
@@ -605,7 +625,7 @@ sendToAgentEmailChannelEmail(projectid, message) {
|
|
|
605
625
|
});
|
|
606
626
|
|
|
607
627
|
} catch (e) {
|
|
608
|
-
winston.warn("Error sending email", {error:e, projectid:projectid, message: message, savedRequest:savedRequest}); //it's better to view error email at this stage
|
|
628
|
+
winston.warn("Error sending requestNotification email", {error:e, projectid:projectid, message: message, savedRequest:savedRequest}); //it's better to view error email at this stage
|
|
609
629
|
}
|
|
610
630
|
//end send email
|
|
611
631
|
|
|
@@ -646,7 +666,7 @@ sendEmailChannelTakingNotification(projectid, request) {
|
|
|
646
666
|
});
|
|
647
667
|
|
|
648
668
|
} catch(e) {
|
|
649
|
-
winston.error("Error sending email", {error:e, projectid:projectid, message:message});
|
|
669
|
+
winston.error("Error sending requestNotification email", {error:e, projectid:projectid, message:message});
|
|
650
670
|
}
|
|
651
671
|
}
|
|
652
672
|
|
|
@@ -684,7 +704,7 @@ sendUserEmail(projectid, message) {
|
|
|
684
704
|
|
|
685
705
|
|
|
686
706
|
if (process.env.DISABLE_SEND_OFFLINE_EMAIL === "true" || process.env.DISABLE_SEND_OFFLINE_EMAIL === true ) {
|
|
687
|
-
return winston.
|
|
707
|
+
return winston.debug("DISABLE_SEND_OFFLINE_EMAIL disabled");
|
|
688
708
|
}
|
|
689
709
|
if (message.attributes && message.attributes.subtype==='info/support') {
|
|
690
710
|
return winston.debug("not sending sendUserEmail for attributes.subtype info/support messages");
|
|
@@ -697,7 +717,7 @@ sendUserEmail(projectid, message) {
|
|
|
697
717
|
|
|
698
718
|
|
|
699
719
|
if (!message.request.lead || !message.request.lead.email) {
|
|
700
|
-
return winston.
|
|
720
|
+
return winston.debug("The lead object is undefined or has empty email");
|
|
701
721
|
}
|
|
702
722
|
|
|
703
723
|
if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.offline && project.settings.email.notification.conversation.offline.blocked == true ) {
|
|
@@ -786,6 +806,7 @@ sendUserEmail(projectid, message) {
|
|
|
786
806
|
}
|
|
787
807
|
winston.debug("tokenQueryString: "+tokenQueryString);
|
|
788
808
|
|
|
809
|
+
//send email unverified so spam check?
|
|
789
810
|
emailService.sendNewMessageNotification(lead.email, message, project, tokenQueryString, sourcePage);
|
|
790
811
|
}
|
|
791
812
|
|
|
@@ -799,7 +820,7 @@ sendUserEmail(projectid, message) {
|
|
|
799
820
|
});
|
|
800
821
|
|
|
801
822
|
} catch(e) {
|
|
802
|
-
winston.error("Error sending email", {error:e, projectid:projectid, message:message});
|
|
823
|
+
winston.error("Error sending requestNotification email", {error:e, projectid:projectid, message:message});
|
|
803
824
|
}
|
|
804
825
|
}
|
|
805
826
|
|
|
@@ -807,7 +828,12 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
807
828
|
// send email
|
|
808
829
|
try {
|
|
809
830
|
|
|
810
|
-
|
|
831
|
+
// console.log("sendAgentEmail")
|
|
832
|
+
if (savedRequest.preflight === true) { //only for channel email and form preflight is false otherwise request.participants.update is used i think?
|
|
833
|
+
winston.debug("preflight request sendAgentEmail disabled")
|
|
834
|
+
return 0;
|
|
835
|
+
}
|
|
836
|
+
|
|
811
837
|
Project.findOne({_id: projectid, status: 100}).select("+settings").exec( async function(err, project){
|
|
812
838
|
if (err) {
|
|
813
839
|
return winston.error(err);
|
|
@@ -828,6 +854,8 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
828
854
|
// TODO fare il controllo anche sul dipartimento con modalità assigned o pooled
|
|
829
855
|
if (savedRequest.status==RequestConstants.UNASSIGNED) { //POOLED
|
|
830
856
|
|
|
857
|
+
winston.debug("savedRequest.status==RequestConstants.UNASSIGNED");
|
|
858
|
+
|
|
831
859
|
if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.pooled == false ) {
|
|
832
860
|
return winston.info("RequestNotification email notification for the project with id : " + projectid + " for the pooled conversation is disabled");
|
|
833
861
|
}
|
|
@@ -875,7 +903,7 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
875
903
|
}
|
|
876
904
|
|
|
877
905
|
User.findOne({_id: userid , status: 100})
|
|
878
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid)
|
|
906
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid) //user_cache
|
|
879
907
|
.exec(function (err, user) {
|
|
880
908
|
if (err) {
|
|
881
909
|
// winston.debug(err);
|
|
@@ -900,6 +928,8 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
900
928
|
// TODO fare il controllo anche sul dipartimento con modalità assigned o pooled
|
|
901
929
|
else if (savedRequest.status==RequestConstants.ASSIGNED) { //ASSIGNED
|
|
902
930
|
|
|
931
|
+
winston.debug("savedRequest.status==RequestConstants.ASSIGNED");
|
|
932
|
+
|
|
903
933
|
if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.assigned == false ) {
|
|
904
934
|
return winston.verbose("RequestNotification email notification for the project with id : " + projectid + " for the assigned conversation is disabled");
|
|
905
935
|
}
|
|
@@ -937,10 +967,10 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
937
967
|
return winston.warn("RequestNotification email notification for the user with id : " + assignedId + " not found project_user");
|
|
938
968
|
}
|
|
939
969
|
User.findOne({_id: assignedId, status: 100})
|
|
940
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
|
|
970
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+assignedId) //user_cache
|
|
941
971
|
.exec(function (err, user) {
|
|
942
972
|
if (err) {
|
|
943
|
-
winston.error("Error sending email to " + savedRequest.participants[0], err);
|
|
973
|
+
winston.error("Error sending requestNotification email to " + savedRequest.participants[0], err);
|
|
944
974
|
}
|
|
945
975
|
if (!user) {
|
|
946
976
|
winston.warn("User not found", savedRequest.participants[0]);
|
|
@@ -988,7 +1018,7 @@ sendAgentEmail(projectid, savedRequest) {
|
|
|
988
1018
|
});
|
|
989
1019
|
|
|
990
1020
|
} catch (e) {
|
|
991
|
-
winston.warn("Error sending email", {error:e, projectid:projectid, savedRequest:savedRequest}); //it's better to view error email at this stage
|
|
1021
|
+
winston.warn("Error sending requestNotification email", {error:e, projectid:projectid, savedRequest:savedRequest}); //it's better to view error email at this stage
|
|
992
1022
|
}
|
|
993
1023
|
//end send email
|
|
994
1024
|
|
|
@@ -2,7 +2,6 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router({mergeParams: true});
|
|
3
3
|
var Event = require("./event");
|
|
4
4
|
var winston = require('../../config/winston');
|
|
5
|
-
const eventEvent = require('./eventEvent');
|
|
6
5
|
var validtoken = require('../../middleware/valid-token');
|
|
7
6
|
const eventService = require('./eventService');
|
|
8
7
|
const { check, validationResult } = require('express-validator');
|
|
@@ -10,6 +9,9 @@ var passport = require('passport');
|
|
|
10
9
|
require('../../middleware/passport')(passport);
|
|
11
10
|
var roleChecker = require('../../middleware/has-role');
|
|
12
11
|
|
|
12
|
+
const messageEvent = require('../../event/messageEvent');
|
|
13
|
+
|
|
14
|
+
|
|
13
15
|
router.post('/', [
|
|
14
16
|
passport.authenticate(['basic', 'jwt'],
|
|
15
17
|
{ session: false }),
|
|
@@ -37,30 +39,53 @@ router.post('/', [
|
|
|
37
39
|
pu = req.projectuser.id
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// // da qui
|
|
45
|
+
|
|
46
|
+
// performance log
|
|
47
|
+
// console.log("************* emit event"+new Date().toISOString());
|
|
48
|
+
|
|
49
|
+
// // message.senderFullname, message.recipient,
|
|
50
|
+
// // message.recipient_fullname, message.text, message.sender, attributes, message.type, message.metadata, timestamp, message.group
|
|
51
|
+
// var recipient = req.body.attributes.request_id;
|
|
52
|
+
// console.log("recipient",recipient);
|
|
53
|
+
// var sender = req.user.id;
|
|
54
|
+
// console.log("sender",sender);
|
|
55
|
+
|
|
56
|
+
// let message = {
|
|
57
|
+
// recipient: recipient,
|
|
58
|
+
// recipient_fullname: "pluto",
|
|
59
|
+
// // sender:"bb0d809b-b093-419b-8b48-11a192cc3619",
|
|
60
|
+
// sender: sender,
|
|
61
|
+
// senderFullname: "Tiledesk",
|
|
62
|
+
// text:"welcome",
|
|
63
|
+
// group: {
|
|
64
|
+
// members: {
|
|
65
|
+
// // "bb0d809b-b093-419b-8b48-11a192cc3619": 1,
|
|
66
|
+
// // sender: 1
|
|
67
|
+
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
// };
|
|
71
|
+
// message.group.members[sender]= 1;
|
|
72
|
+
// console.log("message", message)
|
|
73
|
+
|
|
74
|
+
// messageEvent.emit("message.test", message);
|
|
75
|
+
// res.json({"event":"1"});
|
|
76
|
+
|
|
77
|
+
// //fino qui
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// // emit(name, attributes, id_project, project_user, createdBy, status, user) {
|
|
41
81
|
eventService.emit(req.body.name, req.body.attributes, req.projectid, pu, req.user.id, undefined, req.user).then(function(event) {
|
|
42
|
-
res.json(event);
|
|
43
|
-
}).catch(function(err) {
|
|
44
|
-
winston.error('Error saving the event '+ JSON.stringify(event), err)
|
|
45
|
-
return res.status(500).send({success: false, msg: 'Error saving the event '+ JSON.stringify(event)});
|
|
46
|
-
});
|
|
47
82
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// });
|
|
55
|
-
|
|
56
|
-
// newEvent.save(function(err, savedEvent) {
|
|
57
|
-
// if (err) {
|
|
58
|
-
// winston.error('Error saving the event '+ JSON.stringify(savedEvent), err)
|
|
59
|
-
// return res.status(500).send({success: false, msg: 'Error saving the event '+ JSON.stringify(savedEvent)});
|
|
60
|
-
// }
|
|
61
|
-
|
|
62
|
-
// res.json(savedEvent);
|
|
63
|
-
// });
|
|
83
|
+
res.json(event);
|
|
84
|
+
}).catch(function(err) {
|
|
85
|
+
winston.error('Error saving the event '+ JSON.stringify(event), err)
|
|
86
|
+
return res.status(500).send({success: false, msg: 'Error saving the event '+ JSON.stringify(event)});
|
|
87
|
+
});
|
|
88
|
+
|
|
64
89
|
});
|
|
65
90
|
|
|
66
91
|
|
|
@@ -137,7 +162,7 @@ router.get('/', [passport.authenticate(['basic', 'jwt'],
|
|
|
137
162
|
}
|
|
138
163
|
|
|
139
164
|
// collection.count is deprecated, and will be removed in a future version. Use Collection.countDocuments or Collection.estimatedDocumentCount instead
|
|
140
|
-
return Event.
|
|
165
|
+
return Event.countDocuments(query, function (err, totalRowCount) {
|
|
141
166
|
|
|
142
167
|
var objectToReturn = {
|
|
143
168
|
perPage: limit,
|
|
@@ -4,6 +4,7 @@ const Request = require('../../models/request');
|
|
|
4
4
|
var winston = require('../../config/winston');
|
|
5
5
|
var cacheUtil = require('../../utils/cacheUtil');
|
|
6
6
|
var handlebars = require('handlebars');
|
|
7
|
+
var cacheEnabler = require("../../services/cacheEnabler");
|
|
7
8
|
|
|
8
9
|
class MessageHandlebarsTransformerInterceptor {
|
|
9
10
|
|
|
@@ -38,8 +39,12 @@ class MessageHandlebarsTransformerInterceptor {
|
|
|
38
39
|
populate({path:'requester',populate:{path:'id_user'}});
|
|
39
40
|
// }
|
|
40
41
|
|
|
42
|
+
if (cacheEnabler.request) {
|
|
43
|
+
q1.cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient) //request_cache
|
|
44
|
+
winston.debug('request cache enabled');
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
var request = await q1
|
|
42
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient)
|
|
43
48
|
.exec();
|
|
44
49
|
|
|
45
50
|
|
|
@@ -5,6 +5,7 @@ const Request = require('../../models/request');
|
|
|
5
5
|
var winston = require('../../config/winston');
|
|
6
6
|
var i8nUtil = require("../../utils/i8nUtil");
|
|
7
7
|
var cacheUtil = require('../../utils/cacheUtil');
|
|
8
|
+
var cacheEnabler = require("../../services/cacheEnabler");
|
|
8
9
|
|
|
9
10
|
//TODO rename to LabelMessageTransformerInterceptor
|
|
10
11
|
class MessageTransformerInterceptor {
|
|
@@ -36,15 +37,20 @@ class MessageTransformerInterceptor {
|
|
|
36
37
|
|
|
37
38
|
var language = "EN";
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
var request = await Request.findOne({request_id: message.recipient, id_project: message.id_project})
|
|
40
|
+
let q = Request.findOne({request_id: message.recipient, id_project: message.id_project});
|
|
41
41
|
// populate('lead').
|
|
42
42
|
// populate('department').
|
|
43
43
|
// populate('participatingBots').
|
|
44
44
|
// populate('participatingAgents').
|
|
45
45
|
// populate({path:'requester',populate:{path:'id_user'}}).
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
|
|
47
|
+
if (cacheEnabler.request) {
|
|
48
|
+
q.cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient+":simple") //request_cache nocachepopulatereqired
|
|
49
|
+
winston.debug('request cache enabled');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
var request = await q.exec();
|
|
48
54
|
|
|
49
55
|
winston.debug('request mti: ', request);
|
|
50
56
|
|