Skip to content

Commit

Permalink
restore waiting queue behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 24, 2024
1 parent ad5d85b commit 6592600
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
44 changes: 38 additions & 6 deletions apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,42 @@ export class QueueManager {
return LivechatInquiryStatus.READY;
}

static async queueInquiry(inquiry: ILivechatInquiryRecord, room: IOmnichannelRoom, defaultAgent?: SelectedAgent | null) {
if (inquiry.status === 'ready') {
return RoutingManager.delegateInquiry(inquiry, defaultAgent, undefined, room);
}

static async notifyQueuedInquiry(inquiry: ILivechatInquiryRecord, room: IOmnichannelRoom, defaultAgent?: SelectedAgent | null) {
await callbacks.run('livechat.afterInquiryQueued', inquiry);

void callbacks.run('livechat.chatQueued', room);

await this.dispatchInquiryQueued(inquiry, room, defaultAgent);
}

static async queueInquiry(inquiry: ILivechatInquiryRecord, room: IOmnichannelRoom, defaultAgent?: SelectedAgent | null) {
if (!(await Omnichannel.isWithinMACLimit(room))) {
logger.error({ msg: 'MAC limit reached, not routing inquiry', inquiry });
// We'll queue these inquiries so when new license is applied, they just start rolling again
// Minimizing disruption
await saveQueueInquiry(inquiry);
await this.notifyQueuedInquiry(inquiry, room, defaultAgent);
return;
}

await callbacks.run('livechat.beforeRouteChat', inquiry, defaultAgent);
const dbInquiry = await LivechatInquiry.findOneById(inquiry._id);

if (!dbInquiry) {
throw new Error('inquiry-not-found');
}

if (dbInquiry.status === 'ready') {
logger.debug({ msg: 'Inquiry is ready. Delegating', inquiry, defaultAgent });
return RoutingManager.delegateInquiry(dbInquiry, defaultAgent, undefined, room);
}

if (dbInquiry.status === 'queued') {
logger.debug(`Inquiry with id ${inquiry._id} is queued. Notifying`);
await this.notifyQueuedInquiry(inquiry, room, defaultAgent);
}
}

static async requestRoom({
guest,
rid = Random.id(),
Expand Down Expand Up @@ -252,7 +276,11 @@ export class QueueManager {
throw new Error('room-not-found');
}

if (!newRoom.servedBy && settings.get('Omnichannel_calculate_dispatch_service_queue_statistics')) {
if (
!newRoom.servedBy &&
settings.get('Livechat_waiting_queue') &&
settings.get('Omnichannel_calculate_dispatch_service_queue_statistics')
) {
const [inq] = await LivechatInquiry.getCurrentSortedQueueAsync({
inquiryId: inquiry._id,
department,
Expand Down Expand Up @@ -320,6 +348,10 @@ export class QueueManager {
}

private static dispatchInquiryQueued = async (inquiry: ILivechatInquiryRecord, room: IOmnichannelRoom, agent?: SelectedAgent | null) => {
if (RoutingManager.getConfig()?.autoAssignAgent) {
return;
}

logger.debug(`Notifying agents of new inquiry ${inquiry._id} queued`);

const { department, rid, v } = inquiry;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/RoutingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Routing = {
room: IOmnichannelRoom,
): Promise<IOmnichannelRoom | null | void>;
transferRoom(room: IOmnichannelRoom, guest: ILivechatVisitor, transferData: TransferData): Promise<boolean>;
delegateAgent(agent: SelectedAgent | undefined, inquiry: ILivechatInquiryRecord): Promise<SelectedAgent | null | undefined>;
delegateAgent(agent: SelectedAgent | undefined | null, inquiry: ILivechatInquiryRecord): Promise<SelectedAgent | null | undefined>;
removeAllRoomSubscriptions(room: Pick<IOmnichannelRoom, '_id'>, ignoreUser?: { _id: string }): Promise<void>;

assignAgent(inquiry: InquiryWithAgentInfo, room: IOmnichannelRoom, agent: SelectedAgent): Promise<InquiryWithAgentInfo>;
Expand Down

0 comments on commit 6592600

Please sign in to comment.