fix(telegram): truncate commands to 100 to avoid BOT_COMMANDS_TOO_MUCH

Telegram Bot API limits setMyCommands to 100 commands per scope. When
users have many skills installed (~15+), the combined native + plugin +
custom commands can exceed this limit, causing a 400 error on every
gateway restart.

Truncate the command list to 100 (native commands first, then plugins,
then custom) and log a warning instead of failing the registration.

Fixes #11567
This commit is contained in:
Claude Code
2026-02-09 06:21:54 +01:00
committed by Ayaan Zaidi
parent 0768fc65d2
commit a656dcc199

View File

@@ -358,7 +358,7 @@ export const registerTelegramNativeCommands = ({
existingCommands.add(normalized);
pluginCommands.push({ command: normalized, description });
}
const allCommands: Array<{ command: string; description: string }> = [
const allCommandsFull: Array<{ command: string; description: string }> = [
...nativeCommands.map((command) => ({
command: command.name,
description: command.description,
@@ -366,6 +366,15 @@ export const registerTelegramNativeCommands = ({
...pluginCommands,
...customCommands,
];
// Telegram Bot API limits commands to 100 per scope.
// Truncate with a warning rather than failing with BOT_COMMANDS_TOO_MUCH.
const TELEGRAM_MAX_COMMANDS = 100;
if (allCommandsFull.length > TELEGRAM_MAX_COMMANDS) {
runtime.log?.(
`telegram: truncating ${allCommandsFull.length} commands to ${TELEGRAM_MAX_COMMANDS} (Telegram Bot API limit)`,
);
}
const allCommands = allCommandsFull.slice(0, TELEGRAM_MAX_COMMANDS);
// Clear stale commands before registering new ones to prevent
// leftover commands from deleted skills persisting across restarts (#5717).