fix(telegram): scope DM topic thread keys by chat id

This commit is contained in:
Brian Le
2026-03-01 18:21:39 -05:00
committed by Peter Steinberger
parent bbab94c1fe
commit 049f00ab57
4 changed files with 4 additions and 4 deletions

View File

@@ -290,7 +290,7 @@ export const registerTelegramHandlers = ({
const dmThreadId = !params.isGroup ? params.messageThreadId : undefined;
const threadKeys =
dmThreadId != null
? resolveThreadSessionKeys({ baseSessionKey, threadId: String(dmThreadId) })
? resolveThreadSessionKeys({ baseSessionKey, threadId: `${params.chatId}:${dmThreadId}` })
: null;
const sessionKey = threadKeys?.sessionKey ?? baseSessionKey;
const storePath = resolveStorePath(cfg.session?.store, { agentId: route.agentId });

View File

@@ -19,7 +19,7 @@ describe("buildTelegramMessageContext dm thread sessions", () => {
expect(ctx).not.toBeNull();
expect(ctx?.ctxPayload?.MessageThreadId).toBe(42);
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:main:main:thread:42");
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:main:main:thread:1234:42");
});
it("keeps legacy dm session key when no thread id", async () => {

View File

@@ -204,7 +204,7 @@ export const buildTelegramMessageContext = async ({
const dmThreadId = threadSpec.scope === "dm" ? threadSpec.id : undefined;
const threadKeys =
dmThreadId != null
? resolveThreadSessionKeys({ baseSessionKey, threadId: String(dmThreadId) })
? resolveThreadSessionKeys({ baseSessionKey, threadId: `${chatId}:${dmThreadId}` })
: null;
const sessionKey = threadKeys?.sessionKey ?? baseSessionKey;
const mentionRegexes = buildMentionRegexes(cfg, route.agentId);

View File

@@ -551,7 +551,7 @@ export const registerTelegramNativeCommands = ({
dmThreadId != null
? resolveThreadSessionKeys({
baseSessionKey,
threadId: String(dmThreadId),
threadId: `${chatId}:${dmThreadId}`,
})
: null;
const sessionKey = threadKeys?.sessionKey ?? baseSessionKey;