@tiledesk/tiledesk-server 2.2.39 → 2.3.1-8.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +121 -0
- package/LICENSE +14 -657
- package/README.md +17 -3
- package/app.js +21 -60
- package/channels/chat21/chat21Handler.js +18 -3
- package/channels/chat21/chat21WebHook.js +31 -15
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/deploy.sh +2 -0
- package/event/botEvent.js +1 -1
- package/event/subscriptionEvent.js +11 -0
- package/fonts/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/middleware/ipFilter.js +220 -0
- package/middleware/passport.js +11 -2
- package/models/lead.js +2 -0
- package/models/project.js +10 -0
- package/models/project_user.js +4 -0
- package/models/request.js +50 -12
- package/models/subscriptionLog.js +34 -0
- package/models/tagLibrary.js +42 -0
- package/package.json +6 -12
- package/pubmodules/activities/activityArchiver.js +314 -0
- package/pubmodules/activities/index.js +3 -0
- package/pubmodules/activities/models/activity.js +88 -0
- package/pubmodules/activities/routes/activity.js +710 -0
- package/pubmodules/activities/test/activityRoute.js +85 -0
- package/pubmodules/analytics/analytics.js +1719 -0
- package/pubmodules/analytics/index.js +3 -0
- package/pubmodules/canned/cannedResponse.js +55 -0
- package/pubmodules/canned/cannedResponseRoute.js +163 -0
- package/pubmodules/canned/index.js +3 -0
- package/pubmodules/emailNotification/requestNotification.js +215 -28
- package/pubmodules/events/eventRoute.js +37 -7
- package/pubmodules/messageActions/messageActionsInterceptor.js +4 -2
- package/pubmodules/pubModulesManager.js +129 -5
- package/pubmodules/rasa/listener.js +5 -5
- package/pubmodules/rules/conciergeBot.js +4 -4
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +3 -1
- package/pubmodules/tilebot/index.js +11 -0
- package/pubmodules/tilebot/listener.js +69 -0
- package/pubmodules/trigger/default.js +271 -0
- package/pubmodules/trigger/event/actionEventEmitter.js +10 -0
- package/pubmodules/trigger/event/flowEventEmitter.js +10 -0
- package/pubmodules/trigger/event/triggerEventEmitter.js +10 -0
- package/pubmodules/trigger/index.js +3 -0
- package/pubmodules/trigger/models/trigger.js +149 -0
- package/pubmodules/trigger/rulesTrigger.js +1181 -0
- package/pubmodules/trigger/start.js +118 -0
- package/pubmodules/trigger/triggerRoute.js +150 -0
- package/routes/auth.js +7 -2
- package/routes/department.js +51 -0
- package/routes/faq.js +7 -0
- package/routes/faq_kb.js +1 -1
- package/routes/group.js +140 -0
- package/routes/lead.js +24 -1
- package/routes/message.js +6 -3
- package/routes/project.js +118 -0
- package/routes/project_user.js +9 -0
- package/routes/public-request.js +280 -2
- package/routes/request.js +122 -16
- package/routes/subscription.js +140 -0
- package/routes/tag.js +138 -0
- package/routes/user-request.js +3 -2
- package/routes/users.js +1 -1
- package/routes/widget.js +80 -3
- package/routes/widgetLoader.js +31 -0
- package/services/banUserNotifier.js +86 -0
- package/services/emailService.js +189 -11
- package/services/faqService.js +2 -2
- package/services/geoService.js +30 -4
- package/services/leadService.js +2 -0
- package/services/modulesManager.js +7 -188
- package/services/requestService.js +364 -6
- package/services/subscriptionNotifier.js +485 -0
- package/template/email/assignedEmailMessage.html +1 -1
- package/template/email/assignedRequest.html +1 -1
- package/template/email/newMessage.html +1 -1
- package/template/email/newMessageFollower.html +236 -0
- package/template/email/passwordChanged.html +1 -1
- package/template/email/pooledEmailMessage.html +1 -1
- package/template/email/pooledRequest.html +1 -1
- package/template/email/resetPassword.html +2 -2
- package/template/email/ticket.html +1 -1
- package/test/cannedRoute.js +166 -0
- package/test/messageRoute.js +69 -0
- package/test/requestService.js +3 -1
- package/utils/orgUtil.js +3 -3
- package/views/messages.jade +2 -2
- package/websocket/webSocketServer.js +23 -5
@@ -0,0 +1,55 @@
|
|
1
|
+
var mongoose = require('mongoose');
|
2
|
+
var Schema = mongoose.Schema;
|
3
|
+
var winston = require('../../config/winston');
|
4
|
+
|
5
|
+
|
6
|
+
var CannedResponseSchema = new Schema({
|
7
|
+
|
8
|
+
title: {
|
9
|
+
type: String,
|
10
|
+
required: false,
|
11
|
+
index: true
|
12
|
+
},
|
13
|
+
text: {
|
14
|
+
type: String,
|
15
|
+
required: true,
|
16
|
+
},
|
17
|
+
shared: {
|
18
|
+
type: Boolean,
|
19
|
+
required: true
|
20
|
+
},
|
21
|
+
attributes: {
|
22
|
+
type: Object,
|
23
|
+
},
|
24
|
+
id_project: {
|
25
|
+
type: String,
|
26
|
+
required: true,
|
27
|
+
index: true
|
28
|
+
},
|
29
|
+
createdBy: {
|
30
|
+
type: String,
|
31
|
+
required: true
|
32
|
+
},
|
33
|
+
status: {
|
34
|
+
type: Number,
|
35
|
+
required: false,
|
36
|
+
default: 100,
|
37
|
+
index: true
|
38
|
+
},
|
39
|
+
},{
|
40
|
+
timestamps: true
|
41
|
+
}
|
42
|
+
);
|
43
|
+
|
44
|
+
|
45
|
+
// CannedResponseSchema.index({text: 'text'},
|
46
|
+
// {"name":"cannedresponse_fulltext","default_language": "italian","language_override": "dummy"}); // schema level
|
47
|
+
|
48
|
+
var CannedResponse = mongoose.model('cannedResponse', CannedResponseSchema);
|
49
|
+
|
50
|
+
if (process.env.MONGOOSE_SYNCINDEX) {
|
51
|
+
CannedResponse.syncIndexes();
|
52
|
+
winston.info("CannedResponse syncIndexes")
|
53
|
+
}
|
54
|
+
|
55
|
+
module.exports = CannedResponse;
|
@@ -0,0 +1,163 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
var CannedResponse = require("./cannedResponse");
|
4
|
+
var winston = require('../../config/winston');
|
5
|
+
// const CannedResponseEvent = require('../event/CannedResponseEvent');
|
6
|
+
|
7
|
+
|
8
|
+
router.post('/', function (req, res) {
|
9
|
+
|
10
|
+
winston.debug(req.body);
|
11
|
+
winston.debug("req.user", req.user);
|
12
|
+
|
13
|
+
var newCannedResponse = new CannedResponse({
|
14
|
+
title: req.body.title,
|
15
|
+
text: req.body.text,
|
16
|
+
id_project: req.projectid,
|
17
|
+
createdBy: req.user.id,
|
18
|
+
updatedBy: req.user.id
|
19
|
+
});
|
20
|
+
|
21
|
+
if (req.projectuser.role == 'owner' || req.projectuser.role == 'admin') {
|
22
|
+
newCannedResponse.shared = true;
|
23
|
+
} else {
|
24
|
+
newCannedResponse.shared = false;
|
25
|
+
}
|
26
|
+
|
27
|
+
newCannedResponse.save(function (err, savedCannedResponse) {
|
28
|
+
if (err) {
|
29
|
+
winston.error('--- > ERROR ', err)
|
30
|
+
|
31
|
+
return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
32
|
+
}
|
33
|
+
|
34
|
+
res.json(savedCannedResponse);
|
35
|
+
});
|
36
|
+
});
|
37
|
+
|
38
|
+
router.put('/:cannedResponseid', function (req, res) {
|
39
|
+
winston.debug(req.body);
|
40
|
+
var update = {};
|
41
|
+
|
42
|
+
if (req.body.title!=undefined) {
|
43
|
+
update.title = req.body.title;
|
44
|
+
}
|
45
|
+
if (req.body.text!=undefined) {
|
46
|
+
update.text = req.body.text;
|
47
|
+
}
|
48
|
+
if (req.body.attributes!=undefined) {
|
49
|
+
update.attributes = req.body.attributes;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
CannedResponse.findByIdAndUpdate(req.params.cannedResponseid, update, { new: true, upsert: true }, function (err, updatedCannedResponse) {
|
54
|
+
if (err) {
|
55
|
+
winston.error('--- > ERROR ', err);
|
56
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// CannedResponseEvent.emit('CannedResponse.update', updatedCannedResponse);
|
62
|
+
res.json(updatedCannedResponse);
|
63
|
+
});
|
64
|
+
});
|
65
|
+
|
66
|
+
router.delete('/:cannedResponseid', function (req, res) {
|
67
|
+
winston.debug(req.body);
|
68
|
+
|
69
|
+
CannedResponse.findByIdAndUpdate(req.params.cannedResponseid, {status: 1000}, { new: true, upsert: true }, function (err, updatedCannedResponse) {
|
70
|
+
if (err) {
|
71
|
+
winston.error('--- > ERROR ', err);
|
72
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
// CannedResponseEvent.emit('CannedResponse.delete', updatedCannedResponse);
|
78
|
+
res.json(updatedCannedResponse);
|
79
|
+
});
|
80
|
+
});
|
81
|
+
|
82
|
+
router.delete('/:cannedResponseid/physical', function (req, res) {
|
83
|
+
winston.debug(req.body);
|
84
|
+
|
85
|
+
CannedResponse.remove({ _id: req.params.cannedResponseid }, function (err, cannedResponse) {
|
86
|
+
if (err) {
|
87
|
+
winston.error('--- > ERROR ', err);
|
88
|
+
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
// CannedResponseEvent.emit('CannedResponse.delete', CannedResponse);
|
93
|
+
|
94
|
+
res.json(cannedResponse);
|
95
|
+
});
|
96
|
+
});
|
97
|
+
|
98
|
+
router.get('/:cannedResponseid', function (req, res) {
|
99
|
+
winston.debug(req.body);
|
100
|
+
|
101
|
+
CannedResponse.findById(req.params.cannedResponseid, function (err, cannedResponse) {
|
102
|
+
if (err) {
|
103
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
104
|
+
}
|
105
|
+
if (!cannedResponse) {
|
106
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
107
|
+
}
|
108
|
+
res.json(cannedResponse);
|
109
|
+
});
|
110
|
+
});
|
111
|
+
|
112
|
+
router.get('/', function (req, res) {
|
113
|
+
var limit = 1000; // Number of CannedResponses per page
|
114
|
+
var page = 0;
|
115
|
+
|
116
|
+
if (req.query.page) {
|
117
|
+
page = req.query.page;
|
118
|
+
}
|
119
|
+
|
120
|
+
var skip = page * limit;
|
121
|
+
winston.debug('CannedResponse ROUTE - SKIP PAGE ', skip);
|
122
|
+
|
123
|
+
// var query = { "id_project": req.projectid, "status": {$lt:1000}};
|
124
|
+
console.log("canned_req.user: ", req.user);
|
125
|
+
var query = {"id_project": req.projectid, "status": { $lt:1000 }, $or:[ { shared: true }, { createdBy: req.user._id } ] }
|
126
|
+
|
127
|
+
if (req.query.full_text) {
|
128
|
+
winston.debug('CannedResponse ROUTE req.query.fulltext', req.query.full_text);
|
129
|
+
query.$text = { "$search": req.query.full_text };
|
130
|
+
}
|
131
|
+
|
132
|
+
var direction = -1; //-1 descending , 1 ascending
|
133
|
+
if (req.query.direction) {
|
134
|
+
direction = req.query.direction;
|
135
|
+
}
|
136
|
+
|
137
|
+
var sortField = "createdAt";
|
138
|
+
if (req.query.sort) {
|
139
|
+
sortField = req.query.sort;
|
140
|
+
}
|
141
|
+
|
142
|
+
var sortQuery = {};
|
143
|
+
sortQuery[sortField] = direction;
|
144
|
+
|
145
|
+
winston.debug("sort query", sortQuery);
|
146
|
+
|
147
|
+
return CannedResponse.find(query).
|
148
|
+
skip(skip).limit(limit).
|
149
|
+
sort(sortQuery).
|
150
|
+
exec(function (err, cannedResponses) {
|
151
|
+
if (err) {
|
152
|
+
winston.error('CannedResponse ROUTE - REQUEST FIND ERR ', err)
|
153
|
+
return (err);
|
154
|
+
}
|
155
|
+
|
156
|
+
return res.json(cannedResponses);
|
157
|
+
});
|
158
|
+
});
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
module.exports = router;
|
@@ -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) {
|
@@ -47,7 +61,7 @@ listen() {
|
|
47
61
|
messageEvent.on(messageCreateKey, function(message) {
|
48
62
|
|
49
63
|
setImmediate(() => {
|
50
|
-
winston.debug("
|
64
|
+
winston.debug("messageEvent.on(messageCreateKey", message);
|
51
65
|
|
52
66
|
if (message.attributes && message.attributes.subtype==='info') {
|
53
67
|
return winston.debug("not sending sendUserEmail for attributes.subtype info messages");
|
@@ -56,17 +70,18 @@ listen() {
|
|
56
70
|
|
57
71
|
if (message.request && (message.request.channel.name===ChannelConstants.EMAIL || message.request.channel.name===ChannelConstants.FORM)) {
|
58
72
|
|
73
|
+
//messages sent from admins or agents to requester
|
59
74
|
if (message.sender != message.request.lead.lead_id) {
|
60
75
|
winston.verbose("sending sendToUserEmailChannelEmail for EMAIL or FORM channel");
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return that.sendToUserEmailChannelEmail(message.id_project, message);
|
66
|
-
} else {
|
76
|
+
|
77
|
+
//send email notification to requester (send also to followers)
|
78
|
+
return that.sendToUserEmailChannelEmail(message.id_project, message);
|
79
|
+
} else { //messages sent from requester to agents or admins
|
67
80
|
|
68
81
|
if (message.text != message.request.first_text) {
|
69
82
|
winston.verbose("sending sendToAgentEmailChannelEmail for EMAIL or FORM channel");
|
83
|
+
|
84
|
+
//send email notification to admins and agents(send also to followers)
|
70
85
|
return that.sendToAgentEmailChannelEmail(message.id_project, message);
|
71
86
|
} else {
|
72
87
|
winston.debug("sending sendToAgentEmailChannelEmail for EMAIL or FORM channel disabled for first text message")
|
@@ -76,16 +91,22 @@ listen() {
|
|
76
91
|
|
77
92
|
} else {
|
78
93
|
winston.debug("sendUserEmail chat channel");
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
//
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
//messages sent from admins or agents
|
99
|
+
//send email notification to requester
|
84
100
|
if (message.request && message.request.lead && message.sender != message.request.lead.lead_id) {
|
101
|
+
winston.debug("sendUserEmail");
|
85
102
|
winston.debug("sendUserEmail", message);
|
86
103
|
|
87
|
-
// send an email only if offline and has an email
|
104
|
+
// send an email only if offline and has an email (send also to followers)
|
88
105
|
return that.sendUserEmail(message.id_project, message);
|
106
|
+
} else { //send email to followers
|
107
|
+
|
108
|
+
that.sendToFollower(message.id_project, message);
|
109
|
+
|
89
110
|
}
|
90
111
|
|
91
112
|
}
|
@@ -139,7 +160,6 @@ listen() {
|
|
139
160
|
|
140
161
|
|
141
162
|
|
142
|
-
|
143
163
|
// requestEvent.on("request.update.preflight", function(request) {
|
144
164
|
|
145
165
|
// winston.info("requestEvent request.update.preflight");
|
@@ -227,15 +247,19 @@ listen() {
|
|
227
247
|
|
228
248
|
|
229
249
|
sendToUserEmailChannelEmail(projectid, message) {
|
250
|
+
winston.debug("sendToUserEmailChannelEmail");
|
251
|
+
var that = this;
|
230
252
|
try {
|
231
253
|
|
232
254
|
if (!message.request) {
|
233
255
|
return winston.debug("This is a direct message");
|
234
256
|
}
|
235
257
|
|
236
|
-
|
237
|
-
|
238
|
-
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
239
263
|
|
240
264
|
Project.findOne({_id: projectid, status: 100}).select("+settings").exec(function(err, project){
|
241
265
|
if (err) {
|
@@ -245,6 +269,7 @@ sendToUserEmailChannelEmail(projectid, message) {
|
|
245
269
|
if (!project) {
|
246
270
|
return winston.warn("Project not found", projectid);
|
247
271
|
}
|
272
|
+
|
248
273
|
|
249
274
|
// 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 ) {
|
250
275
|
// return winston.info("RequestNotification offline email notification for the project with id : " + projectid + " for the conversations is blocked");
|
@@ -256,7 +281,7 @@ sendToUserEmailChannelEmail(projectid, message) {
|
|
256
281
|
// }
|
257
282
|
|
258
283
|
let lead = message.request.lead;
|
259
|
-
winston.debug("sending channel
|
284
|
+
winston.debug("sending channel email to lead ", lead);
|
260
285
|
|
261
286
|
|
262
287
|
winston.debug("sending user email to "+ lead.email);
|
@@ -307,8 +332,24 @@ sendToUserEmailChannelEmail(projectid, message) {
|
|
307
332
|
}
|
308
333
|
winston.debug("tokenQueryString: "+tokenQueryString);
|
309
334
|
|
335
|
+
|
336
|
+
|
337
|
+
// winston.info("savedRequest.followers", savedRequest.followers);
|
338
|
+
// winston.info("savedRequest.followers.length:"+ savedRequest.followers.length);
|
339
|
+
that.notifyFollowers(message.request, project, message);
|
340
|
+
|
341
|
+
|
342
|
+
if (message.attributes && message.attributes.subtype==='private') {
|
343
|
+
return winston.debug("not sending sendToUserEmailChannelEmail for attributes.subtype private messages");
|
344
|
+
}
|
345
|
+
|
346
|
+
// nn va bene qui
|
347
|
+
if (!message.request.lead || !message.request.lead.email) {
|
348
|
+
return winston.debug("The lead object is undefined or has empty email");
|
349
|
+
}
|
350
|
+
|
310
351
|
emailService.sendEmailChannelNotification(message.request.lead.email, message, project, tokenQueryString, sourcePage);
|
311
|
-
|
352
|
+
|
312
353
|
|
313
354
|
});
|
314
355
|
|
@@ -318,9 +359,112 @@ sendToUserEmailChannelEmail(projectid, message) {
|
|
318
359
|
}
|
319
360
|
|
320
361
|
|
362
|
+
async notifyFollowers(savedRequest, project, message) {
|
363
|
+
|
364
|
+
if (message.attributes && message.attributes.subtype==='info/support') {
|
365
|
+
return winston.debug("not sending notifyFollowers for attributes.subtype info/support messages");
|
366
|
+
}
|
367
|
+
|
368
|
+
if (message.attributes && message.attributes.subtype==='info') {
|
369
|
+
return winston.debug("not sending notifyFollowers for attributes.subtype info messages");
|
370
|
+
}
|
371
|
+
|
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();
|
380
|
+
winston.debug("reqWithFollowers");
|
381
|
+
winston.debug("reqWithFollowers",reqWithFollowers);
|
382
|
+
// console.log("reqWithFollowers",reqWithFollowers);
|
383
|
+
|
384
|
+
if (reqWithFollowers.followers && reqWithFollowers.followers.length>0) {
|
385
|
+
|
386
|
+
winston.debug("reqWithFollowers.followers.length: "+reqWithFollowers.followers.length);
|
387
|
+
|
388
|
+
reqWithFollowers.followers.forEach(project_user => {
|
389
|
+
winston.debug("project_user", project_user);
|
390
|
+
//TODO skip participants from followers
|
391
|
+
|
392
|
+
var userid = project_user.id_user;
|
393
|
+
|
394
|
+
if (project_user.settings && project_user.settings.email && project_user.settings.email.notification && project_user.settings.email.notification.conversation && project_user.settings.email.notification.conversation.ticket && project_user.settings.email.notification.conversation.ticket.follower == false ) {
|
395
|
+
return winston.verbose("RequestNotification email notification for the user with id " + userid+ " the follower conversation ticket is disabled");
|
396
|
+
}
|
397
|
+
|
398
|
+
User.findOne({_id: userid , status: 100})
|
399
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid)
|
400
|
+
.exec(function (err, user) {
|
401
|
+
if (err) {
|
402
|
+
// winston.debug(err);
|
403
|
+
}
|
404
|
+
if (!user) {
|
405
|
+
winston.warn("User not found", userid);
|
406
|
+
} else {
|
407
|
+
winston.info("Sending notifyFollowers to user with email: "+ user.email);
|
408
|
+
if (user.emailverified) {
|
409
|
+
emailService.sendFollowerNotification(user.email, message, project);
|
410
|
+
// emailService.sendEmailChannelNotification(user.email, message, project);
|
411
|
+
|
412
|
+
// emailService.sendNewAssignedAgentMessageEmailNotification(user.email, savedRequest, project, message);
|
413
|
+
|
414
|
+
}else {
|
415
|
+
winston.info("User email not verified", user.email);
|
416
|
+
}
|
417
|
+
}
|
418
|
+
});
|
419
|
+
|
420
|
+
|
421
|
+
});
|
422
|
+
|
423
|
+
|
424
|
+
}
|
425
|
+
}
|
426
|
+
|
427
|
+
sendToFollower(projectid, message) {
|
428
|
+
winston.debug("sendToFollower");
|
429
|
+
var that = this;
|
430
|
+
let savedRequest = message.request;
|
431
|
+
// send email
|
432
|
+
try {
|
433
|
+
|
434
|
+
|
435
|
+
Project.findOne({_id: projectid, status: 100}).select("+settings").exec(async function(err, project){
|
436
|
+
if (err) {
|
437
|
+
return winston.error(err);
|
438
|
+
}
|
439
|
+
|
440
|
+
if (!project) {
|
441
|
+
return winston.warn("Project not found", projectid);
|
442
|
+
} else {
|
443
|
+
|
444
|
+
winston.debug("project", project);
|
445
|
+
|
446
|
+
// if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.blocked == true ) {
|
447
|
+
// return winston.verbose("RequestNotification email notification for the project with id : " + projectid + " for all the conversations is blocked");
|
448
|
+
// }
|
449
|
+
|
450
|
+
winston.debug("savedRequest", savedRequest);
|
451
|
+
|
452
|
+
|
321
453
|
|
454
|
+
// winston.info("savedRequest.followers", savedRequest.followers);
|
455
|
+
// winston.info("savedRequest.followers.length:"+ savedRequest.followers.length);
|
456
|
+
that.notifyFollowers(message.request, project, message);
|
457
|
+
|
458
|
+
|
459
|
+
}
|
460
|
+
})
|
461
|
+
} catch (e) {
|
462
|
+
winston.warn("Error sending email", {error:e, projectid:projectid, message: message, savedRequest:savedRequest}); //it's better to view error email at this stage
|
463
|
+
}
|
464
|
+
}
|
322
465
|
|
323
466
|
sendToAgentEmailChannelEmail(projectid, message) {
|
467
|
+
var that = this;
|
324
468
|
let savedRequest = message.request;
|
325
469
|
// send email
|
326
470
|
try {
|
@@ -343,9 +487,17 @@ sendToAgentEmailChannelEmail(projectid, message) {
|
|
343
487
|
|
344
488
|
winston.debug("savedRequest", savedRequest);
|
345
489
|
|
346
|
-
|
347
490
|
|
348
491
|
|
492
|
+
// winston.info("savedRequest.followers", savedRequest.followers);
|
493
|
+
// winston.info("savedRequest.followers.length:"+ savedRequest.followers.length);
|
494
|
+
that.notifyFollowers(message.request, project, message);
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
// UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'status' of undefined
|
499
|
+
// at /Users/andrealeo/dev/chat21/ti
|
500
|
+
|
349
501
|
// TODO fare il controllo anche sul dipartimento con modalità assigned o pooled
|
350
502
|
if (savedRequest.status==RequestConstants.UNASSIGNED) { //POOLED
|
351
503
|
|
@@ -523,15 +675,19 @@ sendEmailChannelTakingNotification(projectid, request) {
|
|
523
675
|
|
524
676
|
|
525
677
|
sendUserEmail(projectid, message) {
|
678
|
+
winston.debug("sendUserEmail");
|
679
|
+
var that = this;
|
680
|
+
|
681
|
+
|
526
682
|
try {
|
527
683
|
|
528
684
|
if (!message.request) {
|
529
685
|
return winston.debug("This is a direct message");
|
530
686
|
}
|
687
|
+
|
531
688
|
|
532
|
-
|
533
|
-
|
534
|
-
}
|
689
|
+
|
690
|
+
|
535
691
|
|
536
692
|
Project.findOne({_id: projectid, status: 100}).select("+settings").exec(function(err, project){
|
537
693
|
if (err) {
|
@@ -542,6 +698,28 @@ sendUserEmail(projectid, message) {
|
|
542
698
|
return winston.warn("Project not found", projectid);
|
543
699
|
}
|
544
700
|
|
701
|
+
winston.debug("notifyFollowers");
|
702
|
+
that.notifyFollowers(message.request, project, message);
|
703
|
+
|
704
|
+
|
705
|
+
|
706
|
+
if (process.env.DISABLE_SEND_OFFLINE_EMAIL === "true" || process.env.DISABLE_SEND_OFFLINE_EMAIL === true ) {
|
707
|
+
return winston.debug("DISABLE_SEND_OFFLINE_EMAIL disabled");
|
708
|
+
}
|
709
|
+
if (message.attributes && message.attributes.subtype==='info/support') {
|
710
|
+
return winston.debug("not sending sendUserEmail for attributes.subtype info/support messages");
|
711
|
+
}
|
712
|
+
|
713
|
+
if (message.attributes && message.attributes.subtype==='info') {
|
714
|
+
return winston.debug("not sending sendUserEmail for attributes.subtype info messages");
|
715
|
+
}
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
if (!message.request.lead || !message.request.lead.email) {
|
720
|
+
return winston.debug("The lead object is undefined or has empty email");
|
721
|
+
}
|
722
|
+
|
545
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 ) {
|
546
724
|
return winston.info("RequestNotification offline email notification for the project with id : " + projectid + " for the conversations is blocked");
|
547
725
|
}
|
@@ -550,8 +728,8 @@ sendUserEmail(projectid, message) {
|
|
550
728
|
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.enabled == false ) {
|
551
729
|
return winston.info("RequestNotification offline email notification for the project with id : " + projectid + " for the offline conversation is disabled");
|
552
730
|
}
|
553
|
-
|
554
|
-
|
731
|
+
|
732
|
+
|
555
733
|
|
556
734
|
var recipient = message.request.lead.lead_id;
|
557
735
|
winston.debug("recipient:"+ recipient);
|
@@ -649,7 +827,12 @@ sendAgentEmail(projectid, savedRequest) {
|
|
649
827
|
// send email
|
650
828
|
try {
|
651
829
|
|
652
|
-
|
830
|
+
// console.log("sendAgentEmail")
|
831
|
+
if (savedRequest.preflight === true) { //only for channel email and form preflight is false otherwise request.participants.update is used i think?
|
832
|
+
winston.debug("preflight request sendAgentEmail disabled")
|
833
|
+
return 0;
|
834
|
+
}
|
835
|
+
|
653
836
|
Project.findOne({_id: projectid, status: 100}).select("+settings").exec( async function(err, project){
|
654
837
|
if (err) {
|
655
838
|
return winston.error(err);
|
@@ -670,6 +853,8 @@ sendAgentEmail(projectid, savedRequest) {
|
|
670
853
|
// TODO fare il controllo anche sul dipartimento con modalità assigned o pooled
|
671
854
|
if (savedRequest.status==RequestConstants.UNASSIGNED) { //POOLED
|
672
855
|
|
856
|
+
winston.debug("savedRequest.status==RequestConstants.UNASSIGNED");
|
857
|
+
|
673
858
|
if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.pooled == false ) {
|
674
859
|
return winston.info("RequestNotification email notification for the project with id : " + projectid + " for the pooled conversation is disabled");
|
675
860
|
}
|
@@ -678,7 +863,7 @@ sendAgentEmail(projectid, savedRequest) {
|
|
678
863
|
}
|
679
864
|
|
680
865
|
|
681
|
-
|
866
|
+
|
682
867
|
var snapshotAgents = savedRequest; //riassegno varibile cosi nn cambio righe successive
|
683
868
|
|
684
869
|
|
@@ -742,6 +927,8 @@ sendAgentEmail(projectid, savedRequest) {
|
|
742
927
|
// TODO fare il controllo anche sul dipartimento con modalità assigned o pooled
|
743
928
|
else if (savedRequest.status==RequestConstants.ASSIGNED) { //ASSIGNED
|
744
929
|
|
930
|
+
winston.debug("savedRequest.status==RequestConstants.ASSIGNED");
|
931
|
+
|
745
932
|
if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.assigned == false ) {
|
746
933
|
return winston.verbose("RequestNotification email notification for the project with id : " + projectid + " for the assigned conversation is disabled");
|
747
934
|
}
|