@tiledesk/tiledesk-server 2.4.36 → 2.4.37
Sign up to get free protection for your applications and to get access to all the features.
- package/app.js +5 -3
- package/jobs.js +11 -3
- package/jobsManager.js +9 -1
- package/package.json +1 -1
- package/pubmodules/activities/activityArchiver.js +9 -8
- package/pubmodules/queue/reconnect.js +29 -3
- package/routes/email.js +4 -1
- package/services/emailService.js +72 -71
- package/services/subscriptionNotifier.js +101 -59
- package/services/subscriptionNotifierQueued.js +124 -0
package/app.js
CHANGED
@@ -142,6 +142,9 @@ require('./services/mongoose-cache-fn')(mongoose);
|
|
142
142
|
var subscriptionNotifier = require('./services/subscriptionNotifier');
|
143
143
|
subscriptionNotifier.start();
|
144
144
|
|
145
|
+
var subscriptionNotifierQueued = require('./services/subscriptionNotifierQueued');
|
146
|
+
|
147
|
+
|
145
148
|
var botSubscriptionNotifier = require('./services/BotSubscriptionNotifier');
|
146
149
|
botSubscriptionNotifier.start();
|
147
150
|
|
@@ -150,9 +153,8 @@ trainingService.start();
|
|
150
153
|
|
151
154
|
// job_here
|
152
155
|
|
153
|
-
|
154
156
|
var geoService = require('./services/geoService');
|
155
|
-
// geoService.listen();
|
157
|
+
// geoService.listen(); //queued
|
156
158
|
|
157
159
|
let JobsManager = require('./jobsManager');
|
158
160
|
|
@@ -162,7 +164,7 @@ if (process.env.JOB_WORKER_ENABLED=="true" || process.env.JOB_WORKER_ENABLED ==
|
|
162
164
|
}
|
163
165
|
winston.info("JobsManager jobWorkerEnabled: "+ jobWorkerEnabled);
|
164
166
|
|
165
|
-
let jobsManager = new JobsManager(jobWorkerEnabled,geoService);
|
167
|
+
let jobsManager = new JobsManager(jobWorkerEnabled, geoService, subscriptionNotifierQueued);
|
166
168
|
jobsManager.listen();
|
167
169
|
|
168
170
|
|
package/jobs.js
CHANGED
@@ -21,6 +21,12 @@ let JobsManager = require('./jobsManager');
|
|
21
21
|
|
22
22
|
|
23
23
|
let geoService = require('./services/geoService');
|
24
|
+
// let subscriptionNotifier = require('./services/subscriptionNotifier');
|
25
|
+
var subscriptionNotifierQueued = require('./services/subscriptionNotifierQueued');
|
26
|
+
|
27
|
+
require('./services/mongoose-cache-fn')(mongoose);
|
28
|
+
|
29
|
+
|
24
30
|
var config = require('./config/database');
|
25
31
|
|
26
32
|
|
@@ -39,8 +45,8 @@ var connection = mongoose.connect(databaseUri, { "useNewUrlParser": true, "autoI
|
|
39
45
|
winston.error('Failed to connect to MongoDB on ' + databaseUri + " ", err);
|
40
46
|
process.exit(1);
|
41
47
|
}
|
48
|
+
winston.info("Mongoose connection done on host: "+mongoose.connection.host + " on port: " + mongoose.connection.port + " with name: "+ mongoose.connection.name)// , mongoose.connection.db);
|
42
49
|
});
|
43
|
-
|
44
50
|
// winston.info("mongoose.connection",mongoose.connection);
|
45
51
|
// module.exports = jobsManager;
|
46
52
|
|
@@ -49,10 +55,12 @@ var connection = mongoose.connect(databaseUri, { "useNewUrlParser": true, "autoI
|
|
49
55
|
async function main()
|
50
56
|
{
|
51
57
|
|
52
|
-
|
58
|
+
//************* LOAD QUEUE ************ //
|
59
|
+
require('./pubmodules/queue');
|
60
|
+
|
53
61
|
// require('@tiledesk-ent/tiledesk-server-queue');
|
54
62
|
|
55
|
-
let jobsManager = new JobsManager(undefined, geoService);
|
63
|
+
let jobsManager = new JobsManager(undefined, geoService, subscriptionNotifierQueued);
|
56
64
|
|
57
65
|
jobsManager.listen();
|
58
66
|
|
package/jobsManager.js
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
var winston = require('./config/winston');
|
3
3
|
|
4
4
|
class JobsManager {
|
5
|
-
constructor(jobWorkerEnabled, geoService) {
|
5
|
+
constructor(jobWorkerEnabled, geoService, subscriptionNotifierQueued) {
|
6
6
|
this.geoService = geoService;
|
7
|
+
// this.subscriptionNotifier = subscriptionNotifier;
|
8
|
+
this.subscriptionNotifierQueued = subscriptionNotifierQueued;
|
9
|
+
|
7
10
|
this.emailNotificatio = undefined;
|
8
11
|
this.activityArchiver = undefined;
|
9
12
|
|
13
|
+
|
10
14
|
this.jobWorkerEnabled = jobWorkerEnabled;
|
11
15
|
// this.jobWorkerEnabled = false;
|
12
16
|
// if (process.env.JOB_WORKER_ENABLED=="true" || process.env.JOB_WORKER_ENABLED == true) {
|
@@ -22,6 +26,8 @@ class JobsManager {
|
|
22
26
|
return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listeners");
|
23
27
|
}
|
24
28
|
this.geoService.listen();
|
29
|
+
// this.subscriptionNotifier.start();
|
30
|
+
this.subscriptionNotifierQueued.start();
|
25
31
|
}
|
26
32
|
|
27
33
|
listenEmailNotification(emailNotification) {
|
@@ -33,6 +39,8 @@ class JobsManager {
|
|
33
39
|
this.emailNotification.requestNotification.listen();
|
34
40
|
}
|
35
41
|
|
42
|
+
|
43
|
+
|
36
44
|
listenActivityArchiver(activityArchiver) {
|
37
45
|
winston.info("JobsManager listenActivityArchiver started");
|
38
46
|
if ( this.jobWorkerEnabled == true) {
|
package/package.json
CHANGED
@@ -46,7 +46,7 @@ class ActivityArchiver {
|
|
46
46
|
// if (authEvent.queueEnabled) { //queue not supported.
|
47
47
|
// authProjectUserInvitePendingKey = 'project_user.invite.pending.queue';
|
48
48
|
// }
|
49
|
-
winston.
|
49
|
+
winston.debug('ActivityArchiver authProjectUserInvitePendingKey: ' + authProjectUserInvitePendingKey);
|
50
50
|
|
51
51
|
authEvent.on(authProjectUserInvitePendingKey, function(event) {
|
52
52
|
setImmediate(() => {
|
@@ -67,7 +67,7 @@ class ActivityArchiver {
|
|
67
67
|
// if (authEvent.queueEnabled) { //queue not supported
|
68
68
|
// authProjectUserInviteKey = 'project_user.invite.queue';
|
69
69
|
// }
|
70
|
-
winston.
|
70
|
+
winston.debug('ActivityArchiver authProjectUserInviteKey: ' + authProjectUserInviteKey);
|
71
71
|
|
72
72
|
authEvent.on(authProjectUserInviteKey, function(event) {
|
73
73
|
setImmediate(() => {
|
@@ -90,7 +90,7 @@ class ActivityArchiver {
|
|
90
90
|
if (authEvent.queueEnabled) {
|
91
91
|
authProjectUserUpdateKey = 'project_user.update.queue';
|
92
92
|
}
|
93
|
-
winston.
|
93
|
+
winston.debug('ActivityArchiver authProjectUserUpdateKey: ' + authProjectUserUpdateKey);
|
94
94
|
|
95
95
|
authEvent.on(authProjectUserUpdateKey, function(event) {
|
96
96
|
setImmediate(() => {
|
@@ -130,7 +130,7 @@ class ActivityArchiver {
|
|
130
130
|
// if (authEvent.queueEnabled) { //queue not supported
|
131
131
|
// authProjectUserDeleteKey = 'project_user.delete.queue';
|
132
132
|
// }
|
133
|
-
winston.
|
133
|
+
winston.debug('ActivityArchiver authProjectUserDeleteKey: ' + authProjectUserDeleteKey);
|
134
134
|
|
135
135
|
|
136
136
|
authEvent.on(authProjectUserDeleteKey, function(event) {
|
@@ -297,7 +297,7 @@ class ActivityArchiver {
|
|
297
297
|
if (requestEvent.queueEnabled) {
|
298
298
|
requestCreateKey = 'request.create.queue';
|
299
299
|
}
|
300
|
-
winston.
|
300
|
+
winston.debug('ActivityArchiver requestCreateKey: ' + requestCreateKey);
|
301
301
|
|
302
302
|
requestEvent.on(requestCreateKey, function(request) {
|
303
303
|
setImmediate(() => {
|
@@ -341,7 +341,7 @@ class ActivityArchiver {
|
|
341
341
|
if (requestEvent.queueEnabled) {
|
342
342
|
requestUpdatePreflightKey = 'request.update.preflight.queue';
|
343
343
|
}
|
344
|
-
winston.
|
344
|
+
winston.debug('ActivityArchiver requestUpdatePreflightKey: ' + requestUpdatePreflightKey);
|
345
345
|
|
346
346
|
|
347
347
|
requestEvent.on(requestUpdatePreflightKey, function(request) {
|
@@ -371,14 +371,15 @@ class ActivityArchiver {
|
|
371
371
|
|
372
372
|
|
373
373
|
// verified with queue
|
374
|
-
var requestCloseKey = 'request.close';
|
374
|
+
var requestCloseKey = 'request.close'; //request.close event here queued under job
|
375
375
|
if (requestEvent.queueEnabled) {
|
376
376
|
requestCloseKey = 'request.close.queue';
|
377
377
|
}
|
378
|
-
winston.
|
378
|
+
winston.debug('ActivityArchiver requestCloseKey: ' + requestCloseKey);
|
379
379
|
|
380
380
|
|
381
381
|
requestEvent.on(requestCloseKey, function(request) {
|
382
|
+
winston.debug("request.close event here 7")
|
382
383
|
setImmediate(() => {
|
383
384
|
|
384
385
|
try {
|
@@ -2,6 +2,8 @@ var amqp = require('amqplib/callback_api');
|
|
2
2
|
var winston = require('../../config/winston');
|
3
3
|
const requestEvent = require('../../event/requestEvent');
|
4
4
|
const messageEvent = require('../../event/messageEvent');
|
5
|
+
const leadEvent = require('../../event/leadEvent');
|
6
|
+
|
5
7
|
const botEvent = require('../../event/botEvent');
|
6
8
|
const authEvent = require('../../event/authEvent');
|
7
9
|
// https://elements.heroku.com/addons/cloudamqp
|
@@ -16,9 +18,9 @@ var url = process.env.CLOUDAMQP_URL + "?heartbeat=60" || "amqp://localhost";
|
|
16
18
|
// var url = process.env.AMQP_URL + "?heartbeat=60" || "amqp://localhost?heartbeat=60";
|
17
19
|
|
18
20
|
var durable = false;
|
19
|
-
if (process.env.ENABLE_DURABLE_QUEUE ==
|
20
|
-
|
21
|
-
}
|
21
|
+
// if (process.env.ENABLE_DURABLE_QUEUE == false || process.env.ENABLE_DURABLE_QUEUE == "false") {
|
22
|
+
// durable = false;
|
23
|
+
// }
|
22
24
|
|
23
25
|
var persistent = false;
|
24
26
|
if (process.env.ENABLE_PERSISTENT_QUEUE == true || process.env.ENABLE_PERSISTENT_QUEUE == "true") {
|
@@ -175,6 +177,12 @@ function startWorker() {
|
|
175
177
|
winston.info("Data queue", oka)
|
176
178
|
});
|
177
179
|
|
180
|
+
ch.bindQueue(_ok.queue, exchange, "lead_create", {}, function(err3, oka) {
|
181
|
+
winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: lead_create");
|
182
|
+
winston.info("Data queue", oka)
|
183
|
+
});
|
184
|
+
|
185
|
+
|
178
186
|
|
179
187
|
ch.consume(queueName, processMsg, { noAck: false });
|
180
188
|
winston.info("Worker is started");
|
@@ -255,6 +263,14 @@ function work(msg, cb) {
|
|
255
263
|
// requestEvent.emit('request.update.queue', msg.content);
|
256
264
|
botEvent.emit('faqbot.update.queue', JSON.parse(message_string));
|
257
265
|
}
|
266
|
+
|
267
|
+
if (topic === 'lead_create') {
|
268
|
+
winston.debug("reconnect here topic lead_create:" + topic);
|
269
|
+
// requestEvent.emit('request.update.queue', msg.content);
|
270
|
+
leadEvent.emit('lead.create.queue', JSON.parse(message_string));
|
271
|
+
}
|
272
|
+
|
273
|
+
|
258
274
|
cb(true);
|
259
275
|
// WebSocket.cb(true);
|
260
276
|
// requestEvent.on(msg.KEYYYYYYY+'.ws', msg.content);
|
@@ -360,6 +376,15 @@ function listen() {
|
|
360
376
|
});
|
361
377
|
});
|
362
378
|
|
379
|
+
|
380
|
+
leadEvent.on('lead.create', function(lead) {
|
381
|
+
setImmediate(() => {
|
382
|
+
winston.debug("reconnect lead.create")
|
383
|
+
publish(exchange, "lead_create", Buffer.from(JSON.stringify(lead)));
|
384
|
+
winston.debug("reconnect: "+ Buffer.from(JSON.stringify(lead)))
|
385
|
+
});
|
386
|
+
});
|
387
|
+
|
363
388
|
}
|
364
389
|
|
365
390
|
if (process.env.QUEUE_ENABLED === "true") {
|
@@ -367,6 +392,7 @@ if (process.env.QUEUE_ENABLED === "true") {
|
|
367
392
|
messageEvent.queueEnabled = true;
|
368
393
|
authEvent.queueEnabled = true;
|
369
394
|
botEvent.queueEnabled = true;
|
395
|
+
leadEvent.queueEnabled = true;
|
370
396
|
listen();
|
371
397
|
start();
|
372
398
|
winston.info("Queue enabled. endpint: " + url );
|
package/routes/email.js
CHANGED
@@ -322,8 +322,11 @@ router.post('/send',
|
|
322
322
|
let newto = await recipientEmailUtil.process(to, req.projectid);
|
323
323
|
winston.debug("newto: " + newto);
|
324
324
|
|
325
|
+
let replyto = req.body.replyto;
|
326
|
+
winston.debug("replyto: " + replyto);
|
327
|
+
|
325
328
|
//sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload)
|
326
|
-
emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined, undefined);
|
329
|
+
emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined, undefined, replyto);
|
327
330
|
|
328
331
|
res.json({"queued": true});
|
329
332
|
|
package/services/emailService.js
CHANGED
@@ -401,9 +401,9 @@ class EmailService {
|
|
401
401
|
"X-TILEDESK-TICKET-ID":request.ticket_id,
|
402
402
|
};
|
403
403
|
|
404
|
-
winston.
|
405
|
-
winston.
|
406
|
-
winston.
|
404
|
+
winston.debug("messageId: " + messageId);
|
405
|
+
winston.debug("replyTo: " + replyTo);
|
406
|
+
winston.debug("email headers", headers);
|
407
407
|
}
|
408
408
|
|
409
409
|
let inReplyTo;
|
@@ -416,19 +416,19 @@ class EmailService {
|
|
416
416
|
references = request.attributes.email_references;
|
417
417
|
}
|
418
418
|
}
|
419
|
-
winston.
|
420
|
-
winston.
|
419
|
+
winston.debug("email inReplyTo: "+ inReplyTo);
|
420
|
+
winston.debug("email references: "+ references);
|
421
421
|
|
422
422
|
let from;
|
423
423
|
let configEmail;
|
424
424
|
if (project && project.settings && project.settings.email) {
|
425
425
|
if (project.settings.email.config) {
|
426
426
|
configEmail = project.settings.email.config;
|
427
|
-
winston.
|
427
|
+
winston.debug("custom email configEmail setting found: ", configEmail);
|
428
428
|
}
|
429
429
|
if (project.settings.email.from) {
|
430
430
|
from = project.settings.email.from;
|
431
|
-
winston.
|
431
|
+
winston.debug("custom from email setting found: "+ from);
|
432
432
|
}
|
433
433
|
}
|
434
434
|
|
@@ -554,9 +554,9 @@ class EmailService {
|
|
554
554
|
|
555
555
|
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
556
556
|
|
557
|
-
winston.
|
558
|
-
winston.
|
559
|
-
winston.
|
557
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification messageId: " + messageId);
|
558
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification replyTo: " + replyTo);
|
559
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification email headers", headers);
|
560
560
|
}
|
561
561
|
|
562
562
|
let inReplyTo;
|
@@ -569,19 +569,19 @@ class EmailService {
|
|
569
569
|
references = message.request.attributes.email_references;
|
570
570
|
}
|
571
571
|
}
|
572
|
-
winston.
|
573
|
-
winston.
|
572
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification email inReplyTo: "+ inReplyTo);
|
573
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification email references: "+ references);
|
574
574
|
|
575
575
|
let from;
|
576
576
|
let configEmail;
|
577
577
|
if (project && project.settings && project.settings.email) {
|
578
578
|
if (project.settings.email.config) {
|
579
579
|
configEmail = project.settings.email.config;
|
580
|
-
winston.
|
580
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification custom email configEmail setting found: ", configEmail);
|
581
581
|
}
|
582
582
|
if (project.settings.email.from) {
|
583
583
|
from = project.settings.email.from;
|
584
|
-
winston.
|
584
|
+
winston.debug("sendNewAssignedAgentMessageEmailNotification custom from email setting found: "+ from);
|
585
585
|
}
|
586
586
|
}
|
587
587
|
|
@@ -671,7 +671,7 @@ class EmailService {
|
|
671
671
|
msgText = marked(msgText);
|
672
672
|
}
|
673
673
|
|
674
|
-
winston.
|
674
|
+
winston.debug("msgText: " + msgText);
|
675
675
|
|
676
676
|
var replacements = {
|
677
677
|
request: request,
|
@@ -701,9 +701,9 @@ class EmailService {
|
|
701
701
|
|
702
702
|
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": request.request_id, "X-TILEDESK-TICKET-ID":request.ticket_id };
|
703
703
|
|
704
|
-
winston.
|
705
|
-
winston.
|
706
|
-
winston.
|
704
|
+
winston.debug("sendNewPooledRequestNotification messageId: " + messageId);
|
705
|
+
winston.debug("sendNewPooledRequestNotification replyTo: " + replyTo);
|
706
|
+
winston.debug("sendNewPooledRequestNotification email headers", headers);
|
707
707
|
}
|
708
708
|
|
709
709
|
let inReplyTo;
|
@@ -716,19 +716,19 @@ class EmailService {
|
|
716
716
|
references = request.attributes.email_references;
|
717
717
|
}
|
718
718
|
}
|
719
|
-
winston.
|
720
|
-
winston.
|
719
|
+
winston.debug("sendNewPooledRequestNotification email inReplyTo: "+ inReplyTo);
|
720
|
+
winston.debug("sendNewPooledRequestNotification email references: "+ references);
|
721
721
|
|
722
722
|
let from;
|
723
723
|
let configEmail;
|
724
724
|
if (project && project.settings && project.settings.email) {
|
725
725
|
if (project.settings.email.config) {
|
726
726
|
configEmail = project.settings.email.config;
|
727
|
-
winston.
|
727
|
+
winston.debug("sendNewPooledRequestNotification custom email configEmail setting found: ", configEmail);
|
728
728
|
}
|
729
729
|
if (project.settings.email.from) {
|
730
730
|
from = project.settings.email.from;
|
731
|
-
winston.
|
731
|
+
winston.debug("sendNewPooledRequestNotification custom from email setting found: "+ from);
|
732
732
|
}
|
733
733
|
}
|
734
734
|
|
@@ -807,7 +807,7 @@ class EmailService {
|
|
807
807
|
msgText = marked(msgText);
|
808
808
|
}
|
809
809
|
|
810
|
-
winston.
|
810
|
+
winston.debug("msgText: " + msgText);
|
811
811
|
|
812
812
|
// passa anche tutti i messages in modo da stampare tutto
|
813
813
|
// Stampa anche contact.email
|
@@ -845,9 +845,9 @@ class EmailService {
|
|
845
845
|
|
846
846
|
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
847
847
|
|
848
|
-
winston.
|
849
|
-
winston.
|
850
|
-
winston.
|
848
|
+
winston.debug("sendNewPooledMessageEmailNotification messageId: " + messageId);
|
849
|
+
winston.debug("sendNewPooledMessageEmailNotification replyTo: " + replyTo);
|
850
|
+
winston.debug("sendNewPooledMessageEmailNotification email headers", headers);
|
851
851
|
}
|
852
852
|
|
853
853
|
let inReplyTo;
|
@@ -860,19 +860,19 @@ class EmailService {
|
|
860
860
|
references = message.request.attributes.email_references;
|
861
861
|
}
|
862
862
|
}
|
863
|
-
winston.
|
864
|
-
winston.
|
863
|
+
winston.debug("sendNewPooledMessageEmailNotification email inReplyTo: "+ inReplyTo);
|
864
|
+
winston.debug("sendNewPooledMessageEmailNotification email references: "+ references);
|
865
865
|
|
866
866
|
let from;
|
867
867
|
let configEmail;
|
868
868
|
if (project && project.settings && project.settings.email) {
|
869
869
|
if (project.settings.email.config) {
|
870
870
|
configEmail = project.settings.email.config;
|
871
|
-
winston.
|
871
|
+
winston.debug("sendNewPooledMessageEmailNotification custom email configEmail setting found: ", configEmail);
|
872
872
|
}
|
873
873
|
if (project.settings.email.from) {
|
874
874
|
from = project.settings.email.from;
|
875
|
-
winston.
|
875
|
+
winston.debug("sendNewPooledMessageEmailNotification custom from email setting found: "+ from);
|
876
876
|
}
|
877
877
|
}
|
878
878
|
|
@@ -990,9 +990,9 @@ class EmailService {
|
|
990
990
|
|
991
991
|
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
992
992
|
|
993
|
-
winston.
|
994
|
-
winston.
|
995
|
-
winston.
|
993
|
+
winston.debug("messageId: " + messageId);
|
994
|
+
winston.debug("replyTo: " + replyTo);
|
995
|
+
winston.debug("email headers", headers);
|
996
996
|
}
|
997
997
|
|
998
998
|
let inReplyTo;
|
@@ -1006,19 +1006,19 @@ class EmailService {
|
|
1006
1006
|
references = message.request.attributes.email_references;
|
1007
1007
|
}
|
1008
1008
|
}
|
1009
|
-
winston.
|
1010
|
-
winston.
|
1009
|
+
winston.debug("email inReplyTo: "+ inReplyTo);
|
1010
|
+
winston.debug("email references: "+ references);
|
1011
1011
|
|
1012
1012
|
let from;
|
1013
1013
|
let configEmail;
|
1014
1014
|
if (project && project.settings && project.settings.email) {
|
1015
1015
|
if (project.settings.email.config) {
|
1016
1016
|
configEmail = project.settings.email.config;
|
1017
|
-
winston.
|
1017
|
+
winston.debug("custom email configEmail setting found: ", configEmail);
|
1018
1018
|
}
|
1019
1019
|
if (project.settings.email.from) {
|
1020
1020
|
from = project.settings.email.from;
|
1021
|
-
winston.
|
1021
|
+
winston.debug("custom from email setting found: "+ from);
|
1022
1022
|
}
|
1023
1023
|
}
|
1024
1024
|
|
@@ -1128,9 +1128,9 @@ class EmailService {
|
|
1128
1128
|
|
1129
1129
|
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
1130
1130
|
|
1131
|
-
winston.
|
1132
|
-
winston.
|
1133
|
-
winston.
|
1131
|
+
winston.debug("messageId: " + messageId);
|
1132
|
+
winston.debug("replyTo: " + replyTo);
|
1133
|
+
winston.debug("email headers", headers);
|
1134
1134
|
}
|
1135
1135
|
|
1136
1136
|
|
@@ -1161,21 +1161,21 @@ class EmailService {
|
|
1161
1161
|
}
|
1162
1162
|
|
1163
1163
|
}
|
1164
|
-
winston.
|
1165
|
-
winston.
|
1166
|
-
winston.
|
1167
|
-
winston.
|
1164
|
+
winston.debug("email inReplyTo: "+ inReplyTo);
|
1165
|
+
winston.debug("email references: "+ references);
|
1166
|
+
winston.debug("email cc: ", cc);
|
1167
|
+
winston.debug("email ccString: "+ ccString);
|
1168
1168
|
|
1169
1169
|
let from;
|
1170
1170
|
let configEmail;
|
1171
1171
|
if (project && project.settings && project.settings.email) {
|
1172
1172
|
if (project.settings.email.config) {
|
1173
1173
|
configEmail = project.settings.email.config;
|
1174
|
-
winston.
|
1174
|
+
winston.debug("custom email configEmail setting found: ", configEmail);
|
1175
1175
|
}
|
1176
1176
|
if (project.settings.email.from) {
|
1177
1177
|
from = project.settings.email.from;
|
1178
|
-
winston.
|
1178
|
+
winston.debug("custom from email setting found: "+ from);
|
1179
1179
|
}
|
1180
1180
|
}
|
1181
1181
|
|
@@ -1312,9 +1312,9 @@ class EmailService {
|
|
1312
1312
|
|
1313
1313
|
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
1314
1314
|
|
1315
|
-
winston.
|
1316
|
-
winston.
|
1317
|
-
winston.
|
1315
|
+
winston.debug("messageId: " + messageId);
|
1316
|
+
winston.debug("replyTo: " + replyTo);
|
1317
|
+
winston.debug("email headers", headers);
|
1318
1318
|
}
|
1319
1319
|
|
1320
1320
|
|
@@ -1344,21 +1344,21 @@ class EmailService {
|
|
1344
1344
|
}
|
1345
1345
|
}
|
1346
1346
|
}
|
1347
|
-
winston.
|
1348
|
-
winston.
|
1349
|
-
winston.
|
1350
|
-
winston.
|
1347
|
+
winston.debug("email inReplyTo: "+ inReplyTo);
|
1348
|
+
winston.debug("email references: "+ references);
|
1349
|
+
winston.debug("email cc: ", cc);
|
1350
|
+
winston.debug("email ccString: "+ ccString);
|
1351
1351
|
|
1352
1352
|
let from;
|
1353
1353
|
let configEmail;
|
1354
1354
|
if (project && project.settings && project.settings.email) {
|
1355
1355
|
if (project.settings.email.config) {
|
1356
1356
|
configEmail = project.settings.email.config;
|
1357
|
-
winston.
|
1357
|
+
winston.debug("custom email configEmail setting found: ", configEmail);
|
1358
1358
|
}
|
1359
1359
|
if (project.settings.email.from) {
|
1360
1360
|
from = project.settings.email.from;
|
1361
|
-
winston.
|
1361
|
+
winston.debug("custom from email setting found: "+ from);
|
1362
1362
|
}
|
1363
1363
|
}
|
1364
1364
|
|
@@ -1457,7 +1457,7 @@ class EmailService {
|
|
1457
1457
|
|
1458
1458
|
|
1459
1459
|
|
1460
|
-
async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload) {
|
1460
|
+
async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload, replyTo) {
|
1461
1461
|
|
1462
1462
|
var that = this;
|
1463
1463
|
|
@@ -1507,8 +1507,9 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
|
|
1507
1507
|
winston.debug("html: " + html);
|
1508
1508
|
|
1509
1509
|
|
1510
|
-
let replyTo;
|
1511
|
-
|
1510
|
+
// let replyTo;
|
1511
|
+
|
1512
|
+
if (!replyTo && this.replyEnabled && request_id) {
|
1512
1513
|
replyTo = request_id + this.inboundDomainDomainWithAt;
|
1513
1514
|
}
|
1514
1515
|
|
@@ -1517,11 +1518,11 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
|
|
1517
1518
|
if (project && project.settings && project.settings.email) {
|
1518
1519
|
if (project.settings.email.config) {
|
1519
1520
|
configEmail = project.settings.email.config;
|
1520
|
-
winston.
|
1521
|
+
winston.debug("custom email configEmail setting found: ", configEmail);
|
1521
1522
|
}
|
1522
1523
|
if (project.settings.email.from) {
|
1523
1524
|
from = project.settings.email.from;
|
1524
|
-
winston.
|
1525
|
+
winston.debug("custom from email setting found: "+ from);
|
1525
1526
|
}
|
1526
1527
|
}
|
1527
1528
|
|
@@ -1820,11 +1821,11 @@ async sendRequestTranscript(to, messages, request, project) {
|
|
1820
1821
|
if (project && project.settings && project.settings.email) {
|
1821
1822
|
if (project.settings.email.config) {
|
1822
1823
|
configEmail = project.settings.email.config;
|
1823
|
-
winston.
|
1824
|
+
winston.debug("custom email configEmail setting found: ", configEmail);
|
1824
1825
|
}
|
1825
1826
|
if (project.settings.email.from) {
|
1826
1827
|
from = project.settings.email.from;
|
1827
|
-
winston.
|
1828
|
+
winston.debug("custom from email setting found: "+ from);
|
1828
1829
|
}
|
1829
1830
|
}
|
1830
1831
|
|
@@ -1878,11 +1879,11 @@ parseText(text, payload) {
|
|
1878
1879
|
formatText(templateName, defaultText, payload, settings) {
|
1879
1880
|
|
1880
1881
|
let text = defaultText;
|
1881
|
-
winston.
|
1882
|
+
winston.debug("formatText defaultText: "+ defaultText);
|
1882
1883
|
|
1883
1884
|
let template = this.getTemplate(templateName, settings);
|
1884
1885
|
|
1885
|
-
winston.
|
1886
|
+
winston.debug("formatText template: "+ template);
|
1886
1887
|
|
1887
1888
|
if (template) {
|
1888
1889
|
text = template;
|
@@ -1891,7 +1892,7 @@ formatText(templateName, defaultText, payload, settings) {
|
|
1891
1892
|
var baseScope = JSON.parse(JSON.stringify(this));
|
1892
1893
|
delete baseScope.pass;
|
1893
1894
|
|
1894
|
-
winston.
|
1895
|
+
winston.debug("formatText text: "+ text);
|
1895
1896
|
|
1896
1897
|
var templateHand = handlebars.compile(text);
|
1897
1898
|
|
@@ -1902,7 +1903,7 @@ formatText(templateName, defaultText, payload, settings) {
|
|
1902
1903
|
};
|
1903
1904
|
|
1904
1905
|
var textTemplate = templateHand(replacements);
|
1905
|
-
winston.
|
1906
|
+
winston.debug("formatText textTemplate: "+ textTemplate);
|
1906
1907
|
|
1907
1908
|
return textTemplate;
|
1908
1909
|
|
@@ -1911,21 +1912,21 @@ formatText(templateName, defaultText, payload, settings) {
|
|
1911
1912
|
getTemplate(templateName, settings) {
|
1912
1913
|
|
1913
1914
|
var that = this;
|
1914
|
-
winston.
|
1915
|
+
winston.debug('getTemplate formatSubject: ' + JSON.stringify(settings));
|
1915
1916
|
|
1916
1917
|
|
1917
1918
|
if (settings && settings.email && settings.email.templates) {
|
1918
|
-
winston.
|
1919
|
+
winston.debug('getTemplate settings.email.templates: ',settings.email.templates);
|
1919
1920
|
|
1920
1921
|
var templates = settings.email.templates;
|
1921
|
-
winston.
|
1922
|
+
winston.debug('getTemplate templates: ',templates);
|
1922
1923
|
|
1923
1924
|
var templateDbName = templateName.replace(".subject", "");
|
1924
|
-
winston.
|
1925
|
+
winston.debug('getTemplate templateDbName: '+templateDbName);
|
1925
1926
|
|
1926
1927
|
|
1927
1928
|
var template = templates[templateDbName];
|
1928
|
-
winston.
|
1929
|
+
winston.debug('getTemplate template: '+template);
|
1929
1930
|
|
1930
1931
|
if (template) {
|
1931
1932
|
// that.callback(template);
|
@@ -202,18 +202,23 @@ class SubscriptionNotifier {
|
|
202
202
|
return 0;
|
203
203
|
}
|
204
204
|
|
205
|
+
// queued
|
206
|
+
// var messageCreateKey = 'message.create';
|
207
|
+
// if (messageEvent.queueEnabled) {
|
208
|
+
// messageCreateKey = 'message.create.queue';
|
209
|
+
// }
|
210
|
+
// messageEvent.on(messageCreateKey, function(message) { //queued tested
|
211
|
+
// setImmediate(() => {
|
212
|
+
// winston.info('SubscriptionNotifier message.create');
|
213
|
+
// subscriptionNotifier.subscribe('message.create', message);
|
214
|
+
// });
|
215
|
+
// });
|
205
216
|
|
206
|
-
|
207
|
-
setImmediate(() => {
|
208
|
-
subscriptionNotifier.subscribe('message.create', message);
|
209
|
-
});
|
210
|
-
});
|
211
|
-
|
212
|
-
message2Event.on('message.create.**.channel.*', function(message) {
|
217
|
+
message2Event.on('message.create.**.channel.*', function(message) { //notqueued high
|
213
218
|
// message2Event.on('message.create.request.channel.*', function(message) {
|
214
219
|
winston.debug("message2Event: "+this.event, message);
|
215
220
|
subscriptionNotifier.subscribe(this.event, message);
|
216
|
-
|
221
|
+
}, {async: true});
|
217
222
|
|
218
223
|
|
219
224
|
|
@@ -235,72 +240,103 @@ class SubscriptionNotifier {
|
|
235
240
|
// });
|
236
241
|
|
237
242
|
|
238
|
-
requestEvent.on('request.create', function(request) {
|
239
|
-
setImmediate(() => {
|
240
|
-
subscriptionNotifier.subscribe('request.create', request);
|
241
|
-
});
|
242
|
-
});
|
243
243
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
}
|
244
|
+
// queued
|
245
|
+
// var requestCreateKey = 'request.create';
|
246
|
+
// if (requestEvent.queueEnabled) {
|
247
|
+
// requestCreateKey = 'request.create.queue';
|
248
|
+
// }
|
249
|
+
// requestEvent.on(requestCreateKey, function(request) { //queued tested
|
250
|
+
// setImmediate(() => {
|
251
|
+
// winston.info('SubscriptionNotifier request.create');
|
252
|
+
// subscriptionNotifier.subscribe('request.create', request);
|
253
|
+
// });
|
254
|
+
// });
|
249
255
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
256
|
+
|
257
|
+
// queued
|
258
|
+
// var requestUpdateKey = 'request.update';
|
259
|
+
// if (requestEvent.queueEnabled) {
|
260
|
+
// requestUpdateKey = 'request.update.queue';
|
261
|
+
// }
|
262
|
+
// requestEvent.on(requestUpdateKey, function(request) { //queued tested
|
263
|
+
// setImmediate(() => {
|
264
|
+
// winston.info('SubscriptionNotifier request.update');
|
265
|
+
// subscriptionNotifier.subscribe('request.update', request);
|
266
|
+
// });
|
267
|
+
// });
|
259
268
|
|
260
269
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
270
|
+
// queued
|
271
|
+
// var requestCloseKey = 'request.close'; //request.close event here queued under job
|
272
|
+
// if (requestEvent.queueEnabled) {
|
273
|
+
// requestCloseKey = 'request.close.queue';
|
274
|
+
// }
|
275
|
+
// requestEvent.on(requestCloseKey, function(request) { //request.close event here noqueued //queued tested
|
276
|
+
// winston.info('SubscriptionNotifier request.close');
|
277
|
+
// winston.info("request.close event here 1")
|
278
|
+
// setImmediate(() => {
|
279
|
+
// Message.find({recipient: request.request_id, id_project: request.id_project}).sort({updatedAt: 'asc'}).exec(function(err, messages) {
|
280
|
+
// var requestJson = request;
|
281
|
+
// if (request.toJSON) {
|
282
|
+
// requestJson = request.toJSON();
|
283
|
+
// }
|
284
|
+
|
285
|
+
// requestJson.messages = messages;
|
286
|
+
// subscriptionNotifier.subscribe('request.close', requestJson);
|
287
|
+
// });
|
288
|
+
// });
|
289
|
+
// });
|
266
290
|
|
267
291
|
|
268
|
-
|
292
|
+
// queued
|
293
|
+
// var leadCreateKey = 'lead.create'; //request.close event here queued under job
|
294
|
+
// if (leadEvent.queueEnabled) {
|
295
|
+
// leadCreateKey = 'lead.create.queue';
|
296
|
+
// }
|
297
|
+
// leadEvent.on(leadCreateKey, function(lead) { //notqueued high
|
298
|
+
// setImmediate(() => {
|
299
|
+
// subscriptionNotifier.subscribe('lead.create', lead);
|
300
|
+
// });
|
301
|
+
// });
|
302
|
+
|
303
|
+
|
304
|
+
botEvent.on('faqbot.create', function(faqBot) { //notqueued
|
269
305
|
setImmediate(() => {
|
270
306
|
subscriptionNotifier.subscribe('faqbot.create', faqBot);
|
271
307
|
});
|
272
308
|
});
|
273
309
|
|
274
|
-
botEvent.on('faqbot.update', function(faqBot) {
|
310
|
+
botEvent.on('faqbot.update', function(faqBot) { //queued
|
275
311
|
setImmediate(() => {
|
276
312
|
subscriptionNotifier.subscribe('faqbot.update', faqBot);
|
277
313
|
});
|
278
314
|
});
|
279
315
|
|
280
|
-
botEvent.on('faqbot.delete', function(faqBot) {
|
316
|
+
botEvent.on('faqbot.delete', function(faqBot) { //notqueued
|
281
317
|
setImmediate(() => {
|
282
318
|
subscriptionNotifier.subscribe('faqbot.delete', faqBot);
|
283
319
|
});
|
284
320
|
});
|
285
321
|
|
286
|
-
faqBotEvent.on('faq.create', function(faq) {
|
322
|
+
faqBotEvent.on('faq.create', function(faq) { //notqueued
|
287
323
|
setImmediate(() => {
|
288
324
|
subscriptionNotifier.subscribe('faq.create', faq);
|
289
325
|
});
|
290
326
|
});
|
291
327
|
|
292
|
-
faqBotEvent.on('faq.update', function(faq) {
|
328
|
+
faqBotEvent.on('faq.update', function(faq) { //notqueued
|
293
329
|
setImmediate(() => {
|
294
330
|
subscriptionNotifier.subscribe('faq.update', faq);
|
295
331
|
});
|
296
332
|
});
|
297
|
-
faqBotEvent.on('faq.delete', function(faq) {
|
333
|
+
faqBotEvent.on('faq.delete', function(faq) { //notqueued
|
298
334
|
setImmediate(() => {
|
299
335
|
subscriptionNotifier.subscribe('faq.delete', faq);
|
300
336
|
});
|
301
337
|
});
|
302
338
|
|
303
|
-
authEvent.on('user.signup', function(event) {
|
339
|
+
authEvent.on('user.signup', function(event) { //notqueued
|
304
340
|
setImmediate(() => {
|
305
341
|
var user = event.savedUser;
|
306
342
|
delete user.password;
|
@@ -312,7 +348,7 @@ class SubscriptionNotifier {
|
|
312
348
|
|
313
349
|
// authEvent.emit('project_user.invite', {req:req, savedProject_userPopulated: savedProject_userPopulated});
|
314
350
|
|
315
|
-
authEvent.on('project_user.invite', function(event) {
|
351
|
+
authEvent.on('project_user.invite', function(event) { //notqueued
|
316
352
|
setImmediate(() => {
|
317
353
|
subscriptionNotifier.subscribe('project_user.invite', event.savedProject_userPopulated);
|
318
354
|
});
|
@@ -320,15 +356,21 @@ class SubscriptionNotifier {
|
|
320
356
|
|
321
357
|
// authEvent.emit('project_user.update', {updatedProject_userPopulated:updatedProject_userPopulated, req: req});
|
322
358
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
359
|
+
|
360
|
+
// queued
|
361
|
+
// var authProjectUserUpdateKey = 'project_user.update';
|
362
|
+
// if (authEvent.queueEnabled) {
|
363
|
+
// authProjectUserUpdateKey = 'project_user.update.queue';
|
364
|
+
// }
|
365
|
+
// authEvent.on(authProjectUserUpdateKey, function(event) { //notqueued high
|
366
|
+
// setImmediate(() => {
|
367
|
+
// subscriptionNotifier.subscribe('project_user.update', event.updatedProject_userPopulated);
|
368
|
+
// });
|
369
|
+
// });
|
328
370
|
|
329
371
|
// authEvent.emit('project_user.delete', {req: req, project_userPopulated: project_userPopulated});
|
330
372
|
|
331
|
-
authEvent.on('project_user.delete', function(event) {
|
373
|
+
authEvent.on('project_user.delete', function(event) { //notqueued
|
332
374
|
setImmediate(() => {
|
333
375
|
subscriptionNotifier.subscribe('project_user.delete', event.project_userPopulated);
|
334
376
|
});
|
@@ -337,7 +379,7 @@ class SubscriptionNotifier {
|
|
337
379
|
|
338
380
|
//TODO lanciare user.signin in questo modo uno esternamente con webhook può creare proactive greetings
|
339
381
|
|
340
|
-
departmentEvent.on('operator.select', function(result) {
|
382
|
+
departmentEvent.on('operator.select', function(result) { //notqueued
|
341
383
|
winston.debug("departmentEvent.on(operator.select");
|
342
384
|
|
343
385
|
var operatorSelectedEvent = result.result;
|
@@ -376,53 +418,53 @@ class SubscriptionNotifier {
|
|
376
418
|
});
|
377
419
|
|
378
420
|
|
379
|
-
departmentEvent.on('department.create', function(department) {
|
421
|
+
departmentEvent.on('department.create', function(department) { //notqueued
|
380
422
|
setImmediate(() => {
|
381
423
|
subscriptionNotifier.subscribe('department.create', department);
|
382
424
|
});
|
383
425
|
});
|
384
426
|
|
385
427
|
|
386
|
-
departmentEvent.on('department.update', function(department) {
|
428
|
+
departmentEvent.on('department.update', function(department) { //notqueued
|
387
429
|
setImmediate(() => {
|
388
430
|
subscriptionNotifier.subscribe('department.update', department);
|
389
431
|
});
|
390
432
|
});
|
391
433
|
|
392
|
-
departmentEvent.on('department.delete', function(department) {
|
434
|
+
departmentEvent.on('department.delete', function(department) { //notqueued
|
393
435
|
setImmediate(() => {
|
394
436
|
subscriptionNotifier.subscribe('department.delete', department);
|
395
437
|
});
|
396
438
|
});
|
397
439
|
|
398
440
|
|
399
|
-
groupEvent.on('group.create', function(group) {
|
441
|
+
groupEvent.on('group.create', function(group) { //notqueued
|
400
442
|
setImmediate(() => {
|
401
443
|
subscriptionNotifier.subscribe('group.create', group);
|
402
444
|
});
|
403
445
|
});
|
404
446
|
|
405
447
|
|
406
|
-
groupEvent.on('group.update', function(group) {
|
448
|
+
groupEvent.on('group.update', function(group) { //notqueued
|
407
449
|
setImmediate(() => {
|
408
450
|
subscriptionNotifier.subscribe('group.update', group);
|
409
451
|
});
|
410
452
|
});
|
411
453
|
|
412
|
-
groupEvent.on('group.delete', function(group) {
|
454
|
+
groupEvent.on('group.delete', function(group) { //notqueued
|
413
455
|
setImmediate(() => {
|
414
456
|
subscriptionNotifier.subscribe('group.delete', group);
|
415
457
|
});
|
416
458
|
});
|
417
459
|
|
418
|
-
eventEvent.on('event.emit', function(event) {
|
460
|
+
eventEvent.on('event.emit', function(event) { //notqueued
|
419
461
|
setImmediate(() => {
|
420
462
|
subscriptionNotifier.subscribe('event.emit', event);
|
421
463
|
});
|
422
464
|
});
|
423
465
|
|
424
466
|
// event2Event.on(name, savedEventPopulated);
|
425
|
-
event2Event.on('**', function(savedEventPopulated) {
|
467
|
+
event2Event.on('**', function(savedEventPopulated) { //notqueued
|
426
468
|
setImmediate(() => {
|
427
469
|
winston.debug("eventname",this.event);
|
428
470
|
subscriptionNotifier.subscribe('event.emit.'+this.event, savedEventPopulated);
|
@@ -430,7 +472,7 @@ class SubscriptionNotifier {
|
|
430
472
|
});
|
431
473
|
|
432
474
|
|
433
|
-
projectEvent.on('project.create', function(project) {
|
475
|
+
projectEvent.on('project.create', function(project) { //notqueued
|
434
476
|
setImmediate(() => {
|
435
477
|
var projectJson = project.toJSON();
|
436
478
|
projectJson.id_project = projectJson._id;
|
@@ -438,7 +480,7 @@ class SubscriptionNotifier {
|
|
438
480
|
});
|
439
481
|
});
|
440
482
|
|
441
|
-
projectEvent.on('project.update', function(project) {
|
483
|
+
projectEvent.on('project.update', function(project) { //notqueued
|
442
484
|
setImmediate(() => {
|
443
485
|
var projectJson = project.toJSON();
|
444
486
|
projectJson.id_project = projectJson._id;
|
@@ -446,7 +488,7 @@ class SubscriptionNotifier {
|
|
446
488
|
});
|
447
489
|
});
|
448
490
|
|
449
|
-
projectEvent.on('project.downgrade', function(project) {
|
491
|
+
projectEvent.on('project.downgrade', function(project) { //notqueued
|
450
492
|
setImmediate(() => {
|
451
493
|
var projectJson = project.toJSON();
|
452
494
|
projectJson.id_project = projectJson._id;
|
@@ -454,7 +496,7 @@ class SubscriptionNotifier {
|
|
454
496
|
});
|
455
497
|
});
|
456
498
|
|
457
|
-
projectEvent.on('project.delete', function(project) {
|
499
|
+
projectEvent.on('project.delete', function(project) { //notqueued
|
458
500
|
setImmediate(() => {
|
459
501
|
var projectJson = project.toJSON();
|
460
502
|
projectJson.id_project = projectJson._id;
|
@@ -0,0 +1,124 @@
|
|
1
|
+
const requestEvent = require('../event/requestEvent');
|
2
|
+
const messageEvent = require('../event/messageEvent');
|
3
|
+
const leadEvent = require('../event/leadEvent');
|
4
|
+
const authEvent = require('../event/authEvent');
|
5
|
+
|
6
|
+
var Message = require("../models/message");
|
7
|
+
var winston = require('../config/winston');
|
8
|
+
var subscriptionNotifier = require('../services/subscriptionNotifier');
|
9
|
+
|
10
|
+
class SubscriptionNotifierQueued {
|
11
|
+
|
12
|
+
start() {
|
13
|
+
winston.debug('SubscriptionNotifierQueued start');
|
14
|
+
|
15
|
+
var enabled = process.env.RESTHOOK_ENABLED || "false";
|
16
|
+
winston.debug('SubscriptionNotifierQueued enabled:'+enabled);
|
17
|
+
|
18
|
+
if (enabled==="true") {
|
19
|
+
winston.debug('SubscriptionNotifierQueued enabled');
|
20
|
+
}else {
|
21
|
+
winston.info('Resthook Queued disabled');
|
22
|
+
return 0;
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
var messageCreateKey = 'message.create';
|
27
|
+
if (messageEvent.queueEnabled) {
|
28
|
+
messageCreateKey = 'message.create.queue';
|
29
|
+
}
|
30
|
+
messageEvent.on(messageCreateKey, function(message) { //queued tested
|
31
|
+
setImmediate(() => {
|
32
|
+
winston.debug('SubscriptionNotifier message.create');
|
33
|
+
subscriptionNotifier.subscribe('message.create', message);
|
34
|
+
winston.debug('SubscriptionNotifier message.create sent');
|
35
|
+
});
|
36
|
+
});
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
var requestCreateKey = 'request.create';
|
41
|
+
if (requestEvent.queueEnabled) {
|
42
|
+
requestCreateKey = 'request.create.queue';
|
43
|
+
}
|
44
|
+
requestEvent.on(requestCreateKey, function(request) { //queued tested
|
45
|
+
setImmediate(() => {
|
46
|
+
winston.debug('SubscriptionNotifier request.create');
|
47
|
+
subscriptionNotifier.subscribe('request.create', request);
|
48
|
+
winston.debug('SubscriptionNotifier request.create sent');
|
49
|
+
});
|
50
|
+
});
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
var requestUpdateKey = 'request.update';
|
55
|
+
if (requestEvent.queueEnabled) {
|
56
|
+
requestUpdateKey = 'request.update.queue';
|
57
|
+
}
|
58
|
+
requestEvent.on(requestUpdateKey, function(request) { //queued tested
|
59
|
+
setImmediate(() => {
|
60
|
+
winston.debug('SubscriptionNotifier request.update');
|
61
|
+
subscriptionNotifier.subscribe('request.update', request);
|
62
|
+
winston.debug('SubscriptionNotifier request.update sent');
|
63
|
+
|
64
|
+
});
|
65
|
+
});
|
66
|
+
|
67
|
+
|
68
|
+
var requestCloseKey = 'request.close'; //request.close event here queued under job
|
69
|
+
if (requestEvent.queueEnabled) {
|
70
|
+
requestCloseKey = 'request.close.queue';
|
71
|
+
}
|
72
|
+
requestEvent.on(requestCloseKey, function(request) { //request.close event here noqueued //queued tested
|
73
|
+
winston.debug('SubscriptionNotifier request.close');
|
74
|
+
winston.debug("request.close event here 1")
|
75
|
+
setImmediate(() => {
|
76
|
+
Message.find({recipient: request.request_id, id_project: request.id_project}).sort({updatedAt: 'asc'}).exec(function(err, messages) {
|
77
|
+
var requestJson = request;
|
78
|
+
if (request.toJSON) {
|
79
|
+
requestJson = request.toJSON();
|
80
|
+
}
|
81
|
+
|
82
|
+
requestJson.messages = messages;
|
83
|
+
subscriptionNotifier.subscribe('request.close', requestJson);
|
84
|
+
winston.debug('SubscriptionNotifier request.close sent');
|
85
|
+
|
86
|
+
});
|
87
|
+
});
|
88
|
+
});
|
89
|
+
|
90
|
+
|
91
|
+
var leadCreateKey = 'lead.create'; //lead.create event here queued under job
|
92
|
+
if (leadEvent.queueEnabled) {
|
93
|
+
leadCreateKey = 'lead.create.queue';
|
94
|
+
}
|
95
|
+
leadEvent.on(leadCreateKey, function(lead) { //notqueued high
|
96
|
+
setImmediate(() => {
|
97
|
+
subscriptionNotifier.subscribe('lead.create', lead);
|
98
|
+
winston.debug('SubscriptionNotifier lead.create sent');
|
99
|
+
});
|
100
|
+
});
|
101
|
+
|
102
|
+
var authProjectUserUpdateKey = 'project_user.update';
|
103
|
+
if (authEvent.queueEnabled) {
|
104
|
+
authProjectUserUpdateKey = 'project_user.update.queue';
|
105
|
+
}
|
106
|
+
authEvent.on(authProjectUserUpdateKey, function(event) { //notqueued high
|
107
|
+
setImmediate(() => {
|
108
|
+
subscriptionNotifier.subscribe('project_user.update', event.updatedProject_userPopulated);
|
109
|
+
winston.debug('SubscriptionNotifier project_user.update sent');
|
110
|
+
});
|
111
|
+
});
|
112
|
+
|
113
|
+
winston.info('SubscriptionNotifierQueued started');
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
};
|
120
|
+
|
121
|
+
var subscriptionNotifierQueued = new SubscriptionNotifierQueued();
|
122
|
+
|
123
|
+
|
124
|
+
module.exports = subscriptionNotifierQueued;
|