Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added setting and method to control Livechat system messages visibility #31751

Merged
merged 19 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f0fd186
feat: added method setHiddenSystemMessages to the api
aleksandernsilva Feb 14, 2024
7741095
feat: added new config to allow hiding livechat system messages
aleksandernsilva Feb 14, 2024
f20cb88
chore: moved setting to the correct section
aleksandernsilva Feb 16, 2024
c252ee8
fix: merging configs instead of choosing one or the other
aleksandernsilva Feb 26, 2024
50a73a4
chore: removed empty space
aleksandernsilva Feb 26, 2024
2aa07c4
fix: removed message types not relevant to Livechat
aleksandernsilva Feb 27, 2024
d4c54b5
chore: added pt-BR translations keys
aleksandernsilva Feb 27, 2024
8672ee9
chore: improved EN translation keys
aleksandernsilva Feb 27, 2024
aff886c
chore: changeset
aleksandernsilva Feb 27, 2024
ba2d5e2
chore: changeset
aleksandernsilva Feb 28, 2024
6152f56
refactor: replaced console.error with throw Error
aleksandernsilva Feb 28, 2024
cdadc01
feat: added hideSystemMessages to initialize method
aleksandernsilva Feb 28, 2024
7b78e2a
fix: small adjustment
aleksandernsilva Feb 28, 2024
06c2cd6
fix: filter out invalid system message types
aleksandernsilva Feb 28, 2024
83dd561
chore: added warning for invalid system messages
aleksandernsilva Mar 4, 2024
280332d
chore: removed "video call" message type as an option to hide
aleksandernsilva Mar 13, 2024
fef35b0
refactor: moved setting to ee
aleksandernsilva Mar 14, 2024
00997b0
fix: added missing invalidValue
aleksandernsilva Mar 15, 2024
a222f18
Merge branch 'develop' into feat/livechat-hide-system-messages
kodiakhq[bot] Mar 21, 2024
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
6 changes: 6 additions & 0 deletions .changeset/cyan-shoes-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/livechat": minor
---

Added Livechat setting `Hide system messages` & API method `setHiddenSystemMessages`, to customize system message visibility within the widget.
1 change: 1 addition & 0 deletions apps/meteor/app/livechat/server/api/lib/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export async function settings({ businessUnit = '' }: { businessUnit?: string }
limitTextLength:
initSettings.Livechat_enable_message_character_limit &&
(initSettings.Livechat_message_character_limit || initSettings.Message_MaxAllowedSize),
hiddenSystemMessages: initSettings.Livechat_hide_system_messages,
},
theme: {
title: initSettings.Livechat_title,
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ class LivechatClass {
'Livechat_show_agent_info',
'Livechat_clear_local_storage_when_chat_ended',
'Livechat_history_monitor_type',
'Livechat_hide_system_messages',
] as const;

type SettingTypes = (typeof validSettings)[number] | 'Livechat_Show_Connecting';
Expand Down
17 changes: 17 additions & 0 deletions apps/meteor/ee/app/livechat-enterprise/server/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ export const createSettings = async (): Promise<void> => {
i18nLabel: 'Omnichannel_transcript_pdf',
});

await settingsRegistry.add('Livechat_hide_system_messages', ['uj', 'ul', 'livechat-close'], {
type: 'multiSelect',
group: 'Omnichannel',
section: 'Livechat',
enterprise: true,
modules: ['livechat-enterprise'],
invalidValue: ['uj', 'ul', 'livechat-close'],
public: true,
values: [
{ key: 'uj', i18nLabel: 'Message_HideType_uj' },
{ key: 'ul', i18nLabel: 'Message_HideType_ul' },
{ key: 'livechat-close', i18nLabel: 'Message_HideType_livechat_closed' },
{ key: 'livechat-started', i18nLabel: 'Message_HideType_livechat_started' },
{ key: 'livechat_transfer_history', i18nLabel: 'Message_HideType_livechat_transfer_history' },
],
});

await Settings.addOptionValueById('Livechat_Routing_Method', {
key: 'Load_Balancing',
i18nLabel: 'Load_Balancing',
Expand Down
4 changes: 4 additions & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3175,6 +3175,7 @@
"Livechat_offline": "Omnichannel offline",
"Livechat_offline_message_sent": "Livechat offline message sent",
"Livechat_OfflineMessageToChannel_enabled": "Send Livechat offline messages to a channel",
"Livechat_hide_system_messages": "Hide system messages",
"Omnichannel_chat_closed_due_to_inactivity": "The chat was automatically closed because we haven't received any reply from {{guest}} in {{timeout}} seconds",
"Omnichannel_actions": "Omnichannel actions",
"Omnichannel_on_hold_chat_resumed": "On Hold Chat Resumed: {{comment}}",
Expand Down Expand Up @@ -3532,6 +3533,9 @@
"Message_HideType_changed_announcement": "Hide \"Room announcement changed to\" messages",
"Message_HideType_ut": "Hide \"User Joined Conversation\" messages",
"Message_HideType_wm": "Hide \"Welcome\" messages",
"Message_HideType_livechat_closed": "Hide \"Conversation finished\" messages",
"Message_HideType_livechat_started": "Hide \"Conversation started\" messages",
"Message_HideType_livechat_transfer_history": "Hide \"Conversation transfered\" messages",
"Message_Id": "Message Id",
"Message_Ignored": "This message was ignored",
"message-impersonate": "Impersonate Other Users",
Expand Down
4 changes: 4 additions & 0 deletions packages/i18n/src/locales/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@
"Livechat_offline": "Omnichannel offline",
"Livechat_offline_message_sent": "Mensagem offline do livechat enviada",
"Livechat_OfflineMessageToChannel_enabled": "Envie mensagens offline do livechat para um canal",
"Livechat_hide_system_messages": "Ocultar mensagens do sistema",
"Omnichannel_on_hold_chat_resumed": "Conversa em espera retomada: {{comment}}",
"Omnichannel_on_hold_chat_automatically": "A conversa foi automaticamente retomada de em espera após receber uma nova mensagem de {{guest}}",
"Omnichannel_on_hold_chat_resumed_manually": "A conversa foi manualmente retomada de em espera por {{user}}",
Expand Down Expand Up @@ -2961,6 +2962,9 @@
"Message_HideType_user_removed_room_from_team": "Ocultar mensagens de \"Usuário removeu sala da equipe\"",
"Message_HideType_ut": "Ocultar mensagens de \"Usuário entrou na conversa\"",
"Message_HideType_wm": "Ocultar mensagens de \"Bem-vindo\"",
"Message_HideType_livechat_closed": "Ocultar mensagens de \"Conversa encerrada\"",
"Message_HideType_livechat_started": "Ocultar mensagens de \"Conversa iniciada\"",
"Message_HideType_livechat_transfer_history": "Ocultar mensagens de \"Histórico de transferência\"",
"Message_Id": "ID da mensagem",
"Message_Ignored": "Esta mensagem foi ignorada",
"message-impersonate": "Personificar outros usuários",
Expand Down
29 changes: 21 additions & 8 deletions packages/livechat/src/helpers/canRenderMessage.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
import {
MESSAGE_TYPE_COMMAND,
MESSAGE_TYPE_LIVECHAT_CLOSED,
MESSAGE_TYPE_LIVECHAT_NAVIGATION_HISTORY,
MESSAGE_TYPE_PRIORITY_CHANGE,
MESSAGE_TYPE_ROOM_NAME_CHANGED,
MESSAGE_TYPE_SLA_CHANGE,
MESSAGE_TYPE_USER_ADDED,
MESSAGE_TYPE_USER_JOINED,
MESSAGE_TYPE_USER_LEFT,
MESSAGE_TYPE_USER_REMOVED,
MESSAGE_TYPE_WELCOME,
MESSAGE_VIDEO_CALL,
MESSAGE_WEBRTC_CALL,
} from '../components/Messages/constants';
import store from '../store';

const msgTypesNotRendered = [
MESSAGE_TYPE_WELCOME,
MESSAGE_TYPE_ROOM_NAME_CHANGED,
MESSAGE_TYPE_USER_ADDED,
MESSAGE_TYPE_USER_REMOVED,
MESSAGE_VIDEO_CALL,
MESSAGE_WEBRTC_CALL,
MESSAGE_TYPE_LIVECHAT_NAVIGATION_HISTORY,
MESSAGE_TYPE_USER_ADDED,
MESSAGE_TYPE_COMMAND,
MESSAGE_TYPE_USER_JOINED,
MESSAGE_TYPE_USER_LEFT,
MESSAGE_TYPE_LIVECHAT_CLOSED,
MESSAGE_TYPE_PRIORITY_CHANGE,
MESSAGE_TYPE_SLA_CHANGE,
];

export const canRenderMessage = ({ t }: { t: string }) => !msgTypesNotRendered.includes(t);
export const getHiddenSystemMessages = () => {
const { config, iframe } = store.state;
const configHiddenSystemMessages = config.settings.hiddenSystemMessages || [];
const localHiddenSystemMessages = iframe.hiddenSystemMessages || [];

return [...configHiddenSystemMessages, ...localHiddenSystemMessages] as string[];
};

export const canRenderMessage = ({ t }: { t: string }) => {
const hiddenSystemMessages = getHiddenSystemMessages();

return !msgTypesNotRendered.includes(t) && !hiddenSystemMessages.includes(t);
MarcosSpessatto marked this conversation as resolved.
Show resolved Hide resolved
};
6 changes: 6 additions & 0 deletions packages/livechat/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,16 @@ const api = {
setParentUrl: (parentUrl: StoreState['parentUrl']) => {
store.setState({ parentUrl });
},

setGuestMetadata(metadata: StoreState['iframe']['guestMetadata']) {
const { iframe } = store.state;
store.setState({ iframe: { ...iframe, guestMetadata: metadata } });
},

setHiddenSystemMessages: (hiddenSystemMessages: StoreState['iframe']['hiddenSystemMessages']) => {
const { iframe } = store.state;
store.setState({ iframe: { ...iframe, hiddenSystemMessages } });
},
};

function onNewMessageHandler(event: MessageEvent<LivechatMessageEventData<HooksWidgetAPI>>) {
Expand Down
9 changes: 9 additions & 0 deletions packages/livechat/src/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { parentCall } from '../lib/parentCall';
import { createToken } from '../lib/random';
import Store from './Store';

export type LivechatHiddenSytemMessageType =
| 'uj' // User joined
| 'ul' // User left
| 'livechat-close' // Chat closed
| 'livechat-started' // Chat started
| 'livechat_transfer_history'; // Chat transfered

export type StoreState = {
token: string;
typing: string[];
Expand Down Expand Up @@ -45,6 +52,7 @@ export type StoreState = {
showConnecting?: any;
limitTextLength?: any;
displayOfflineForm?: boolean;
hiddenSystemMessages?: LivechatHiddenSytemMessageType[];
};
online?: boolean;
departments: Department[];
Expand Down Expand Up @@ -73,6 +81,7 @@ export type StoreState = {
department?: string;
language?: string;
defaultDepartment?: string;
hiddenSystemMessages?: LivechatHiddenSytemMessageType[];
};
gdpr: {
accepted: boolean;
Expand Down
24 changes: 24 additions & 0 deletions packages/livechat/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type InitializeParams = {
agent: StoreState['defaultAgent'];
parentUrl: string;
setGuestMetadata: StoreState['iframe']['guestMetadata'];
hiddenSystemMessages: StoreState['iframe']['hiddenSystemMessages'];
};

const WIDGET_OPEN_WIDTH = 365;
Expand Down Expand Up @@ -75,6 +76,8 @@ export const VALID_CALLBACKS = [
'no-agent-online',
];

const VALID_SYSTEM_MESSAGES = ['uj', 'ul', 'livechat-close', 'livechat-started', 'livechat_transfer_history'];

const callbacks = mitt();

function registerCallback(eventName: string, fn: () => unknown) {
Expand Down Expand Up @@ -355,6 +358,23 @@ function setGuestMetadata(metadata: StoreState['iframe']['guestMetadata']) {
callHook('setGuestMetadata', metadata);
}

function setHiddenSystemMessages(hidden: StoreState['iframe']['hiddenSystemMessages']) {
aleksandernsilva marked this conversation as resolved.
Show resolved Hide resolved
if (!Array.isArray(hidden)) {
throw new Error('Error: Invalid parameters. Value must be an array of strings');
}

const hiddenSystemMessages = hidden.filter((h) => {
if (VALID_SYSTEM_MESSAGES.includes(h)) {
return true;
}

console.warn(`Error: Invalid system message "${h}"`);
return false;
});

callHook('setHiddenSystemMessages', hiddenSystemMessages);
}

function initialize(initParams: Partial<InitializeParams>) {
for (const initKey in initParams) {
if (!initParams.hasOwnProperty(initKey)) {
Expand Down Expand Up @@ -407,6 +427,9 @@ function initialize(initParams: Partial<InitializeParams>) {
case 'setGuestMetadata':
setGuestMetadata(params as InitializeParams['setGuestMetadata']);
continue;
case 'hiddenSystemMessages':
setHiddenSystemMessages(params as InitializeParams['hiddenSystemMessages']);
continue;
default:
continue;
}
Expand Down Expand Up @@ -506,6 +529,7 @@ const livechatWidgetAPI = {
setParentUrl,
setGuestMetadata,
clearAllCallbacks,
setHiddenSystemMessages,

// callbacks
onChatMaximized(fn: () => void) {
Expand Down
Loading