[NEW] Add Livechat website URL to the offline message e-mail (#17429)

* Add Web Site URL from where the message has been sent.

* Turn the host field mandatory.

* Check the host variable beforing adding it to the html content.

Co-authored-by: Marcos Spessatto Defendi <marcos.defendi@ulbra.inf.br>
pull/17442/head
Renato Becker 5 years ago committed by GitHub
parent c05eac5d58
commit 90b591ac22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/livechat/server/api/v1/offlineMessage.js
  2. 30
      app/livechat/server/lib/Livechat.js

@ -12,10 +12,11 @@ API.v1.addRoute('livechat/offline.message', {
email: String,
message: String,
department: Match.Maybe(String),
host: Match.Maybe(String),
});
const { name, email, message, department } = this.bodyParams;
if (!Livechat.sendOfflineMessage({ name, email, message, department })) {
const { name, email, message, department, host } = this.bodyParams;
if (!Livechat.sendOfflineMessage({ name, email, message, department, host })) {
return API.v1.failure({ message: TAPi18n.__('Error_sending_livechat_offline_message') });
}

@ -986,13 +986,18 @@ export const Livechat = {
return false;
}
const message = `${ data.message }`.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2');
const { message, name, email, department, host } = data;
const emailMessage = `${ message }`.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2');
const html = `
<h1>New livechat message</h1>
<p><strong>Visitor name:</strong> ${ data.name }</p>
<p><strong>Visitor email:</strong> ${ data.email }</p>
<p><strong>Message:</strong><br>${ message }</p>`;
let html = '<h1>New livechat message</h1>';
if (host && host !== '') {
html = html.concat(`<p><strong>Sent from:</strong><a href='${ host }'> ${ host }</a></p>`);
}
html = html.concat(`
<p><strong>Visitor name:</strong> ${ name }</p>
<p><strong>Visitor email:</strong> ${ email }</p>
<p><strong>Message:</strong><br>${ emailMessage }</p>`,
);
let fromEmail = settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);
@ -1003,7 +1008,7 @@ export const Livechat = {
}
if (settings.get('Livechat_validate_offline_email')) {
const emailDomain = data.email.substr(data.email.lastIndexOf('@') + 1);
const emailDomain = email.substr(email.lastIndexOf('@') + 1);
try {
Meteor.wrapAsync(dns.resolveMx)(emailDomain);
@ -1013,15 +1018,14 @@ export const Livechat = {
}
let emailTo = settings.get('Livechat_offline_email');
if (data.department) {
const dep = LivechatDepartment.findOneByIdOrName(data.department);
if (department && department !== '') {
const dep = LivechatDepartment.findOneByIdOrName(department);
emailTo = dep.email || emailTo;
}
const from = `${ data.name } - ${ data.email } <${ fromEmail }>`;
const replyTo = `${ data.name } <${ data.email }>`;
const subject = `Livechat offline message from ${ data.name }: ${ `${ data.message }`.substring(0, 20) }`;
const from = `${ name } - ${ email } <${ fromEmail }>`;
const replyTo = `${ name } <${ email }>`;
const subject = `Livechat offline message from ${ name }: ${ `${ emailMessage }`.substring(0, 20) }`;
this.sendEmail(from, emailTo, replyTo, subject, html);
Meteor.defer(() => {

Loading…
Cancel
Save