Skip to content

Commit

Permalink
fix: Don't propagate Mailer error to Livechat offline form (#30152)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Aug 30, 2023
1 parent 2e2a89e commit 69a5213
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-spiders-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed an issue where a mailer error was being sent to customers using offline message's form on Omnichannel instead of the translated one
9 changes: 5 additions & 4 deletions apps/meteor/app/livechat/server/api/v1/offlineMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ API.v1.addRoute(
{
async post() {
const { name, email, message, department, host } = this.bodyParams;
if (!(await Livechat.sendOfflineMessage({ name, email, message, department, host }))) {
return API.v1.failure({ message: i18n.t('Error_sending_livechat_offline_message') });
try {
await Livechat.sendOfflineMessage({ name, email, message, department, host });
return API.v1.success({ message: i18n.t('Livechat_offline_message_sent') });
} catch (e) {
return API.v1.failure(i18n.t('Error_sending_livechat_offline_message'));
}

return API.v1.success({ message: i18n.t('Livechat_offline_message_sent') });
},
},
);
4 changes: 1 addition & 3 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ export const Livechat = {

async sendOfflineMessage(data = {}) {
if (!settings.get('Livechat_display_offline_form')) {
return false;
throw new Error('error-offline-form-disabled');
}

const { message, name, email, department, host } = data;
Expand Down Expand Up @@ -894,8 +894,6 @@ export const Livechat = {
setImmediate(() => {
callbacks.run('livechat.offlineMessage', data);
});

return true;
},

async notifyAgentStatusChanged(userId, status) {
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/methods/sendOfflineMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Livechat } from '../lib/Livechat';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
'livechat:sendOfflineMessage'(data: { name: string; email: string; message: string }): Promise<boolean>;
'livechat:sendOfflineMessage'(data: { name: string; email: string; message: string }): Promise<void>;
}
}

Expand All @@ -23,7 +23,7 @@ Meteor.methods<ServerMethods>({
message: String,
});

return Livechat.sendOfflineMessage(data);
await Livechat.sendOfflineMessage(data);
},
});

Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/mailer/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ export const wrap = (html: string, data: { [key: string]: unknown } = {}): strin
}

if (!body) {
throw new Error('`body` is not set yet');
throw new Error('error-email-body-not-initialized');
}

return replaceEscaped(body.replace('{{body}}', html), data);
};

export const inlinecss = (html: string): string => {
const css = settings.get<string>('email_style');
return css ? juice.inlineContent(html, css) : html;
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,7 @@
"error-duplicate-priority-name": "A priority with the same name already exists",
"error-edit-permissions-not-allowed": "Editing permissions is not allowed",
"error-email-domain-blacklisted": "The email domain is blacklisted",
"error-email-body-not-initialized": "Email body not initialized. Setup Email's Header & Footer on Email settings before sending rich emails",
"error-email-send-failed": "Error trying to send email: {{message}}",
"error-essential-app-disabled": "Error: a Rocket.Chat App that is essential for this is disabled. Please contact your administrator",
"error-failed-to-delete-department": "Failed to delete department",
Expand Down

0 comments on commit 69a5213

Please sign in to comment.