Auto answer callback query plugin
This plugin auto answer on callback_query
events with answerCallbackQuery
method if you haven't done it yet.
Installation
bash
npm install @gramio/auto-answer-callback-query
bash
yarn add @gramio/auto-answer-callback-query
bash
pnpm add @gramio/auto-answer-callback-query
bash
bun install @gramio/auto-answer-callback-query
ts
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");
});
Params
You can pass params for answerCallbackQuery method
ts
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.