Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/livechat/client/views/app/livechatDepartmentForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@
<label><input type="radio" name="showOnOfflineForm" value="0" checked="{{showOnOfflineForm false}}" /> {{_ "No"}}</label>
</div>
</div>
<div class="input-line">
{{> livechatAutocompleteUser
onClickTag=onClickTagOfflineMessageChannel
list=selectedOfflineMessageChannel
onSelect=onSelectOfflineMessageChannel
collection='CachedChannelList'
endpoint='rooms.autocomplete.channelAndPrivate'
field='name'
sort='name'
label="Livechat_DepartmentOfflineMessageToChannel"
placeholder="Channel_name"
name="offlineMessageChannelName"
noMatchTemplate="roomSearchEmpty"
templateItem="popupList_item_channel"
modifier=offlineMessageChannelModifier
showLabel=true
}}
</div>
<div class="input-line">
<label>{{_ "Request_tag_before_closing_chat"}}</label>
<div>
Expand Down
44 changes: 43 additions & 1 deletion app/livechat/client/views/app/livechatDepartmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { t, handleError } from '../../../../utils';
import { hasPermission } from '../../../../authorization';
import { getCustomFormTemplate } from './customTemplates/register';
import './livechatDepartmentForm.html';
import { APIClient } from '../../../../utils/client';
import { APIClient, roomTypes } from '../../../../utils/client';

Template.livechatDepartmentForm.helpers({
department() {
Expand Down Expand Up @@ -91,6 +91,21 @@ Template.livechatDepartmentForm.helpers({
hasChatClosingTags() {
return [...Template.instance().chatClosingTags.get()].length > 0;
},
onClickTagOfflineMessageChannel() {
return Template.instance().onClickTagOfflineMessageChannel;
},
selectedOfflineMessageChannel() {
return Template.instance().offlineMessageChannel.get();
},
onSelectOfflineMessageChannel() {
return Template.instance().onSelectOfflineMessageChannel;
},
offlineMessageChannelModifier() {
return (filter, text = '') => {
const f = filter.get();
return `#${ f.length === 0 ? text : text.replace(new RegExp(filter.get()), (part) => `<strong>${ part }</strong>`) }`;
};
},
});

Template.livechatDepartmentForm.events({
Expand All @@ -111,6 +126,9 @@ Template.livechatDepartmentForm.events({
const showOnOfflineForm = instance.$('input[name=showOnOfflineForm]:checked').val();
const requestTagBeforeClosingChat = instance.$('input[name=requestTagBeforeClosingChat]:checked').val();
const chatClosingTags = instance.chatClosingTags.get();
const [offlineMessageChannel] = instance.offlineMessageChannel.get();
const offlineMessageChannelName = (offlineMessageChannel && roomTypes.getRoomName(offlineMessageChannel.t, offlineMessageChannel)) || '';

if (enabled !== '1' && enabled !== '0') {
return toastr.error(t('Please_select_enabled_yes_or_no'));
}
Expand All @@ -132,6 +150,7 @@ Template.livechatDepartmentForm.events({
requestTagBeforeClosingChat: requestTagBeforeClosingChat === '1',
email: email.trim(),
chatClosingTags,
offlineMessageChannelName,
};
}

Expand Down Expand Up @@ -242,7 +261,17 @@ Template.livechatDepartmentForm.onCreated(async function() {
this.chatClosingTags = new ReactiveVar([]);
this.availableTags = new ReactiveVar([]);
this.availableDepartmentTags = new ReactiveVar([]);
this.offlineMessageChannel = new ReactiveVar([]);

this.onClickTagOfflineMessageChannel = () => {
this.offlineMessageChannel.set([]);
};

this.onSelectOfflineMessageChannel = async ({ item }) => {
const { room } = await APIClient.v1.get(`rooms.info?roomId=${ item._id }`);
room.text = room.name;
this.offlineMessageChannel.set([room]);
};
this.onSelectAgents = ({ item: agent }) => {
this.selectedAgents.set([agent]);
};
Expand Down Expand Up @@ -272,4 +301,17 @@ Template.livechatDepartmentForm.onCreated(async function() {
this.loadAvailableTags(id);
}
});

this.autorun(async () => {
const department = this.department.get();
let offlineChannel;
if (department?.offlineMessageChannelName) {
const { room } = await APIClient.v1.get(`rooms.info?roomName=${ department?.offlineMessageChannelName }`);
if (room) {
room.text = room.name;
offlineChannel = [{ ...room }];
}
}
this.offlineMessageChannel.set(offlineChannel);
});
});
16 changes: 16 additions & 0 deletions app/livechat/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@ Meteor.startup(function() {
i18nDescription: 'Domains_allowed_to_embed_the_livechat_widget',
});

settings.add('Livechat_OfflineMessageToChannel_enabled', false, {
type: 'boolean',
group: 'Omnichannel',
section: 'Livechat',
public: true,
});

settings.add('Livechat_OfflineMessageToChannel_channel_name', '', {
type: 'string',
group: 'Omnichannel',
section: 'Livechat',
public: true,
enableQuery: { _id: 'Livechat_OfflineMessageToChannel_enabled', value: true },
i18nLabel: 'Channel_name',
});

settings.add('Livechat_Facebook_Enabled', false, {
type: 'boolean',
group: 'Omnichannel',
Expand Down
58 changes: 58 additions & 0 deletions app/livechat/server/hooks/offlineMessageToChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { callbacks } from '../../../callbacks';
import { settings } from '../../../settings';
import { sendMessage } from '../../../lib';
import { LivechatDepartment, Rooms, Users } from '../../../models';

callbacks.add('livechat.offlineMessage', (data) => {
if (!settings.get('Livechat_OfflineMessageToChannel_enabled')) {
return data;
}

let channelName = settings.get('Livechat_OfflineMessageToChannel_channel_name');
let departmentName;
const { name, email, department, message: text, host } = data;
if (department && department !== '') {
const dept = LivechatDepartment.findOneById(department, { fields: { name: 1, offlineMessageChannelName: 1 } });
departmentName = dept?.name;
if (dept?.offlineMessageChannelName) {
channelName = dept.offlineMessageChannelName;
}
}

if (!channelName || channelName === '') {
return data;
}

const room = Rooms.findOneByName(channelName, { fields: { t: 1, archived: 1 } });
if (!room || room.archived || room.closedAt) {
return data;
}

const user = Users.findOneById('rocket.cat', { fields: { username: 1 } });
if (!user) {
return data;
}

const lng = settings.get('Language') || 'en';

let msg = `${ TAPi18n.__('New_Livechat_offline_message_has_been_sent', { lng }) }: \n`;
if (host && host !== '') {
msg = msg.concat(`${ TAPi18n.__('Sent_from', { lng }) }: ${ host } \n`);
}
msg = msg.concat(`${ TAPi18n.__('Visitor_Name', { lng }) }: ${ name } \n`);
msg = msg.concat(`${ TAPi18n.__('Visitor_Email', { lng }) }: ${ email } \n`);
if (departmentName) {
msg = msg.concat(`${ TAPi18n.__('Department', { lng }) }: ${ departmentName } \n`);
}
msg = msg.concat(`${ TAPi18n.__('Message', { lng }) }: ${ text } \n`);

const message = {
rid: room._id,
msg,
groupable: false,
};

sendMessage(user, message, room, true);
}, callbacks.priority.MEDIUM, 'livechat-send-email-offline-message-to-channel');
1 change: 1 addition & 0 deletions app/livechat/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import './hooks/externalMessage';
import './hooks/leadCapture';
import './hooks/markRoomResponded';
import './hooks/offlineMessage';
import './hooks/offlineMessageToChannel';
import './hooks/RDStation';
import './hooks/saveAnalyticsData';
import './hooks/sendToCRM';
Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,7 @@
"Livechat_AllowedDomainsList": "Livechat Allowed Domains",
"Livechat_Appearance": "Livechat Appearance",
"Livechat_Dashboard": "Omnichannel Dashboard",
"Livechat_DepartmentOfflineMessageToChannel": "Send this department's Livechat offline messages to a channel",
"Livechat_enabled": "Omnichannel enabled",
"Livechat_Facebook_API_Key": "OmniChannel API Key",
"Livechat_Facebook_API_Secret": "OmniChannel API Secret",
Expand All @@ -2150,7 +2151,8 @@
"Livechat_Managers": "Managers",
"Livechat_offline": "Omnichannel offline",
"Livechat_online": "Omnichannel on-line",
"Livechat_offline_message_sent": "Omnichannel offline message sent",
"Livechat_OfflineMessageToChannel_enabled": "Send Livechat offline messages to a channel",
"Livechat_offline_message_sent": "Livechat offline message sent",
"Livechat_Queue": "Omnichannel Queue",
"Livechat_registration_form": "Registration Form",
"Livechat_registration_form_message": "Registration Form Message",
Expand Down Expand Up @@ -2456,6 +2458,7 @@
"New_discussion_first_message": "Usually, a discussion starts with a question, like \"How do I upload a picture?\"",
"New_integration": "New integration",
"New_line_message_compose_input": "`%s` - New line in message compose input",
"New_Livechat_offline_message_has_been_sent": "A new Livechat offline Message has been sent",
"New_logs": "New logs",
"New_Message_Notification": "New Message Notification",
"New_messages": "New messages",
Expand Down Expand Up @@ -3036,6 +3039,7 @@
"Send_your_JSON_payloads_to_this_URL": "Send your JSON payloads to this URL.",
"Sending": "Sending...",
"Sent_an_attachment": "Sent an attachment",
"Sent_from": "Sent from",
"Served_By": "Served By",
"Server_File_Path": "Server File Path",
"Server_Folder_Path": "Server Folder Path",
Expand Down Expand Up @@ -3662,7 +3666,9 @@
"Visible": "Visible",
"Visit_Site_Url_and_try_the_best_open_source_chat_solution_available_today": "Visit __Site_URL__ and try the best open source chat solution available today!",
"Visitor": "Visitor",
"Visitor_Email": "Visitor E-mail",
"Visitor_Info": "Visitor Info",
"Visitor_Name": "Visitor Name",
"Visitor_Navigation": "Visitor Navigation",
"Visitor_page_URL": "Visitor page URL",
"Visitor_time_on_site": "Visitor time on site",
Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,7 @@
"Livechat_AllowedDomainsList": "Domínios permitidos em Livechat",
"Livechat_Appearance": "Aparência do Livechat",
"Livechat_Dashboard": "Painel Omnichannel",
"Livechat_DepartmentOfflineMessageToChannel": "Enviar as mensagens offline de Livechat deste departamento para um canal",
"Livechat_enabled": "Omnichannel habilitado",
"Livechat_Facebook_API_Key": "Chave da API OmniChannel",
"Livechat_Facebook_API_Secret": "Secret da API OmniChannel",
Expand All @@ -1970,7 +1971,8 @@
"Livechat_managers": "Gerentes do Omnichannel",
"Livechat_offline": "Omnichannel offline",
"Livechat_online": "Omnichannel on-line",
"Livechat_offline_message_sent": "Mensagem offline de Omnichannel enviada",
"Livechat_offline_message_sent": "Mensagem offline do Livechat enviada",
"Livechat_OfflineMessageToChannel_enabled": "Envie mensagens offline do Livechat para um canal",
"Livechat_Queue": "Fila Omnichannel",
"Livechat_registration_form": "Formulário de Registro",
"Livechat_registration_form_message": "Mensagem do Formulário de Registro",
Expand Down Expand Up @@ -2239,6 +2241,7 @@
"New_discussion_first_message": "Normalmente, uma discussão começa com uma pergunta, como \"Como faço o carregamento de uma imagem?\"",
"New_integration": "Nova integração",
"New_line_message_compose_input": "`%s` - Nova linha na mensagem compor a entrada",
"New_Livechat_offline_message_has_been_sent": "Uma nova mensagem offline de Livechat foi enviada",
"New_logs": "Novos logs",
"New_Message_Notification": "Notificação de nova mensagem",
"New_messages": "Novas mensagens",
Expand Down Expand Up @@ -2760,6 +2763,7 @@
"Send_your_JSON_payloads_to_this_URL": "Envie seu payload JSON para esta URL.",
"Sending": "Enviando ...",
"Sent_an_attachment": "Enviou um anexo",
"Sent_from": "Enviado de",
"Served_By": "Atendido Por",
"Server_Info": "Informações do servidor",
"Server_Type": "Tipo de servidor",
Expand Down Expand Up @@ -3319,7 +3323,9 @@
"Visible": "Visível",
"Visit_Site_Url_and_try_the_best_open_source_chat_solution_available_today": "Visite __Site_URL__ e experimente a melhor solução de chat de código aberto disponível!",
"Visitor": "Visitante",
"Visitor_Email": "E-mail do Visitante",
"Visitor_Info": "Informações do Visitante",
"Visitor_Name": "Nome do Visitante",
"Visitor_Navigation": "Navegação do Visitante",
"Visitor_page_URL": "URL da página de visitante",
"Visitor_time_on_site": "Tempo do visitante no site",
Expand Down