This plugin auto answer on callback_query
events with answerCallbackQuery
method if you haven't done it yet.
import { Bot, InlineKeyboard } from "gramio";
import { autoAnswerCallbackQuery } from "@gramio/auto-answer-callback-query";
const bot = new Bot(process.env.BOT_TOKEN as string)
.extend(autoAnswerCallbackQuery())
.command("start", (context) =>
context.send("Hello!", {
reply_markup: new InlineKeyboard()
.text("test", "test")
.text("test2", "test2"),
})
)
.callbackQuery("test", () => {
// The plugin will call an answerCallbackQuery method since you didn't do it
return context.send("Hii");
})
.callbackQuery("test2", (context) => {
// you already answered so plugin won't try to answer
return context.answer("HII");
});
You can pass params for answerCallbackQuery method
bot.extend(
autoAnswerCallbackQuery({
text: "Auto answer",
show_alert: true,
})
);
Important
This plugin hijack the context.answerCallbackQuery
(context.answer
too) method to determine if the callback query was already answered or not. Please avoid global usage of bot.api.answerCallbackQuery
method in context because plugin can not work properly in this case.