diff --git a/apps/meteor/app/livechat/server/hooks/sendToCRM.ts b/apps/meteor/app/livechat/server/hooks/sendToCRM.ts index 483cbd757da..e6a75f5b237 100644 --- a/apps/meteor/app/livechat/server/hooks/sendToCRM.ts +++ b/apps/meteor/app/livechat/server/hooks/sendToCRM.ts @@ -166,19 +166,6 @@ callbacks.add( 'livechat-send-crm-close-room', ); -callbacks.add( - 'livechat.chatQueued', - (room) => { - if (!settings.get('Livechat_webhook_on_chat_queued')) { - return room; - } - - return sendToCRM('LivechatSessionQueued', room); - }, - callbacks.priority.MEDIUM, - 'livechat-send-crm-room-queued', -); - callbacks.add( 'livechat.afterForwardChatToAgent', async (params) => { diff --git a/apps/meteor/app/livechat/server/lib/Helper.ts b/apps/meteor/app/livechat/server/lib/Helper.ts index 09b7f4d3386..330d37eae47 100644 --- a/apps/meteor/app/livechat/server/lib/Helper.ts +++ b/apps/meteor/app/livechat/server/lib/Helper.ts @@ -41,7 +41,7 @@ import { queueInquiry, saveQueueInquiry } from './QueueManager'; import { RoutingManager } from './RoutingManager'; import { isVerifiedChannelInSource } from './contacts/isVerifiedChannelInSource'; import { migrateVisitorIfMissingContact } from './contacts/migrateVisitorIfMissingContact'; -import { beforeNewRoom } from './hooks'; +import { afterRoomQueued, beforeNewRoom } from './hooks'; import { checkOnlineAgents, getOnlineAgents } from './service-status'; import { saveTransferHistory } from './transfer'; import { callbacks } from '../../../../lib/callbacks'; @@ -413,7 +413,7 @@ export const dispatchInquiryQueued = async (inquiry: ILivechatInquiryRecord, age return; } - setImmediate(() => callbacks.run('livechat.chatQueued', room)); + void afterRoomQueued(room); if (RoutingManager.getConfig()?.autoAssignAgent) { return; diff --git a/apps/meteor/app/livechat/server/lib/QueueManager.ts b/apps/meteor/app/livechat/server/lib/QueueManager.ts index 83fd0b3e3c2..4149fb4fd4b 100644 --- a/apps/meteor/app/livechat/server/lib/QueueManager.ts +++ b/apps/meteor/app/livechat/server/lib/QueueManager.ts @@ -23,7 +23,7 @@ import { createLivechatRoom, createLivechatInquiry, allowAgentSkipQueue, prepare import { RoutingManager } from './RoutingManager'; import { isVerifiedChannelInSource } from './contacts/isVerifiedChannelInSource'; import { checkOnlineForDepartment } from './departmentsLib'; -import { afterInquiryQueued, beforeDelegateAgent, onNewRoom } from './hooks'; +import { afterInquiryQueued, afterRoomQueued, beforeDelegateAgent, onNewRoom } from './hooks'; import { checkOnlineAgents, getOnlineAgents } from './service-status'; import { getInquirySortMechanismSetting } from './settings'; import { dispatchInquiryPosition } from '../../../../ee/app/livechat-enterprise/server/lib/Helper'; @@ -172,8 +172,7 @@ export class QueueManager { } if (inquiry.status === LivechatInquiryStatus.QUEUED) { - await afterInquiryQueued(inquiry); - await callbacks.run('livechat.chatQueued', room); + await Promise.all([afterInquiryQueued(inquiry), afterRoomQueued(room)]); if (defaultAgent) { logger.debug(`Setting default agent for inquiry ${inquiry._id} to ${defaultAgent.username}`); diff --git a/apps/meteor/app/livechat/server/lib/hooks.ts b/apps/meteor/app/livechat/server/lib/hooks.ts index d9487f2c74a..1a942e77ce8 100644 --- a/apps/meteor/app/livechat/server/lib/hooks.ts +++ b/apps/meteor/app/livechat/server/lib/hooks.ts @@ -124,3 +124,11 @@ export const afterTakeInquiry = makeFunction( export const afterInquiryQueued = makeFunction(async (_inquiry: ILivechatInquiryRecord) => { return void 0; }); + +export const afterRoomQueued = makeFunction((room: IOmnichannelRoom) => { + if (!settings.get('Livechat_webhook_on_chat_queued')) { + return; + } + + return sendToCRM('LivechatSessionQueued', room); +}); diff --git a/apps/meteor/lib/callbacks.ts b/apps/meteor/lib/callbacks.ts index 6b5747a53f3..73cf586b7f4 100644 --- a/apps/meteor/lib/callbacks.ts +++ b/apps/meteor/lib/callbacks.ts @@ -181,7 +181,6 @@ type ChainedCallbackSignatures = { }; 'livechat.beforeListTags': () => ILivechatTag[]; 'livechat.offlineMessage': (data: { name: string; email: string; message: string; department?: string; host?: string }) => void; - 'livechat.chatQueued': (room: IOmnichannelRoom) => IOmnichannelRoom; 'livechat.leadCapture': (room: IOmnichannelRoom) => IOmnichannelRoom; 'beforeSendMessageNotifications': (message: string) => string; 'livechat.onAgentAssignmentFailed': ( @@ -220,7 +219,6 @@ export type Hook = | 'beforeRemoveFromRoom' | 'beforeValidateLogin' | 'livechat.beforeForwardRoomToDepartment' - | 'livechat.chatQueued' | 'livechat.checkAgentBeforeTakeInquiry' | 'livechat.sendTranscript' | 'livechat.closeRoom'