@tiledesk/tiledesk-server 2.1.41 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.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 +198 -1
- package/Dockerfile +1 -1
- package/Dockerfile-en +1 -1
- package/README.md +5 -7
- package/app.js +12 -1
- package/channels/chat21/chat21Contact.js +34 -8
- package/channels/chat21/chat21Handler.js +48 -5
- package/channels/chat21/chat21WebHook.js +34 -5
- package/channels/chat21/nativeauth.js +2 -2
- package/config/email.js +2 -1
- 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/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 +3 -3
- package/models/request.js +33 -3
- package/package.json +31 -28
- package/pubmodules/emailNotification/requestNotification.js +380 -62
- package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
- package/pubmodules/messageTransformer/index.js +1 -1
- package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
- package/pubmodules/pubModulesManager.js +66 -14
- package/pubmodules/rules/conciergeBot.js +81 -49
- package/routes/auth.js +34 -10
- package/routes/campaigns.js +117 -25
- package/routes/faq.js +19 -0
- package/routes/faq_kb.js +13 -4
- package/routes/faqpub.js +1 -1
- 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 +1103 -298
- package/services/faqBotHandler.js +176 -61
- package/services/faqBotSupport.js +181 -117
- package/services/faqService.js +17 -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 +78 -52
- package/template/email/ticket.txt +5 -1
- 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 +5 -5
- 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/template/email/ticket-taking.txt +0 -7
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,28 +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
|
|
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
|
49
78
|
this.replyTo = process.env.EMAIL_REPLY_TO || config.replyTo;
|
50
79
|
winston.info('EmailService replyTo address: '+ this.replyTo);
|
51
80
|
|
52
|
-
this.
|
53
|
-
winston.info('EmailService
|
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);
|
54
86
|
|
55
|
-
this.
|
87
|
+
this.pass = process.env.EMAIL_PASSWORD;
|
56
88
|
|
57
89
|
var maskedemailPassword;
|
58
|
-
if (this.
|
59
|
-
maskedemailPassword = MaskData.maskPhone(this.
|
90
|
+
if (this.pass) {
|
91
|
+
maskedemailPassword = MaskData.maskPhone(this.pass, maskOptions);
|
60
92
|
}else {
|
61
|
-
maskedemailPassword = this.
|
93
|
+
maskedemailPassword = this.pass;
|
62
94
|
}
|
63
95
|
|
64
|
-
winston.info('EmailService
|
96
|
+
winston.info('EmailService pass: ' + maskedemailPassword);
|
65
97
|
|
66
98
|
this.host = process.env.EMAIL_HOST || config.host;
|
67
99
|
winston.info('EmailService host: ' + this.host);
|
68
100
|
|
69
|
-
this.
|
70
|
-
winston.info('EmailService
|
101
|
+
this.secure = process.env.EMAIL_SECURE || false;
|
102
|
+
winston.info('EmailService secure: ' + this.secure);
|
71
103
|
|
72
104
|
this.user = process.env.EMAIL_USERNAME || config.username;
|
73
105
|
winston.info('EmailService username: ' + this.user);
|
@@ -75,42 +107,110 @@ class EmailService {
|
|
75
107
|
this.port = process.env.EMAIL_PORT;
|
76
108
|
winston.info('EmailService port: ' + this.port);
|
77
109
|
|
78
|
-
}
|
79
110
|
|
111
|
+
this.markdown = process.env.EMAIL_MARKDOWN || true;
|
112
|
+
winston.info('EmailService markdown: '+ this.markdown);
|
80
113
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
+
});
|
90
156
|
});
|
91
157
|
};
|
92
158
|
|
93
159
|
|
94
|
-
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
|
+
}
|
95
174
|
|
175
|
+
winston.debug("getTransport configEmail: "+ JSON.stringify(configEmail));
|
96
176
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
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,
|
102
181
|
auth: {
|
103
|
-
user:
|
104
|
-
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
|
105
198
|
}
|
106
|
-
}
|
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);
|
107
205
|
return transporter;
|
108
206
|
}
|
109
207
|
|
110
|
-
|
111
|
-
|
112
|
-
}
|
113
|
-
|
208
|
+
// @deprecated
|
209
|
+
// send(to, subject, html) {
|
210
|
+
// return this.sendMail({to:to, subject:subject, html:html});
|
211
|
+
// }
|
212
|
+
|
213
|
+
send(mail) {
|
114
214
|
|
115
215
|
if (!this.enabled) {
|
116
216
|
winston.info('EmailService is disabled. Not sending email');
|
@@ -120,16 +220,22 @@ class EmailService {
|
|
120
220
|
return winston.warn("EmailService not sending email for testing");
|
121
221
|
}
|
122
222
|
|
123
|
-
|
124
|
-
|
125
223
|
let mailOptions = {
|
126
224
|
from: mail.from || this.from, // sender address
|
127
225
|
to: mail.to,
|
226
|
+
cc: mail.cc,
|
128
227
|
// bcc: config.bcc,
|
129
228
|
replyTo: mail.replyTo || this.replyTo,
|
229
|
+
inReplyTo: mail.inReplyTo,
|
230
|
+
references: mail.references,
|
130
231
|
subject: mail.subject, // Subject line
|
131
232
|
text: mail.text, // plain text body
|
132
|
-
html: mail.html
|
233
|
+
html: mail.html,
|
234
|
+
|
235
|
+
headers: mail.headers || this.headers,
|
236
|
+
|
237
|
+
messageId: mail.messageId,
|
238
|
+
sender: mail.sender
|
133
239
|
};
|
134
240
|
|
135
241
|
winston.debug('mailOptions', mailOptions);
|
@@ -139,11 +245,12 @@ class EmailService {
|
|
139
245
|
}
|
140
246
|
|
141
247
|
// send mail with defined transport object
|
142
|
-
this.getTransport().sendMail(mailOptions, (error, info) => {
|
248
|
+
this.getTransport(mail.config).sendMail(mailOptions, (error, info) => {
|
143
249
|
if (error) {
|
144
250
|
return winston.error("Error sending email ", {error:error, mailOptions:mailOptions});
|
145
251
|
}
|
146
|
-
winston.
|
252
|
+
winston.verbose('Email sent:', {info: info});
|
253
|
+
winston.debug('Email sent:', {info: info, mailOptions: mailOptions});
|
147
254
|
// Preview only available when sending through an Ethereal account
|
148
255
|
// winston.debug('Preview URL: %s', nodemailer.getTestMessageUrl(info));
|
149
256
|
|
@@ -153,215 +260,912 @@ class EmailService {
|
|
153
260
|
}
|
154
261
|
|
155
262
|
|
156
|
-
sendTest(to) {
|
263
|
+
async sendTest(to) {
|
157
264
|
|
158
265
|
var that = this;
|
159
266
|
|
160
|
-
this.readTemplateFile('test.html'
|
267
|
+
var html = await this.readTemplateFile('test.html');
|
161
268
|
|
162
|
-
|
269
|
+
var template = handlebars.compile(html);
|
163
270
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
271
|
+
var replacements = {
|
272
|
+
user: {name: "andrea"},
|
273
|
+
enabled: true
|
274
|
+
};
|
168
275
|
|
169
|
-
|
276
|
+
var html = template(replacements);
|
170
277
|
|
171
|
-
|
278
|
+
that.send({to:to, subject:`TileDesk test email`,html: html});
|
279
|
+
|
280
|
+
//that.send(that.bcc, `TileDesk test email - notification`, html);
|
172
281
|
|
173
|
-
that.send(that.bcc, `TileDesk test email - notification`, html);
|
174
282
|
|
175
|
-
});
|
176
|
-
|
177
283
|
|
178
284
|
|
179
285
|
}
|
180
286
|
|
181
287
|
|
182
|
-
|
183
|
-
sendNewAssignedRequestNotification(to,
|
288
|
+
|
289
|
+
async sendNewAssignedRequestNotification(to, request, project) {
|
184
290
|
|
185
291
|
var that = this;
|
186
292
|
|
187
|
-
|
293
|
+
//if the request came from rabbit mq?
|
294
|
+
if (request.toJSON) {
|
295
|
+
request = request.toJSON();
|
296
|
+
}
|
188
297
|
|
298
|
+
if (project.toJSON) {
|
299
|
+
project = project.toJSON();
|
300
|
+
}
|
189
301
|
|
190
|
-
|
191
|
-
winston.debug("envTemplate: " + envTemplate);
|
302
|
+
var html = await this.readTemplate('assignedRequest.html', project.settings);
|
192
303
|
|
193
|
-
|
194
|
-
|
195
|
-
}
|
304
|
+
var envTemplate = process.env.EMAIL_ASSIGN_REQUEST_HTML_TEMPLATE;
|
305
|
+
winston.debug("envTemplate: " + envTemplate);
|
196
306
|
|
197
|
-
|
307
|
+
if (envTemplate) {
|
308
|
+
html = envTemplate;
|
309
|
+
}
|
198
310
|
|
199
|
-
|
311
|
+
winston.debug("html: " + html);
|
200
312
|
|
201
|
-
|
202
|
-
|
313
|
+
var template = handlebars.compile(html);
|
314
|
+
|
315
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
316
|
+
delete baseScope.pass;
|
203
317
|
|
204
|
-
|
318
|
+
// passa anche tutti i messages in modo da stampare tutto
|
205
319
|
// Stampa anche contact.email
|
206
320
|
|
207
|
-
var replacements = {
|
208
|
-
savedRequest: savedRequest.toJSON(),
|
209
|
-
project: project.toJSON(),
|
210
|
-
baseScope: baseScope
|
211
|
-
};
|
212
321
|
|
213
|
-
|
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
|
+
};
|
214
340
|
|
215
|
-
|
216
|
-
winston.debug("html after: " + html);
|
341
|
+
winston.debug("replacements ", replacements);
|
217
342
|
|
343
|
+
var html = template(replacements);
|
344
|
+
winston.debug("html after: " + html);
|
218
345
|
|
219
|
-
|
346
|
+
|
347
|
+
let messageId = "notification" + "@" + MESSAGE_ID_DOMAIN;
|
220
348
|
|
221
|
-
|
349
|
+
let replyTo;
|
350
|
+
if (this.replyEnabled) { //fai anche per gli altri
|
351
|
+
replyTo = request.request_id + this.inboundDomainDomainWithAt;
|
352
|
+
}
|
222
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
|
223
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
|
+
|
224
438
|
|
225
439
|
}
|
226
440
|
|
227
|
-
|
228
|
-
|
441
|
+
|
442
|
+
async sendNewAssignedAgentMessageEmailNotification(to, request, project, message) {
|
229
443
|
|
230
444
|
var that = this;
|
231
445
|
|
232
|
-
|
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);
|
233
456
|
|
234
457
|
|
235
|
-
|
236
|
-
|
458
|
+
var envTemplate = process.env.EMAIL_ASSIGN_MESSAGE_EMAIL_HTML_TEMPLATE;
|
459
|
+
winston.debug("envTemplate: " + envTemplate);
|
237
460
|
|
238
|
-
|
239
|
-
|
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);
|
240
543
|
}
|
544
|
+
}
|
241
545
|
|
242
|
-
winston.debug("html: " + html);
|
243
546
|
|
244
|
-
|
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
|
+
|
245
560
|
|
246
|
-
|
247
|
-
|
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;
|
248
620
|
|
249
621
|
// passa anche tutti i messages in modo da stampare tutto
|
250
622
|
// Stampa anche contact.email
|
251
|
-
var replacements = {
|
252
|
-
savedRequest: savedRequest.toJSON(),
|
253
|
-
project: project.toJSON(),
|
254
|
-
baseScope: baseScope
|
255
|
-
};
|
256
623
|
|
257
|
-
|
624
|
+
let msgText = request.first_text;//.replace(/[\n\r]/g, '<br>');
|
625
|
+
msgText = encode(msgText);
|
626
|
+
if (this.markdown) {
|
627
|
+
msgText = marked(msgText);
|
628
|
+
}
|
258
629
|
|
630
|
+
winston.verbose("msgText: " + msgText);
|
259
631
|
|
260
|
-
|
261
|
-
|
632
|
+
var replacements = {
|
633
|
+
request: request,
|
634
|
+
project: project,
|
635
|
+
msgText: msgText,
|
636
|
+
baseScope: baseScope
|
637
|
+
};
|
638
|
+
|
639
|
+
var html = template(replacements);
|
262
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
|
+
}
|
657
|
+
|
658
|
+
headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": request.request_id, "X-TILEDESK-TICKET-ID":request.ticket_id };
|
659
|
+
|
660
|
+
winston.verbose("sendNewPooledRequestNotification messageId: " + messageId);
|
661
|
+
winston.verbose("sendNewPooledRequestNotification replyTo: " + replyTo);
|
662
|
+
winston.verbose("sendNewPooledRequestNotification email headers", headers);
|
663
|
+
}
|
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
|
263
715
|
});
|
716
|
+
// this.send(that.bcc, `[TileDesk ${project ? project.name : '-'}] New Pooled Request`, html);
|
717
|
+
|
264
718
|
}
|
265
719
|
|
266
720
|
|
267
|
-
|
721
|
+
|
722
|
+
|
723
|
+
|
724
|
+
async sendNewPooledMessageEmailNotification(to, request, project, message) {
|
268
725
|
|
269
726
|
var that = this;
|
270
727
|
|
271
|
-
|
728
|
+
|
729
|
+
//if the request came from rabbit mq?
|
730
|
+
if (request.toJSON) {
|
731
|
+
request = request.toJSON();
|
732
|
+
}
|
272
733
|
|
734
|
+
if (project.toJSON) {
|
735
|
+
project = project.toJSON();
|
736
|
+
}
|
273
737
|
|
274
|
-
|
275
|
-
winston.debug("envTemplate: " + envTemplate);
|
738
|
+
var html = await this.readTemplate('pooledEmailMessage.html', project.settings);
|
276
739
|
|
277
|
-
if (envTemplate) {
|
278
|
-
html = envTemplate;
|
279
|
-
}
|
280
740
|
|
281
|
-
|
741
|
+
var envTemplate = process.env.EMAIL_POOLED_MESSAGE_EMAIL_HTML_TEMPLATE;
|
742
|
+
winston.debug("envTemplate: " + envTemplate);
|
282
743
|
|
283
|
-
var template = handlebars.compile(html);
|
284
744
|
|
285
|
-
|
286
|
-
|
745
|
+
if (envTemplate) {
|
746
|
+
html = envTemplate;
|
747
|
+
}
|
287
748
|
|
288
|
-
|
289
|
-
message: message,
|
290
|
-
project: project.toJSON(),
|
291
|
-
tokenQueryString: tokenQueryString,
|
292
|
-
baseScope: baseScope
|
293
|
-
};
|
749
|
+
winston.debug("html: " + html);
|
294
750
|
|
295
|
-
|
296
|
-
winston.debug("html: " + html);
|
751
|
+
var template = handlebars.compile(html);
|
297
752
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
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);
|
302
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) {
|
303
934
|
|
935
|
+
messageId = message.request.request_id + "+" + messageId;
|
304
936
|
|
305
|
-
|
306
|
-
|
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 };
|
307
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
|
308
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
|
+
|
309
1003
|
}
|
310
1004
|
|
311
1005
|
|
312
1006
|
|
313
|
-
sendEmailChannelNotification(to, message, project, tokenQueryString) {
|
1007
|
+
async sendEmailChannelNotification(to, message, project, tokenQueryString, sourcePage) {
|
314
1008
|
|
315
1009
|
var that = this;
|
316
1010
|
|
317
|
-
this.readTemplateFile('ticket.txt', function(err, html) {
|
318
|
-
// this.readTemplateFile('ticket.html', function(err, html) {
|
319
1011
|
|
1012
|
+
if (project.toJSON) {
|
1013
|
+
project = project.toJSON();
|
1014
|
+
}
|
320
1015
|
|
321
|
-
|
322
|
-
|
1016
|
+
var html = await this.readTemplate('ticket.html', project.settings);
|
1017
|
+
// this.readTemplateFile('ticket.txt', function(err, html) {
|
323
1018
|
|
324
|
-
if (envTemplate) {
|
325
|
-
html = envTemplate;
|
326
|
-
}
|
327
1019
|
|
328
|
-
|
1020
|
+
var envTemplate = process.env.EMAIL_TICKET_HTML_TEMPLATE;
|
1021
|
+
winston.debug("envTemplate: " + envTemplate);
|
329
1022
|
|
330
|
-
|
1023
|
+
if (envTemplate) {
|
1024
|
+
html = envTemplate;
|
1025
|
+
}
|
331
1026
|
|
332
|
-
|
333
|
-
delete baseScope.emailPassword;
|
1027
|
+
winston.debug("html: " + html);
|
334
1028
|
|
335
|
-
|
336
|
-
message: message,
|
337
|
-
project: project.toJSON(),
|
338
|
-
tokenQueryString: tokenQueryString,
|
339
|
-
baseScope: baseScope
|
340
|
-
};
|
1029
|
+
var template = handlebars.compile(html);
|
341
1030
|
|
342
|
-
|
343
|
-
|
1031
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1032
|
+
delete baseScope.pass;
|
344
1033
|
|
345
|
-
let replyTo;
|
346
|
-
if (message.request) {
|
347
|
-
replyTo = message.request.request_id+"@"+that.replyToDomain;
|
348
|
-
winston.info("replyTo: " + replyTo);
|
349
|
-
}
|
350
1034
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
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) {
|
355
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
|
+
}
|
356
1125
|
|
357
|
-
that.sendMail({to:to, replyTo: replyTo, subject:`R: ${message.request ? message.request.subject : '-'}`, text:html }); //html:html
|
358
|
-
that.sendMail({to: config.bcc, replyTo: replyTo, subject: `R: ${message.request ? message.request.subject : '-'} - notification`, text:html});//html:html
|
359
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
|
360
1163
|
});
|
361
|
-
}
|
362
1164
|
|
1165
|
+
}
|
363
1166
|
|
364
1167
|
|
1168
|
+
/*
|
365
1169
|
sendEmailChannelTakingNotification(to, request, project, tokenQueryString) {
|
366
1170
|
|
367
1171
|
var that = this;
|
@@ -382,7 +1186,7 @@ class EmailService {
|
|
382
1186
|
var template = handlebars.compile(html);
|
383
1187
|
|
384
1188
|
var baseScope = JSON.parse(JSON.stringify(that));
|
385
|
-
delete baseScope.
|
1189
|
+
delete baseScope.pass;
|
386
1190
|
|
387
1191
|
var replacements = {
|
388
1192
|
request: request,
|
@@ -394,11 +1198,6 @@ class EmailService {
|
|
394
1198
|
var html = template(replacements);
|
395
1199
|
winston.debug("html: " + html);
|
396
1200
|
|
397
|
-
let replyTo;
|
398
|
-
if (request) {
|
399
|
-
replyTo = request.request_id+"@"+that.replyToDomain;
|
400
|
-
winston.info("replyTo: " + replyTo);
|
401
|
-
}
|
402
1201
|
|
403
1202
|
// if (message.request && message.request.lead && message.request.lead.email) {
|
404
1203
|
// winston.info("message.request.lead.email: " + message.request.lead.email);
|
@@ -406,89 +1205,86 @@ class EmailService {
|
|
406
1205
|
// }
|
407
1206
|
|
408
1207
|
|
409
|
-
that.
|
410
|
-
that.
|
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
|
411
1210
|
|
412
1211
|
});
|
413
1212
|
}
|
414
|
-
|
1213
|
+
*/
|
415
1214
|
|
416
1215
|
// ok
|
417
|
-
sendPasswordResetRequestEmail(to, resetPswRequestId, userFirstname, userLastname) {
|
1216
|
+
async sendPasswordResetRequestEmail(to, resetPswRequestId, userFirstname, userLastname) {
|
418
1217
|
|
419
1218
|
var that = this;
|
420
1219
|
|
421
|
-
this.
|
1220
|
+
var html = await this.readTemplate('resetPassword.html');
|
422
1221
|
|
423
1222
|
|
424
|
-
|
425
|
-
|
1223
|
+
var envTemplate = process.env.EMAIL_RESET_PASSWORD_HTML_TEMPLATE;
|
1224
|
+
winston.debug("envTemplate: " + envTemplate);
|
426
1225
|
|
427
|
-
|
428
|
-
|
429
|
-
|
1226
|
+
if (envTemplate) {
|
1227
|
+
html = envTemplate;
|
1228
|
+
}
|
430
1229
|
|
431
|
-
|
1230
|
+
winston.debug("html: " + html);
|
432
1231
|
|
433
|
-
|
1232
|
+
var template = handlebars.compile(html);
|
434
1233
|
|
435
|
-
|
436
|
-
|
1234
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1235
|
+
delete baseScope.pass;
|
437
1236
|
|
438
1237
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
1238
|
+
var replacements = {
|
1239
|
+
resetPswRequestId: resetPswRequestId,
|
1240
|
+
userFirstname: userFirstname,
|
1241
|
+
userLastname: userLastname,
|
1242
|
+
baseScope: baseScope
|
1243
|
+
};
|
445
1244
|
|
446
|
-
|
1245
|
+
var html = template(replacements);
|
447
1246
|
|
448
1247
|
|
449
|
-
|
450
|
-
|
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 });
|
451
1250
|
|
452
|
-
});
|
453
1251
|
}
|
454
1252
|
|
455
1253
|
// ok
|
456
|
-
sendYourPswHasBeenChangedEmail(to, userFirstname, userLastname) {
|
1254
|
+
async sendYourPswHasBeenChangedEmail(to, userFirstname, userLastname) {
|
457
1255
|
|
458
1256
|
var that = this;
|
459
1257
|
|
460
|
-
this.readTemplateFile('passwordChanged.html'
|
1258
|
+
var html = await this.readTemplateFile('passwordChanged.html');
|
461
1259
|
|
462
1260
|
|
463
|
-
|
464
|
-
|
1261
|
+
var envTemplate = process.env.EMAIL_PASSWORD_CHANGED_HTML_TEMPLATE;
|
1262
|
+
winston.debug("envTemplate: " + envTemplate);
|
465
1263
|
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
winston.debug("html: " + html);
|
1264
|
+
if (envTemplate) {
|
1265
|
+
html = envTemplate;
|
1266
|
+
}
|
471
1267
|
|
472
|
-
|
1268
|
+
winston.debug("html: " + html);
|
473
1269
|
|
474
|
-
|
475
|
-
delete baseScope.emailPassword;
|
1270
|
+
var template = handlebars.compile(html);
|
476
1271
|
|
1272
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1273
|
+
delete baseScope.pass;
|
477
1274
|
|
478
|
-
var replacements = {
|
479
|
-
userFirstname: userFirstname,
|
480
|
-
userLastname: userLastname,
|
481
|
-
to: to,
|
482
|
-
baseScope: baseScope
|
483
|
-
};
|
484
1275
|
|
485
|
-
|
1276
|
+
var replacements = {
|
1277
|
+
userFirstname: userFirstname,
|
1278
|
+
userLastname: userLastname,
|
1279
|
+
to: to,
|
1280
|
+
baseScope: baseScope
|
1281
|
+
};
|
486
1282
|
|
1283
|
+
var html = template(replacements);
|
487
1284
|
|
488
|
-
that.send(to, '[TileDesk] Your password has been changed', html);
|
489
|
-
that.send(that.bcc, '[TileDesk] Your password has been changed - notification', html);
|
490
1285
|
|
491
|
-
});
|
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 });
|
492
1288
|
|
493
1289
|
}
|
494
1290
|
|
@@ -499,46 +1295,43 @@ class EmailService {
|
|
499
1295
|
/**
|
500
1296
|
*! *** EMAIL: YOU HAVE BEEN INVITED AT THE PROJECT ***
|
501
1297
|
*/
|
502
|
-
|
1298
|
+
async sendYouHaveBeenInvited(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserFirstname, invitedUserLastname, invitedUserRole) {
|
503
1299
|
|
504
1300
|
var that = this;
|
505
1301
|
|
506
|
-
this.readTemplateFile('beenInvitedExistingUser.html'
|
1302
|
+
var html = await this.readTemplateFile('beenInvitedExistingUser.html');
|
507
1303
|
|
1304
|
+
var envTemplate = process.env.EMAIL_EXUSER_INVITED_HTML_TEMPLATE;
|
1305
|
+
winston.debug("envTemplate: " + envTemplate);
|
508
1306
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
if (envTemplate) {
|
513
|
-
html = envTemplate;
|
514
|
-
}
|
515
|
-
|
516
|
-
winston.debug("html: " + html);
|
1307
|
+
if (envTemplate) {
|
1308
|
+
html = envTemplate;
|
1309
|
+
}
|
517
1310
|
|
518
|
-
|
1311
|
+
winston.debug("html: " + html);
|
519
1312
|
|
520
|
-
|
521
|
-
delete baseScope.emailPassword;
|
1313
|
+
var template = handlebars.compile(html);
|
522
1314
|
|
1315
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1316
|
+
delete baseScope.pass;
|
523
1317
|
|
524
|
-
var replacements = {
|
525
|
-
currentUserFirstname: currentUserFirstname,
|
526
|
-
currentUserLastname: currentUserLastname,
|
527
|
-
projectName: projectName,
|
528
|
-
id_project: id_project,
|
529
|
-
invitedUserFirstname: invitedUserFirstname,
|
530
|
-
invitedUserLastname: invitedUserLastname,
|
531
|
-
invitedUserRole: invitedUserRole,
|
532
|
-
baseScope: baseScope
|
533
|
-
};
|
534
1318
|
|
535
|
-
|
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
|
+
};
|
536
1329
|
|
1330
|
+
var html = template(replacements);
|
537
1331
|
|
538
|
-
that.send(to, `[TileDesk] You have been invited to the '${projectName}' project`, html);
|
539
|
-
that.send(that.bcc, `[TileDesk] You have been invited to the '${projectName}' project - notification`, html);
|
540
1332
|
|
541
|
-
});
|
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});
|
542
1335
|
}
|
543
1336
|
|
544
1337
|
// ok
|
@@ -547,83 +1340,82 @@ class EmailService {
|
|
547
1340
|
/**
|
548
1341
|
*! *** EMAIL: YOU HAVE BEEN INVITED AT THE PROJECT (USER NOT REGISTERED) ***
|
549
1342
|
*/
|
550
|
-
|
1343
|
+
async sendInvitationEmail_UserNotRegistered(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserRole, pendinginvitationid) {
|
551
1344
|
|
552
1345
|
|
553
1346
|
var that = this;
|
554
1347
|
|
555
|
-
this.readTemplateFile('beenInvitedNewUser.html'
|
1348
|
+
var html = await this.readTemplateFile('beenInvitedNewUser.html');
|
556
1349
|
|
1350
|
+
var envTemplate = process.env.EMAIL_NEWUSER_INVITED_HTML_TEMPLATE;
|
1351
|
+
winston.debug("envTemplate: " + envTemplate);
|
557
1352
|
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
if (envTemplate) {
|
562
|
-
html = envTemplate;
|
563
|
-
}
|
1353
|
+
if (envTemplate) {
|
1354
|
+
html = envTemplate;
|
1355
|
+
}
|
564
1356
|
|
565
|
-
|
1357
|
+
winston.debug("html: " + html);
|
566
1358
|
|
567
|
-
|
1359
|
+
var template = handlebars.compile(html);
|
568
1360
|
|
569
|
-
|
570
|
-
|
1361
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1362
|
+
delete baseScope.pass;
|
571
1363
|
|
572
1364
|
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
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
|
+
};
|
582
1374
|
|
583
|
-
|
1375
|
+
var html = template(replacements);
|
584
1376
|
|
585
|
-
|
586
|
-
|
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});
|
587
1379
|
|
588
|
-
});
|
589
1380
|
}
|
590
1381
|
|
591
1382
|
// ok
|
592
|
-
sendVerifyEmailAddress(to, savedUser) {
|
1383
|
+
async sendVerifyEmailAddress(to, savedUser) {
|
593
1384
|
|
594
1385
|
|
595
1386
|
var that = this;
|
596
1387
|
|
597
|
-
|
598
|
-
|
1388
|
+
if (savedUser.toJSON) {
|
1389
|
+
savedUser = savedUser.toJSON();
|
1390
|
+
}
|
1391
|
+
var html = await this.readTemplateFile('verify.html');
|
599
1392
|
|
600
|
-
|
601
|
-
|
1393
|
+
var envTemplate = process.env.EMAIL_VERIFY_HTML_TEMPLATE;
|
1394
|
+
winston.debug("envTemplate: " + envTemplate);
|
602
1395
|
|
603
|
-
|
604
|
-
|
605
|
-
|
1396
|
+
if (envTemplate) {
|
1397
|
+
html = envTemplate;
|
1398
|
+
}
|
606
1399
|
|
607
|
-
|
1400
|
+
winston.debug("html: " + html);
|
608
1401
|
|
609
|
-
|
1402
|
+
var template = handlebars.compile(html);
|
610
1403
|
|
611
|
-
|
612
|
-
|
1404
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1405
|
+
delete baseScope.pass;
|
613
1406
|
|
614
1407
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
1408
|
+
var replacements = {
|
1409
|
+
savedUser: savedUser,
|
1410
|
+
baseScope: baseScope
|
1411
|
+
};
|
619
1412
|
|
620
|
-
|
1413
|
+
var html = template(replacements);
|
621
1414
|
|
622
1415
|
|
623
|
-
|
624
|
-
|
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 });
|
625
1418
|
|
626
|
-
});
|
627
1419
|
}
|
628
1420
|
|
629
1421
|
|
@@ -634,7 +1426,17 @@ class EmailService {
|
|
634
1426
|
|
635
1427
|
// ok
|
636
1428
|
|
637
|
-
|
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
|
+
// }
|
638
1440
|
|
639
1441
|
var transcriptAsHtml = ""; //https://handlebarsjs.com/guide/expressions.html#html-escaping
|
640
1442
|
messages.forEach(message => {
|
@@ -646,41 +1448,42 @@ class EmailService {
|
|
646
1448
|
|
647
1449
|
var that = this;
|
648
1450
|
|
649
|
-
this.
|
650
|
-
|
651
|
-
|
652
|
-
var envTemplate = process.env.EMAIL_SEND_TRANSCRIPT_HTML_TEMPLATE;
|
653
|
-
winston.debug("envTemplate: " + envTemplate);
|
654
|
-
|
655
|
-
if (envTemplate) {
|
656
|
-
html = envTemplate;
|
657
|
-
}
|
1451
|
+
var html = await this.readTemplate('sendTranscript.html', project.settings);
|
658
1452
|
|
659
|
-
|
1453
|
+
var envTemplate = process.env.EMAIL_SEND_TRANSCRIPT_HTML_TEMPLATE;
|
1454
|
+
winston.debug("envTemplate: " + envTemplate);
|
660
1455
|
|
661
|
-
|
1456
|
+
if (envTemplate) {
|
1457
|
+
html = envTemplate;
|
1458
|
+
}
|
662
1459
|
|
663
|
-
|
664
|
-
delete baseScope.emailPassword;
|
1460
|
+
winston.debug("html: " + html);
|
665
1461
|
|
1462
|
+
var template = handlebars.compile(html);
|
666
1463
|
|
667
|
-
|
668
|
-
|
669
|
-
request: request.toJSON(),
|
670
|
-
formattedCreatedAt: request.createdAt.toLocaleString('en', { timeZone: 'UTC' }),
|
671
|
-
transcriptAsHtml: transcriptAsHtml,
|
672
|
-
baseScope: baseScope
|
673
|
-
};
|
1464
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
1465
|
+
delete baseScope.pass;
|
674
1466
|
|
675
|
-
var html = template(replacements);
|
676
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
|
+
};
|
677
1475
|
|
1476
|
+
var html = template(replacements);
|
678
1477
|
|
679
|
-
|
680
|
-
|
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
|
+
}
|
681
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 });
|
682
1486
|
|
683
|
-
});
|
684
1487
|
}
|
685
1488
|
|
686
1489
|
|
@@ -691,4 +1494,6 @@ class EmailService {
|
|
691
1494
|
|
692
1495
|
var emailService = new EmailService();
|
693
1496
|
|
1497
|
+
//emailService.sendTest("al@f21.it");
|
1498
|
+
|
694
1499
|
module.exports = emailService;
|