Fix Telegram DM last-route metadata leakage (#19491)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 16b025b3aa
Co-authored-by: guirguispierre <22091706+guirguispierre@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
Pierre
2026-02-21 21:59:59 -08:00
committed by GitHub
parent 54e5f80424
commit 4f700e96af
5 changed files with 86 additions and 4 deletions

View File

@@ -41,8 +41,9 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute includes threadId
const updateLastRoute = getUpdateLastRoute() as { threadId?: string } | undefined;
const updateLastRoute = getUpdateLastRoute() as { threadId?: string; to?: string } | undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:1234");
expect(updateLastRoute?.threadId).toBe("42");
});
@@ -57,8 +58,9 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute does NOT include threadId
const updateLastRoute = getUpdateLastRoute() as { threadId?: string } | undefined;
const updateLastRoute = getUpdateLastRoute() as { threadId?: string; to?: string } | undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:1234");
expect(updateLastRoute?.threadId).toBeUndefined();
});

View File

@@ -765,7 +765,7 @@ export const buildTelegramMessageContext = async ({
? {
sessionKey: route.mainSessionKey,
channel: "telegram",
to: String(chatId),
to: `telegram:${chatId}`,
accountId: route.accountId,
// Preserve DM topic threadId for replies (fixes #8891)
threadId: dmThreadId != null ? String(dmThreadId) : undefined,