test: guard telegram native commands when mock lacks .command

This commit is contained in:
Peter Steinberger
2026-01-12 22:12:16 +00:00
parent 59063a7c15
commit f13db1c836

View File

@@ -951,13 +951,18 @@ export function createTelegramBot(opts: TelegramBotOptions) {
); );
} }
for (const command of nativeCommands) { if (typeof bot.command !== "function") {
bot.command(command.name, async (ctx) => { runtime.info?.(
const msg = ctx.message; "telegram: bot.command not available on api mock; skipping native command handlers",
if (!msg) return; );
if (shouldSkipUpdate(ctx)) return; } else {
const chatId = msg.chat.id; for (const command of nativeCommands) {
const isGroup = bot.command(command.name, async (ctx) => {
const msg = ctx.message;
if (!msg) return;
if (shouldSkipUpdate(ctx)) return;
const chatId = msg.chat.id;
const isGroup =
msg.chat.type === "group" || msg.chat.type === "supergroup"; msg.chat.type === "group" || msg.chat.type === "supergroup";
const messageThreadId = (msg as { message_thread_id?: number }) const messageThreadId = (msg as { message_thread_id?: number })
.message_thread_id; .message_thread_id;
@@ -1138,7 +1143,8 @@ export function createTelegramBot(opts: TelegramBotOptions) {
textLimit, textLimit,
messageThreadId, messageThreadId,
}); });
}); });
}
} }
} else if (nativeDisabledExplicit) { } else if (nativeDisabledExplicit) {
bot.api.setMyCommands([]).catch((err) => { bot.api.setMyCommands([]).catch((err) => {