@tiledesk/tiledesk-server 2.1.40 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- package/.circleci/config.yml +54 -0
- package/.env.sample +1 -1
- package/.github/workflows/docker-community-push-latest.yml +22 -0
- package/.github/workflows/{docker-image-push.yml → docker-image-en-tag-push.yml} +1 -1
- package/.github/workflows/docker-image-tag-community-tag-push.yml +21 -0
- package/.github/workflows/{docker-push-latest.yml → docker-push-en-push-latest.yml} +1 -1
- package/CHANGELOG.md +195 -1
- package/Dockerfile +1 -1
- package/Dockerfile-en +1 -1
- package/README.md +5 -7
- package/app.js +12 -1
- package/channels/channelManager.js +1 -1
- package/channels/chat21/chat21Contact.js +34 -8
- package/channels/chat21/chat21Handler.js +48 -5
- package/channels/chat21/chat21WebHook.js +34 -9
- package/channels/chat21/nativeauth.js +2 -2
- package/channels/chat21/package-lock.json +3013 -0
- package/config/email.js +2 -0
- package/config/global.js +3 -0
- package/config/labels/widget.json +170 -16
- package/event/messageEvent.js +18 -1
- package/middleware/passport.js +10 -4
- package/migrations/1619185894304-request-remove-duplicated-request-by-request_id--autosync.js +67 -0
- package/models/actionsConstants.js +7 -0
- package/models/department.js +3 -0
- package/models/faq.js +8 -2
- package/models/faq_kb.js +6 -0
- package/models/message.js +10 -4
- package/models/messageConstants.js +9 -3
- package/models/request.js +33 -3
- package/package.json +31 -28
- package/pubmodules/emailNotification/requestNotification.js +483 -56
- package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
- package/pubmodules/messageTransformer/index.js +5 -1
- package/pubmodules/messageTransformer/messageTransformerInterceptor.js +4 -2
- package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
- package/pubmodules/messageTransformer/microLanguageTransformerInterceptor.js +67 -0
- package/pubmodules/pubModulesManager.js +66 -13
- package/pubmodules/rules/conciergeBot.js +81 -49
- package/routes/auth.js +46 -11
- package/routes/campaigns.js +117 -25
- package/routes/department.js +2 -2
- package/routes/faq.js +19 -0
- package/routes/faq_kb.js +13 -4
- package/routes/faqpub.js +1 -1
- package/routes/files.js +17 -2
- package/routes/images.js +1 -1
- package/routes/jwt.js +0 -1
- package/routes/logs.js +26 -0
- package/routes/message.js +7 -2
- package/routes/messagesRoot.js +73 -16
- package/routes/project_user.js +36 -1
- package/routes/request.js +88 -12
- package/routes/requestUtilRoot.js +30 -0
- package/routes/urls.js +12 -0
- package/routes/users.js +5 -1
- package/services/BotSubscriptionNotifier.js +1 -0
- package/services/departmentService.js +29 -5
- package/services/emailService.js +1170 -239
- package/services/faqBotHandler.js +176 -61
- package/services/faqBotSupport.js +182 -117
- package/services/faqService.js +18 -14
- package/services/messageService.js +57 -9
- package/services/modulesManager.js +86 -23
- package/services/requestService.js +58 -17
- package/template/email/assignedEmailMessage.html +205 -0
- package/template/email/assignedRequest.html +44 -14
- package/template/email/beenInvitedExistingUser.html +2 -2
- package/template/email/beenInvitedNewUser.html +1 -1
- package/template/email/newMessage.html +31 -12
- package/template/email/passwordChanged.html +2 -3
- package/template/email/pooledEmailMessage.html +208 -0
- package/template/email/pooledRequest.html +41 -14
- package/template/email/resetPassword.html +2 -3
- package/template/email/sendTranscript.html +1 -1
- package/template/email/test.html +1 -1
- package/template/email/ticket.html +191 -0
- package/template/email/ticket.txt +11 -0
- package/template/email/verify.html +1 -1
- package/test/authentication.js +76 -4
- package/test/authenticationJwt.js +76 -2
- package/test/campaignsRoute.js +226 -0
- package/test/faqService.js +3 -3
- package/test/faqkbRoute.js +3 -2
- package/test/messageRootRoute.js +193 -0
- package/test/messageRoute.js +75 -0
- package/test/messageService.js +39 -2
- package/test/requestRoute.js +27 -9
- package/test/requestService.js +472 -11
- package/test-int/bot.js +673 -8
- package/websocket/webSocketServer.js +7 -4
package/services/emailService.js
CHANGED
@@ -2,8 +2,18 @@
|
|
2
2
|
|
3
3
|
const nodemailer = require('nodemailer');
|
4
4
|
var config = require('../config/email');
|
5
|
+
var configGlobal = require('../config/global');
|
5
6
|
var winston = require('../config/winston');
|
7
|
+
var marked = require('marked');
|
6
8
|
var handlebars = require('handlebars');
|
9
|
+
var encode = require('html-entities').encode;
|
10
|
+
|
11
|
+
handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
|
12
|
+
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
|
13
|
+
});
|
14
|
+
|
15
|
+
// var options = {};
|
16
|
+
// handlebars.registerHelper('markdown', markdown(options));
|
7
17
|
|
8
18
|
// handlebars.registerHelper('ifCond', function(v1, v2, options) {
|
9
19
|
// if(v1 === v2) {
|
@@ -29,16 +39,28 @@ const maskOptions = {
|
|
29
39
|
unmaskedEndDigits : 3 // Should be positive Integer
|
30
40
|
};
|
31
41
|
|
42
|
+
// const X_REQUEST_ID_HEADER_KEY = "X-TILEDESK-REQUEST-ID";
|
43
|
+
// const X_TICKET_ID_HEADER_KEY = "X-TILEDESK-TICKET-ID";
|
44
|
+
// const X_PROJECT_ID_HEADER_KEY = "X-TILEDESK-PROJECT-ID";
|
45
|
+
|
46
|
+
const MESSAGE_ID_DOMAIN = "tiledesk.com";
|
32
47
|
|
33
48
|
class EmailService {
|
34
49
|
|
35
50
|
constructor() {
|
36
51
|
|
37
|
-
this.enabled =
|
52
|
+
this.enabled = false;
|
53
|
+
if (process.env.EMAIL_ENABLED ==="true" || process.env.EMAIL_ENABLED === true ) {
|
54
|
+
this.enabled = true;
|
55
|
+
}
|
56
|
+
|
38
57
|
winston.info('EmailService enabled: '+ this.enabled);
|
39
58
|
|
40
59
|
this.baseUrl = process.env.EMAIL_BASEURL || config.baseUrl;
|
41
60
|
winston.info('EmailService baseUrl: '+ this.baseUrl);
|
61
|
+
|
62
|
+
this.apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
63
|
+
winston.info('EmailService apiUrl: '+ this.apiUrl);
|
42
64
|
|
43
65
|
this.from = process.env.EMAIL_FROM_ADDRESS || config.from;
|
44
66
|
winston.info('EmailService from email: '+ this.from);
|
@@ -46,22 +68,38 @@ class EmailService {
|
|
46
68
|
this.bcc = process.env.EMAIL_BCC || config.bcc;
|
47
69
|
winston.info('EmailService bcc address: '+ this.bcc);
|
48
70
|
|
49
|
-
this.
|
71
|
+
this.replyEnabled = config.replyEnabled;
|
72
|
+
if (process.env.EMAIL_REPLY_ENABLED === "true" || process.env.EMAIL_REPLY_ENABLED === true ) {
|
73
|
+
this.replyEnabled = true;
|
74
|
+
}
|
75
|
+
winston.info('EmailService replyEnabled : '+ this.replyEnabled);
|
76
|
+
|
77
|
+
// this is used as fixed reply to url, but this is unused we always return support-group-dynamic
|
78
|
+
this.replyTo = process.env.EMAIL_REPLY_TO || config.replyTo;
|
79
|
+
winston.info('EmailService replyTo address: '+ this.replyTo);
|
80
|
+
|
81
|
+
this.inboundDomain = process.env.EMAIL_INBOUND_DOMAIN || config.inboundDomain;
|
82
|
+
winston.info('EmailService inboundDomain : '+ this.inboundDomain);
|
83
|
+
|
84
|
+
this.inboundDomainDomainWithAt = "@"+this.inboundDomain;
|
85
|
+
winston.verbose('EmailService inboundDomainDomainWithAt : '+ this.inboundDomainDomainWithAt);
|
86
|
+
|
87
|
+
this.pass = process.env.EMAIL_PASSWORD;
|
50
88
|
|
51
89
|
var maskedemailPassword;
|
52
|
-
if (this.
|
53
|
-
maskedemailPassword = MaskData.maskPhone(this.
|
90
|
+
if (this.pass) {
|
91
|
+
maskedemailPassword = MaskData.maskPhone(this.pass, maskOptions);
|
54
92
|
}else {
|
55
|
-
maskedemailPassword = this.
|
93
|
+
maskedemailPassword = this.pass;
|
56
94
|
}
|
57
95
|
|
58
|
-
winston.info('EmailService
|
96
|
+
winston.info('EmailService pass: ' + maskedemailPassword);
|
59
97
|
|
60
98
|
this.host = process.env.EMAIL_HOST || config.host;
|
61
99
|
winston.info('EmailService host: ' + this.host);
|
62
100
|
|
63
|
-
this.
|
64
|
-
winston.info('EmailService
|
101
|
+
this.secure = process.env.EMAIL_SECURE || false;
|
102
|
+
winston.info('EmailService secure: ' + this.secure);
|
65
103
|
|
66
104
|
this.user = process.env.EMAIL_USERNAME || config.username;
|
67
105
|
winston.info('EmailService username: ' + this.user);
|
@@ -69,39 +107,110 @@ class EmailService {
|
|
69
107
|
this.port = process.env.EMAIL_PORT;
|
70
108
|
winston.info('EmailService port: ' + this.port);
|
71
109
|
|
72
|
-
}
|
73
110
|
|
111
|
+
this.markdown = process.env.EMAIL_MARKDOWN || true;
|
112
|
+
winston.info('EmailService markdown: '+ this.markdown);
|
74
113
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
114
|
+
this.headers = {
|
115
|
+
// "X-Mailer": "Tiledesk Mailer",
|
116
|
+
}
|
117
|
+
winston.info('EmailService headers: ' + JSON.stringify(this.headers));
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
readTemplate(templateName, settings) {
|
122
|
+
var that = this;
|
123
|
+
winston.debug('EmailService readTemplate: '+ templateName + ' ' + JSON.stringify(settings));
|
124
|
+
|
125
|
+
if (settings && settings.email && settings.email.templates) {
|
126
|
+
var templates = settings.email.templates;
|
127
|
+
winston.debug('EmailService templates: ',templates);
|
128
|
+
var template = templates[templateName];
|
129
|
+
winston.debug('EmailService template: '+template);
|
130
|
+
if (template) {
|
131
|
+
// that.callback(template);
|
132
|
+
return new Promise(function (resolve, reject) {
|
133
|
+
return resolve(template);
|
134
|
+
});
|
135
|
+
}else {
|
136
|
+
return that.readTemplateFile(templateName);
|
137
|
+
}
|
138
|
+
} else {
|
139
|
+
return that.readTemplateFile(templateName);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
readTemplateFile(templateName) {
|
143
|
+
// var that = this;
|
144
|
+
return new Promise(function (resolve, reject) {
|
145
|
+
fs.readFile(appRoot + '/template/email/'+templateName, {encoding: 'utf-8'}, function (err, html) {
|
146
|
+
if (err) {
|
147
|
+
winston.error('error readTemplateFile getting ', err);
|
148
|
+
// callback(err);
|
149
|
+
return reject(err);
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
// callback(null, html);
|
153
|
+
return resolve(html);
|
154
|
+
}
|
155
|
+
});
|
84
156
|
});
|
85
157
|
};
|
86
158
|
|
87
159
|
|
88
|
-
getTransport() {
|
160
|
+
getTransport(configEmail) {
|
161
|
+
|
162
|
+
if (configEmail === undefined) {
|
163
|
+
configEmail = {
|
164
|
+
host: this.host,
|
165
|
+
port: this.port, // defaults to 587 if is secure is false or 465 if true
|
166
|
+
secure: this.secure,
|
167
|
+
user: this.user,
|
168
|
+
pass: this.pass
|
169
|
+
}
|
170
|
+
winston.debug("getTransport initialized with default");
|
171
|
+
} else {
|
172
|
+
winston.verbose("getTransport custom", configEmail);
|
173
|
+
}
|
89
174
|
|
175
|
+
winston.debug("getTransport configEmail: "+ JSON.stringify(configEmail));
|
90
176
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
secure: this.secureEmail,
|
177
|
+
let transport = {
|
178
|
+
host: configEmail.host,
|
179
|
+
port: configEmail.port, // defaults to 587 if is secure is false or 465 if true
|
180
|
+
secure: configEmail.secure,
|
96
181
|
auth: {
|
97
|
-
user:
|
98
|
-
pass:
|
182
|
+
user: configEmail.user,
|
183
|
+
pass: configEmail.pass
|
184
|
+
},
|
185
|
+
|
186
|
+
// openssl genrsa -out dkim_private.pem 2048
|
187
|
+
// openssl rsa -in dkim_private.pem -pubout -outform der 2>/dev/null | openssl base64 -A
|
188
|
+
// ->
|
189
|
+
// v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunT2EopDAYnHwAOHd33KhlzjUXJfhmA+fK+cG85i9Pm33oyv1NoGrOynsni0PO6j7oRxxHqs6EMDOw4I/Q0C7aWn20oBomJZehTOkCV2xpuPKESiRktCe/MIZqbkRdypis4jSkFfFFkBHwgkAg5tb11E9elJap0ed/lN5/XlpGedqoypKxp+nEabgYO5mBMMNKRvbHx0eQttRYyIaNkTuMbAaqs4y3TkHOpGvZTJsvUonVMGAstSCfUmXnjF38aKpgyTausTSsxHbaxh3ieUB4ex+svnvsJ4Uh5Skklr+bxLVEHeJN55rxmV67ytLg5XCRWqdKIcJHFvSlm2YwJfcwIDAQABMacAL
|
190
|
+
// testdkim._domainkey.tiledesk.com. 86400 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunT2EopDAYnHwAOHd33KhlzjUXJfhmA+fK+cG85i9Pm33oyv1NoGrOynsni0PO6j7oRxxHqs6EMDOw4I/Q0C7aWn20oBomJZehTOkCV2xpuPKESiRktCe/MIZqbkRdypis4jSkFfFFkBHwgkAg5tb11E9elJap0ed/lN5/XlpGedqoypKxp+nEabgYO5mBMMNKRvbHx0eQttRYyIaNkTuMbAaqs4y3TkHOpGvZTJsvUonVMGAstSCfUmXnjF38aKpgyTausTSsxHbaxh3ieUB4ex+svnvsJ4Uh5Skklr+bxLVEHeJN55rxmV67ytLg5XCRWqdKIcJHFvSlm2YwJfcwIDAQABMacAL"
|
191
|
+
|
192
|
+
dkim: {
|
193
|
+
domainName: "example.com",
|
194
|
+
keySelector: "2017",
|
195
|
+
privateKey: "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBg...",
|
196
|
+
cacheDir: "/tmp",
|
197
|
+
cacheTreshold: 100 * 1024
|
99
198
|
}
|
100
|
-
}
|
199
|
+
};
|
200
|
+
|
201
|
+
winston.debug("getTransport transport: ",transport);
|
202
|
+
|
203
|
+
// create reusable transporter object using the default SMTP transport
|
204
|
+
let transporter = nodemailer.createTransport(transport);
|
101
205
|
return transporter;
|
102
206
|
}
|
103
207
|
|
104
|
-
|
208
|
+
// @deprecated
|
209
|
+
// send(to, subject, html) {
|
210
|
+
// return this.sendMail({to:to, subject:subject, html:html});
|
211
|
+
// }
|
212
|
+
|
213
|
+
send(mail) {
|
105
214
|
|
106
215
|
if (!this.enabled) {
|
107
216
|
winston.info('EmailService is disabled. Not sending email');
|
@@ -112,21 +221,36 @@ class EmailService {
|
|
112
221
|
}
|
113
222
|
|
114
223
|
let mailOptions = {
|
115
|
-
from: this.from, // sender address
|
116
|
-
to: to,
|
224
|
+
from: mail.from || this.from, // sender address
|
225
|
+
to: mail.to,
|
226
|
+
cc: mail.cc,
|
117
227
|
// bcc: config.bcc,
|
118
|
-
|
119
|
-
|
120
|
-
|
228
|
+
replyTo: mail.replyTo || this.replyTo,
|
229
|
+
inReplyTo: mail.inReplyTo,
|
230
|
+
references: mail.references,
|
231
|
+
subject: mail.subject, // Subject line
|
232
|
+
text: mail.text, // plain text body
|
233
|
+
html: mail.html,
|
234
|
+
|
235
|
+
headers: mail.headers || this.headers,
|
236
|
+
|
237
|
+
messageId: mail.messageId,
|
238
|
+
sender: mail.sender
|
121
239
|
};
|
240
|
+
|
122
241
|
winston.debug('mailOptions', mailOptions);
|
123
242
|
|
243
|
+
if (!mail.to) {
|
244
|
+
return winston.warn("EmailService send method. to field is not defined", mailOptions);
|
245
|
+
}
|
246
|
+
|
124
247
|
// send mail with defined transport object
|
125
|
-
this.getTransport().sendMail(mailOptions, (error, info) => {
|
248
|
+
this.getTransport(mail.config).sendMail(mailOptions, (error, info) => {
|
126
249
|
if (error) {
|
127
|
-
return winston.error("Error sending email ", {error:error,
|
250
|
+
return winston.error("Error sending email ", {error:error, mailOptions:mailOptions});
|
128
251
|
}
|
129
|
-
winston.
|
252
|
+
winston.verbose('Email sent:', {info: info});
|
253
|
+
winston.debug('Email sent:', {info: info, mailOptions: mailOptions});
|
130
254
|
// Preview only available when sending through an Ethereal account
|
131
255
|
// winston.debug('Preview URL: %s', nodemailer.getTestMessageUrl(info));
|
132
256
|
|
@@ -136,125 +260,921 @@ class EmailService {
|
|
136
260
|
}
|
137
261
|
|
138
262
|
|
139
|
-
sendTest(to) {
|
263
|
+
async sendTest(to) {
|
140
264
|
|
141
265
|
var that = this;
|
142
266
|
|
143
|
-
this.
|
267
|
+
var html = await this.readTemplateFile('test.html');
|
144
268
|
|
145
|
-
|
269
|
+
var template = handlebars.compile(html);
|
146
270
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
271
|
+
var replacements = {
|
272
|
+
user: {name: "andrea"},
|
273
|
+
enabled: true
|
274
|
+
};
|
151
275
|
|
152
|
-
|
276
|
+
var html = template(replacements);
|
153
277
|
|
154
|
-
|
278
|
+
that.send({to:to, subject:`TileDesk test email`,html: html});
|
279
|
+
|
280
|
+
//that.send(that.bcc, `TileDesk test email - notification`, html);
|
155
281
|
|
156
|
-
that.send(that.bcc, `TileDesk test email`, html);
|
157
282
|
|
158
|
-
});
|
159
|
-
|
160
283
|
|
161
284
|
|
162
285
|
}
|
163
286
|
|
164
287
|
|
165
|
-
|
166
|
-
sendNewAssignedRequestNotification(to,
|
288
|
+
|
289
|
+
async sendNewAssignedRequestNotification(to, request, project) {
|
167
290
|
|
168
291
|
var that = this;
|
169
292
|
|
170
|
-
|
293
|
+
//if the request came from rabbit mq?
|
294
|
+
if (request.toJSON) {
|
295
|
+
request = request.toJSON();
|
296
|
+
}
|
171
297
|
|
298
|
+
if (project.toJSON) {
|
299
|
+
project = project.toJSON();
|
300
|
+
}
|
172
301
|
|
173
|
-
|
174
|
-
winston.debug("envTemplate: " + envTemplate);
|
302
|
+
var html = await this.readTemplate('assignedRequest.html', project.settings);
|
175
303
|
|
176
|
-
|
177
|
-
|
178
|
-
}
|
304
|
+
var envTemplate = process.env.EMAIL_ASSIGN_REQUEST_HTML_TEMPLATE;
|
305
|
+
winston.debug("envTemplate: " + envTemplate);
|
179
306
|
|
180
|
-
|
307
|
+
if (envTemplate) {
|
308
|
+
html = envTemplate;
|
309
|
+
}
|
181
310
|
|
182
|
-
|
311
|
+
winston.debug("html: " + html);
|
183
312
|
|
184
|
-
|
185
|
-
delete baseScope.emailPassword;
|
313
|
+
var template = handlebars.compile(html);
|
186
314
|
|
187
|
-
|
315
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
316
|
+
delete baseScope.pass;
|
317
|
+
|
318
|
+
// passa anche tutti i messages in modo da stampare tutto
|
188
319
|
// Stampa anche contact.email
|
189
320
|
|
190
|
-
var replacements = {
|
191
|
-
savedRequest: savedRequest.toJSON(),
|
192
|
-
project: project.toJSON(),
|
193
|
-
baseScope: baseScope
|
194
|
-
};
|
195
321
|
|
196
|
-
|
322
|
+
let msgText = request.first_text;//.replace(/[\n\r]/g, '<br>');
|
323
|
+
// winston.verbose("msgText: " + msgText);
|
324
|
+
msgText = encode(msgText);
|
325
|
+
// winston.verbose("msgText: " + msgText);
|
326
|
+
if (this.markdown) {
|
327
|
+
msgText = marked(msgText);
|
328
|
+
}
|
329
|
+
|
330
|
+
|
331
|
+
winston.debug("msgText: " + msgText);
|
332
|
+
|
333
|
+
var replacements = {
|
334
|
+
request: request,
|
335
|
+
project: project,
|
336
|
+
msgText: msgText,
|
337
|
+
baseScope: baseScope,
|
338
|
+
// tools: {marked:marked}
|
339
|
+
};
|
197
340
|
|
198
|
-
|
199
|
-
winston.debug("html after: " + html);
|
341
|
+
winston.debug("replacements ", replacements);
|
200
342
|
|
343
|
+
var html = template(replacements);
|
344
|
+
winston.debug("html after: " + html);
|
201
345
|
|
202
|
-
|
346
|
+
|
347
|
+
let messageId = "notification" + "@" + MESSAGE_ID_DOMAIN;
|
203
348
|
|
204
|
-
|
349
|
+
let replyTo;
|
350
|
+
if (this.replyEnabled) { //fai anche per gli altri
|
351
|
+
replyTo = request.request_id + this.inboundDomainDomainWithAt;
|
352
|
+
}
|
205
353
|
|
354
|
+
let headers;
|
355
|
+
if (request) {
|
356
|
+
|
357
|
+
messageId = request.request_id + "+" + messageId;
|
358
|
+
|
359
|
+
if (request.attributes && request.attributes.email_replyTo) {
|
360
|
+
replyTo = request.attributes.email_replyTo;
|
361
|
+
}
|
362
|
+
|
363
|
+
headers = {
|
364
|
+
"X-TILEDESK-PROJECT-ID": project._id,
|
365
|
+
"X-TILEDESK-REQUEST-ID": request.request_id,
|
366
|
+
"X-TILEDESK-TICKET-ID":request.ticket_id,
|
367
|
+
};
|
368
|
+
|
369
|
+
winston.verbose("messageId: " + messageId);
|
370
|
+
winston.verbose("replyTo: " + replyTo);
|
371
|
+
winston.verbose("email headers", headers);
|
372
|
+
}
|
373
|
+
|
374
|
+
let inReplyTo;
|
375
|
+
let references;
|
376
|
+
if (request.attributes) {
|
377
|
+
if (request.attributes.email_messageId) {
|
378
|
+
inReplyTo = request.attributes.email_messageId;
|
379
|
+
}
|
380
|
+
if (request.attributes.email_references) {
|
381
|
+
references = request.attributes.email_references;
|
382
|
+
}
|
383
|
+
}
|
384
|
+
winston.verbose("email inReplyTo: "+ inReplyTo);
|
385
|
+
winston.verbose("email references: "+ references);
|
386
|
+
|
387
|
+
let from;
|
388
|
+
let configEmail;
|
389
|
+
if (project && project.settings && project.settings.email) {
|
390
|
+
if (project.settings.email.config) {
|
391
|
+
configEmail = project.settings.email.config;
|
392
|
+
winston.verbose("custom email configEmail setting found: ", configEmail);
|
393
|
+
}
|
394
|
+
if (project.settings.email.from) {
|
395
|
+
from = project.settings.email.from;
|
396
|
+
winston.verbose("custom from email setting found: "+ from);
|
397
|
+
}
|
398
|
+
}
|
399
|
+
|
400
|
+
let subject = `[TileDesk ${project ? project.name : '-'}] New Assigned Chat`;
|
401
|
+
|
402
|
+
if (request.subject) {
|
403
|
+
subject = `[TileDesk ${project ? project.name : '-'}] ${request.subject}`;
|
404
|
+
}
|
405
|
+
|
406
|
+
// if (request.ticket_id) {
|
407
|
+
// subject = `[Ticket #${request.ticket_id}] New Assigned Chat`;
|
408
|
+
// }
|
409
|
+
|
410
|
+
// if (request.ticket_id && request.subject) {
|
411
|
+
// subject = `[Ticket #${request.ticket_id}] ${request.subject}`;
|
412
|
+
// }
|
413
|
+
|
414
|
+
that.send({
|
415
|
+
messageId: messageId,
|
416
|
+
from:from,
|
417
|
+
to:to,
|
418
|
+
replyTo: replyTo,
|
419
|
+
subject: subject,
|
420
|
+
html:html,
|
421
|
+
config: configEmail,
|
422
|
+
headers:headers
|
206
423
|
});
|
424
|
+
|
425
|
+
messageId = "notification" + messageId;
|
426
|
+
|
427
|
+
|
428
|
+
// togliere bcc
|
429
|
+
that.send({
|
430
|
+
messageId: messageId,
|
431
|
+
to: that.bcc,
|
432
|
+
replyTo: replyTo,
|
433
|
+
subject: subject + ` ${to} - notification`,
|
434
|
+
html:html,
|
435
|
+
headers:headers
|
436
|
+
});
|
437
|
+
|
207
438
|
|
208
439
|
}
|
209
440
|
|
210
|
-
|
211
|
-
|
441
|
+
|
442
|
+
async sendNewAssignedAgentMessageEmailNotification(to, request, project, message) {
|
212
443
|
|
213
444
|
var that = this;
|
214
445
|
|
215
|
-
|
446
|
+
//if the request came from rabbit mq?
|
447
|
+
if (request.toJSON) {
|
448
|
+
request = request.toJSON();
|
449
|
+
}
|
450
|
+
|
451
|
+
if (project.toJSON) {
|
452
|
+
project = project.toJSON();
|
453
|
+
}
|
454
|
+
|
455
|
+
var html = await this.readTemplate('assignedEmailMessage.html', project.settings);
|
216
456
|
|
217
457
|
|
218
|
-
|
219
|
-
|
458
|
+
var envTemplate = process.env.EMAIL_ASSIGN_MESSAGE_EMAIL_HTML_TEMPLATE;
|
459
|
+
winston.debug("envTemplate: " + envTemplate);
|
220
460
|
|
221
|
-
|
222
|
-
|
461
|
+
if (envTemplate) {
|
462
|
+
html = envTemplate;
|
463
|
+
}
|
464
|
+
|
465
|
+
winston.debug("html: " + html);
|
466
|
+
|
467
|
+
var template = handlebars.compile(html);
|
468
|
+
|
469
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
470
|
+
delete baseScope.pass;
|
471
|
+
|
472
|
+
// passa anche tutti i messages in modo da stampare tutto
|
473
|
+
// Stampa anche contact.email
|
474
|
+
|
475
|
+
let msgText = message.text;//.replace(/[\n\r]/g, '<br>');
|
476
|
+
msgText = encode(msgText);
|
477
|
+
if (this.markdown) {
|
478
|
+
msgText = marked(msgText);
|
479
|
+
}
|
480
|
+
|
481
|
+
winston.debug("msgText: " + msgText);
|
482
|
+
|
483
|
+
var replacements = {
|
484
|
+
request: request,
|
485
|
+
project: project,
|
486
|
+
message: message,
|
487
|
+
msgText: msgText,
|
488
|
+
baseScope: baseScope
|
489
|
+
};
|
490
|
+
|
491
|
+
winston.debug("replacements ", replacements);
|
492
|
+
|
493
|
+
var html = template(replacements);
|
494
|
+
winston.debug("html after: " + html);
|
495
|
+
|
496
|
+
|
497
|
+
let messageId = message._id + "@" + MESSAGE_ID_DOMAIN;
|
498
|
+
|
499
|
+
let replyTo;
|
500
|
+
if (this.replyEnabled) {
|
501
|
+
replyTo = message.request.request_id + this.inboundDomainDomainWithAt;
|
502
|
+
}
|
503
|
+
|
504
|
+
let headers;
|
505
|
+
if (message.request) {
|
506
|
+
|
507
|
+
messageId = message.request.request_id + "+" + messageId;
|
508
|
+
|
509
|
+
if (message.request.attributes && message.request.attributes.email_replyTo) {
|
510
|
+
replyTo = message.request.attributes.email_replyTo;
|
511
|
+
}
|
512
|
+
|
513
|
+
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
514
|
+
|
515
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification messageId: " + messageId);
|
516
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification replyTo: " + replyTo);
|
517
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification email headers", headers);
|
518
|
+
}
|
519
|
+
|
520
|
+
let inReplyTo;
|
521
|
+
let references;
|
522
|
+
if (message.attributes) {
|
523
|
+
if (message.attributes.email_messageId) {
|
524
|
+
inReplyTo = message.attributes.email_messageId;
|
525
|
+
}
|
526
|
+
if (message.attributes.email_references) {
|
527
|
+
references = message.attributes.email_references;
|
528
|
+
}
|
529
|
+
}
|
530
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification email inReplyTo: "+ inReplyTo);
|
531
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification email references: "+ references);
|
532
|
+
|
533
|
+
let from;
|
534
|
+
let configEmail;
|
535
|
+
if (project && project.settings && project.settings.email) {
|
536
|
+
if (project.settings.email.config) {
|
537
|
+
configEmail = project.settings.email.config;
|
538
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification custom email configEmail setting found: ", configEmail);
|
539
|
+
}
|
540
|
+
if (project.settings.email.from) {
|
541
|
+
from = project.settings.email.from;
|
542
|
+
winston.verbose("sendNewAssignedAgentMessageEmailNotification custom from email setting found: "+ from);
|
223
543
|
}
|
544
|
+
}
|
224
545
|
|
225
|
-
winston.debug("html: " + html);
|
226
546
|
|
227
|
-
|
547
|
+
let subject = `[TileDesk ${project ? project.name : '-'}] New message`;
|
548
|
+
|
549
|
+
if (request.subject) {
|
550
|
+
subject = `[TileDesk ${project ? project.name : '-'}] ${request.subject}`;
|
551
|
+
}
|
552
|
+
if (request.ticket_id) {
|
553
|
+
subject = `[Ticket #${request.ticket_id}] New message`;
|
554
|
+
}
|
555
|
+
|
556
|
+
if (request.ticket_id && request.subject) {
|
557
|
+
subject = `[Ticket #${request.ticket_id}] ${request.subject}`;
|
558
|
+
}
|
559
|
+
|
228
560
|
|
229
|
-
|
230
|
-
|
561
|
+
|
562
|
+
that.send({
|
563
|
+
messageId: messageId,
|
564
|
+
from:from,
|
565
|
+
to:to,
|
566
|
+
replyTo: replyTo,
|
567
|
+
// inReplyTo: inReplyTo,???
|
568
|
+
// references: references,??
|
569
|
+
subject: subject,
|
570
|
+
html:html,
|
571
|
+
config: configEmail,
|
572
|
+
headers:headers
|
573
|
+
});
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
messageId = "notification" + messageId;
|
578
|
+
|
579
|
+
that.send({
|
580
|
+
messageId: messageId,
|
581
|
+
to: that.bcc,
|
582
|
+
replyTo: replyTo,
|
583
|
+
subject: subject + ` - notification`,
|
584
|
+
html:html,
|
585
|
+
headers:headers
|
586
|
+
});
|
587
|
+
|
588
|
+
|
589
|
+
}
|
590
|
+
|
591
|
+
|
592
|
+
async sendNewPooledRequestNotification(to, request, project) {
|
593
|
+
|
594
|
+
//if the request came from rabbit mq?
|
595
|
+
if (request.toJSON) {
|
596
|
+
request = request.toJSON();
|
597
|
+
}
|
598
|
+
|
599
|
+
if (project.toJSON) {
|
600
|
+
project = project.toJSON();
|
601
|
+
}
|
602
|
+
|
603
|
+
var that = this;
|
604
|
+
|
605
|
+
var html = await this.readTemplate('pooledRequest.html', project.settings);
|
606
|
+
|
607
|
+
var envTemplate = process.env.EMAIL_POOLED_REQUEST_HTML_TEMPLATE;
|
608
|
+
winston.debug("envTemplate: " + envTemplate);
|
609
|
+
|
610
|
+
if (envTemplate) {
|
611
|
+
html = envTemplate;
|
612
|
+
}
|
613
|
+
|
614
|
+
winston.debug("html: " + html);
|
615
|
+
|
616
|
+
var template = handlebars.compile(html);
|
617
|
+
|
618
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
619
|
+
delete baseScope.pass;
|
231
620
|
|
232
621
|
// passa anche tutti i messages in modo da stampare tutto
|
233
622
|
// Stampa anche contact.email
|
234
|
-
var replacements = {
|
235
|
-
savedRequest: savedRequest.toJSON(),
|
236
|
-
project: project.toJSON(),
|
237
|
-
baseScope: baseScope
|
238
|
-
};
|
239
623
|
|
240
|
-
|
624
|
+
let msgText = request.first_text;//.replace(/[\n\r]/g, '<br>');
|
625
|
+
msgText = encode(msgText);
|
626
|
+
if (this.markdown) {
|
627
|
+
msgText = marked(msgText);
|
628
|
+
}
|
629
|
+
|
630
|
+
winston.verbose("msgText: " + msgText);
|
631
|
+
|
632
|
+
var replacements = {
|
633
|
+
request: request,
|
634
|
+
project: project,
|
635
|
+
msgText: msgText,
|
636
|
+
baseScope: baseScope
|
637
|
+
};
|
638
|
+
|
639
|
+
var html = template(replacements);
|
640
|
+
|
641
|
+
|
642
|
+
let messageId = "notification-pooled" + new Date().getTime() + "@" + MESSAGE_ID_DOMAIN;
|
643
|
+
|
644
|
+
let replyTo;
|
645
|
+
if (this.replyEnabled) {
|
646
|
+
replyTo = request.request_id + this.inboundDomainDomainWithAt;
|
647
|
+
}
|
648
|
+
|
649
|
+
let headers;
|
650
|
+
if (request) {
|
651
|
+
|
652
|
+
messageId = request.request_id + "+" + messageId;
|
653
|
+
|
654
|
+
if (request.attributes && request.attributes.email_replyTo) {
|
655
|
+
replyTo = request.attributes.email_replyTo;
|
656
|
+
}
|
241
657
|
|
658
|
+
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": request.request_id, "X-TILEDESK-TICKET-ID":request.ticket_id };
|
242
659
|
|
243
|
-
|
244
|
-
|
660
|
+
winston.verbose("sendNewPooledRequestNotification messageId: " + messageId);
|
661
|
+
winston.verbose("sendNewPooledRequestNotification replyTo: " + replyTo);
|
662
|
+
winston.verbose("sendNewPooledRequestNotification email headers", headers);
|
663
|
+
}
|
245
664
|
|
665
|
+
let inReplyTo;
|
666
|
+
let references;
|
667
|
+
if (request.attributes) {
|
668
|
+
if (request.attributes.email_messageId) {
|
669
|
+
inReplyTo = request.attributes.email_messageId;
|
670
|
+
}
|
671
|
+
if (request.attributes.email_references) {
|
672
|
+
references = request.attributes.email_references;
|
673
|
+
}
|
674
|
+
}
|
675
|
+
winston.verbose("sendNewPooledRequestNotification email inReplyTo: "+ inReplyTo);
|
676
|
+
winston.verbose("sendNewPooledRequestNotification email references: "+ references);
|
677
|
+
|
678
|
+
let from;
|
679
|
+
let configEmail;
|
680
|
+
if (project && project.settings && project.settings.email) {
|
681
|
+
if (project.settings.email.config) {
|
682
|
+
configEmail = project.settings.email.config;
|
683
|
+
winston.verbose("sendNewPooledRequestNotification custom email configEmail setting found: ", configEmail);
|
684
|
+
}
|
685
|
+
if (project.settings.email.from) {
|
686
|
+
from = project.settings.email.from;
|
687
|
+
winston.verbose("sendNewPooledRequestNotification custom from email setting found: "+ from);
|
688
|
+
}
|
689
|
+
}
|
690
|
+
|
691
|
+
let subject = `[TileDesk ${project ? project.name : '-'}] New Pooled Chat`;
|
692
|
+
|
693
|
+
if (request.subject) {
|
694
|
+
subject = `[TileDesk ${project ? project.name : '-'}] ${request.subject}`;
|
695
|
+
}
|
696
|
+
// if (request.ticket_id) {
|
697
|
+
// subject = `[Ticket #${request.ticket_id}] New Pooled Chat`;
|
698
|
+
// }
|
699
|
+
|
700
|
+
// if (request.ticket_id && request.subject) {
|
701
|
+
// subject = `[Ticket #${request.ticket_id}] ${request.subject}`;
|
702
|
+
// }
|
703
|
+
|
704
|
+
|
705
|
+
|
706
|
+
that.send({
|
707
|
+
messageId: messageId,
|
708
|
+
from:from,
|
709
|
+
to: to,
|
710
|
+
replyTo: replyTo,
|
711
|
+
subject: subject,
|
712
|
+
html:html,
|
713
|
+
config:configEmail,
|
714
|
+
headers:headers
|
246
715
|
});
|
716
|
+
// this.send(that.bcc, `[TileDesk ${project ? project.name : '-'}] New Pooled Request`, html);
|
717
|
+
|
247
718
|
}
|
248
719
|
|
249
720
|
|
250
|
-
|
721
|
+
|
722
|
+
|
723
|
+
|
724
|
+
async sendNewPooledMessageEmailNotification(to, request, project, message) {
|
251
725
|
|
252
726
|
var that = this;
|
253
727
|
|
254
|
-
|
728
|
+
|
729
|
+
//if the request came from rabbit mq?
|
730
|
+
if (request.toJSON) {
|
731
|
+
request = request.toJSON();
|
732
|
+
}
|
733
|
+
|
734
|
+
if (project.toJSON) {
|
735
|
+
project = project.toJSON();
|
736
|
+
}
|
737
|
+
|
738
|
+
var html = await this.readTemplate('pooledEmailMessage.html', project.settings);
|
255
739
|
|
256
740
|
|
257
|
-
|
741
|
+
var envTemplate = process.env.EMAIL_POOLED_MESSAGE_EMAIL_HTML_TEMPLATE;
|
742
|
+
winston.debug("envTemplate: " + envTemplate);
|
743
|
+
|
744
|
+
|
745
|
+
if (envTemplate) {
|
746
|
+
html = envTemplate;
|
747
|
+
}
|
748
|
+
|
749
|
+
winston.debug("html: " + html);
|
750
|
+
|
751
|
+
var template = handlebars.compile(html);
|
752
|
+
|
753
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
754
|
+
delete baseScope.pass;
|
755
|
+
|
756
|
+
let msgText = message.text;//.replace(/[\n\r]/g, '<br>');
|
757
|
+
msgText = encode(msgText);
|
758
|
+
if (this.markdown) {
|
759
|
+
msgText = marked(msgText);
|
760
|
+
}
|
761
|
+
|
762
|
+
winston.verbose("msgText: " + msgText);
|
763
|
+
|
764
|
+
// passa anche tutti i messages in modo da stampare tutto
|
765
|
+
// Stampa anche contact.email
|
766
|
+
|
767
|
+
var replacements = {
|
768
|
+
request: request,
|
769
|
+
project: project,
|
770
|
+
message: message,
|
771
|
+
msgText: msgText,
|
772
|
+
baseScope: baseScope
|
773
|
+
};
|
774
|
+
|
775
|
+
winston.debug("replacements ", replacements);
|
776
|
+
|
777
|
+
var html = template(replacements);
|
778
|
+
winston.debug("html after: " + html);
|
779
|
+
|
780
|
+
|
781
|
+
|
782
|
+
let messageId = message._id + "@" + MESSAGE_ID_DOMAIN;
|
783
|
+
|
784
|
+
let replyTo;
|
785
|
+
if (this.replyEnabled) {
|
786
|
+
replyTo = message.request.request_id + this.inboundDomainDomainWithAt;
|
787
|
+
}
|
788
|
+
|
789
|
+
let headers;
|
790
|
+
if (message.request) {
|
791
|
+
|
792
|
+
messageId = message.request.request_id + "+" + messageId;
|
793
|
+
|
794
|
+
if (message.request.attributes && message.request.attributes.email_replyTo) {
|
795
|
+
replyTo = message.request.attributes.email_replyTo;
|
796
|
+
}
|
797
|
+
|
798
|
+
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
799
|
+
|
800
|
+
winston.verbose("sendNewPooledMessageEmailNotification messageId: " + messageId);
|
801
|
+
winston.verbose("sendNewPooledMessageEmailNotification replyTo: " + replyTo);
|
802
|
+
winston.verbose("sendNewPooledMessageEmailNotification email headers", headers);
|
803
|
+
}
|
804
|
+
|
805
|
+
let inReplyTo;
|
806
|
+
let references;
|
807
|
+
if (message.attributes) {
|
808
|
+
if (message.attributes.email_messageId) {
|
809
|
+
inReplyTo = message.attributes.email_messageId;
|
810
|
+
}
|
811
|
+
if (message.attributes.email_references) {
|
812
|
+
references = message.attributes.email_references;
|
813
|
+
}
|
814
|
+
}
|
815
|
+
winston.verbose("sendNewPooledMessageEmailNotification email inReplyTo: "+ inReplyTo);
|
816
|
+
winston.verbose("sendNewPooledMessageEmailNotification email references: "+ references);
|
817
|
+
|
818
|
+
let from;
|
819
|
+
let configEmail;
|
820
|
+
if (project && project.settings && project.settings.email) {
|
821
|
+
if (project.settings.email.config) {
|
822
|
+
configEmail = project.settings.email.config;
|
823
|
+
winston.verbose("sendNewPooledMessageEmailNotification custom email configEmail setting found: ", configEmail);
|
824
|
+
}
|
825
|
+
if (project.settings.email.from) {
|
826
|
+
from = project.settings.email.from;
|
827
|
+
winston.verbose("sendNewPooledMessageEmailNotification custom from email setting found: "+ from);
|
828
|
+
}
|
829
|
+
}
|
830
|
+
|
831
|
+
|
832
|
+
let subject = `[TileDesk ${project ? project.name : '-'}] New Message`;
|
833
|
+
|
834
|
+
if (request.subject) {
|
835
|
+
subject = `[TileDesk ${project ? project.name : '-'}] ${request.subject}`;
|
836
|
+
}
|
837
|
+
if (request.ticket_id) {
|
838
|
+
subject = `[Ticket #${request.ticket_id}] New Message`;
|
839
|
+
}
|
840
|
+
|
841
|
+
if (request.ticket_id && request.subject) {
|
842
|
+
subject = `[Ticket #${request.ticket_id}] ${request.subject}`;
|
843
|
+
}
|
844
|
+
|
845
|
+
|
846
|
+
that.send({
|
847
|
+
messageId: messageId,
|
848
|
+
from:from,
|
849
|
+
to:to,
|
850
|
+
replyTo: replyTo,
|
851
|
+
// inReplyTo: inReplyTo,???
|
852
|
+
// references: references,??
|
853
|
+
subject: subject,
|
854
|
+
html:html,
|
855
|
+
config: configEmail,
|
856
|
+
headers:headers
|
857
|
+
});
|
858
|
+
|
859
|
+
|
860
|
+
|
861
|
+
// messageId = "notification" + messageId;
|
862
|
+
|
863
|
+
// that.send({
|
864
|
+
// messageId: messageId,
|
865
|
+
// to: that.bcc,
|
866
|
+
// replyTo: replyTo,
|
867
|
+
// subject: `[TileDesk ${project ? project.name : '-'}] - ${request.subject ? request.subject : 'New message'} - notification`,
|
868
|
+
// html:html,
|
869
|
+
// headers:headers
|
870
|
+
// });
|
871
|
+
|
872
|
+
|
873
|
+
}
|
874
|
+
|
875
|
+
|
876
|
+
async sendNewMessageNotification(to, message, project, tokenQueryString, sourcePage) {
|
877
|
+
|
878
|
+
var that = this;
|
879
|
+
|
880
|
+
//if the request came from rabbit mq?
|
881
|
+
|
882
|
+
if (project.toJSON) {
|
883
|
+
project = project.toJSON();
|
884
|
+
}
|
885
|
+
|
886
|
+
var html = await this.readTemplate('newMessage.html', project.settings);
|
887
|
+
|
888
|
+
|
889
|
+
|
890
|
+
var envTemplate = process.env.EMAIL_NEW_MESSAGE_HTML_TEMPLATE;
|
891
|
+
winston.debug("envTemplate: " + envTemplate);
|
892
|
+
|
893
|
+
if (envTemplate) {
|
894
|
+
html = envTemplate;
|
895
|
+
}
|
896
|
+
|
897
|
+
winston.debug("html: " + html);
|
898
|
+
|
899
|
+
var template = handlebars.compile(html);
|
900
|
+
|
901
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
902
|
+
delete baseScope.pass;
|
903
|
+
|
904
|
+
let msgText = message.text;//.replace(/[\n\r]/g, '<br>');
|
905
|
+
msgText = encode(msgText);
|
906
|
+
if (this.markdown) {
|
907
|
+
msgText = marked(msgText);
|
908
|
+
}
|
909
|
+
|
910
|
+
winston.debug("msgText: " + msgText);
|
911
|
+
|
912
|
+
var replacements = {
|
913
|
+
message: message,
|
914
|
+
project: project,
|
915
|
+
msgText:msgText,
|
916
|
+
seamlessPage: sourcePage,
|
917
|
+
tokenQueryString: tokenQueryString,
|
918
|
+
baseScope: baseScope
|
919
|
+
};
|
920
|
+
|
921
|
+
var html = template(replacements);
|
922
|
+
winston.debug("html: " + html);
|
923
|
+
|
924
|
+
|
925
|
+
let messageId = message._id + "@" + MESSAGE_ID_DOMAIN;
|
926
|
+
|
927
|
+
let replyTo;
|
928
|
+
if (this.replyEnabled) {
|
929
|
+
replyTo = message.request.request_id + this.inboundDomainDomainWithAt;
|
930
|
+
}
|
931
|
+
|
932
|
+
let headers;
|
933
|
+
if (message.request) {
|
934
|
+
|
935
|
+
messageId = message.request.request_id + "+" + messageId;
|
936
|
+
|
937
|
+
if (message.request.attributes && message.request.attributes.email_replyTo) {
|
938
|
+
replyTo = message.request.attributes.email_replyTo;
|
939
|
+
}
|
940
|
+
|
941
|
+
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
942
|
+
|
943
|
+
winston.verbose("messageId: " + messageId);
|
944
|
+
winston.verbose("replyTo: " + replyTo);
|
945
|
+
winston.verbose("email headers", headers);
|
946
|
+
}
|
947
|
+
|
948
|
+
let inReplyTo;
|
949
|
+
let references;
|
950
|
+
if (message.attributes) {
|
951
|
+
if (message.attributes.email_messageId) {
|
952
|
+
inReplyTo = message.attributes.email_messageId;
|
953
|
+
}
|
954
|
+
if (message.attributes.email_references) {
|
955
|
+
references = message.attributes.email_references;
|
956
|
+
}
|
957
|
+
}
|
958
|
+
winston.verbose("email inReplyTo: "+ inReplyTo);
|
959
|
+
winston.verbose("email references: "+ references);
|
960
|
+
|
961
|
+
let from;
|
962
|
+
let configEmail;
|
963
|
+
if (project && project.settings && project.settings.email) {
|
964
|
+
if (project.settings.email.config) {
|
965
|
+
configEmail = project.settings.email.config;
|
966
|
+
winston.verbose("custom email configEmail setting found: ", configEmail);
|
967
|
+
}
|
968
|
+
if (project.settings.email.from) {
|
969
|
+
from = project.settings.email.from;
|
970
|
+
winston.verbose("custom from email setting found: "+ from);
|
971
|
+
}
|
972
|
+
}
|
973
|
+
|
974
|
+
|
975
|
+
that.send({
|
976
|
+
messageId: messageId,
|
977
|
+
// sender: message.senderFullname, //must be an email
|
978
|
+
from:from,
|
979
|
+
to:to,
|
980
|
+
replyTo: replyTo,
|
981
|
+
inReplyTo: inReplyTo,
|
982
|
+
references: references,
|
983
|
+
subject:`[TileDesk ${project ? project.name : '-'}] New Offline Message`,
|
984
|
+
html:html,
|
985
|
+
config:configEmail,
|
986
|
+
headers: headers
|
987
|
+
});
|
988
|
+
|
989
|
+
messageId = "notification" + messageId;
|
990
|
+
|
991
|
+
that.send({
|
992
|
+
messageId: messageId,
|
993
|
+
// sender: message.senderFullname, //must be an email
|
994
|
+
to: that.bcc,
|
995
|
+
replyTo: replyTo,
|
996
|
+
inReplyTo: inReplyTo,
|
997
|
+
references: references,
|
998
|
+
subject: `[TileDesk ${project ? project.name : '-'}] New Offline Message - notification`,
|
999
|
+
html:html,
|
1000
|
+
headers: headers
|
1001
|
+
});
|
1002
|
+
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
|
1006
|
+
|
1007
|
+
async sendEmailChannelNotification(to, message, project, tokenQueryString, sourcePage) {
|
1008
|
+
|
1009
|
+
var that = this;
|
1010
|
+
|
1011
|
+
|
1012
|
+
if (project.toJSON) {
|
1013
|
+
project = project.toJSON();
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
var html = await this.readTemplate('ticket.html', project.settings);
|
1017
|
+
// this.readTemplateFile('ticket.txt', function(err, html) {
|
1018
|
+
|
1019
|
+
|
1020
|
+
var envTemplate = process.env.EMAIL_TICKET_HTML_TEMPLATE;
|
1021
|
+
winston.debug("envTemplate: " + envTemplate);
|
1022
|
+
|
1023
|
+
if (envTemplate) {
|
1024
|
+
html = envTemplate;
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
winston.debug("html: " + html);
|
1028
|
+
|
1029
|
+
var template = handlebars.compile(html);
|
1030
|
+
|
1031
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1032
|
+
delete baseScope.pass;
|
1033
|
+
|
1034
|
+
|
1035
|
+
let msgText = message.text;//.replace(/[\n\r]/g, '<br>');
|
1036
|
+
msgText = encode(msgText);
|
1037
|
+
if (this.markdown) {
|
1038
|
+
msgText = marked(msgText);
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
winston.debug("msgText: " + msgText);
|
1042
|
+
winston.debug("baseScope: " + JSON.stringify(baseScope));
|
1043
|
+
|
1044
|
+
|
1045
|
+
var replacements = {
|
1046
|
+
message: message,
|
1047
|
+
project: project,
|
1048
|
+
seamlessPage: sourcePage,
|
1049
|
+
msgText: msgText,
|
1050
|
+
tokenQueryString: tokenQueryString,
|
1051
|
+
baseScope: baseScope
|
1052
|
+
};
|
1053
|
+
|
1054
|
+
var html = template(replacements);
|
1055
|
+
winston.debug("html: " + html);
|
1056
|
+
|
1057
|
+
|
1058
|
+
|
1059
|
+
|
1060
|
+
let messageId = message._id + "@" + MESSAGE_ID_DOMAIN;
|
1061
|
+
|
1062
|
+
let replyTo;
|
1063
|
+
if (this.replyEnabled) {
|
1064
|
+
replyTo = message.request.request_id + this.inboundDomainDomainWithAt;
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
let headers;
|
1068
|
+
if (message.request) {
|
1069
|
+
|
1070
|
+
messageId = message.request.request_id + "+" + messageId;
|
1071
|
+
|
1072
|
+
if (message.request.attributes && message.request.attributes.email_replyTo) {
|
1073
|
+
replyTo = message.request.attributes.email_replyTo;
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
|
1077
|
+
|
1078
|
+
winston.verbose("messageId: " + messageId);
|
1079
|
+
winston.verbose("replyTo: " + replyTo);
|
1080
|
+
winston.verbose("email headers", headers);
|
1081
|
+
}
|
1082
|
+
|
1083
|
+
|
1084
|
+
let inReplyTo;
|
1085
|
+
let references;
|
1086
|
+
let cc;
|
1087
|
+
let ccString;
|
1088
|
+
|
1089
|
+
if (message.attributes) {
|
1090
|
+
|
1091
|
+
winston.verbose("email message.attributes: ", message.attributes);
|
1092
|
+
// per email touching manca
|
1093
|
+
if (message.attributes.email_messageId) {
|
1094
|
+
inReplyTo = message.attributes.email_messageId;
|
1095
|
+
}
|
1096
|
+
if (message.attributes.email_references) {
|
1097
|
+
references = message.attributes.email_references;
|
1098
|
+
}
|
1099
|
+
if (message.attributes.email_cc) {
|
1100
|
+
cc = message.attributes.email_cc;
|
1101
|
+
}
|
1102
|
+
winston.verbose("email message.attributes.email_ccStr: "+ message.attributes.email_ccStr);
|
1103
|
+
if (message.attributes.email_ccStr!=undefined) {
|
1104
|
+
ccString = message.attributes.email_ccStr;
|
1105
|
+
winston.verbose("email set ccString");
|
1106
|
+
}
|
1107
|
+
}
|
1108
|
+
winston.verbose("email inReplyTo: "+ inReplyTo);
|
1109
|
+
winston.verbose("email references: "+ references);
|
1110
|
+
winston.verbose("email cc: ", cc);
|
1111
|
+
winston.verbose("email ccString: "+ ccString);
|
1112
|
+
|
1113
|
+
let from;
|
1114
|
+
let configEmail;
|
1115
|
+
if (project && project.settings && project.settings.email) {
|
1116
|
+
if (project.settings.email.config) {
|
1117
|
+
configEmail = project.settings.email.config;
|
1118
|
+
winston.verbose("custom email configEmail setting found: ", configEmail);
|
1119
|
+
}
|
1120
|
+
if (project.settings.email.from) {
|
1121
|
+
from = project.settings.email.from;
|
1122
|
+
winston.verbose("custom from email setting found: "+ from);
|
1123
|
+
}
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
|
1127
|
+
// if (message.request && message.request.lead && message.request.lead.email) {
|
1128
|
+
// winston.info("message.request.lead.email: " + message.request.lead.email);
|
1129
|
+
// replyTo = replyTo + ", "+ message.request.lead.email;
|
1130
|
+
// }
|
1131
|
+
|
1132
|
+
that.send({
|
1133
|
+
messageId: messageId,
|
1134
|
+
// sender: message.senderFullname, //must be an email
|
1135
|
+
from:from,
|
1136
|
+
to:to,
|
1137
|
+
cc: ccString,
|
1138
|
+
replyTo: replyTo,
|
1139
|
+
inReplyTo: inReplyTo,
|
1140
|
+
references: references,
|
1141
|
+
// subject:`${message.request ? message.request.subject : '-'}`,
|
1142
|
+
subject:`R: ${message.request ? message.request.subject : '-'}`, //gmail uses subject
|
1143
|
+
text:html,
|
1144
|
+
html:html,
|
1145
|
+
config:configEmail,
|
1146
|
+
headers:headers
|
1147
|
+
});
|
1148
|
+
|
1149
|
+
messageId = "notification" + messageId;
|
1150
|
+
|
1151
|
+
that.send({
|
1152
|
+
messageId: messageId,
|
1153
|
+
// sender: message.senderFullname, //must be an email
|
1154
|
+
to: that.bcc,
|
1155
|
+
replyTo: replyTo,
|
1156
|
+
inReplyTo: inReplyTo,
|
1157
|
+
references: references,
|
1158
|
+
// subject: `${message.request ? message.request.subject : '-'} - notification`,
|
1159
|
+
subject: `R: ${message.request ? message.request.subject : '-'} - notification`,
|
1160
|
+
text:html,
|
1161
|
+
html:html,
|
1162
|
+
headers:headers
|
1163
|
+
});
|
1164
|
+
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
|
1168
|
+
/*
|
1169
|
+
sendEmailChannelTakingNotification(to, request, project, tokenQueryString) {
|
1170
|
+
|
1171
|
+
var that = this;
|
1172
|
+
|
1173
|
+
this.readTemplateFile('ticket-taking.txt', function(err, html) {
|
1174
|
+
// this.readTemplateFile('ticket.html', function(err, html) {
|
1175
|
+
|
1176
|
+
|
1177
|
+
var envTemplate = process.env.EMAIL_TICKET_HTML_TEMPLATE;
|
258
1178
|
winston.debug("envTemplate: " + envTemplate);
|
259
1179
|
|
260
1180
|
if (envTemplate) {
|
@@ -266,10 +1186,10 @@ class EmailService {
|
|
266
1186
|
var template = handlebars.compile(html);
|
267
1187
|
|
268
1188
|
var baseScope = JSON.parse(JSON.stringify(that));
|
269
|
-
delete baseScope.
|
1189
|
+
delete baseScope.pass;
|
270
1190
|
|
271
1191
|
var replacements = {
|
272
|
-
|
1192
|
+
request: request,
|
273
1193
|
project: project.toJSON(),
|
274
1194
|
tokenQueryString: tokenQueryString,
|
275
1195
|
baseScope: baseScope
|
@@ -279,90 +1199,92 @@ class EmailService {
|
|
279
1199
|
winston.debug("html: " + html);
|
280
1200
|
|
281
1201
|
|
282
|
-
|
283
|
-
|
1202
|
+
// if (message.request && message.request.lead && message.request.lead.email) {
|
1203
|
+
// winston.info("message.request.lead.email: " + message.request.lead.email);
|
1204
|
+
// replyTo = replyTo + ", "+ request.lead.email;
|
1205
|
+
// }
|
1206
|
+
|
1207
|
+
|
1208
|
+
that.send({to:to, replyTo: replyTo, subject:`R: ${request ? request.subject : '-'}`, text:html }); //html:html
|
1209
|
+
that.send({to: that.bcc, replyTo: replyTo, subject: `R: ${request ? request.subject : '-'} - notification`, text:html});//html:html
|
284
1210
|
|
285
1211
|
});
|
286
1212
|
}
|
287
|
-
|
288
|
-
|
1213
|
+
*/
|
289
1214
|
|
290
1215
|
// ok
|
291
|
-
sendPasswordResetRequestEmail(to, resetPswRequestId, userFirstname, userLastname) {
|
1216
|
+
async sendPasswordResetRequestEmail(to, resetPswRequestId, userFirstname, userLastname) {
|
292
1217
|
|
293
1218
|
var that = this;
|
294
1219
|
|
295
|
-
this.
|
1220
|
+
var html = await this.readTemplate('resetPassword.html', project.settings);
|
296
1221
|
|
297
1222
|
|
298
|
-
|
299
|
-
|
1223
|
+
var envTemplate = process.env.EMAIL_RESET_PASSWORD_HTML_TEMPLATE;
|
1224
|
+
winston.debug("envTemplate: " + envTemplate);
|
300
1225
|
|
301
|
-
|
302
|
-
|
303
|
-
|
1226
|
+
if (envTemplate) {
|
1227
|
+
html = envTemplate;
|
1228
|
+
}
|
304
1229
|
|
305
|
-
|
1230
|
+
winston.debug("html: " + html);
|
306
1231
|
|
307
|
-
|
1232
|
+
var template = handlebars.compile(html);
|
308
1233
|
|
309
|
-
|
310
|
-
|
1234
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1235
|
+
delete baseScope.pass;
|
311
1236
|
|
312
1237
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
1238
|
+
var replacements = {
|
1239
|
+
resetPswRequestId: resetPswRequestId,
|
1240
|
+
userFirstname: userFirstname,
|
1241
|
+
userLastname: userLastname,
|
1242
|
+
baseScope: baseScope
|
1243
|
+
};
|
319
1244
|
|
320
|
-
|
1245
|
+
var html = template(replacements);
|
321
1246
|
|
322
1247
|
|
323
|
-
|
324
|
-
|
1248
|
+
that.send({to: to, subject: '[TileDesk] Password reset request', html:html});
|
1249
|
+
that.send({to:that.bcc, subject: '[TileDesk] Password reset request - notification', html:html });
|
325
1250
|
|
326
|
-
});
|
327
1251
|
}
|
328
1252
|
|
329
1253
|
// ok
|
330
|
-
sendYourPswHasBeenChangedEmail(to, userFirstname, userLastname) {
|
1254
|
+
async sendYourPswHasBeenChangedEmail(to, userFirstname, userLastname) {
|
331
1255
|
|
332
1256
|
var that = this;
|
333
1257
|
|
334
|
-
this.
|
1258
|
+
var html = await this.readTemplateFile('passwordChanged.html');
|
335
1259
|
|
336
1260
|
|
337
|
-
|
338
|
-
|
1261
|
+
var envTemplate = process.env.EMAIL_PASSWORD_CHANGED_HTML_TEMPLATE;
|
1262
|
+
winston.debug("envTemplate: " + envTemplate);
|
339
1263
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
winston.debug("html: " + html);
|
1264
|
+
if (envTemplate) {
|
1265
|
+
html = envTemplate;
|
1266
|
+
}
|
345
1267
|
|
346
|
-
|
1268
|
+
winston.debug("html: " + html);
|
347
1269
|
|
348
|
-
|
349
|
-
delete baseScope.emailPassword;
|
1270
|
+
var template = handlebars.compile(html);
|
350
1271
|
|
1272
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1273
|
+
delete baseScope.pass;
|
351
1274
|
|
352
|
-
var replacements = {
|
353
|
-
userFirstname: userFirstname,
|
354
|
-
userLastname: userLastname,
|
355
|
-
to: to,
|
356
|
-
baseScope: baseScope
|
357
|
-
};
|
358
1275
|
|
359
|
-
|
1276
|
+
var replacements = {
|
1277
|
+
userFirstname: userFirstname,
|
1278
|
+
userLastname: userLastname,
|
1279
|
+
to: to,
|
1280
|
+
baseScope: baseScope
|
1281
|
+
};
|
360
1282
|
|
1283
|
+
var html = template(replacements);
|
361
1284
|
|
362
|
-
that.send(to, '[TileDesk] Your password has been changed', html);
|
363
|
-
that.send(that.bcc, '[TileDesk] Your password has been changed', html);
|
364
1285
|
|
365
|
-
});
|
1286
|
+
that.send({to: to, subject:'[TileDesk] Your password has been changed', html:html });
|
1287
|
+
that.send({to: that.bcc, subject: '[TileDesk] Your password has been changed - notification', html: html });
|
366
1288
|
|
367
1289
|
}
|
368
1290
|
|
@@ -373,46 +1295,43 @@ class EmailService {
|
|
373
1295
|
/**
|
374
1296
|
*! *** EMAIL: YOU HAVE BEEN INVITED AT THE PROJECT ***
|
375
1297
|
*/
|
376
|
-
|
1298
|
+
async sendYouHaveBeenInvited(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserFirstname, invitedUserLastname, invitedUserRole) {
|
377
1299
|
|
378
1300
|
var that = this;
|
379
1301
|
|
380
|
-
this.
|
381
|
-
|
382
|
-
|
383
|
-
var envTemplate = process.env.EMAIL_EXUSER_INVITED_HTML_TEMPLATE;
|
384
|
-
winston.debug("envTemplate: " + envTemplate);
|
1302
|
+
var html = await this.readTemplateFile('passwordChanged.html');
|
385
1303
|
|
386
|
-
|
387
|
-
|
388
|
-
}
|
1304
|
+
var envTemplate = process.env.EMAIL_EXUSER_INVITED_HTML_TEMPLATE;
|
1305
|
+
winston.debug("envTemplate: " + envTemplate);
|
389
1306
|
|
390
|
-
|
1307
|
+
if (envTemplate) {
|
1308
|
+
html = envTemplate;
|
1309
|
+
}
|
391
1310
|
|
392
|
-
|
1311
|
+
winston.debug("html: " + html);
|
393
1312
|
|
394
|
-
|
395
|
-
delete baseScope.emailPassword;
|
1313
|
+
var template = handlebars.compile(html);
|
396
1314
|
|
1315
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1316
|
+
delete baseScope.pass;
|
397
1317
|
|
398
|
-
var replacements = {
|
399
|
-
currentUserFirstname: currentUserFirstname,
|
400
|
-
currentUserLastname: currentUserLastname,
|
401
|
-
projectName: projectName,
|
402
|
-
id_project: id_project,
|
403
|
-
invitedUserFirstname: invitedUserFirstname,
|
404
|
-
invitedUserLastname: invitedUserLastname,
|
405
|
-
invitedUserRole: invitedUserRole,
|
406
|
-
baseScope: baseScope
|
407
|
-
};
|
408
1318
|
|
409
|
-
|
1319
|
+
var replacements = {
|
1320
|
+
currentUserFirstname: currentUserFirstname,
|
1321
|
+
currentUserLastname: currentUserLastname,
|
1322
|
+
projectName: projectName,
|
1323
|
+
id_project: id_project,
|
1324
|
+
invitedUserFirstname: invitedUserFirstname,
|
1325
|
+
invitedUserLastname: invitedUserLastname,
|
1326
|
+
invitedUserRole: invitedUserRole,
|
1327
|
+
baseScope: baseScope
|
1328
|
+
};
|
410
1329
|
|
1330
|
+
var html = template(replacements);
|
411
1331
|
|
412
|
-
that.send(to, `[TileDesk] You have been invited to the '${projectName}' project`, html);
|
413
|
-
that.send(that.bcc, `[TileDesk] You have been invited to the '${projectName}' project`, html);
|
414
1332
|
|
415
|
-
});
|
1333
|
+
that.send({to:to, subject: `[TileDesk] You have been invited to the '${projectName}' project`, html:html});
|
1334
|
+
that.send({to: that.bcc, subject: `[TileDesk] You have been invited to the '${projectName}' project - notification`, html: html});
|
416
1335
|
}
|
417
1336
|
|
418
1337
|
// ok
|
@@ -421,83 +1340,82 @@ class EmailService {
|
|
421
1340
|
/**
|
422
1341
|
*! *** EMAIL: YOU HAVE BEEN INVITED AT THE PROJECT (USER NOT REGISTERED) ***
|
423
1342
|
*/
|
424
|
-
|
1343
|
+
async sendInvitationEmail_UserNotRegistered(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserRole, pendinginvitationid) {
|
425
1344
|
|
426
1345
|
|
427
1346
|
var that = this;
|
428
1347
|
|
429
|
-
this.
|
430
|
-
|
1348
|
+
var html = await this.readTemplateFile('passwordChanged.html');
|
431
1349
|
|
432
|
-
|
433
|
-
|
1350
|
+
var envTemplate = process.env.EMAIL_NEWUSER_INVITED_HTML_TEMPLATE;
|
1351
|
+
winston.debug("envTemplate: " + envTemplate);
|
434
1352
|
|
435
|
-
|
436
|
-
|
437
|
-
|
1353
|
+
if (envTemplate) {
|
1354
|
+
html = envTemplate;
|
1355
|
+
}
|
438
1356
|
|
439
|
-
|
1357
|
+
winston.debug("html: " + html);
|
440
1358
|
|
441
|
-
|
1359
|
+
var template = handlebars.compile(html);
|
442
1360
|
|
443
|
-
|
444
|
-
|
1361
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1362
|
+
delete baseScope.pass;
|
445
1363
|
|
446
1364
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
1365
|
+
var replacements = {
|
1366
|
+
currentUserFirstname: currentUserFirstname,
|
1367
|
+
currentUserLastname: currentUserLastname,
|
1368
|
+
projectName: projectName,
|
1369
|
+
id_project: id_project,
|
1370
|
+
invitedUserRole: invitedUserRole,
|
1371
|
+
pendinginvitationid: pendinginvitationid,
|
1372
|
+
baseScope: baseScope
|
1373
|
+
};
|
456
1374
|
|
457
|
-
|
1375
|
+
var html = template(replacements);
|
458
1376
|
|
459
|
-
|
460
|
-
|
1377
|
+
that.send({to:to, subject: `[TileDesk] You have been invited to the '${projectName}' project`, html:html });
|
1378
|
+
that.send({to: that.bcc, subject: `[TileDesk] You have been invited to the '${projectName}' project - notification`, html: html});
|
461
1379
|
|
462
|
-
});
|
463
1380
|
}
|
464
1381
|
|
465
1382
|
// ok
|
466
|
-
sendVerifyEmailAddress(to, savedUser) {
|
1383
|
+
async sendVerifyEmailAddress(to, savedUser) {
|
467
1384
|
|
468
1385
|
|
469
1386
|
var that = this;
|
470
1387
|
|
471
|
-
|
472
|
-
|
1388
|
+
if (savedUser.toJSON) {
|
1389
|
+
savedUser = savedUser.toJSON();
|
1390
|
+
}
|
1391
|
+
var html = await this.readTemplateFile('verify.html');
|
473
1392
|
|
474
|
-
|
475
|
-
|
1393
|
+
var envTemplate = process.env.EMAIL_VERIFY_HTML_TEMPLATE;
|
1394
|
+
winston.debug("envTemplate: " + envTemplate);
|
476
1395
|
|
477
|
-
|
478
|
-
|
479
|
-
|
1396
|
+
if (envTemplate) {
|
1397
|
+
html = envTemplate;
|
1398
|
+
}
|
480
1399
|
|
481
|
-
|
1400
|
+
winston.debug("html: " + html);
|
482
1401
|
|
483
|
-
|
1402
|
+
var template = handlebars.compile(html);
|
484
1403
|
|
485
|
-
|
486
|
-
|
1404
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1405
|
+
delete baseScope.pass;
|
487
1406
|
|
488
1407
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
1408
|
+
var replacements = {
|
1409
|
+
savedUser: savedUser,
|
1410
|
+
baseScope: baseScope
|
1411
|
+
};
|
493
1412
|
|
494
|
-
|
1413
|
+
var html = template(replacements);
|
495
1414
|
|
496
1415
|
|
497
|
-
|
498
|
-
|
1416
|
+
that.send({to: to, subject: `[TileDesk] Verify your email address`, html:html });
|
1417
|
+
that.send({to: that.bcc, subject: `[TileDesk] Verify your email address `+to + " - notification", html:html });
|
499
1418
|
|
500
|
-
});
|
501
1419
|
}
|
502
1420
|
|
503
1421
|
|
@@ -508,7 +1426,17 @@ class EmailService {
|
|
508
1426
|
|
509
1427
|
// ok
|
510
1428
|
|
511
|
-
|
1429
|
+
async sendRequestTranscript(to, messages, request, project) {
|
1430
|
+
|
1431
|
+
|
1432
|
+
//if the request came from rabbit mq?
|
1433
|
+
if (request.toJSON) {
|
1434
|
+
request = request.toJSON();
|
1435
|
+
}
|
1436
|
+
|
1437
|
+
// if (project.toJSON) {
|
1438
|
+
// project = project.toJSON();
|
1439
|
+
// }
|
512
1440
|
|
513
1441
|
var transcriptAsHtml = ""; //https://handlebarsjs.com/guide/expressions.html#html-escaping
|
514
1442
|
messages.forEach(message => {
|
@@ -520,41 +1448,42 @@ class EmailService {
|
|
520
1448
|
|
521
1449
|
var that = this;
|
522
1450
|
|
523
|
-
this.
|
524
|
-
|
525
|
-
|
526
|
-
var envTemplate = process.env.EMAIL_SEND_TRANSCRIPT_HTML_TEMPLATE;
|
527
|
-
winston.debug("envTemplate: " + envTemplate);
|
528
|
-
|
529
|
-
if (envTemplate) {
|
530
|
-
html = envTemplate;
|
531
|
-
}
|
1451
|
+
var html = await this.readTemplate('sendTranscript.html', project.settings);
|
532
1452
|
|
533
|
-
|
1453
|
+
var envTemplate = process.env.EMAIL_SEND_TRANSCRIPT_HTML_TEMPLATE;
|
1454
|
+
winston.debug("envTemplate: " + envTemplate);
|
534
1455
|
|
535
|
-
|
1456
|
+
if (envTemplate) {
|
1457
|
+
html = envTemplate;
|
1458
|
+
}
|
536
1459
|
|
537
|
-
|
538
|
-
delete baseScope.emailPassword;
|
1460
|
+
winston.debug("html: " + html);
|
539
1461
|
|
1462
|
+
var template = handlebars.compile(html);
|
540
1463
|
|
541
|
-
|
542
|
-
|
543
|
-
request: request.toJSON(),
|
544
|
-
formattedCreatedAt: request.createdAt.toLocaleString('en', { timeZone: 'UTC' }),
|
545
|
-
transcriptAsHtml: transcriptAsHtml,
|
546
|
-
baseScope: baseScope
|
547
|
-
};
|
1464
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1465
|
+
delete baseScope.pass;
|
548
1466
|
|
549
|
-
var html = template(replacements);
|
550
1467
|
|
1468
|
+
var replacements = {
|
1469
|
+
messages: messages,
|
1470
|
+
request: request,
|
1471
|
+
formattedCreatedAt: request.createdAt.toLocaleString('en', { timeZone: 'UTC' }),
|
1472
|
+
transcriptAsHtml: transcriptAsHtml,
|
1473
|
+
baseScope: baseScope
|
1474
|
+
};
|
551
1475
|
|
1476
|
+
var html = template(replacements);
|
552
1477
|
|
553
|
-
|
554
|
-
|
1478
|
+
let configEmail;
|
1479
|
+
if (project && project.settings && project.settings.email && project.settings.email.config) {
|
1480
|
+
configEmail = project.settings.email.config;
|
1481
|
+
winston.verbose("custom email setting found: ", configEmail);
|
1482
|
+
}
|
555
1483
|
|
1484
|
+
that.send({to:to, subject: '[TileDesk] Transcript', html:html, config: configEmail});
|
1485
|
+
that.send({to: that.bcc, subject: '[TileDesk] Transcript - notification', html:html });
|
556
1486
|
|
557
|
-
});
|
558
1487
|
}
|
559
1488
|
|
560
1489
|
|
@@ -565,4 +1494,6 @@ class EmailService {
|
|
565
1494
|
|
566
1495
|
var emailService = new EmailService();
|
567
1496
|
|
1497
|
+
//emailService.sendTest("al@f21.it");
|
1498
|
+
|
568
1499
|
module.exports = emailService;
|