[FIX] Omnichannel On hold chats being forwarded to offline agents (#23185)

* Fix on-hold chats being forwarded to offline agents

* Dispatch agent changed event for livechat upon resuming onhold chat + logger issues

* Apply suggestions from code review

Co-authored-by: Kevin Aleman <kevin.aleman@rocket.chat>

Co-authored-by: Kevin Aleman <kevin.aleman@rocket.chat>
pull/23150/head
Murtaza Patrawala 5 years ago committed by GitHub
parent 26db22bc7a
commit 6ea78fdecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 54
      ee/app/livechat-enterprise/server/hooks/checkAgentBeforeTakeInquiry.ts
  2. 5
      ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts

@ -1,32 +1,64 @@
import { Meteor } from 'meteor/meteor';
import { callbacks } from '../../../../../app/callbacks';
import { callbacks } from '../../../../../app/callbacks/server';
import { Users } from '../../../../../app/models/server/raw';
import { settings } from '../../../../../app/settings';
import { settings } from '../../../../../app/settings/server';
import { getMaxNumberSimultaneousChat } from '../lib/Helper';
import { allowAgentSkipQueue } from '../../../../../app/livechat/server/lib/Helper';
import { cbLogger } from '../lib/logger';
import { Livechat } from '../../../../../app/livechat/server';
callbacks.add('livechat.checkAgentBeforeTakeInquiry', async ({ agent, inquiry, options }) => {
if (!settings.get('Livechat_waiting_queue')) {
cbLogger.debug('Skipping callback. Disabled by setting');
return agent;
callbacks.add('livechat.checkAgentBeforeTakeInquiry', async ({
agent,
inquiry,
options,
}: {
agent: {
agentId: string;
};
inquiry: {
_id: string;
department: string;
};
options: {
forwardingToDepartment? : {
oldDepartmentId: string;
transferData: any;
};
clientAction? : boolean;
};
}) => {
if (!inquiry?._id || !agent?.agentId) {
cbLogger.debug('Callback with error. No inquiry or agent provided');
return null;
}
const {
agentId,
} = agent;
if (!inquiry || !agent) {
cbLogger.debug('Callback with error. No inquiry or agent provided');
if (!Livechat.checkOnlineAgents(null, agent)) {
cbLogger.debug('Callback with error. provided agent is not online');
return null;
}
if (!settings.get('Livechat_waiting_queue')) {
cbLogger.debug('Skipping callback. Disabled by setting');
return agent;
}
if (allowAgentSkipQueue(agent)) {
cbLogger.debug(`Callback success. Agent ${ agent.agentId } can skip queue`);
return agent;
}
const { department: departmentId } = inquiry;
const { agentId } = agent;
const {
department: departmentId,
} = inquiry;
const maxNumberSimultaneousChat = getMaxNumberSimultaneousChat({ agentId, departmentId });
const maxNumberSimultaneousChat = getMaxNumberSimultaneousChat({
agentId,
departmentId,
});
if (maxNumberSimultaneousChat === 0) {
cbLogger.debug(`Callback success. Agent ${ agentId } max number simultaneous chats on range`);
return agent;

@ -3,6 +3,7 @@ import { LivechatInquiry, Subscriptions, LivechatRooms } from '../../../../../ap
import { queueInquiry } from '../../../../../app/livechat/server/lib/QueueManager';
import { settings } from '../../../../../app/settings/server';
import { cbLogger } from '../lib/logger';
import { dispatchAgentDelegated } from '../../../../../app/livechat/server/lib/Helper';
const handleOnAgentAssignmentFailed = async ({ inquiry, room, options }: { inquiry: any; room: any; options: { forwardingToDepartment?: { oldDepartmentId: string; transferData: any }; clientAction?: boolean} }): Promise<any> => {
if (!inquiry || !room) {
@ -15,10 +16,12 @@ const handleOnAgentAssignmentFailed = async ({ inquiry, room, options }: { inqui
const { _id: roomId } = room;
const { _id: inquiryId } = inquiry;
LivechatInquiry.readyInquiry(inquiryId);
LivechatInquiry.queueInquiry(inquiryId);
LivechatInquiry.removeDefaultAgentById(inquiryId);
LivechatRooms.removeAgentByRoomId(roomId);
Subscriptions.removeByRoomId(roomId);
dispatchAgentDelegated(roomId, null);
const newInquiry = LivechatInquiry.findOneById(inquiryId);
await queueInquiry(room, newInquiry);

Loading…
Cancel
Save