Skip to content

Commit

Permalink
[FIX] Stop queue when Omnichannel is disabled or the routing method d…
Browse files Browse the repository at this point in the history
…oes not support it (#23261)

* Stop queue when livechat is disabled or the routing method does not support queueing

* Fix error when Routing method was not set yet

Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com>
  • Loading branch information
KevLehman and murtaza98 authored Sep 23, 2021
1 parent 558bab0 commit 88b2698
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
4 changes: 3 additions & 1 deletion app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export const Livechat = {
}
}

return Livechat.checkOnlineAgents(department);
const agentsOnline = Livechat.checkOnlineAgents(department);
Livechat.logger.debug(`Are online agents ${ department ? `for department ${ department }` : '' }?: ${ agentsOnline }`);
return agentsOnline;
},

getNextAgent(department) {
Expand Down
4 changes: 2 additions & 2 deletions app/livechat/server/lib/QueueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const saveQueueInquiry = (inquiry) => {

export const queueInquiry = async (room, inquiry, defaultAgent) => {
const inquiryAgent = RoutingManager.delegateAgent(defaultAgent, inquiry);
logger.debug(`Delegating inquiry with id ${ inquiry._id } to agent ${ defaultAgent?._id }`);
logger.debug(`Delegating inquiry with id ${ inquiry._id } to agent ${ defaultAgent?.username }`);

await callbacks.run('livechat.beforeRouteChat', inquiry, inquiryAgent);
inquiry = LivechatInquiry.findOneById(inquiry._id);

if (inquiry.status === 'ready') {
logger.debug(`Inquiry with id ${ inquiry._id } is ready. Delegating to agent ${ inquiryAgent?._id }`);
logger.debug(`Inquiry with id ${ inquiry._id } is ready. Delegating to agent ${ inquiryAgent?.username }`);
return RoutingManager.delegateInquiry(inquiry, inquiryAgent);
}
};
Expand Down
7 changes: 4 additions & 3 deletions app/livechat/server/lib/RoutingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const RoutingManager = {
},

async getNextAgent(department, ignoreAgentId) {
logger.debug(`Getting next available agent with method ${ this.name }`);
logger.debug(`Getting next available agent with method ${ this.methodName }`);
return this.getMethod().getNextAgent(department, ignoreAgentId);
},

Expand All @@ -55,14 +55,15 @@ export const RoutingManager = {
if (!agent || (agent.username && !Users.findOneOnlineAgentByUserList(agent.username) && !allowAgentSkipQueue(agent))) {
logger.debug(`Agent offline or invalid. Using routing method to get next agent for inquiry ${ inquiry._id }`);
agent = await this.getNextAgent(department);
logger.debug(`Routing method returned agent ${ agent && agent.agentId } for inquiry ${ inquiry._id }`);
}

if (!agent) {
logger.debug(`No agents available. Unable to delegate inquiry ${ inquiry._id }`);
return LivechatRooms.findOneById(rid);
}

logger.debug(`Inquiry ${ inquiry._id } will be taken by agent ${ agent._id }`);
logger.debug(`Inquiry ${ inquiry._id } will be taken by agent ${ agent.agentId }`);
return this.takeInquiry(inquiry, agent, options);
},

Expand Down Expand Up @@ -195,7 +196,7 @@ export const RoutingManager = {
const defaultAgent = callbacks.run('livechat.beforeDelegateAgent', agent, { department: inquiry?.department });

if (defaultAgent) {
logger.debug(`Delegating Inquiry ${ inquiry._id } to agent ${ defaultAgent._id }`);
logger.debug(`Delegating Inquiry ${ inquiry._id } to agent ${ defaultAgent.username }`);
LivechatInquiry.setDefaultAgentById(inquiry._id, defaultAgent);
}

Expand Down
15 changes: 11 additions & 4 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import Subscriptions from './Subscriptions';
import { settings } from '../../../settings/server/functions/settings';

const queryStatusAgentOnline = (extraFilters = {}) => ({
status: {
$exists: true,
$ne: 'offline',
},
statusLivechat: 'available',
roles: 'livechat-agent',
$or: [{
status: {
$exists: true,
$ne: 'offline',
},
roles: {
$ne: 'bot',
},
}, {
roles: 'bot',
}],
...extraFilters,
...settings.get('Livechat_enabled_when_agent_idle') === false && { statusConnection: { $ne: 'away' } },
});
Expand Down
8 changes: 7 additions & 1 deletion ee/app/livechat-enterprise/server/lib/LivechatEnterprise.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ const queueWorker = {
},
};

settings.onload('Livechat_Routing_Method', function() {
function shouldQueueStart() {
const routingSupportsAutoAssign = RoutingManager.getConfig().autoAssignAgent;
queueLogger.debug(`Routing method ${ RoutingManager.methodName } supports auto assignment: ${ routingSupportsAutoAssign }. ${
routingSupportsAutoAssign
Expand All @@ -268,4 +268,10 @@ settings.onload('Livechat_Routing_Method', function() {
} queue`);

routingSupportsAutoAssign ? queueWorker.start() : queueWorker.stop();
}

settings.get('Livechat_enabled', (_, value) => {
value && settings.get('Livechat_Routing_Method') ? shouldQueueStart() : queueWorker.stop();
});

settings.onload('Livechat_Routing_Method', shouldQueueStart);

0 comments on commit 88b2698

Please sign in to comment.