mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 13:13:06 +00:00
fix(regression): handle telegram command error envelopes
This commit is contained in:
@@ -279,4 +279,32 @@ describe("bot-native-command-menu", () => {
|
||||
);
|
||||
expect(runtimeError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ label: "description envelope", error: { description: "BOT_COMMANDS_TOO_MUCH" } },
|
||||
{ label: "message envelope", error: { message: "BOT_COMMANDS_TOO_MUCH" } },
|
||||
])("retries when Telegram returns a plain-object $label error", async ({ error }) => {
|
||||
const deleteMyCommands = vi.fn(async () => undefined);
|
||||
const setMyCommands = vi.fn().mockRejectedValueOnce(error).mockResolvedValue(undefined);
|
||||
const runtimeLog = vi.fn();
|
||||
|
||||
syncMenuCommandsWithMocks({
|
||||
deleteMyCommands,
|
||||
setMyCommands,
|
||||
runtimeLog,
|
||||
commandsToRegister: Array.from({ length: 10 }, (_, i) => ({
|
||||
command: `cmd_${i}`,
|
||||
description: `Command ${i}`,
|
||||
})),
|
||||
accountId: `test-envelope-${Date.now()}`,
|
||||
botIdentity: "bot-a",
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(setMyCommands).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
expect(runtimeLog).toHaveBeenCalledWith(
|
||||
"Telegram rejected 10 commands (BOT_COMMANDS_TOO_MUCH); retrying with 8.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ function readErrorTextField(value: unknown, key: "description" | "message"): str
|
||||
if (!value || typeof value !== "object" || !(key in value)) {
|
||||
return undefined;
|
||||
}
|
||||
const text = value[key];
|
||||
const text = (value as Record<string, unknown>)[key];
|
||||
return typeof text === "string" ? text : undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user