Skip to content

Commit 90b8f3f

Browse files
Lucenx9steipete
authored andcommitted
fix(telegram): tighten permanent edit error match
1 parent d8b18f1 commit 90b8f3f

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

extensions/telegram/src/bot-handlers.runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ export const registerTelegramHandlers = ({
675675
}
676676

677677
const TELEGRAM_PERMANENT_CALLBACK_EDIT_ERROR_RE =
678-
/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;
678+
/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;
679679

680680
const isPermanentTelegramCallbackEditError = (err: unknown): boolean =>
681681
TELEGRAM_PERMANENT_CALLBACK_EDIT_ERROR_RE.test(String(err));

extensions/telegram/src/bot.create-telegram-bot.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,6 +3384,43 @@ describe("createTelegramBot", () => {
33843384
expect(editMessageTextSpy).toHaveBeenCalledTimes(1);
33853385
});
33863386

3387+
it("does not swallow unprefixed command pagination edit failures", async () => {
3388+
createTelegramBot({ token: "tok" });
3389+
const callbackHandler = getOnHandler("callback_query");
3390+
3391+
const ctx = {
3392+
update: { update_id: 778 },
3393+
callbackQuery: {
3394+
id: "cbq-commands-non-telegram-edit-1",
3395+
data: "commands_page_2:main",
3396+
from: { id: 9, first_name: "Ada", username: "ada_bot" },
3397+
message: {
3398+
chat: { id: 1234, type: "private" },
3399+
date: 1736380800,
3400+
message_id: 21,
3401+
},
3402+
},
3403+
me: { username: "openclaw_bot" },
3404+
getFile: async () => ({ download: async () => new Uint8Array() }),
3405+
};
3406+
3407+
editMessageTextSpy.mockRejectedValueOnce(new Error("message can't be edited"));
3408+
3409+
await expect(
3410+
runTelegramMiddlewareChain({
3411+
ctx,
3412+
finalHandler: callbackHandler,
3413+
}),
3414+
).rejects.toThrow("message can't be edited");
3415+
3416+
await runTelegramMiddlewareChain({
3417+
ctx,
3418+
finalHandler: callbackHandler,
3419+
});
3420+
3421+
expect(editMessageTextSpy).toHaveBeenCalledTimes(2);
3422+
});
3423+
33873424
it("retries command pagination callbacks after a bubbled preflight failure", async () => {
33883425
const listSkillCommandsMock = listSkillCommandsForAgents as unknown as ReturnType<typeof vi.fn>;
33893426
listSkillCommandsMock.mockClear();

0 commit comments

Comments
 (0)