Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down