From 4945d9dd25006e902bd6f60b10f5693cf5d787c0 Mon Sep 17 00:00:00 2001 From: Maneek21 <208369276+Maneek21@users.noreply.github.com> Date: Tue, 21 Jul 2026 13:21:15 +0530 Subject: [PATCH] Fix chat notification deep links --- apps/api/src/routes/messages.ts | 4 ++-- apps/api/src/workers/handlers/blocked-alert.ts | 2 +- apps/api/test/agent-mention-detection.test.ts | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/api/src/routes/messages.ts b/apps/api/src/routes/messages.ts index 62e5f95b..2e880e85 100644 --- a/apps/api/src/routes/messages.ts +++ b/apps/api/src/routes/messages.ts @@ -515,7 +515,7 @@ messageRoutes.post('/:spaceId', async (c) => { type: 'mention', title: `${userData?.name ?? 'Someone'} mentioned you`, body: normalizedContent.slice(0, 200), - link: `/spaces/${spaceId}?message=${message!.id}`, + link: `/chat?space=${encodeURIComponent(spaceId)}&message=${encodeURIComponent(message!.id)}`, }, { channel: 'chat', spaceId, isMention: true }); if (notification) { @@ -543,7 +543,7 @@ messageRoutes.post('/:spaceId', async (c) => { type: 'mention', title: `${userData?.name ?? 'Someone'} replied to your message`, body: normalizedContent.slice(0, 200), - link: `/spaces/${spaceId}?message=${parsed.data.parent_id}`, + link: `/chat?space=${encodeURIComponent(spaceId)}&message=${encodeURIComponent(parsed.data.parent_id)}`, }, { channel: 'chat', spaceId, isMention: true }); if (notification) { diff --git a/apps/api/src/workers/handlers/blocked-alert.ts b/apps/api/src/workers/handlers/blocked-alert.ts index d774309b..1070851f 100644 --- a/apps/api/src/workers/handlers/blocked-alert.ts +++ b/apps/api/src/workers/handlers/blocked-alert.ts @@ -129,7 +129,7 @@ export async function handleBlockedAlert(job: JobData): Promise { type: 'agent_suggestion', title: 'Blocked Team Member', body: message, - link: `/spaces/${spaceId}?message=${messageId}`, + link: `/chat?space=${encodeURIComponent(spaceId)}&message=${encodeURIComponent(messageId)}`, metadata: { task_id: task.id, nudge_type: 'blocked', diff --git a/apps/api/test/agent-mention-detection.test.ts b/apps/api/test/agent-mention-detection.test.ts index 92487ffe..421810be 100644 --- a/apps/api/test/agent-mention-detection.test.ts +++ b/apps/api/test/agent-mention-detection.test.ts @@ -225,6 +225,21 @@ test('structured mention of Defty user triggers agent-reply dispatch', async () assert.ok(body.id, 'response should include message id'); createdMessageIds.push(body.id!); + const [mentionNotification] = await db + .select({ link: notifications.link }) + .from(notifications) + .where(and( + eq(notifications.user_id, deftyUserId), + eq(notifications.type, 'mention'), + eq(notifications.link, `/chat?space=${spaceId}&message=${body.id}`), + )) + .limit(1); + assert.equal( + mentionNotification?.link, + `/chat?space=${spaceId}&message=${body.id}`, + 'mention notification should deep-link to the message on the chat surface', + ); + const dispatched = await findAgentReplyJob(body.id!); assert.ok(dispatched, 'agent-reply job should be enqueued for Defty mention'); const employeeQueued = await findAgentEmployeeMessageJob(body.id!);