fix(telegram): unify inbound handling for message-like updates (#20591)

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

Prepared head SHA: 442a100071
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
Ayaan Zaidi
2026-02-19 09:54:47 +05:30
committed by GitHub
parent 6b05916c14
commit d17a1f387b
5 changed files with 181 additions and 161 deletions

View File

@@ -151,6 +151,18 @@ describe("createTelegramBot", () => {
update: { message: mockMessage({ chat: mockChat({ id: 555 }) }) },
}),
).toBe("telegram:555");
expect(
getTelegramSequentialKey({
channelPost: mockMessage({ chat: mockChat({ id: -100777111222, type: "channel" }) }),
}),
).toBe("telegram:-100777111222");
expect(
getTelegramSequentialKey({
update: {
channel_post: mockMessage({ chat: mockChat({ id: -100777111223, type: "channel" }) }),
},
}),
).toBe("telegram:-100777111223");
expect(
getTelegramSequentialKey({
message: mockMessage({ chat: mockChat({ id: 123 }), text: "/stop" }),
@@ -1992,6 +2004,44 @@ describe("createTelegramBot", () => {
await handler(ctx);
await handler(ctx);
expect(replySpy).toHaveBeenCalledTimes(1);
});
it("dedupes duplicate channel_post updates by chat/message key", async () => {
onSpy.mockReset();
replySpy.mockReset();
loadConfig.mockReturnValue({
channels: {
telegram: {
groupPolicy: "open",
groups: {
"-100777111222": {
enabled: true,
requireMention: false,
},
},
},
},
});
createTelegramBot({ token: "tok" });
const handler = getOnHandler("channel_post") as (ctx: Record<string, unknown>) => Promise<void>;
const ctx = {
channelPost: {
chat: { id: -100777111222, type: "channel", title: "Wake Channel" },
from: { id: 98765, is_bot: true, first_name: "wakebot", username: "wake_bot" },
message_id: 777,
text: "wake check",
date: 1736380800,
},
me: { username: "openclaw_bot" },
getFile: async () => ({}),
};
await handler(ctx);
await handler(ctx);
expect(replySpy).toHaveBeenCalledTimes(1);
});
});