Skip to content

onResponse

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

Параметры

Объект с:

  • method - название метода API
  • params - параметры метода API
  • response - ответ

Пример

ts
import { 
Bot
} from "gramio";
const
bot
= new
Bot
(
process
.
env
.
BOT_TOKEN
as string).
onResponse
((
context
) => {
console
.
log
("ответ для",
context
.
method
,
context
.
response
);
});

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

ts
bot.onResponse("sendMessage", (context) => {
    console.log("ответ для sendMessage", context.response);
});
// или массив
bot.onResponse(["sendMessage", "sendPhoto"], (context) => {
    console.log("ответ для", context.method, context.response);
});