





















@@ -2588,13 +2588,29 @@ describe("createTelegramBot", () => {
2588258825892589it("reloads topic agent overrides between messages without recreating the bot", async () => {
25902590let topicAgentId = "topic-a";
2591-const resolveTopicConfig = () =>
2592-resolveTelegramScopedGroupConfig(
2593-{
2594-groupPolicy: "open",
2595-groups: {
2596-"-1001234567890": {
2597-requireMention: false,
2591+const configForTopicAgent = () => ({
2592+session: {
2593+typingMode: "never",
2594+},
2595+messages: {
2596+inbound: {
2597+debounceMs: 0,
2598+},
2599+},
2600+channels: {
2601+telegram: {
2602+botToken: "tok",
2603+dmPolicy: "open",
2604+allowFrom: ["*"],
2605+direct: {
2606+"123": {
2607+topics: {
2608+"99": {
2609+agentId: topicAgentId,
2610+},
2611+},
2612+},
2613+"124": {
25982614topics: {
25992615"99": {
26002616agentId: topicAgentId,
@@ -2603,13 +2619,42 @@ describe("createTelegramBot", () => {
26032619},
26042620},
26052621},
2606--1001234567890,
2607-99,
2608-).topicConfig;
2622+},
2623+agents: {
2624+list: [{ id: "topic-a" }, { id: "topic-b" }],
2625+},
2626+});
2627+loadConfig.mockImplementation(configForTopicAgent);
2628+2629+createTelegramBot({ token: "tok" });
2630+const handler = getOnHandler("message") as (ctx: Record<string, unknown>) => Promise<void>;
2631+replySpy.mockImplementation(async () => undefined);
2632+2633+const sendTopicMessage = async (chatId: number, messageId: number, text: string) => {
2634+await handler({
2635+message: {
2636+chat: { id: chatId, type: "private" },
2637+from: { id: chatId, username: `user${chatId}` },
2638+ text,
2639+date: 1736380800 + messageId,
2640+message_id: messageId,
2641+message_thread_id: 99,
2642+},
2643+me: { username: "openclaw_bot" },
2644+getFile: async () => ({ download: async () => new Uint8Array() }),
2645+});
2646+};
2647+2648+await sendTopicMessage(123, 44, "topic one");
2649+expect(replySpy).toHaveBeenCalledTimes(1);
2650+expect(replySpy.mock.calls.at(0)?.[0].SessionKey).toContain("agent:topic-a:");
2651+expect(replySpy.mock.calls.at(0)?.[0].SessionKey).toContain("thread:123:99");
260926522610-expect(resolveTopicConfig()?.agentId).toBe("topic-a");
26112653topicAgentId = "topic-b";
2612-expect(resolveTopicConfig()?.agentId).toBe("topic-b");
2654+await sendTopicMessage(124, 45, "topic two");
2655+expect(replySpy).toHaveBeenCalledTimes(2);
2656+expect(replySpy.mock.calls.at(1)?.[0].SessionKey).toContain("agent:topic-b:");
2657+expect(replySpy.mock.calls.at(1)?.[0].SessionKey).toContain("thread:124:99");
26132658});
2614265926152660it("routes non-default account DMs to the per-account fallback session without explicit bindings", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。