From 90b8f3fba20c5ebad3af1f423cf62148c91a3da9 Mon Sep 17 00:00:00 2001 From: Lucenx9 <185146821+Lucenx9@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:02:21 +0200 Subject: [PATCH] fix(telegram): tighten permanent edit error match --- .../telegram/src/bot-handlers.runtime.ts | 2 +- .../src/bot.create-telegram-bot.test.ts | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/extensions/telegram/src/bot-handlers.runtime.ts b/extensions/telegram/src/bot-handlers.runtime.ts index 015642f986c..05512a3441d 100644 --- a/extensions/telegram/src/bot-handlers.runtime.ts +++ b/extensions/telegram/src/bot-handlers.runtime.ts @@ -675,7 +675,7 @@ export const registerTelegramHandlers = ({ } const TELEGRAM_PERMANENT_CALLBACK_EDIT_ERROR_RE = - /400:\s*Bad Request:\s*message to edit not found|400:\s*Bad Request:\s*there is no text in the message to edit|MESSAGE_ID_INVALID|message can't be edited/i; + /400:\s*Bad Request:\s*message to edit not found|400:\s*Bad Request:\s*there is no text in the message to edit|MESSAGE_ID_INVALID|400:\s*Bad Request:\s*message can't be edited/i; const isPermanentTelegramCallbackEditError = (err: unknown): boolean => TELEGRAM_PERMANENT_CALLBACK_EDIT_ERROR_RE.test(String(err)); diff --git a/extensions/telegram/src/bot.create-telegram-bot.test.ts b/extensions/telegram/src/bot.create-telegram-bot.test.ts index 6d3674aa5d7..cae4087a620 100644 --- a/extensions/telegram/src/bot.create-telegram-bot.test.ts +++ b/extensions/telegram/src/bot.create-telegram-bot.test.ts @@ -3384,6 +3384,43 @@ describe("createTelegramBot", () => { expect(editMessageTextSpy).toHaveBeenCalledTimes(1); }); + it("does not swallow unprefixed command pagination edit failures", async () => { + createTelegramBot({ token: "tok" }); + const callbackHandler = getOnHandler("callback_query"); + + const ctx = { + update: { update_id: 778 }, + callbackQuery: { + id: "cbq-commands-non-telegram-edit-1", + data: "commands_page_2:main", + from: { id: 9, first_name: "Ada", username: "ada_bot" }, + message: { + chat: { id: 1234, type: "private" }, + date: 1736380800, + message_id: 21, + }, + }, + me: { username: "openclaw_bot" }, + getFile: async () => ({ download: async () => new Uint8Array() }), + }; + + editMessageTextSpy.mockRejectedValueOnce(new Error("message can't be edited")); + + await expect( + runTelegramMiddlewareChain({ + ctx, + finalHandler: callbackHandler, + }), + ).rejects.toThrow("message can't be edited"); + + await runTelegramMiddlewareChain({ + ctx, + finalHandler: callbackHandler, + }); + + expect(editMessageTextSpy).toHaveBeenCalledTimes(2); + }); + it("retries command pagination callbacks after a bubbled preflight failure", async () => { const listSkillCommandsMock = listSkillCommandsForAgents as unknown as ReturnType; listSkillCommandsMock.mockClear();