fix: handle forum/topics in Telegram DM thread routing (#17980)

resolveTelegramThreadSpec now checks isForum in the non-group path.
DMs with forum/topics enabled return scope 'forum' so each topic
gets its own session, while plain DM threads keep scope 'dm'.
This commit is contained in:
8BlT
2026-02-16 18:52:26 +07:00
committed by Peter Steinberger
parent c25c276e00
commit e20b87f1ba
2 changed files with 37 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import {
expandTextLinks,
normalizeForwardedContext,
resolveTelegramForumThreadId,
resolveTelegramThreadSpec,
} from "./helpers.js";
describe("resolveTelegramForumThreadId", () => {
@@ -32,6 +33,34 @@ describe("resolveTelegramForumThreadId", () => {
});
});
describe("resolveTelegramThreadSpec", () => {
it("returns dm scope for plain DM (no forum, no thread id)", () => {
expect(resolveTelegramThreadSpec({ isGroup: false })).toEqual({ scope: "dm" });
});
it("preserves thread id with dm scope when DM has thread id but is not a forum", () => {
expect(
resolveTelegramThreadSpec({ isGroup: false, isForum: false, messageThreadId: 42 }),
).toEqual({ id: 42, scope: "dm" });
});
it("returns forum scope when DM has isForum and thread id", () => {
expect(
resolveTelegramThreadSpec({ isGroup: false, isForum: true, messageThreadId: 99 }),
).toEqual({ id: 99, scope: "forum" });
});
it("falls back to dm scope when DM has isForum but no thread id", () => {
expect(resolveTelegramThreadSpec({ isGroup: false, isForum: true })).toEqual({ scope: "dm" });
});
it("delegates to group path for groups", () => {
expect(
resolveTelegramThreadSpec({ isGroup: true, isForum: true, messageThreadId: 50 }),
).toEqual({ id: 50, scope: "forum" });
});
});
describe("buildTelegramThreadParams", () => {
it("omits General topic thread id for message sends", () => {
expect(buildTelegramThreadParams({ id: 1, scope: "forum" })).toBeUndefined();