[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
parent
26db22bc7a
commit
6ea78fdecc
@ -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; |
||||
Loading…
Reference in new issue