Skip to content

onResponseError

Этот хук вызывается после получения ответа с ошибкой от Telegram Bot API.

Параметры

TelegramError

Пример

ts
import { 
Bot
} from "gramio";
const
bot
= new
Bot
(
process
.
env
.
BOT_TOKEN
as string).
onResponseError
(
(
context
) => {
console
.
log
("Ошибка для",
context
.
method
,
context
.
message
);
} );

Добавление хука только для определенных методов API

ts
bot.onResponseError("sendMessage", (context) => {
    console.log("Ошибка для sendMessage", context.message);
});
// или массив
bot.onResponseError(["sendMessage", "sendPhoto"], (context) => {
    console.log("Ошибка для", context.method, context.message);
});