From 15b585c74674c1436d92be498408b25c152ba799 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 4 Sep 2024 11:10:13 -0600 Subject: [PATCH 1/3] find room before calling aftertakeinquiry --- .../app/livechat/server/lib/RoutingManager.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/meteor/app/livechat/server/lib/RoutingManager.ts b/apps/meteor/app/livechat/server/lib/RoutingManager.ts index f4a2288305e54..390d533fed600 100644 --- a/apps/meteor/app/livechat/server/lib/RoutingManager.ts +++ b/apps/meteor/app/livechat/server/lib/RoutingManager.ts @@ -265,11 +265,21 @@ export const RoutingManager: Routing = { logger.info(`Inquiry ${inquiry._id} taken by agent ${agent.agentId}`); + // assignAgent changes the room data to add the agent serving the conversation. afterTakeInquiry expects room object to be updated + const inq = await this.assignAgent(inquiry as InquiryWithAgentInfo, room, agent); + const roomAfterUpdate = await LivechatRooms.findOneById(rid); + + if (!roomAfterUpdate) { + // This should never happen + throw new Error('error-room-not-found'); + } + callbacks.runAsync( 'livechat.afterTakeInquiry', { - inquiry: await this.assignAgent(inquiry as InquiryWithAgentInfo, room, agent), - room, + inquiry: inq, + // @eslint-disable-next-line @typescript-eslint/no-non-null-assertion + room: roomAfterUpdate, }, agent, ); @@ -282,7 +292,7 @@ export const RoutingManager: Routing = { queuedAt: undefined, }); - return LivechatRooms.findOneById(rid); + return roomAfterUpdate; }, async transferRoom(room, guest, transferData) { From f1ce8b6b186352ad3bae3e33bbcc024dac009905 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 4 Sep 2024 11:12:49 -0600 Subject: [PATCH 2/3] Create spicy-rocks-burn.md --- .changeset/spicy-rocks-burn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/spicy-rocks-burn.md diff --git a/.changeset/spicy-rocks-burn.md b/.changeset/spicy-rocks-burn.md new file mode 100644 index 0000000000000..6468dbbec2413 --- /dev/null +++ b/.changeset/spicy-rocks-burn.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixed `LivechatSessionTaken` webhook event being called without the `agent` param, which represents the agent serving the room. From c417b3b6d65749dd42e91752f660ce7802cfca96 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Thu, 5 Sep 2024 07:42:09 -0600 Subject: [PATCH 3/3] Update RoutingManager.ts --- apps/meteor/app/livechat/server/lib/RoutingManager.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/meteor/app/livechat/server/lib/RoutingManager.ts b/apps/meteor/app/livechat/server/lib/RoutingManager.ts index 390d533fed600..28e5c72efc16b 100644 --- a/apps/meteor/app/livechat/server/lib/RoutingManager.ts +++ b/apps/meteor/app/livechat/server/lib/RoutingManager.ts @@ -278,7 +278,6 @@ export const RoutingManager: Routing = { 'livechat.afterTakeInquiry', { inquiry: inq, - // @eslint-disable-next-line @typescript-eslint/no-non-null-assertion room: roomAfterUpdate, }, agent,