mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-01 18:48:16 +00:00
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:
@@ -5,6 +5,7 @@ import {
|
|||||||
expandTextLinks,
|
expandTextLinks,
|
||||||
normalizeForwardedContext,
|
normalizeForwardedContext,
|
||||||
resolveTelegramForumThreadId,
|
resolveTelegramForumThreadId,
|
||||||
|
resolveTelegramThreadSpec,
|
||||||
} from "./helpers.js";
|
} from "./helpers.js";
|
||||||
|
|
||||||
describe("resolveTelegramForumThreadId", () => {
|
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", () => {
|
describe("buildTelegramThreadParams", () => {
|
||||||
it("omits General topic thread id for message sends", () => {
|
it("omits General topic thread id for message sends", () => {
|
||||||
expect(buildTelegramThreadParams({ id: 1, scope: "forum" })).toBeUndefined();
|
expect(buildTelegramThreadParams({ id: 1, scope: "forum" })).toBeUndefined();
|
||||||
|
|||||||
@@ -101,13 +101,15 @@ export function resolveTelegramThreadSpec(params: {
|
|||||||
scope: params.isForum ? "forum" : "none",
|
scope: params.isForum ? "forum" : "none",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (params.messageThreadId == null) {
|
// DM with forum/topics enabled — treat like a forum, not a flat DM
|
||||||
return { scope: "dm" };
|
if (params.isForum && params.messageThreadId != null) {
|
||||||
|
return { id: params.messageThreadId, scope: "forum" };
|
||||||
}
|
}
|
||||||
return {
|
// Preserve thread ID for non-forum DM threads (session routing, #8891)
|
||||||
id: params.messageThreadId,
|
if (params.messageThreadId != null) {
|
||||||
scope: "dm",
|
return { id: params.messageThreadId, scope: "dm" };
|
||||||
};
|
}
|
||||||
|
return { scope: "dm" };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user