@tiledesk/tiledesk-server 2.4.99 → 2.4.101

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,9 @@ var winston = require('../config/winston');
7
7
  var marked = require('marked');
8
8
  var handlebars = require('handlebars');
9
9
  var encode = require('html-entities').encode;
10
+ const emailEvent = require('../event/emailEvent');
10
11
 
11
- handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
12
+ handlebars.registerHelper('ifEquals', function (arg1, arg2, options) {
12
13
  return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
13
14
  });
14
15
 
@@ -33,14 +34,14 @@ const MaskData = require("maskdata");
33
34
 
34
35
  const maskOptions = {
35
36
  // Character to mask the data. default value is '*'
36
- maskWith : "*",
37
+ maskWith: "*",
37
38
  // If the starting 'n' digits needs to be unmasked
38
39
  // Default value is 4
39
- unmaskedStartDigits : 3, //Should be positive Integer
40
+ unmaskedStartDigits: 3, //Should be positive Integer
40
41
  //If the ending 'n' digits needs to be unmasked
41
42
  // Default value is 1
42
- unmaskedEndDigits : 3 // Should be positive Integer
43
- };
43
+ unmaskedEndDigits: 3 // Should be positive Integer
44
+ };
44
45
 
45
46
  // const X_REQUEST_ID_HEADER_KEY = "X-TILEDESK-REQUEST-ID";
46
47
  // const X_TICKET_ID_HEADER_KEY = "X-TILEDESK-TICKET-ID";
@@ -55,46 +56,46 @@ class EmailService {
55
56
  constructor() {
56
57
 
57
58
  this.enabled = false;
58
- if (process.env.EMAIL_ENABLED ==="true" || process.env.EMAIL_ENABLED === true ) {
59
+ if (process.env.EMAIL_ENABLED === "true" || process.env.EMAIL_ENABLED === true) {
59
60
  this.enabled = true;
60
61
  }
61
62
 
62
- winston.info('EmailService enabled: '+ this.enabled);
63
+ winston.info('EmailService enabled: ' + this.enabled);
63
64
 
64
65
  this.baseUrl = process.env.EMAIL_BASEURL || config.baseUrl;
65
- winston.info('EmailService baseUrl: '+ this.baseUrl);
66
-
66
+ winston.info('EmailService baseUrl: ' + this.baseUrl);
67
+
67
68
  this.apiUrl = process.env.API_URL || configGlobal.apiUrl;
68
- winston.info('EmailService apiUrl: '+ this.apiUrl);
69
+ winston.info('EmailService apiUrl: ' + this.apiUrl);
69
70
 
70
71
  this.from = process.env.EMAIL_FROM_ADDRESS || config.from;
71
- winston.info('EmailService from email: '+ this.from);
72
+ winston.info('EmailService from email: ' + this.from);
72
73
 
73
74
  this.bcc = process.env.EMAIL_BCC || config.bcc;
74
- winston.info('EmailService bcc address: '+ this.bcc);
75
+ winston.info('EmailService bcc address: ' + this.bcc);
75
76
 
76
77
  this.replyEnabled = config.replyEnabled;
77
- if (process.env.EMAIL_REPLY_ENABLED === "true" || process.env.EMAIL_REPLY_ENABLED === true ) {
78
+ if (process.env.EMAIL_REPLY_ENABLED === "true" || process.env.EMAIL_REPLY_ENABLED === true) {
78
79
  this.replyEnabled = true;
79
80
  }
80
- winston.info('EmailService replyEnabled : '+ this.replyEnabled);
81
+ winston.info('EmailService replyEnabled : ' + this.replyEnabled);
81
82
 
82
83
  // this is used as fixed reply to url, but this is unused we always return support-group-dynamic
83
84
  this.replyTo = process.env.EMAIL_REPLY_TO || config.replyTo;
84
- winston.info('EmailService replyTo address: '+ this.replyTo);
85
+ winston.info('EmailService replyTo address: ' + this.replyTo);
85
86
 
86
- this.inboundDomain = process.env.EMAIL_INBOUND_DOMAIN || config.inboundDomain;
87
- winston.info('EmailService inboundDomain : '+ this.inboundDomain);
88
-
89
- this.inboundDomainDomainWithAt = "@"+this.inboundDomain;
90
- winston.verbose('EmailService inboundDomainDomainWithAt : '+ this.inboundDomainDomainWithAt);
87
+ this.inboundDomain = process.env.EMAIL_INBOUND_DOMAIN || config.inboundDomain;
88
+ winston.info('EmailService inboundDomain : ' + this.inboundDomain);
89
+
90
+ this.inboundDomainDomainWithAt = "@" + this.inboundDomain;
91
+ winston.verbose('EmailService inboundDomainDomainWithAt : ' + this.inboundDomainDomainWithAt);
91
92
 
92
93
  this.pass = process.env.EMAIL_PASSWORD;
93
94
 
94
95
  var maskedemailPassword;
95
96
  if (this.pass) {
96
97
  maskedemailPassword = MaskData.maskPhone(this.pass, maskOptions);
97
- }else {
98
+ } else {
98
99
  maskedemailPassword = this.pass;
99
100
  }
100
101
 
@@ -103,26 +104,26 @@ class EmailService {
103
104
  this.host = process.env.EMAIL_HOST || config.host;
104
105
  winston.info('EmailService host: ' + this.host);
105
106
 
106
- this.secure = false;
107
- if (process.env.EMAIL_SECURE == "true" || process.env.EMAIL_SECURE ==true) {
108
- this.secure = true;
107
+ this.secure = false;
108
+ if (process.env.EMAIL_SECURE == "true" || process.env.EMAIL_SECURE == true) {
109
+ this.secure = true;
109
110
  }
110
111
  // this.secure = process.env.EMAIL_SECURE || false;
111
112
  winston.info('EmailService secure: ' + this.secure);
112
113
 
113
- this.user = process.env.EMAIL_USERNAME || config.username;
114
+ this.user = process.env.EMAIL_USERNAME || config.username;
114
115
  winston.info('EmailService username: ' + this.user);
115
116
 
116
- this.port = process.env.EMAIL_PORT; //default is 587
117
+ this.port = process.env.EMAIL_PORT; //default is 587
117
118
  winston.info('EmailService port: ' + this.port);
118
119
 
119
120
 
120
121
  this.markdown = true;
121
- if (process.env.EMAIL_MARKDOWN =="false" || process.env.EMAIL_MARKDOWN ==false) {
122
+ if (process.env.EMAIL_MARKDOWN == "false" || process.env.EMAIL_MARKDOWN == false) {
122
123
  this.markdown = false;
123
124
  }
124
125
  // this.markdown = process.env.EMAIL_MARKDOWN || true;
125
- winston.info('EmailService markdown: '+ this.markdown);
126
+ winston.info('EmailService markdown: ' + this.markdown);
126
127
 
127
128
  this.headers = {
128
129
  // "X-Mailer": "Tiledesk Mailer",
@@ -131,7 +132,7 @@ class EmailService {
131
132
 
132
133
  this.ccEnabled = false //cc creates loop when you send an email with cc: support@tiledesk.com -> Tiledesk generates an email with ticket id with in cc support@tiledesk.com that loop
133
134
 
134
- if (process.env.EMAIL_CC_ENABLED ==="true" || process.env.EMAIL_CC_ENABLED === true ) {
135
+ if (process.env.EMAIL_CC_ENABLED === "true" || process.env.EMAIL_CC_ENABLED === true) {
135
136
  this.ccEnabled = true;
136
137
  }
137
138
  winston.info('EmailService ccEnabled: ' + this.ccEnabled);
@@ -141,49 +142,49 @@ class EmailService {
141
142
  readTemplate(templateName, settings) {
142
143
  // aggiunsta questo
143
144
  var that = this;
144
- winston.debug('EmailService readTemplate: '+ templateName + ' ' + JSON.stringify(settings));
145
-
145
+ winston.debug('EmailService readTemplate: ' + templateName + ' ' + JSON.stringify(settings));
146
+
146
147
 
147
- if (settings && settings.email && settings.email.templates) {
148
+ if (settings && settings.email && settings.email.templates) {
148
149
 
149
- var templates = settings.email.templates;
150
- winston.debug('EmailService templates: ',templates);
150
+ var templates = settings.email.templates;
151
+ winston.debug('EmailService templates: ', templates);
151
152
 
152
- var templateDbName = templateName.replace(".html", "");
153
- winston.debug('EmailService templateDbName: '+templateDbName);
153
+ var templateDbName = templateName.replace(".html", "");
154
+ winston.debug('EmailService templateDbName: ' + templateDbName);
154
155
 
155
156
 
156
- var template = templates[templateDbName];
157
- winston.debug('EmailService template: '+template);
157
+ var template = templates[templateDbName];
158
+ winston.debug('EmailService template: ' + template);
158
159
 
159
- if (template) {
160
+ if (template) {
160
161
  // that.callback(template);
161
- return new Promise(function (resolve, reject) {
162
- return resolve(template);
163
- });
164
- }else {
165
- return that.readTemplateFile(templateName);
166
- }
162
+ return new Promise(function (resolve, reject) {
163
+ return resolve(template);
164
+ });
167
165
  } else {
168
166
  return that.readTemplateFile(templateName);
169
- }
167
+ }
168
+ } else {
169
+ return that.readTemplateFile(templateName);
170
+ }
170
171
  }
171
172
  readTemplateFile(templateName) {
172
173
  // var that = this;
173
174
  return new Promise(function (resolve, reject) {
174
- fs.readFile(appRoot + '/template/email/'+templateName, {encoding: 'utf-8'}, function (err, html) {
175
- if (err) {
176
- winston.error('error readTemplateFile getting ', err);
177
- // callback(err);
178
- return reject(err);
179
- }
180
- else {
181
- // callback(null, html);
182
- return resolve(html);
183
- }
184
- });
175
+ fs.readFile(appRoot + '/template/email/' + templateName, { encoding: 'utf-8' }, function (err, html) {
176
+ if (err) {
177
+ winston.error('error readTemplateFile getting ', err);
178
+ // callback(err);
179
+ return reject(err);
180
+ }
181
+ else {
182
+ // callback(null, html);
183
+ return resolve(html);
184
+ }
185
+ });
185
186
  });
186
- };
187
+ };
187
188
 
188
189
 
189
190
  getTransport(configEmail) {
@@ -192,21 +193,21 @@ class EmailService {
192
193
  configEmail = {
193
194
  host: this.host,
194
195
  port: this.port, // defaults to 587 if is secure is false or 465 if true
195
- secure: this.secure,
196
+ secure: this.secure,
196
197
  user: this.user,
197
- pass: this.pass
198
+ pass: this.pass
198
199
  }
199
200
  winston.debug("getTransport initialized with default");
200
201
  } else {
201
202
  winston.verbose("getTransport custom", configEmail);
202
203
  }
203
204
 
204
- winston.debug("getTransport configEmail: "+ JSON.stringify(configEmail));
205
+ winston.debug("getTransport configEmail: " + JSON.stringify(configEmail));
205
206
 
206
207
  let transport = {
207
208
  host: configEmail.host,
208
209
  port: configEmail.port, // defaults to 587 if is secure is false or 465 if true
209
- secure: configEmail.secure,
210
+ secure: configEmail.secure,
210
211
  auth: {
211
212
  user: configEmail.user,
212
213
  pass: configEmail.pass
@@ -216,11 +217,11 @@ class EmailService {
216
217
  // ciphers:'SSLv3'
217
218
  // },
218
219
 
219
- // openssl genrsa -out dkim_private.pem 2048
220
- // openssl rsa -in dkim_private.pem -pubout -outform der 2>/dev/null | openssl base64 -A
221
- // ->
222
- // v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunT2EopDAYnHwAOHd33KhlzjUXJfhmA+fK+cG85i9Pm33oyv1NoGrOynsni0PO6j7oRxxHqs6EMDOw4I/Q0C7aWn20oBomJZehTOkCV2xpuPKESiRktCe/MIZqbkRdypis4jSkFfFFkBHwgkAg5tb11E9elJap0ed/lN5/XlpGedqoypKxp+nEabgYO5mBMMNKRvbHx0eQttRYyIaNkTuMbAaqs4y3TkHOpGvZTJsvUonVMGAstSCfUmXnjF38aKpgyTausTSsxHbaxh3ieUB4ex+svnvsJ4Uh5Skklr+bxLVEHeJN55rxmV67ytLg5XCRWqdKIcJHFvSlm2YwJfcwIDAQABMacAL
223
- // testdkim._domainkey.tiledesk.com. 86400 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunT2EopDAYnHwAOHd33KhlzjUXJfhmA+fK+cG85i9Pm33oyv1NoGrOynsni0PO6j7oRxxHqs6EMDOw4I/Q0C7aWn20oBomJZehTOkCV2xpuPKESiRktCe/MIZqbkRdypis4jSkFfFFkBHwgkAg5tb11E9elJap0ed/lN5/XlpGedqoypKxp+nEabgYO5mBMMNKRvbHx0eQttRYyIaNkTuMbAaqs4y3TkHOpGvZTJsvUonVMGAstSCfUmXnjF38aKpgyTausTSsxHbaxh3ieUB4ex+svnvsJ4Uh5Skklr+bxLVEHeJN55rxmV67ytLg5XCRWqdKIcJHFvSlm2YwJfcwIDAQABMacAL"
220
+ // openssl genrsa -out dkim_private.pem 2048
221
+ // openssl rsa -in dkim_private.pem -pubout -outform der 2>/dev/null | openssl base64 -A
222
+ // ->
223
+ // v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunT2EopDAYnHwAOHd33KhlzjUXJfhmA+fK+cG85i9Pm33oyv1NoGrOynsni0PO6j7oRxxHqs6EMDOw4I/Q0C7aWn20oBomJZehTOkCV2xpuPKESiRktCe/MIZqbkRdypis4jSkFfFFkBHwgkAg5tb11E9elJap0ed/lN5/XlpGedqoypKxp+nEabgYO5mBMMNKRvbHx0eQttRYyIaNkTuMbAaqs4y3TkHOpGvZTJsvUonVMGAstSCfUmXnjF38aKpgyTausTSsxHbaxh3ieUB4ex+svnvsJ4Uh5Skklr+bxLVEHeJN55rxmV67ytLg5XCRWqdKIcJHFvSlm2YwJfcwIDAQABMacAL
224
+ // testdkim._domainkey.tiledesk.com. 86400 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunT2EopDAYnHwAOHd33KhlzjUXJfhmA+fK+cG85i9Pm33oyv1NoGrOynsni0PO6j7oRxxHqs6EMDOw4I/Q0C7aWn20oBomJZehTOkCV2xpuPKESiRktCe/MIZqbkRdypis4jSkFfFFkBHwgkAg5tb11E9elJap0ed/lN5/XlpGedqoypKxp+nEabgYO5mBMMNKRvbHx0eQttRYyIaNkTuMbAaqs4y3TkHOpGvZTJsvUonVMGAstSCfUmXnjF38aKpgyTausTSsxHbaxh3ieUB4ex+svnvsJ4Uh5Skklr+bxLVEHeJN55rxmV67ytLg5XCRWqdKIcJHFvSlm2YwJfcwIDAQABMacAL"
224
225
 
225
226
  // dkim: {
226
227
  // domainName: "example.com",
@@ -231,7 +232,7 @@ class EmailService {
231
232
  // }
232
233
  };
233
234
 
234
- winston.debug("getTransport transport: ",transport);
235
+ winston.debug("getTransport transport: ", transport);
235
236
 
236
237
  // create reusable transporter object using the default SMTP transport
237
238
  let transporter = nodemailer.createTransport(transport);
@@ -243,16 +244,32 @@ class EmailService {
243
244
  // return this.sendMail({to:to, subject:subject, html:html});
244
245
  // }
245
246
 
246
- send(mail) {
247
+ async send(mail, quoteEnabled, project, quoteManager) {
247
248
 
248
249
  if (!this.enabled) {
249
250
  winston.info('EmailService is disabled. Not sending email');
250
251
  return 0;
251
252
  }
252
- if (process.env.NODE_ENV == 'test') {
253
+ if (process.env.NODE_ENV == 'test') {
253
254
  return winston.warn("EmailService not sending email for testing");
254
255
  }
255
256
 
257
+ let payload = { project: project }
258
+ if (quoteEnabled && quoteEnabled === true) {
259
+ mail.createdAt = new Date();
260
+ payload.email = mail;
261
+
262
+ if (quoteManager) {
263
+ let result = await quoteManager.checkQuote(project, mail, 'email');
264
+ if (result === false) {
265
+ // Stop
266
+ winston.verbose('Unable to send email - Quota exceeded')
267
+ return false;
268
+ }
269
+ }
270
+ }
271
+
272
+
256
273
  let mailOptions = {
257
274
  from: mail.from || this.from, // sender address
258
275
  to: mail.to,
@@ -266,33 +283,38 @@ class EmailService {
266
283
  html: mail.html,
267
284
 
268
285
  headers: mail.headers || this.headers,
269
-
286
+
270
287
  messageId: mail.messageId,
271
288
  sender: mail.sender
272
289
  };
273
290
 
274
291
  winston.debug('mailOptions', mailOptions);
275
- winston.debug(' mail.config', mail.config);
276
-
292
+ winston.debug(' mail.config', mail.config);
293
+
277
294
  if (!mail.to) {
278
295
  return winston.warn("EmailService send method. to field is not defined", mailOptions);
279
296
  }
280
297
 
281
298
  // send mail with defined transport object
282
299
  this.getTransport(mail.config).sendMail(mailOptions, (error, info) => {
283
- if (error) {
284
- if (mail.callback){
285
- mail.callback(error, {info:info});
300
+ if (error) {
301
+ if (mail.callback) {
302
+ mail.callback(error, { info: info });
286
303
  }
287
- return winston.error("Error sending email ", {error:error, mailConfig: mail.config, mailOptions:mailOptions});
304
+ return winston.error("Error sending email ", { error: error, mailConfig: mail.config, mailOptions: mailOptions });
288
305
  }
289
- winston.verbose('Email sent:', {info: info});
290
- winston.debug('Email sent:', {info: info, mailOptions: mailOptions});
306
+ winston.verbose('Email sent:', { info: info });
307
+ winston.debug('Email sent:', { info: info, mailOptions: mailOptions });
291
308
 
292
- if (mail.callback){
293
- mail.callback(error, {info:info});
309
+ if (quoteEnabled && quoteEnabled === true) {
310
+ emailEvent.emit('email.send.quote', payload);
311
+ winston.verbose("email.send.quote event emitted");
294
312
  }
295
-
313
+
314
+ if (mail.callback) {
315
+ mail.callback(error, { info: info });
316
+ }
317
+
296
318
  // Preview only available when sending through an Ethereal account
297
319
  // winston.debug('Preview URL: %s', nodemailer.getTestMessageUrl(info));
298
320
 
@@ -302,26 +324,26 @@ class EmailService {
302
324
  }
303
325
 
304
326
 
305
- async sendTest(to, configEmail, callback) {
327
+ async sendTest(to, configEmail, callback) {
306
328
 
307
329
  var that = this;
308
330
 
309
- var html = await this.readTemplate('test.html',{ "email" : {"templates": {test: "123"}}});
331
+ var html = await this.readTemplate('test.html', { "email": { "templates": { test: "123" } } });
310
332
 
311
333
  var template = handlebars.compile(html);
312
334
 
313
- var replacements = {
335
+ var replacements = {
314
336
  };
315
337
 
316
338
  var html = template(replacements);
317
-
318
- return that.send({to:to, subject:`Tiledesk test email`, config: configEmail, html: html, callback: callback});
319
-
339
+
340
+ return that.send({ to: to, subject: `Tiledesk test email`, config: configEmail, html: html, callback: callback });
341
+
320
342
  }
321
343
 
322
344
 
323
345
 
324
- async sendNewAssignedRequestNotification(to, request, project) {
346
+ async sendNewAssignedRequestNotification(to, request, project) {
325
347
 
326
348
  var that = this;
327
349
 
@@ -337,10 +359,10 @@ class EmailService {
337
359
  var html = await this.readTemplate('assignedRequest.html', project.settings);
338
360
 
339
361
  var envTemplate = process.env.EMAIL_ASSIGN_REQUEST_HTML_TEMPLATE;
340
- winston.debug("envTemplate: " + envTemplate);
362
+ winston.debug("envTemplate: " + envTemplate);
341
363
 
342
364
  if (envTemplate) {
343
- html = envTemplate;
365
+ html = envTemplate;
344
366
  }
345
367
 
346
368
  winston.debug("html: " + html);
@@ -351,7 +373,7 @@ class EmailService {
351
373
  delete baseScope.pass;
352
374
 
353
375
  // passa anche tutti i messages in modo da stampare tutto
354
- // Stampa anche contact.email
376
+ // Stampa anche contact.email
355
377
 
356
378
 
357
379
  let msgText = request.first_text;//.replace(/[\n\r]/g, '<br>');
@@ -361,11 +383,11 @@ class EmailService {
361
383
  if (this.markdown) {
362
384
  msgText = marked(msgText);
363
385
  }
364
-
365
-
386
+
387
+
366
388
  winston.debug("msgText: " + msgText);
367
389
 
368
- var replacements = {
390
+ var replacements = {
369
391
  request: request,
370
392
  project: project,
371
393
  msgText: msgText,
@@ -378,7 +400,7 @@ class EmailService {
378
400
  var html = template(replacements);
379
401
  winston.debug("html after: " + html);
380
402
 
381
-
403
+
382
404
  let messageId = "notification" + "@" + MESSAGE_ID_DOMAIN;
383
405
 
384
406
  let replyTo;
@@ -387,19 +409,19 @@ class EmailService {
387
409
  }
388
410
 
389
411
  let headers;
390
- if (request) {
391
-
392
- messageId = request.request_id + "+" + messageId;
393
-
394
- if (request.attributes && request.attributes.email_replyTo) {
395
- replyTo = request.attributes.email_replyTo;
396
- }
397
-
412
+ if (request) {
413
+
414
+ messageId = request.request_id + "+" + messageId;
415
+
416
+ if (request.attributes && request.attributes.email_replyTo) {
417
+ replyTo = request.attributes.email_replyTo;
418
+ }
419
+
398
420
  headers = {
399
- "X-TILEDESK-PROJECT-ID": project._id,
400
- "X-TILEDESK-REQUEST-ID": request.request_id,
401
- "X-TILEDESK-TICKET-ID":request.ticket_id,
402
- };
421
+ "X-TILEDESK-PROJECT-ID": project._id,
422
+ "X-TILEDESK-REQUEST-ID": request.request_id,
423
+ "X-TILEDESK-TICKET-ID": request.ticket_id,
424
+ };
403
425
 
404
426
  winston.debug("messageId: " + messageId);
405
427
  winston.debug("replyTo: " + replyTo);
@@ -411,13 +433,13 @@ class EmailService {
411
433
  if (request.attributes) {
412
434
  if (request.attributes.email_messageId) {
413
435
  inReplyTo = request.attributes.email_messageId;
414
- }
415
- if (request.attributes.email_references) {
436
+ }
437
+ if (request.attributes.email_references) {
416
438
  references = request.attributes.email_references;
417
- }
439
+ }
418
440
  }
419
- winston.debug("email inReplyTo: "+ inReplyTo);
420
- winston.debug("email references: "+ references);
441
+ winston.debug("email inReplyTo: " + inReplyTo);
442
+ winston.debug("email references: " + references);
421
443
 
422
444
  let from;
423
445
  let configEmail;
@@ -428,7 +450,7 @@ class EmailService {
428
450
  }
429
451
  if (project.settings.email.from) {
430
452
  from = project.settings.email.from;
431
- winston.debug("custom from email setting found: "+ from);
453
+ winston.debug("custom from email setting found: " + from);
432
454
  }
433
455
  }
434
456
 
@@ -448,40 +470,40 @@ class EmailService {
448
470
  // if (request.ticket_id) {
449
471
  // subject = `[Ticket #${request.ticket_id}] New Assigned Chat`;
450
472
  // }
451
-
473
+
452
474
  // if (request.ticket_id && request.subject) {
453
475
  // subject = `[Ticket #${request.ticket_id}] ${request.subject}`;
454
476
  // }
455
477
 
456
478
  that.send({
457
479
  messageId: messageId,
458
- from:from,
459
- to:to,
480
+ from: from,
481
+ to: to,
460
482
  replyTo: replyTo,
461
- subject: subject,
462
- html:html,
483
+ subject: subject,
484
+ html: html,
463
485
  config: configEmail,
464
- headers:headers
486
+ headers: headers
465
487
  });
466
488
 
467
- messageId = "notification" + messageId;
489
+ messageId = "notification" + messageId;
468
490
 
469
491
 
470
492
  // togliere bcc
471
493
  that.send({
472
494
  messageId: messageId,
473
- to: that.bcc,
495
+ to: that.bcc,
474
496
  replyTo: replyTo,
475
- subject: subject + ` ${to} - notification`,
476
- html:html,
477
- headers:headers
497
+ subject: subject + ` ${to} - notification`,
498
+ html: html,
499
+ headers: headers
478
500
  });
479
501
 
480
-
502
+
481
503
  }
482
504
 
483
505
 
484
- async sendNewAssignedAgentMessageEmailNotification(to, request, project, message) {
506
+ async sendNewAssignedAgentMessageEmailNotification(to, request, project, message) {
485
507
 
486
508
  var that = this;
487
509
 
@@ -493,15 +515,15 @@ class EmailService {
493
515
  if (project.toJSON) {
494
516
  project = project.toJSON();
495
517
  }
496
-
518
+
497
519
  var html = await this.readTemplate('assignedEmailMessage.html', project.settings);
498
520
 
499
521
 
500
522
  var envTemplate = process.env.EMAIL_ASSIGN_MESSAGE_EMAIL_HTML_TEMPLATE;
501
- winston.debug("envTemplate: " + envTemplate);
523
+ winston.debug("envTemplate: " + envTemplate);
502
524
 
503
525
  if (envTemplate) {
504
- html = envTemplate;
526
+ html = envTemplate;
505
527
  }
506
528
 
507
529
  winston.debug("html: " + html);
@@ -512,22 +534,22 @@ class EmailService {
512
534
  delete baseScope.pass;
513
535
 
514
536
  // passa anche tutti i messages in modo da stampare tutto
515
- // Stampa anche contact.email
537
+ // Stampa anche contact.email
516
538
 
517
- let msgText = message.text;//.replace(/[\n\r]/g, '<br>');
518
- msgText = encode(msgText);
519
- if (this.markdown) {
520
- msgText = marked(msgText);
521
- }
539
+ let msgText = message.text;//.replace(/[\n\r]/g, '<br>');
540
+ msgText = encode(msgText);
541
+ if (this.markdown) {
542
+ msgText = marked(msgText);
543
+ }
522
544
 
523
- winston.debug("msgText: " + msgText);
545
+ winston.debug("msgText: " + msgText);
524
546
 
525
- var replacements = {
547
+ var replacements = {
526
548
  request: request,
527
549
  project: project,
528
550
  message: message,
529
551
  msgText: msgText,
530
- baseScope: baseScope
552
+ baseScope: baseScope
531
553
  };
532
554
 
533
555
  winston.debug("replacements ", replacements);
@@ -544,15 +566,15 @@ class EmailService {
544
566
  }
545
567
 
546
568
  let headers;
547
- if (message.request) {
548
-
549
- messageId = message.request.request_id + "+" + messageId;
569
+ if (message.request) {
550
570
 
551
- if (message.request.attributes && message.request.attributes.email_replyTo) {
571
+ messageId = message.request.request_id + "+" + messageId;
572
+
573
+ if (message.request.attributes && message.request.attributes.email_replyTo) {
552
574
  replyTo = message.request.attributes.email_replyTo;
553
- }
554
-
555
- headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
575
+ }
576
+
577
+ headers = { "X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID": message.request.ticket_id };
556
578
 
557
579
  winston.debug("sendNewAssignedAgentMessageEmailNotification messageId: " + messageId);
558
580
  winston.debug("sendNewAssignedAgentMessageEmailNotification replyTo: " + replyTo);
@@ -569,8 +591,8 @@ class EmailService {
569
591
  references = message.request.attributes.email_references;
570
592
  }
571
593
  }
572
- winston.debug("sendNewAssignedAgentMessageEmailNotification email inReplyTo: "+ inReplyTo);
573
- winston.debug("sendNewAssignedAgentMessageEmailNotification email references: "+ references);
594
+ winston.debug("sendNewAssignedAgentMessageEmailNotification email inReplyTo: " + inReplyTo);
595
+ winston.debug("sendNewAssignedAgentMessageEmailNotification email references: " + references);
574
596
 
575
597
  let from;
576
598
  let configEmail;
@@ -581,7 +603,7 @@ class EmailService {
581
603
  }
582
604
  if (project.settings.email.from) {
583
605
  from = project.settings.email.from;
584
- winston.debug("sendNewAssignedAgentMessageEmailNotification custom from email setting found: "+ from);
606
+ winston.debug("sendNewAssignedAgentMessageEmailNotification custom from email setting found: " + from);
585
607
  }
586
608
  }
587
609
 
@@ -594,7 +616,7 @@ class EmailService {
594
616
  if (request.ticket_id) {
595
617
  subjectDef = `[Ticket #${request.ticket_id}] New message`;
596
618
  }
597
-
619
+
598
620
  if (request.ticket_id && request.subject) {
599
621
  subjectDef = `[Ticket #${request.ticket_id}] ${request.subject}`;
600
622
  }
@@ -605,34 +627,34 @@ class EmailService {
605
627
 
606
628
  that.send({
607
629
  messageId: messageId,
608
- from:from,
609
- to:to,
630
+ from: from,
631
+ to: to,
610
632
  replyTo: replyTo,
611
633
  // inReplyTo: inReplyTo,???
612
634
  // references: references,??
613
635
  subject: subject,
614
- html:html,
615
- config: configEmail,
616
- headers:headers
636
+ html: html,
637
+ config: configEmail,
638
+ headers: headers
617
639
  });
618
640
 
619
641
 
620
-
621
- messageId = "notification" + messageId;
642
+
643
+ messageId = "notification" + messageId;
622
644
 
623
645
  that.send({
624
646
  messageId: messageId,
625
- to: that.bcc,
647
+ to: that.bcc,
626
648
  replyTo: replyTo,
627
- subject: subject + ` - notification`,
628
- html:html,
629
- headers:headers
649
+ subject: subject + ` - notification`,
650
+ html: html,
651
+ headers: headers
630
652
  });
631
653
 
632
-
654
+
633
655
  }
634
656
 
635
-
657
+
636
658
  async sendNewPooledRequestNotification(to, request, project) {
637
659
 
638
660
  //if the request came from rabbit mq?
@@ -649,10 +671,10 @@ class EmailService {
649
671
  var html = await this.readTemplate('pooledRequest.html', project.settings);
650
672
 
651
673
  var envTemplate = process.env.EMAIL_POOLED_REQUEST_HTML_TEMPLATE;
652
- winston.debug("envTemplate: " + envTemplate);
674
+ winston.debug("envTemplate: " + envTemplate);
653
675
 
654
676
  if (envTemplate) {
655
- html = envTemplate;
677
+ html = envTemplate;
656
678
  }
657
679
 
658
680
  winston.debug("html: " + html);
@@ -662,8 +684,8 @@ class EmailService {
662
684
  var baseScope = JSON.parse(JSON.stringify(that));
663
685
  delete baseScope.pass;
664
686
 
665
- // passa anche tutti i messages in modo da stampare tutto
666
- // Stampa anche contact.email
687
+ // passa anche tutti i messages in modo da stampare tutto
688
+ // Stampa anche contact.email
667
689
 
668
690
  let msgText = request.first_text;//.replace(/[\n\r]/g, '<br>');
669
691
  msgText = encode(msgText);
@@ -673,16 +695,16 @@ class EmailService {
673
695
 
674
696
  winston.debug("msgText: " + msgText);
675
697
 
676
- var replacements = {
698
+ var replacements = {
677
699
  request: request,
678
700
  project: project,
679
701
  msgText: msgText,
680
- baseScope: baseScope
702
+ baseScope: baseScope
681
703
  };
682
-
704
+
683
705
  var html = template(replacements);
684
706
 
685
-
707
+
686
708
  let messageId = "notification-pooled" + new Date().getTime() + "@" + MESSAGE_ID_DOMAIN;
687
709
 
688
710
  let replyTo;
@@ -691,15 +713,15 @@ class EmailService {
691
713
  }
692
714
 
693
715
  let headers;
694
- if (request) {
695
-
696
- messageId = request.request_id + "+" + messageId;
716
+ if (request) {
717
+
718
+ messageId = request.request_id + "+" + messageId;
697
719
 
698
- if (request.attributes && request.attributes.email_replyTo) {
720
+ if (request.attributes && request.attributes.email_replyTo) {
699
721
  replyTo = request.attributes.email_replyTo;
700
- }
722
+ }
701
723
 
702
- headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": request.request_id, "X-TILEDESK-TICKET-ID":request.ticket_id };
724
+ headers = { "X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": request.request_id, "X-TILEDESK-TICKET-ID": request.ticket_id };
703
725
 
704
726
  winston.debug("sendNewPooledRequestNotification messageId: " + messageId);
705
727
  winston.debug("sendNewPooledRequestNotification replyTo: " + replyTo);
@@ -711,13 +733,13 @@ class EmailService {
711
733
  if (request.attributes) {
712
734
  if (request.attributes.email_messageId) {
713
735
  inReplyTo = request.attributes.email_messageId;
714
- }
715
- if (request.attributes.email_references) {
736
+ }
737
+ if (request.attributes.email_references) {
716
738
  references = request.attributes.email_references;
717
- }
739
+ }
718
740
  }
719
- winston.debug("sendNewPooledRequestNotification email inReplyTo: "+ inReplyTo);
720
- winston.debug("sendNewPooledRequestNotification email references: "+ references);
741
+ winston.debug("sendNewPooledRequestNotification email inReplyTo: " + inReplyTo);
742
+ winston.debug("sendNewPooledRequestNotification email references: " + references);
721
743
 
722
744
  let from;
723
745
  let configEmail;
@@ -728,7 +750,7 @@ class EmailService {
728
750
  }
729
751
  if (project.settings.email.from) {
730
752
  from = project.settings.email.from;
731
- winston.debug("sendNewPooledRequestNotification custom from email setting found: "+ from);
753
+ winston.debug("sendNewPooledRequestNotification custom from email setting found: " + from);
732
754
  }
733
755
  }
734
756
 
@@ -744,7 +766,7 @@ class EmailService {
744
766
  // if (request.ticket_id) {
745
767
  // subject = `[Ticket #${request.ticket_id}] New Pooled Chat`;
746
768
  // }
747
-
769
+
748
770
  // if (request.ticket_id && request.subject) {
749
771
  // subject = `[Ticket #${request.ticket_id}] ${request.subject}`;
750
772
  // }
@@ -753,16 +775,16 @@ class EmailService {
753
775
 
754
776
  that.send({
755
777
  messageId: messageId,
756
- from:from,
757
- to: to,
778
+ from: from,
779
+ to: to,
758
780
  replyTo: replyTo,
759
- subject: subject,
760
- html:html,
761
- config:configEmail,
762
- headers:headers
781
+ subject: subject,
782
+ html: html,
783
+ config: configEmail,
784
+ headers: headers
763
785
  });
764
- // this.send(that.bcc, `[TileDesk ${project ? project.name : '-'}] New Pooled Request`, html);
765
-
786
+ // this.send(that.bcc, `[TileDesk ${project ? project.name : '-'}] New Pooled Request`, html);
787
+
766
788
  }
767
789
 
768
790
 
@@ -773,7 +795,7 @@ class EmailService {
773
795
 
774
796
  var that = this;
775
797
 
776
-
798
+
777
799
  //if the request came from rabbit mq?
778
800
  if (request.toJSON) {
779
801
  request = request.toJSON();
@@ -791,7 +813,7 @@ class EmailService {
791
813
 
792
814
 
793
815
  if (envTemplate) {
794
- html = envTemplate;
816
+ html = envTemplate;
795
817
  }
796
818
 
797
819
  winston.debug("html: " + html);
@@ -810,14 +832,14 @@ class EmailService {
810
832
  winston.debug("msgText: " + msgText);
811
833
 
812
834
  // passa anche tutti i messages in modo da stampare tutto
813
- // Stampa anche contact.email
835
+ // Stampa anche contact.email
814
836
 
815
- var replacements = {
837
+ var replacements = {
816
838
  request: request,
817
839
  project: project,
818
840
  message: message,
819
841
  msgText: msgText,
820
- baseScope: baseScope
842
+ baseScope: baseScope
821
843
  };
822
844
 
823
845
  winston.debug("replacements ", replacements);
@@ -835,15 +857,15 @@ class EmailService {
835
857
  }
836
858
 
837
859
  let headers;
838
- if (message.request) {
839
-
840
- messageId = message.request.request_id + "+" + messageId;
860
+ if (message.request) {
841
861
 
842
- if (message.request.attributes && message.request.attributes.email_replyTo) {
843
- replyTo = message.request.attributes.email_replyTo;
844
- }
845
-
846
- headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
862
+ messageId = message.request.request_id + "+" + messageId;
863
+
864
+ if (message.request.attributes && message.request.attributes.email_replyTo) {
865
+ replyTo = message.request.attributes.email_replyTo;
866
+ }
867
+
868
+ headers = { "X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID": message.request.ticket_id };
847
869
 
848
870
  winston.debug("sendNewPooledMessageEmailNotification messageId: " + messageId);
849
871
  winston.debug("sendNewPooledMessageEmailNotification replyTo: " + replyTo);
@@ -860,8 +882,8 @@ class EmailService {
860
882
  references = message.request.attributes.email_references;
861
883
  }
862
884
  }
863
- winston.debug("sendNewPooledMessageEmailNotification email inReplyTo: "+ inReplyTo);
864
- winston.debug("sendNewPooledMessageEmailNotification email references: "+ references);
885
+ winston.debug("sendNewPooledMessageEmailNotification email inReplyTo: " + inReplyTo);
886
+ winston.debug("sendNewPooledMessageEmailNotification email references: " + references);
865
887
 
866
888
  let from;
867
889
  let configEmail;
@@ -872,7 +894,7 @@ class EmailService {
872
894
  }
873
895
  if (project.settings.email.from) {
874
896
  from = project.settings.email.from;
875
- winston.debug("sendNewPooledMessageEmailNotification custom from email setting found: "+ from);
897
+ winston.debug("sendNewPooledMessageEmailNotification custom from email setting found: " + from);
876
898
  }
877
899
  }
878
900
 
@@ -885,7 +907,7 @@ class EmailService {
885
907
  if (request.ticket_id) {
886
908
  subjectDef = `[Ticket #${request.ticket_id}] New Message`;
887
909
  }
888
-
910
+
889
911
  if (request.ticket_id && request.subject) {
890
912
  subjectDef = `[Ticket #${request.ticket_id}] ${request.subject}`;
891
913
  }
@@ -895,19 +917,19 @@ class EmailService {
895
917
 
896
918
  that.send({
897
919
  messageId: messageId,
898
- from:from,
899
- to:to,
920
+ from: from,
921
+ to: to,
900
922
  replyTo: replyTo,
901
923
  // inReplyTo: inReplyTo,???
902
924
  // references: references,??
903
925
  subject: subject,
904
- html:html,
905
- config: configEmail,
906
- headers:headers
926
+ html: html,
927
+ config: configEmail,
928
+ headers: headers
907
929
  });
908
930
 
909
931
 
910
-
932
+
911
933
  // messageId = "notification" + messageId;
912
934
 
913
935
  // that.send({
@@ -919,7 +941,7 @@ class EmailService {
919
941
  // headers:headers
920
942
  // });
921
943
 
922
-
944
+
923
945
  }
924
946
 
925
947
 
@@ -928,7 +950,7 @@ class EmailService {
928
950
  var that = this;
929
951
 
930
952
  //if the request came from rabbit mq?
931
-
953
+
932
954
  if (project.toJSON) {
933
955
  project = project.toJSON();
934
956
  }
@@ -938,10 +960,10 @@ class EmailService {
938
960
 
939
961
 
940
962
  var envTemplate = process.env.EMAIL_NEW_MESSAGE_HTML_TEMPLATE;
941
- winston.debug("envTemplate: " + envTemplate);
963
+ winston.debug("envTemplate: " + envTemplate);
942
964
 
943
965
  if (envTemplate) {
944
- html = envTemplate;
966
+ html = envTemplate;
945
967
  }
946
968
 
947
969
  winston.debug("html: " + html);
@@ -959,13 +981,13 @@ class EmailService {
959
981
 
960
982
  winston.debug("msgText: " + msgText);
961
983
 
962
- var replacements = {
984
+ var replacements = {
963
985
  message: message,
964
986
  project: project,
965
- msgText:msgText,
987
+ msgText: msgText,
966
988
  seamlessPage: sourcePage,
967
989
  tokenQueryString: tokenQueryString,
968
- baseScope: baseScope
990
+ baseScope: baseScope
969
991
  };
970
992
 
971
993
  var html = template(replacements);
@@ -980,15 +1002,15 @@ class EmailService {
980
1002
  }
981
1003
 
982
1004
  let headers;
983
- if (message.request) {
984
-
985
- messageId = message.request.request_id + "+" + messageId;
1005
+ if (message.request) {
986
1006
 
987
- if (message.request.attributes && message.request.attributes.email_replyTo) {
1007
+ messageId = message.request.request_id + "+" + messageId;
1008
+
1009
+ if (message.request.attributes && message.request.attributes.email_replyTo) {
988
1010
  replyTo = message.request.attributes.email_replyTo;
989
- }
990
-
991
- headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
1011
+ }
1012
+
1013
+ headers = { "X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID": message.request.ticket_id };
992
1014
 
993
1015
  winston.debug("messageId: " + messageId);
994
1016
  winston.debug("replyTo: " + replyTo);
@@ -1006,8 +1028,8 @@ class EmailService {
1006
1028
  references = message.request.attributes.email_references;
1007
1029
  }
1008
1030
  }
1009
- winston.debug("email inReplyTo: "+ inReplyTo);
1010
- winston.debug("email references: "+ references);
1031
+ winston.debug("email inReplyTo: " + inReplyTo);
1032
+ winston.debug("email references: " + references);
1011
1033
 
1012
1034
  let from;
1013
1035
  let configEmail;
@@ -1018,7 +1040,7 @@ class EmailService {
1018
1040
  }
1019
1041
  if (project.settings.email.from) {
1020
1042
  from = project.settings.email.from;
1021
- winston.debug("custom from email setting found: "+ from);
1043
+ winston.debug("custom from email setting found: " + from);
1022
1044
  }
1023
1045
  }
1024
1046
 
@@ -1028,35 +1050,35 @@ class EmailService {
1028
1050
  that.send({
1029
1051
  messageId: messageId,
1030
1052
  // sender: message.senderFullname, //must be an email
1031
- from:from,
1032
- to:to,
1033
- replyTo: replyTo,
1053
+ from: from,
1054
+ to: to,
1055
+ replyTo: replyTo,
1034
1056
  inReplyTo: inReplyTo,
1035
1057
  references: references,
1036
- subject:subject, //TODO (anche per il cloud) aggiungere variabile env per cambiare i subjects
1037
- html:html,
1038
- config:configEmail,
1058
+ subject: subject, //TODO (anche per il cloud) aggiungere variabile env per cambiare i subjects
1059
+ html: html,
1060
+ config: configEmail,
1039
1061
  headers: headers
1040
1062
  });
1041
1063
 
1042
- messageId = "notification" + messageId;
1064
+ messageId = "notification" + messageId;
1043
1065
 
1044
1066
  that.send({
1045
1067
  messageId: messageId,
1046
1068
  // sender: message.senderFullname, //must be an email
1047
- to: that.bcc,
1069
+ to: that.bcc,
1048
1070
  replyTo: replyTo,
1049
- inReplyTo: inReplyTo,
1071
+ inReplyTo: inReplyTo,
1050
1072
  references: references,
1051
- subject: `[Tiledesk ${project ? project.name : '-'}] New Offline Message - notification`,
1052
- html:html,
1073
+ subject: `[Tiledesk ${project ? project.name : '-'}] New Offline Message - notification`,
1074
+ html: html,
1053
1075
  headers: headers
1054
1076
  });
1055
1077
 
1056
1078
  }
1057
1079
 
1058
-
1059
-
1080
+
1081
+
1060
1082
  async sendEmailChannelNotification(to, message, project, tokenQueryString, sourcePage) {
1061
1083
 
1062
1084
  var that = this;
@@ -1071,10 +1093,10 @@ class EmailService {
1071
1093
 
1072
1094
 
1073
1095
  var envTemplate = process.env.EMAIL_TICKET_HTML_TEMPLATE;
1074
- winston.debug("envTemplate: " + envTemplate);
1096
+ winston.debug("envTemplate: " + envTemplate);
1075
1097
 
1076
1098
  if (envTemplate) {
1077
- html = envTemplate;
1099
+ html = envTemplate;
1078
1100
  }
1079
1101
 
1080
1102
  winston.debug("html: " + html);
@@ -1090,26 +1112,26 @@ class EmailService {
1090
1112
  if (this.markdown) {
1091
1113
  msgText = marked(msgText);
1092
1114
  }
1093
-
1115
+
1094
1116
  winston.debug("msgText: " + msgText);
1095
1117
  winston.debug("baseScope: " + JSON.stringify(baseScope));
1096
-
1097
1118
 
1098
- var replacements = {
1119
+
1120
+ var replacements = {
1099
1121
  message: message,
1100
1122
  project: project,
1101
1123
  seamlessPage: sourcePage,
1102
1124
  msgText: msgText,
1103
1125
  tokenQueryString: tokenQueryString,
1104
- baseScope: baseScope
1126
+ baseScope: baseScope
1105
1127
  };
1106
1128
 
1107
1129
  var html = template(replacements);
1108
1130
  winston.debug("html: " + html);
1109
1131
 
1110
-
1111
-
1112
-
1132
+
1133
+
1134
+
1113
1135
  let messageId = message._id + "@" + MESSAGE_ID_DOMAIN;
1114
1136
 
1115
1137
  let replyTo;
@@ -1118,21 +1140,21 @@ class EmailService {
1118
1140
  }
1119
1141
 
1120
1142
  let headers;
1121
- if (message.request) {
1122
-
1123
- messageId = message.request.request_id + "+" + messageId;
1143
+ if (message.request) {
1124
1144
 
1125
- if (message.request.attributes && message.request.attributes.email_replyTo) {
1126
- replyTo = message.request.attributes.email_replyTo;
1127
- }
1128
-
1129
- headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
1145
+ messageId = message.request.request_id + "+" + messageId;
1146
+
1147
+ if (message.request.attributes && message.request.attributes.email_replyTo) {
1148
+ replyTo = message.request.attributes.email_replyTo;
1149
+ }
1150
+
1151
+ headers = { "X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID": message.request.ticket_id };
1130
1152
 
1131
1153
  winston.debug("messageId: " + messageId);
1132
1154
  winston.debug("replyTo: " + replyTo);
1133
1155
  winston.debug("email headers", headers);
1134
1156
  }
1135
-
1157
+
1136
1158
 
1137
1159
  let inReplyTo;
1138
1160
  let references;
@@ -1147,24 +1169,24 @@ class EmailService {
1147
1169
  }
1148
1170
  if (message.request.attributes.email_references) {
1149
1171
  references = message.request.attributes.email_references;
1150
- }
1172
+ }
1151
1173
 
1152
- if (that.ccEnabled==true) {
1174
+ if (that.ccEnabled == true) {
1153
1175
  if (message.request.attributes.email_cc) {
1154
- cc = message.request.attributes.email_cc;
1176
+ cc = message.request.attributes.email_cc;
1155
1177
  }
1156
- winston.debug("email message.request.attributes.email_ccStr: "+ message.request.attributes.email_ccStr);
1157
- if (message.request.attributes.email_ccStr!=undefined) {
1178
+ winston.debug("email message.request.attributes.email_ccStr: " + message.request.attributes.email_ccStr);
1179
+ if (message.request.attributes.email_ccStr != undefined) {
1158
1180
  ccString = message.request.attributes.email_ccStr;
1159
1181
  winston.debug("email set ccString");
1160
1182
  }
1161
1183
  }
1162
-
1184
+
1163
1185
  }
1164
- winston.debug("email inReplyTo: "+ inReplyTo);
1165
- winston.debug("email references: "+ references);
1186
+ winston.debug("email inReplyTo: " + inReplyTo);
1187
+ winston.debug("email references: " + references);
1166
1188
  winston.debug("email cc: ", cc);
1167
- winston.debug("email ccString: "+ ccString);
1189
+ winston.debug("email ccString: " + ccString);
1168
1190
 
1169
1191
  let from;
1170
1192
  let configEmail;
@@ -1175,7 +1197,7 @@ class EmailService {
1175
1197
  }
1176
1198
  if (project.settings.email.from) {
1177
1199
  from = project.settings.email.from;
1178
- winston.debug("custom from email setting found: "+ from);
1200
+ winston.debug("custom from email setting found: " + from);
1179
1201
  }
1180
1202
  }
1181
1203
 
@@ -1183,7 +1205,7 @@ class EmailService {
1183
1205
  let subject = that.formatText("ticketSubject", `R: ${message.request ? message.request.subject : '-'}`, message, project.settings);
1184
1206
 
1185
1207
  //ocf
1186
- //prod //pre
1208
+ //prod //pre
1187
1209
  // if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
1188
1210
  // subject = "Richiesta di supporto #" + message.request.ticket_id;
1189
1211
  // if (message.request.subject) {
@@ -1191,43 +1213,43 @@ class EmailService {
1191
1213
  // }
1192
1214
  // // console.log("subject",subject);
1193
1215
  // }
1194
-
1216
+
1195
1217
  // if (message.request && message.request.lead && message.request.lead.email) {
1196
1218
  // winston.info("message.request.lead.email: " + message.request.lead.email);
1197
1219
  // replyTo = replyTo + ", "+ message.request.lead.email;
1198
1220
  // }
1199
-
1221
+
1200
1222
  that.send({
1201
1223
  messageId: messageId,
1202
1224
  // sender: message.senderFullname, //must be an email
1203
- from:from,
1204
- to:to,
1225
+ from: from,
1226
+ to: to,
1205
1227
  cc: ccString,
1206
- replyTo: replyTo,
1228
+ replyTo: replyTo,
1207
1229
  inReplyTo: inReplyTo,
1208
1230
  references: references,
1209
1231
  // subject:`${message.request ? message.request.subject : '-'}`,
1210
1232
  subject: subject,
1211
- text:html,
1212
- html:html,
1213
- config:configEmail,
1214
- headers:headers
1215
- });
1216
-
1217
- messageId = "notification" + messageId;
1233
+ text: html,
1234
+ html: html,
1235
+ config: configEmail,
1236
+ headers: headers
1237
+ });
1238
+
1239
+ messageId = "notification" + messageId;
1218
1240
 
1219
1241
  that.send({
1220
1242
  messageId: messageId,
1221
1243
  // sender: message.senderFullname, //must be an email
1222
- to: that.bcc,
1223
- replyTo: replyTo,
1244
+ to: that.bcc,
1245
+ replyTo: replyTo,
1224
1246
  inReplyTo: inReplyTo,
1225
1247
  references: references,
1226
1248
  // subject: `${message.request ? message.request.subject : '-'} - notification`,
1227
- subject: `R: ${message.request ? message.request.subject : '-'} - notification`,
1228
- text:html,
1229
- html:html,
1230
- headers:headers
1249
+ subject: `R: ${message.request ? message.request.subject : '-'} - notification`,
1250
+ text: html,
1251
+ html: html,
1252
+ headers: headers
1231
1253
  });
1232
1254
 
1233
1255
  }
@@ -1241,7 +1263,7 @@ class EmailService {
1241
1263
 
1242
1264
 
1243
1265
 
1244
-
1266
+
1245
1267
  async sendFollowerNotification(to, message, project) {
1246
1268
 
1247
1269
  var that = this;
@@ -1255,10 +1277,10 @@ class EmailService {
1255
1277
 
1256
1278
 
1257
1279
  var envTemplate = process.env.EMAIL_FOLLOWER_HTML_TEMPLATE;
1258
- winston.debug("envTemplate: " + envTemplate);
1280
+ winston.debug("envTemplate: " + envTemplate);
1259
1281
 
1260
1282
  if (envTemplate) {
1261
- html = envTemplate;
1283
+ html = envTemplate;
1262
1284
  }
1263
1285
 
1264
1286
  winston.debug("html: " + html);
@@ -1274,26 +1296,26 @@ class EmailService {
1274
1296
  if (this.markdown) {
1275
1297
  msgText = marked(msgText);
1276
1298
  }
1277
-
1299
+
1278
1300
  winston.debug("msgText: " + msgText);
1279
1301
  winston.debug("baseScope: " + JSON.stringify(baseScope));
1280
-
1281
1302
 
1282
- var replacements = {
1303
+
1304
+ var replacements = {
1283
1305
  message: message,
1284
1306
  project: project,
1285
1307
  msgText: msgText,
1286
- baseScope: baseScope
1308
+ baseScope: baseScope
1287
1309
  };
1288
1310
 
1289
- var html = template(replacements);
1311
+ var html = template(replacements);
1290
1312
  winston.debug("html: " + html);
1291
1313
 
1292
1314
  const fs = require('fs');
1293
1315
  fs.writeFileSync('tem1111.html', html);
1294
1316
 
1295
-
1296
-
1317
+
1318
+
1297
1319
  let messageId = message._id + "@" + MESSAGE_ID_DOMAIN;
1298
1320
 
1299
1321
  let replyTo;
@@ -1302,21 +1324,21 @@ class EmailService {
1302
1324
  }
1303
1325
 
1304
1326
  let headers;
1305
- if (message.request) {
1306
-
1307
- messageId = message.request.request_id + "+" + messageId;
1327
+ if (message.request) {
1308
1328
 
1309
- if (message.request.attributes && message.request.attributes.email_replyTo) {
1310
- replyTo = message.request.attributes.email_replyTo;
1311
- }
1312
-
1313
- headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
1329
+ messageId = message.request.request_id + "+" + messageId;
1330
+
1331
+ if (message.request.attributes && message.request.attributes.email_replyTo) {
1332
+ replyTo = message.request.attributes.email_replyTo;
1333
+ }
1334
+
1335
+ headers = { "X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID": message.request.ticket_id };
1314
1336
 
1315
1337
  winston.debug("messageId: " + messageId);
1316
1338
  winston.debug("replyTo: " + replyTo);
1317
1339
  winston.debug("email headers", headers);
1318
1340
  }
1319
-
1341
+
1320
1342
 
1321
1343
  let inReplyTo;
1322
1344
  let references;
@@ -1331,23 +1353,23 @@ class EmailService {
1331
1353
  }
1332
1354
  if (message.request.attributes.email_references) {
1333
1355
  references = message.request.attributes.email_references;
1334
- }
1356
+ }
1335
1357
 
1336
- if (that.ccEnabled==true) {
1358
+ if (that.ccEnabled == true) {
1337
1359
  if (message.request.attributes.email_cc) {
1338
- cc = message.request.attributes.email_cc;
1360
+ cc = message.request.attributes.email_cc;
1339
1361
  }
1340
- winston.debug("email message.request.attributes.email_ccStr: "+ message.request.attributes.email_ccStr);
1341
- if (message.request.attributes.email_ccStr!=undefined) {
1362
+ winston.debug("email message.request.attributes.email_ccStr: " + message.request.attributes.email_ccStr);
1363
+ if (message.request.attributes.email_ccStr != undefined) {
1342
1364
  ccString = message.request.attributes.email_ccStr;
1343
1365
  winston.debug("email set ccString");
1344
1366
  }
1345
1367
  }
1346
1368
  }
1347
- winston.debug("email inReplyTo: "+ inReplyTo);
1348
- winston.debug("email references: "+ references);
1369
+ winston.debug("email inReplyTo: " + inReplyTo);
1370
+ winston.debug("email references: " + references);
1349
1371
  winston.debug("email cc: ", cc);
1350
- winston.debug("email ccString: "+ ccString);
1372
+ winston.debug("email ccString: " + ccString);
1351
1373
 
1352
1374
  let from;
1353
1375
  let configEmail;
@@ -1358,32 +1380,32 @@ class EmailService {
1358
1380
  }
1359
1381
  if (project.settings.email.from) {
1360
1382
  from = project.settings.email.from;
1361
- winston.debug("custom from email setting found: "+ from);
1383
+ winston.debug("custom from email setting found: " + from);
1362
1384
  }
1363
1385
  }
1364
1386
 
1365
1387
 
1366
1388
  let subject = that.formatText("newMessageFollowerSubject", `${message.request ? message.request.ticket_id : '-'}`, message, project.settings);
1367
1389
 
1368
-
1369
-
1390
+
1391
+
1370
1392
  that.send({
1371
1393
  messageId: messageId,
1372
1394
  // sender: message.senderFullname, //must be an email
1373
- from:from,
1374
- to:to,
1395
+ from: from,
1396
+ to: to,
1375
1397
  cc: ccString,
1376
- replyTo: replyTo,
1398
+ replyTo: replyTo,
1377
1399
  inReplyTo: inReplyTo,
1378
1400
  references: references,
1379
1401
  // subject:`${message.request ? message.request.subject : '-'}`,
1380
1402
  subject: subject, //gmail uses subject
1381
- text:html,
1382
- html:html,
1383
- config:configEmail,
1384
- headers:headers
1385
- });
1386
-
1403
+ text: html,
1404
+ html: html,
1405
+ config: configEmail,
1406
+ headers: headers
1407
+ });
1408
+
1387
1409
  // // messageId = "notification" + messageId;
1388
1410
 
1389
1411
  // // that.send({
@@ -1404,151 +1426,153 @@ class EmailService {
1404
1426
  }
1405
1427
 
1406
1428
 
1407
- /*
1408
- sendEmailChannelTakingNotification(to, request, project, tokenQueryString) {
1409
-
1410
- var that = this;
1411
-
1412
- this.readTemplateFile('ticket-taking.txt', function(err, html) {
1413
- // this.readTemplateFile('ticket.html', function(err, html) {
1414
-
1415
-
1416
- var envTemplate = process.env.EMAIL_TICKET_HTML_TEMPLATE;
1417
- winston.debug("envTemplate: " + envTemplate);
1429
+ /*
1430
+ sendEmailChannelTakingNotification(to, request, project, tokenQueryString) {
1431
+
1432
+ var that = this;
1433
+
1434
+ this.readTemplateFile('ticket-taking.txt', function(err, html) {
1435
+ // this.readTemplateFile('ticket.html', function(err, html) {
1436
+
1437
+
1438
+ var envTemplate = process.env.EMAIL_TICKET_HTML_TEMPLATE;
1439
+ winston.debug("envTemplate: " + envTemplate);
1440
+
1441
+ if (envTemplate) {
1442
+ html = envTemplate;
1443
+ }
1444
+
1445
+ winston.debug("html: " + html);
1446
+
1447
+ var template = handlebars.compile(html);
1448
+
1449
+ var baseScope = JSON.parse(JSON.stringify(that));
1450
+ delete baseScope.pass;
1451
+
1452
+ var replacements = {
1453
+ request: request,
1454
+ project: project.toJSON(),
1455
+ tokenQueryString: tokenQueryString,
1456
+ baseScope: baseScope
1457
+ };
1458
+
1459
+ var html = template(replacements);
1460
+ winston.debug("html: " + html);
1461
+
1462
+
1463
+ // if (message.request && message.request.lead && message.request.lead.email) {
1464
+ // winston.info("message.request.lead.email: " + message.request.lead.email);
1465
+ // replyTo = replyTo + ", "+ request.lead.email;
1466
+ // }
1467
+
1468
+
1469
+ that.send({to:to, replyTo: replyTo, subject:`R: ${request ? request.subject : '-'}`, text:html }); //html:html
1470
+ that.send({to: that.bcc, replyTo: replyTo, subject: `R: ${request ? request.subject : '-'} - notification`, text:html});//html:html
1471
+
1472
+ });
1473
+ }
1474
+ */
1418
1475
 
1419
- if (envTemplate) {
1420
- html = envTemplate;
1421
- }
1422
1476
 
1423
- winston.debug("html: " + html);
1424
1477
 
1425
- var template = handlebars.compile(html);
1426
1478
 
1427
- var baseScope = JSON.parse(JSON.stringify(that));
1428
- delete baseScope.pass;
1429
1479
 
1430
- var replacements = {
1431
- request: request,
1432
- project: project.toJSON(),
1433
- tokenQueryString: tokenQueryString,
1434
- baseScope: baseScope
1435
- };
1436
1480
 
1437
- var html = template(replacements);
1438
- winston.debug("html: " + html);
1439
1481
 
1482
+ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload, replyTo, quoteManager) {
1440
1483
 
1441
- // if (message.request && message.request.lead && message.request.lead.email) {
1442
- // winston.info("message.request.lead.email: " + message.request.lead.email);
1443
- // replyTo = replyTo + ", "+ request.lead.email;
1444
- // }
1445
-
1484
+ var that = this;
1446
1485
 
1447
- that.send({to:to, replyTo: replyTo, subject:`R: ${request ? request.subject : '-'}`, text:html }); //html:html
1448
- that.send({to: that.bcc, replyTo: replyTo, subject: `R: ${request ? request.subject : '-'} - notification`, text:html});//html:html
1449
1486
 
1450
- });
1451
- }
1452
- */
1487
+ if (project.toJSON) {
1488
+ project = project.toJSON();
1489
+ }
1453
1490
 
1491
+ var html = await this.readTemplate('emailDirect.html', project.settings);
1454
1492
 
1493
+ var envTemplate = process.env.EMAIL_DIRECT_HTML_TEMPLATE;
1494
+ winston.debug("envTemplate: " + envTemplate);
1455
1495
 
1496
+ if (envTemplate) {
1497
+ html = envTemplate;
1498
+ }
1456
1499
 
1500
+ winston.debug("html: " + html);
1457
1501
 
1502
+ var template = handlebars.compile(html);
1458
1503
 
1459
-
1460
- async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload, replyTo) {
1504
+ var baseScope = JSON.parse(JSON.stringify(that));
1505
+ delete baseScope.pass;
1461
1506
 
1462
- var that = this;
1463
1507
 
1508
+ let msgText = text;
1509
+ msgText = encode(msgText);
1510
+ if (this.markdown) {
1511
+ msgText = marked(msgText);
1512
+ }
1464
1513
 
1465
- if (project.toJSON) {
1466
- project = project.toJSON();
1467
- }
1514
+ winston.debug("msgText: " + msgText);
1515
+ winston.debug("baseScope: " + JSON.stringify(baseScope));
1468
1516
 
1469
- var html = await this.readTemplate('emailDirect.html', project.settings);
1470
1517
 
1471
- var envTemplate = process.env.EMAIL_DIRECT_HTML_TEMPLATE;
1472
- winston.debug("envTemplate: " + envTemplate);
1518
+ var replacements = {
1519
+ project: project,
1520
+ request_id: request_id,
1521
+ seamlessPage: sourcePage,
1522
+ msgText: msgText,
1523
+ tokenQueryString: tokenQueryString,
1524
+ baseScope: baseScope,
1525
+ payload: payload
1526
+ };
1473
1527
 
1474
- if (envTemplate) {
1475
- html = envTemplate;
1476
- }
1528
+ var html = template(replacements);
1529
+ winston.debug("html: " + html);
1477
1530
 
1478
- winston.debug("html: " + html);
1479
1531
 
1480
- var template = handlebars.compile(html);
1532
+ // let replyTo;
1481
1533
 
1482
- var baseScope = JSON.parse(JSON.stringify(that));
1483
- delete baseScope.pass;
1534
+ if (!replyTo && this.replyEnabled && request_id) {
1535
+ replyTo = request_id + this.inboundDomainDomainWithAt;
1536
+ }
1484
1537
 
1538
+ let from;
1539
+ let configEmail;
1540
+ if (project && project.settings && project.settings.email) {
1541
+ if (project.settings.email.config) {
1542
+ configEmail = project.settings.email.config;
1543
+ winston.debug("custom email configEmail setting found: ", configEmail);
1544
+ }
1545
+ if (project.settings.email.from) {
1546
+ from = project.settings.email.from;
1547
+ winston.debug("custom from email setting found: " + from);
1548
+ }
1549
+ }
1485
1550
 
1486
- let msgText = text;
1487
- msgText = encode(msgText);
1488
- if (this.markdown) {
1489
- msgText = marked(msgText);
1490
- }
1491
-
1492
- winston.debug("msgText: " + msgText);
1493
- winston.debug("baseScope: " + JSON.stringify(baseScope));
1494
-
1551
+ let subjectParsed = that.parseText(subject, payload);
1495
1552
 
1496
- var replacements = {
1497
- project: project,
1498
- request_id: request_id,
1499
- seamlessPage: sourcePage,
1500
- msgText: msgText,
1501
- tokenQueryString: tokenQueryString,
1502
- baseScope: baseScope,
1503
- payload: payload
1504
- };
1553
+ // if (message.request && message.request.lead && message.request.lead.email) {
1554
+ // winston.info("message.request.lead.email: " + message.request.lead.email);
1555
+ // replyTo = replyTo + ", "+ message.request.lead.email;
1556
+ // }
1505
1557
 
1506
- var html = template(replacements);
1507
- winston.debug("html: " + html);
1558
+ // if (!subject) {
1559
+ // subject = "Tiledesk"
1560
+ // }
1508
1561
 
1509
-
1510
- // let replyTo;
1562
+ let email_enabled = true;
1511
1563
 
1512
- if (!replyTo && this.replyEnabled && request_id) {
1513
- replyTo = request_id + this.inboundDomainDomainWithAt;
1514
- }
1564
+ that.send({
1565
+ from: from,
1566
+ to: to,
1567
+ replyTo: replyTo,
1568
+ subject: subjectParsed,
1569
+ text: html,
1570
+ html: html,
1571
+ config: configEmail,
1572
+ }, email_enabled, project, quoteManager);
1515
1573
 
1516
- let from;
1517
- let configEmail;
1518
- if (project && project.settings && project.settings.email) {
1519
- if (project.settings.email.config) {
1520
- configEmail = project.settings.email.config;
1521
- winston.debug("custom email configEmail setting found: ", configEmail);
1522
- }
1523
- if (project.settings.email.from) {
1524
- from = project.settings.email.from;
1525
- winston.debug("custom from email setting found: "+ from);
1526
- }
1527
1574
  }
1528
1575
 
1529
- let subjectParsed = that.parseText(subject, payload);
1530
-
1531
- // if (message.request && message.request.lead && message.request.lead.email) {
1532
- // winston.info("message.request.lead.email: " + message.request.lead.email);
1533
- // replyTo = replyTo + ", "+ message.request.lead.email;
1534
- // }
1535
-
1536
- // if (!subject) {
1537
- // subject = "Tiledesk"
1538
- // }
1539
-
1540
- that.send({
1541
- from:from,
1542
- to:to,
1543
- replyTo: replyTo,
1544
- subject:subjectParsed,
1545
- text:html,
1546
- html:html,
1547
- config:configEmail,
1548
- });
1549
-
1550
- }
1551
-
1552
1576
 
1553
1577
 
1554
1578
  // ok
@@ -1560,13 +1584,13 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1560
1584
 
1561
1585
 
1562
1586
  var envTemplate = process.env.EMAIL_RESET_PASSWORD_HTML_TEMPLATE;
1563
- winston.debug("envTemplate: " + envTemplate);
1587
+ winston.debug("envTemplate: " + envTemplate);
1564
1588
 
1565
1589
  if (envTemplate) {
1566
- html = envTemplate;
1590
+ html = envTemplate;
1567
1591
  }
1568
1592
 
1569
- winston.debug("html: " + html);
1593
+ winston.debug("html: " + html);
1570
1594
 
1571
1595
  var template = handlebars.compile(html);
1572
1596
 
@@ -1574,18 +1598,18 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1574
1598
  delete baseScope.pass;
1575
1599
 
1576
1600
 
1577
- var replacements = {
1601
+ var replacements = {
1578
1602
  resetPswRequestId: resetPswRequestId,
1579
1603
  userFirstname: userFirstname,
1580
1604
  userLastname: userLastname,
1581
- baseScope: baseScope
1605
+ baseScope: baseScope
1582
1606
  };
1583
1607
 
1584
1608
  var html = template(replacements);
1585
1609
 
1586
1610
 
1587
- that.send({to: to, subject: '[Tiledesk] Password reset request', html:html});
1588
- that.send({to:that.bcc, subject: '[Tiledesk] Password reset request - notification', html:html });
1611
+ that.send({ to: to, subject: '[Tiledesk] Password reset request', html: html });
1612
+ that.send({ to: that.bcc, subject: '[Tiledesk] Password reset request - notification', html: html });
1589
1613
 
1590
1614
  }
1591
1615
 
@@ -1598,13 +1622,13 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1598
1622
 
1599
1623
 
1600
1624
  var envTemplate = process.env.EMAIL_PASSWORD_CHANGED_HTML_TEMPLATE;
1601
- winston.debug("envTemplate: " + envTemplate);
1625
+ winston.debug("envTemplate: " + envTemplate);
1602
1626
 
1603
1627
  if (envTemplate) {
1604
- html = envTemplate;
1628
+ html = envTemplate;
1605
1629
  }
1606
1630
 
1607
- winston.debug("html: " + html);
1631
+ winston.debug("html: " + html);
1608
1632
 
1609
1633
  var template = handlebars.compile(html);
1610
1634
 
@@ -1612,42 +1636,42 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1612
1636
  delete baseScope.pass;
1613
1637
 
1614
1638
 
1615
- var replacements = {
1639
+ var replacements = {
1616
1640
  userFirstname: userFirstname,
1617
1641
  userLastname: userLastname,
1618
1642
  to: to,
1619
- baseScope: baseScope
1643
+ baseScope: baseScope
1620
1644
  };
1621
1645
 
1622
1646
  var html = template(replacements);
1623
1647
 
1624
1648
 
1625
- that.send({to: to, subject:'[Tiledesk] Your password has been changed', html:html });
1626
- that.send({to: that.bcc, subject: '[Tiledesk] Your password has been changed - notification', html: html });
1649
+ that.send({ to: to, subject: '[Tiledesk] Your password has been changed', html: html });
1650
+ that.send({ to: that.bcc, subject: '[Tiledesk] Your password has been changed - notification', html: html });
1627
1651
 
1628
1652
  }
1629
1653
 
1630
1654
 
1631
- // ok
1655
+ // ok
1632
1656
 
1633
1657
 
1634
1658
  /**
1635
1659
  *! *** EMAIL: YOU HAVE BEEN INVITED AT THE PROJECT ***
1636
1660
  */
1637
- async sendYouHaveBeenInvited(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserFirstname, invitedUserLastname, invitedUserRole) {
1661
+ async sendYouHaveBeenInvited(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserFirstname, invitedUserLastname, invitedUserRole) {
1638
1662
 
1639
1663
  var that = this;
1640
1664
 
1641
1665
  var html = await this.readTemplateFile('beenInvitedExistingUser.html');
1642
1666
 
1643
1667
  var envTemplate = process.env.EMAIL_EXUSER_INVITED_HTML_TEMPLATE;
1644
- winston.debug("envTemplate: " + envTemplate);
1668
+ winston.debug("envTemplate: " + envTemplate);
1645
1669
 
1646
1670
  if (envTemplate) {
1647
- html = envTemplate;
1671
+ html = envTemplate;
1648
1672
  }
1649
1673
 
1650
- winston.debug("html: " + html);
1674
+ winston.debug("html: " + html);
1651
1675
 
1652
1676
  var template = handlebars.compile(html);
1653
1677
 
@@ -1655,7 +1679,7 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1655
1679
  delete baseScope.pass;
1656
1680
 
1657
1681
 
1658
- var replacements = {
1682
+ var replacements = {
1659
1683
  currentUserFirstname: currentUserFirstname,
1660
1684
  currentUserLastname: currentUserLastname,
1661
1685
  projectName: projectName,
@@ -1663,37 +1687,37 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1663
1687
  invitedUserFirstname: invitedUserFirstname,
1664
1688
  invitedUserLastname: invitedUserLastname,
1665
1689
  invitedUserRole: invitedUserRole,
1666
- baseScope: baseScope
1690
+ baseScope: baseScope
1667
1691
  };
1668
1692
 
1669
1693
  var html = template(replacements);
1670
1694
 
1671
1695
 
1672
- that.send({to:to, subject: `[Tiledesk] You have been invited to the '${projectName}' project`, html:html});
1673
- that.send({to: that.bcc, subject: `[Tiledesk] You have been invited to the '${projectName}' project - notification`, html: html});
1696
+ that.send({ to: to, subject: `[Tiledesk] You have been invited to the '${projectName}' project`, html: html });
1697
+ that.send({ to: that.bcc, subject: `[Tiledesk] You have been invited to the '${projectName}' project - notification`, html: html });
1674
1698
  }
1675
1699
 
1676
- // ok
1700
+ // ok
1677
1701
 
1678
1702
 
1679
1703
  /**
1680
1704
  *! *** EMAIL: YOU HAVE BEEN INVITED AT THE PROJECT (USER NOT REGISTERED) ***
1681
1705
  */
1682
- async sendInvitationEmail_UserNotRegistered(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserRole, pendinginvitationid) {
1706
+ async sendInvitationEmail_UserNotRegistered(to, currentUserFirstname, currentUserLastname, projectName, id_project, invitedUserRole, pendinginvitationid) {
1707
+
1683
1708
 
1684
-
1685
1709
  var that = this;
1686
1710
 
1687
1711
  var html = await this.readTemplateFile('beenInvitedNewUser.html');
1688
1712
 
1689
1713
  var envTemplate = process.env.EMAIL_NEWUSER_INVITED_HTML_TEMPLATE;
1690
- winston.debug("envTemplate: " + envTemplate);
1714
+ winston.debug("envTemplate: " + envTemplate);
1691
1715
 
1692
1716
  if (envTemplate) {
1693
- html = envTemplate;
1717
+ html = envTemplate;
1694
1718
  }
1695
1719
 
1696
- winston.debug("html: " + html);
1720
+ winston.debug("html: " + html);
1697
1721
 
1698
1722
  var template = handlebars.compile(html);
1699
1723
 
@@ -1701,27 +1725,27 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1701
1725
  delete baseScope.pass;
1702
1726
 
1703
1727
 
1704
- var replacements = {
1728
+ var replacements = {
1705
1729
  currentUserFirstname: currentUserFirstname,
1706
1730
  currentUserLastname: currentUserLastname,
1707
1731
  projectName: projectName,
1708
1732
  id_project: id_project,
1709
1733
  invitedUserRole: invitedUserRole,
1710
1734
  pendinginvitationid: pendinginvitationid,
1711
- baseScope: baseScope
1735
+ baseScope: baseScope
1712
1736
  };
1713
1737
 
1714
1738
  var html = template(replacements);
1715
1739
 
1716
- that.send({to:to, subject: `[Tiledesk] You have been invited to the '${projectName}' project`, html:html });
1717
- that.send({to: that.bcc, subject: `[Tiledesk] You have been invited to the '${projectName}' project - notification`, html: html});
1740
+ that.send({ to: to, subject: `[Tiledesk] You have been invited to the '${projectName}' project`, html: html });
1741
+ that.send({ to: that.bcc, subject: `[Tiledesk] You have been invited to the '${projectName}' project - notification`, html: html });
1718
1742
 
1719
1743
  }
1720
1744
 
1721
1745
  // ok
1722
1746
  async sendVerifyEmailAddress(to, savedUser) {
1723
1747
 
1724
-
1748
+
1725
1749
  var that = this;
1726
1750
 
1727
1751
  if (savedUser.toJSON) {
@@ -1730,13 +1754,13 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1730
1754
  var html = await this.readTemplateFile('verify.html');
1731
1755
 
1732
1756
  var envTemplate = process.env.EMAIL_VERIFY_HTML_TEMPLATE;
1733
- winston.debug("envTemplate: " + envTemplate);
1757
+ winston.debug("envTemplate: " + envTemplate);
1734
1758
 
1735
1759
  if (envTemplate) {
1736
- html = envTemplate;
1760
+ html = envTemplate;
1737
1761
  }
1738
1762
 
1739
- winston.debug("html: " + html);
1763
+ winston.debug("html: " + html);
1740
1764
 
1741
1765
  var template = handlebars.compile(html);
1742
1766
 
@@ -1744,16 +1768,16 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1744
1768
  delete baseScope.pass;
1745
1769
 
1746
1770
 
1747
- var replacements = {
1748
- savedUser: savedUser,
1749
- baseScope: baseScope
1771
+ var replacements = {
1772
+ savedUser: savedUser,
1773
+ baseScope: baseScope
1750
1774
  };
1751
1775
 
1752
1776
  var html = template(replacements);
1753
1777
 
1754
1778
 
1755
- that.send({to: to, subject: `[Tiledesk] Verify your email address`, html:html });
1756
- that.send({to: that.bcc, subject: `[Tiledesk] Verify your email address `+to + " - notification", html:html });
1779
+ that.send({ to: to, subject: `[Tiledesk] Verify your email address`, html: html });
1780
+ that.send({ to: that.bcc, subject: `[Tiledesk] Verify your email address ` + to + " - notification", html: html });
1757
1781
 
1758
1782
  }
1759
1783
 
@@ -1763,13 +1787,13 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1763
1787
 
1764
1788
 
1765
1789
 
1766
- // ok
1790
+ // ok
1767
1791
 
1768
- async sendRequestTranscript(to, messages, request, project) {
1769
- winston.debug("sendRequestTranscript: "+to);
1792
+ async sendRequestTranscript(to, messages, request, project) {
1793
+ winston.debug("sendRequestTranscript: " + to);
1770
1794
 
1771
- //if the request came from rabbit mq?
1772
- if (request.toJSON) {
1795
+ //if the request came from rabbit mq?
1796
+ if (request.toJSON) {
1773
1797
  request = request.toJSON();
1774
1798
  }
1775
1799
 
@@ -1779,24 +1803,24 @@ async sendRequestTranscript(to, messages, request, project) {
1779
1803
 
1780
1804
  var transcriptAsHtml = ""; //https://handlebarsjs.com/guide/expressions.html#html-escaping
1781
1805
  messages.forEach(message => {
1782
- transcriptAsHtml = transcriptAsHtml + '['+ message.createdAt.toLocaleTimeString('en', { timeZone: 'UTC' }) +'] ' + message.senderFullname + ': ' + message.text + '<br>';
1806
+ transcriptAsHtml = transcriptAsHtml + '[' + message.createdAt.toLocaleTimeString('en', { timeZone: 'UTC' }) + '] ' + message.senderFullname + ': ' + message.text + '<br>';
1783
1807
  });
1784
1808
  winston.debug("transcriptAsHtml: " + transcriptAsHtml);
1785
-
1786
-
1787
-
1809
+
1810
+
1811
+
1788
1812
  var that = this;
1789
1813
 
1790
1814
  var html = await this.readTemplate('sendTranscript.html', project.settings);
1791
1815
 
1792
1816
  var envTemplate = process.env.EMAIL_SEND_TRANSCRIPT_HTML_TEMPLATE;
1793
- winston.debug("envTemplate: " + envTemplate);
1817
+ winston.debug("envTemplate: " + envTemplate);
1794
1818
 
1795
1819
  if (envTemplate) {
1796
- html = envTemplate;
1820
+ html = envTemplate;
1797
1821
  }
1798
1822
 
1799
- winston.debug("html: " + html);
1823
+ winston.debug("html: " + html);
1800
1824
 
1801
1825
  var template = handlebars.compile(html);
1802
1826
 
@@ -1804,17 +1828,17 @@ async sendRequestTranscript(to, messages, request, project) {
1804
1828
  delete baseScope.pass;
1805
1829
 
1806
1830
 
1807
- var replacements = {
1808
- messages: messages,
1809
- request: request,
1831
+ var replacements = {
1832
+ messages: messages,
1833
+ request: request,
1810
1834
  formattedCreatedAt: request.createdAt.toLocaleString('en', { timeZone: 'UTC' }),
1811
1835
  transcriptAsHtml: transcriptAsHtml,
1812
- baseScope: baseScope
1836
+ baseScope: baseScope
1813
1837
  };
1814
1838
 
1815
1839
  var html = template(replacements);
1816
1840
 
1817
-
1841
+
1818
1842
 
1819
1843
  let from;
1820
1844
  let configEmail;
@@ -1825,7 +1849,7 @@ async sendRequestTranscript(to, messages, request, project) {
1825
1849
  }
1826
1850
  if (project.settings.email.from) {
1827
1851
  from = project.settings.email.from;
1828
- winston.debug("custom from email setting found: "+ from);
1852
+ winston.debug("custom from email setting found: " + from);
1829
1853
  }
1830
1854
  }
1831
1855
 
@@ -1835,7 +1859,7 @@ async sendRequestTranscript(to, messages, request, project) {
1835
1859
  // console.log("ocf",project._id);
1836
1860
  let subject = that.formatText("sendTranscriptSubject", '[Tiledesk] Transcript', request, project.settings);
1837
1861
 
1838
- //prod //pre
1862
+ //prod //pre
1839
1863
  // if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
1840
1864
  // subject = "Segnalazione #" + request.ticket_id;
1841
1865
  // // subject = "Richiesta di supporto #" + request.ticket_id;
@@ -1846,136 +1870,136 @@ async sendRequestTranscript(to, messages, request, project) {
1846
1870
  // }
1847
1871
  // hcustomization.emailTranscript(to, subject, html, configEmail)
1848
1872
 
1849
- that.send({from:from, to:to, subject: subject, html:html, config: configEmail});
1850
- that.send({to: that.bcc, subject: '[Tiledesk] Transcript - notification', html:html });
1873
+ that.send({ from: from, to: to, subject: subject, html: html, config: configEmail });
1874
+ that.send({ to: that.bcc, subject: '[Tiledesk] Transcript - notification', html: html });
1851
1875
 
1852
- }
1876
+ }
1853
1877
 
1854
- async sendEmailRedirectOnDesktop(to, token, project_id, chatbot_id) {
1855
- winston.debug("sendEmailRedirectOnDesktop: " + to);
1878
+ async sendEmailRedirectOnDesktop(to, token, project_id, chatbot_id) {
1879
+ winston.debug("sendEmailRedirectOnDesktop: " + to);
1856
1880
 
1857
- var that = this;
1881
+ var that = this;
1858
1882
 
1859
- let html = await this.readTemplate('redirectToDesktopEmail.html');
1883
+ let html = await this.readTemplate('redirectToDesktopEmail.html');
1860
1884
 
1861
- let envTemplate = process.env.EMAIL_REDIRECT_TO_DESKTOP_TEMPLATE
1862
- winston.debug("envTemplate: " + envTemplate);
1885
+ let envTemplate = process.env.EMAIL_REDIRECT_TO_DESKTOP_TEMPLATE
1886
+ winston.debug("envTemplate: " + envTemplate);
1863
1887
 
1864
- if (envTemplate) {
1865
- html = envTemplate;
1866
- }
1888
+ if (envTemplate) {
1889
+ html = envTemplate;
1890
+ }
1867
1891
 
1868
- winston.debug("html: " + html);
1892
+ winston.debug("html: " + html);
1869
1893
 
1870
- let template = handlebars.compile(html);
1894
+ let template = handlebars.compile(html);
1871
1895
 
1872
- let baseScope = JSON.parse(JSON.stringify(that));
1873
- delete baseScope.pass;
1896
+ let baseScope = JSON.parse(JSON.stringify(that));
1897
+ delete baseScope.pass;
1874
1898
 
1875
- let replacements = {
1876
- baseScope: baseScope,
1877
- token: token,
1878
- project_id: project_id,
1879
- chatbot_id: chatbot_id
1880
- }
1899
+ let replacements = {
1900
+ baseScope: baseScope,
1901
+ token: token,
1902
+ project_id: project_id,
1903
+ chatbot_id: chatbot_id
1904
+ }
1881
1905
 
1882
- html = template(replacements);
1906
+ html = template(replacements);
1883
1907
 
1884
- that.send({ to: to, subject: "Join Tiledesk from Desktop", html: html });
1908
+ that.send({ to: to, subject: "Join Tiledesk from Desktop", html: html });
1885
1909
 
1886
- }
1910
+ }
1887
1911
 
1888
- parseText(text, payload) {
1912
+ parseText(text, payload) {
1889
1913
 
1890
-
1891
1914
 
1892
- var baseScope = JSON.parse(JSON.stringify(this));
1893
- delete baseScope.pass;
1894
1915
 
1895
- winston.debug("parseText text: "+ text);
1916
+ var baseScope = JSON.parse(JSON.stringify(this));
1917
+ delete baseScope.pass;
1896
1918
 
1897
- var templateHand = handlebars.compile(text);
1919
+ winston.debug("parseText text: " + text);
1898
1920
 
1899
- var replacements = {
1900
- payload: payload,
1901
- baseScope: baseScope,
1902
- test: "test"
1903
- };
1921
+ var templateHand = handlebars.compile(text);
1904
1922
 
1905
- var textTemplate = templateHand(replacements);
1906
- winston.debug("parseText textTemplate: "+ textTemplate);
1923
+ var replacements = {
1924
+ payload: payload,
1925
+ baseScope: baseScope,
1926
+ test: "test"
1927
+ };
1907
1928
 
1908
- return textTemplate;
1929
+ var textTemplate = templateHand(replacements);
1930
+ winston.debug("parseText textTemplate: " + textTemplate);
1909
1931
 
1932
+ return textTemplate;
1910
1933
 
1911
- }
1912
1934
 
1913
- formatText(templateName, defaultText, payload, settings) {
1935
+ }
1914
1936
 
1915
- let text = defaultText;
1916
- winston.debug("formatText defaultText: "+ defaultText);
1937
+ formatText(templateName, defaultText, payload, settings) {
1917
1938
 
1918
- let template = this.getTemplate(templateName, settings);
1939
+ let text = defaultText;
1940
+ winston.debug("formatText defaultText: " + defaultText);
1919
1941
 
1920
- winston.debug("formatText template: "+ template);
1942
+ let template = this.getTemplate(templateName, settings);
1921
1943
 
1922
- if (template) {
1923
- text = template;
1924
- }
1944
+ winston.debug("formatText template: " + template);
1925
1945
 
1926
- var baseScope = JSON.parse(JSON.stringify(this));
1927
- delete baseScope.pass;
1946
+ if (template) {
1947
+ text = template;
1948
+ }
1928
1949
 
1929
- winston.debug("formatText text: "+ text);
1950
+ var baseScope = JSON.parse(JSON.stringify(this));
1951
+ delete baseScope.pass;
1930
1952
 
1931
- var templateHand = handlebars.compile(text);
1953
+ winston.debug("formatText text: " + text);
1932
1954
 
1933
- var replacements = {
1934
- payload: payload,
1935
- baseScope: baseScope,
1936
- test: "test"
1937
- };
1955
+ var templateHand = handlebars.compile(text);
1956
+
1957
+ var replacements = {
1958
+ payload: payload,
1959
+ baseScope: baseScope,
1960
+ test: "test"
1961
+ };
1938
1962
 
1939
- var textTemplate = templateHand(replacements);
1940
- winston.debug("formatText textTemplate: "+ textTemplate);
1963
+ var textTemplate = templateHand(replacements);
1964
+ winston.debug("formatText textTemplate: " + textTemplate);
1941
1965
 
1942
- return textTemplate;
1966
+ return textTemplate;
1943
1967
 
1944
- }
1968
+ }
1945
1969
 
1946
- getTemplate(templateName, settings) {
1970
+ getTemplate(templateName, settings) {
1971
+
1972
+ var that = this;
1973
+ winston.debug('getTemplate formatSubject: ' + JSON.stringify(settings));
1947
1974
 
1948
- var that = this;
1949
- winston.debug('getTemplate formatSubject: ' + JSON.stringify(settings));
1950
-
1951
1975
 
1952
- if (settings && settings.email && settings.email.templates) {
1953
- winston.debug('getTemplate settings.email.templates: ',settings.email.templates);
1976
+ if (settings && settings.email && settings.email.templates) {
1977
+ winston.debug('getTemplate settings.email.templates: ', settings.email.templates);
1954
1978
 
1955
- var templates = settings.email.templates;
1956
- winston.debug('getTemplate templates: ',templates);
1979
+ var templates = settings.email.templates;
1980
+ winston.debug('getTemplate templates: ', templates);
1957
1981
 
1958
- var templateDbName = templateName.replace(".subject", "");
1959
- winston.debug('getTemplate templateDbName: '+templateDbName);
1982
+ var templateDbName = templateName.replace(".subject", "");
1983
+ winston.debug('getTemplate templateDbName: ' + templateDbName);
1960
1984
 
1961
1985
 
1962
- var template = templates[templateDbName];
1963
- winston.debug('getTemplate template: '+template);
1986
+ var template = templates[templateDbName];
1987
+ winston.debug('getTemplate template: ' + template);
1964
1988
 
1965
- if (template) {
1989
+ if (template) {
1966
1990
  // that.callback(template);
1967
- // return new Promise(function (resolve, reject) {
1968
- // return resolve(template);
1969
- return template;
1970
- // });
1971
- }else {
1972
- return undefined;
1973
- }
1991
+ // return new Promise(function (resolve, reject) {
1992
+ // return resolve(template);
1993
+ return template;
1994
+ // });
1974
1995
  } else {
1975
1996
  return undefined;
1976
- }
1997
+ }
1998
+ } else {
1999
+ return undefined;
2000
+ }
1977
2001
 
1978
- }
2002
+ }
1979
2003
 
1980
2004
 
1981
2005