Skip to content

Commit

Permalink
Merge pull request RocketChat#584 from WideChat/kill_bot_switch
Browse files Browse the repository at this point in the history
[NEW] Livechat agent communication disable switch
  • Loading branch information
chadgoss committed Apr 5, 2021
2 parents 082c8c2 + fd537e1 commit cb8b539
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/livechat/server/api/lib/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ export function settings(url) {
return {
enabled: initSettings.Livechat_enabled,
settings: {
emergencyLivechatDisable: initSettings.Livechat_kill_switch,
emergencyLivechatDisableMessage: initSettings.Livechat_kill_switch_message,
registrationForm: shouldShowRegistrationForm(),
startSessionOnNewChat: initSettings.Livechat_start_session_on_new_chat,
allowSwitchingDepartments: initSettings.Livechat_allow_switching_departments,
Expand Down
15 changes: 15 additions & 0 deletions app/livechat/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ Meteor.startup(function() {
public: true,
});

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

settings.add('Livechat_kill_switch_message', 'Livechat is currently offline', {
type: 'string',
group: 'Omnichannel',
section: 'Livechat',
public: true,
});

settings.add('Livechat_title_color', '#C1272D', {
type: 'color',
editor: 'color',
Expand Down
4 changes: 3 additions & 1 deletion app/livechat/server/hooks/beforeDelegateAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { Users, LivechatDepartmentAgents } from '../../../models';

callbacks.add('livechat.beforeDelegateAgent', (options = {}) => {
const { department, agent } = options;

if (!settings.get('Livechat_kill_switch')) {
return null;
}
if (agent) {
return agent;
}
Expand Down
9 changes: 9 additions & 0 deletions app/livechat/server/hooks/leadCapture.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Meteor } from 'meteor/meteor';

import { callbacks } from '../../../callbacks';
import { settings } from '../../../settings';
import { LivechatVisitors } from '../../../models';


function validateMessage(message, room) {
// skips this callback if the message was edited
if (message.editedAt) {
Expand Down Expand Up @@ -45,3 +48,9 @@ callbacks.add('afterSaveMessage', function(message, room) {

return message;
}, callbacks.priority.LOW, 'leadCapture');

callbacks.add('beforeSaveMessage', () => {
if (settings.get('Livechat_kill_switch')) {
throw new Meteor.Error(settings.get('Livechat_kill_switch_message'));
}
}, callbacks.priority.MEDIUM, 'leadCapture');
2 changes: 2 additions & 0 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ export const Livechat = {
const rcSettings = {};

Settings.findNotHiddenPublic([
'Livechat_kill_switch',
'Livechat_kill_switch_message',
'Livechat_title',
'Livechat_title_color',
'Livechat_enable_message_character_limit',
Expand Down
5 changes: 4 additions & 1 deletion app/livechat/server/lib/routing/AutoSelection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RoutingManager } from '../RoutingManager';
import { LivechatDepartmentAgents, Users } from '../../../../models/server';
import { settings } from '../../../../settings/server';

/* Auto Selection Queuing method:
*
Expand All @@ -20,10 +21,12 @@ class AutoSelection {
}

getNextAgent(department, ignoreAgentId) {
if (!settings.get('Livechat_kill_switch')) {
return;
}
if (department) {
return LivechatDepartmentAgents.getNextAgentForDepartment(department, ignoreAgentId);
}

return Users.getNextAgent(ignoreAgentId);
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/livechat/server/lib/routing/External.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ class ExternalQueue {
'X-RocketChat-Secret-Token': settings.get('Livechat_External_Queue_Token'),
},
});

if (result && result.data && result.data.username) {
const agent = Users.findOneOnlineAgentByUsername(result.data.username);

if (agent) {
return {
agentId: agent._id,
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,8 @@
"Livechat_DepartmentOfflineMessageToChannel": "Send this department's Livechat offline messages to a channel",
"Livechat_enable_message_character_limit": "Enable message character limit",
"Livechat_enabled": "Omnichannel enabled",
"Livechat_kill_switch": "Disable Livechat",
"Livechat_kill_switch_message": "Disable Livechat Message",
"Livechat_Facebook_API_Key": "OmniChannel API Key",
"Livechat_Facebook_API_Secret": "OmniChannel API Secret",
"Livechat_Facebook_Enabled": "Facebook integration enabled",
Expand Down Expand Up @@ -3742,6 +3744,7 @@
"Technology_Provider": "Technology Provider",
"Technology_Services": "Technology Services",
"Telecom": "Telecom",
"Temporary_livechat_shutdown": "Temporarily disable livechat communication between users and agents",
"Terms": "Terms",
"Test_Connection": "Test Connection",
"Test_Desktop_Notifications": "Test Desktop Notifications",
Expand Down

0 comments on commit cb8b539

Please sign in to comment.