mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 18:54:58 +00:00
fix(telegram): degrade command sync on BOT_COMMANDS_TOO_MUCH
When Telegram rejects native command registration for excessive commands, progressively retry with fewer commands instead of hard-failing startup.
Made-with: Cursor
(cherry picked from commit a02c40483e)
This commit is contained in:
committed by
Peter Steinberger
parent
79176cc4e5
commit
1ba525f94d
@@ -86,4 +86,42 @@ describe("bot-native-command-menu", () => {
|
||||
|
||||
expect(callOrder).toEqual(["delete", "set"]);
|
||||
});
|
||||
|
||||
it("retries with fewer commands on BOT_COMMANDS_TOO_MUCH", async () => {
|
||||
const deleteMyCommands = vi.fn(async () => undefined);
|
||||
const setMyCommands = vi
|
||||
.fn()
|
||||
.mockRejectedValueOnce(new Error("400: Bad Request: BOT_COMMANDS_TOO_MUCH"))
|
||||
.mockResolvedValue(undefined);
|
||||
const runtimeLog = vi.fn();
|
||||
|
||||
syncTelegramMenuCommands({
|
||||
bot: {
|
||||
api: {
|
||||
deleteMyCommands,
|
||||
setMyCommands,
|
||||
},
|
||||
} as unknown as Parameters<typeof syncTelegramMenuCommands>[0]["bot"],
|
||||
runtime: {
|
||||
log: runtimeLog,
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(),
|
||||
} as Parameters<typeof syncTelegramMenuCommands>[0]["runtime"],
|
||||
commandsToRegister: Array.from({ length: 100 }, (_, i) => ({
|
||||
command: `cmd_${i}`,
|
||||
description: `Command ${i}`,
|
||||
})),
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(setMyCommands).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
const firstPayload = setMyCommands.mock.calls[0]?.[0] as Array<unknown>;
|
||||
const secondPayload = setMyCommands.mock.calls[1]?.[0] as Array<unknown>;
|
||||
expect(firstPayload).toHaveLength(100);
|
||||
expect(secondPayload).toHaveLength(80);
|
||||
expect(runtimeLog).toHaveBeenCalledWith(
|
||||
"Telegram rejected 100 commands (BOT_COMMANDS_TOO_MUCH); retrying with 80.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user