import type { IRoutingMethod, RoutingMethodConfig, SelectedAgent } from '@rocket.chat/core-typings'; import { LivechatDepartmentAgents, Users } from '@rocket.chat/models'; import { settings } from '../../../settings'; import { callbacks } from '../../callbacks'; import { RoutingManager } from '../RoutingManager'; /* Auto Selection Queuing method: * * default method where the agent with the least number * of open chats is paired with the incoming livechat */ class AutoSelection implements IRoutingMethod { config: RoutingMethodConfig; constructor() { this.config = { previewRoom: false, showConnecting: false, showQueue: false, showQueueLink: true, returnQueue: false, enableTriggerAction: true, autoAssignAgent: true, }; } async getNextAgent(department?: string, ignoreAgentId?: string): Promise { const extraQuery = await callbacks.run('livechat.applySimultaneousChatRestrictions', undefined, { ...(department ? { departmentId: department } : {}), }); if (department) { return LivechatDepartmentAgents.getNextAgentForDepartment( department, settings.get('Livechat_enabled_when_agent_idle'), ignoreAgentId, extraQuery, settings.get('Livechat_accept_chats_with_no_agents'), ); } return Users.getNextAgent( ignoreAgentId, extraQuery, settings.get('Livechat_enabled_when_agent_idle'), settings.get('Livechat_accept_chats_with_no_agents'), ); } } RoutingManager.registerMethod('Auto_Selection', AutoSelection);