diff --git a/app/livechat/server/lib/QueueManager.js b/app/livechat/server/lib/QueueManager.js index 6767cdc99c9e4..46ed51b7a14e6 100644 --- a/app/livechat/server/lib/QueueManager.js +++ b/app/livechat/server/lib/QueueManager.js @@ -35,11 +35,14 @@ export const QueueManager = { } inquiry = await callbacks.run('livechat.beforeRouteChat', inquiry, agent); - if (inquiry.status !== 'ready') { + if (inquiry.status === 'ready') { + return RoutingManager.delegateInquiry(inquiry, agent); + } + + if (inquiry.status === 'queued') { Meteor.defer(() => callbacks.run('livechat.chatQueued', room)); - return room; } - return RoutingManager.delegateInquiry(inquiry, agent); + return room; }, }; diff --git a/app/livechat/server/lib/routing/ManualSelection.js b/app/livechat/server/lib/routing/ManualSelection.js index f217424cf0628..1c14fe05e1857 100644 --- a/app/livechat/server/lib/routing/ManualSelection.js +++ b/app/livechat/server/lib/routing/ManualSelection.js @@ -5,6 +5,7 @@ import { Livechat } from '../Livechat'; import { RoutingManager } from '../RoutingManager'; import { sendNotification } from '../../../../lib/server'; import { LivechatRooms, LivechatInquiry, Users } from '../../../../models/server'; +import { callbacks } from '../../../../callbacks/server'; /* Manual Selection Queuing Method: * @@ -82,6 +83,8 @@ class ManualSelection { }); }); + Meteor.defer(() => callbacks.run('livechat.chatQueued', room)); + return agent; } } diff --git a/ee/app/livechat-enterprise/server/hooks/beforeRoutingChat.js b/ee/app/livechat-enterprise/server/hooks/beforeRoutingChat.js index aec059e676498..dd5cefce1bfad 100644 --- a/ee/app/livechat-enterprise/server/hooks/beforeRoutingChat.js +++ b/ee/app/livechat-enterprise/server/hooks/beforeRoutingChat.js @@ -25,7 +25,7 @@ callbacks.add('livechat.beforeRouteChat', async (inquiry) => { dispatchInquiryPosition(inq); } - checkWaitingQueue(department); + await checkWaitingQueue(department); return LivechatInquiry.findOneById(_id); }, callbacks.priority.HIGH, 'livechat-before-routing-chat'); diff --git a/ee/app/livechat-enterprise/server/lib/Helper.js b/ee/app/livechat-enterprise/server/lib/Helper.js index 072e98ac7d7fc..00964271e2304 100644 --- a/ee/app/livechat-enterprise/server/lib/Helper.js +++ b/ee/app/livechat-enterprise/server/lib/Helper.js @@ -118,7 +118,7 @@ const processWaitingQueue = async (department) => { await dispatchWaitingQueueStatus(departmentId); }; -export const checkWaitingQueue = (department) => { +export const checkWaitingQueue = async (department) => { if (!settings.get('Livechat_waiting_queue')) { return; } @@ -128,7 +128,7 @@ export const checkWaitingQueue = (department) => { return processWaitingQueue(); } - departments.forEach((department) => processWaitingQueue(department)); + return Promise.all(departments.forEach((department) => processWaitingQueue(department))); }; export const allowAgentSkipQueue = (agent) => {