gpt4 book ai didi

javascript - Telegram Bot - 如何将 InlineKeyboardButton 与 CallbackQuery 绑定(bind)

转载 作者:行者123 更新时间:2023-11-30 11:45:08 35 4
gpt4 key购买 nike

我正在使用 node-telegram-bot-api。我会有多个 InlineKeyboardButton并用不同的 CallbackQuery 绑定(bind)它们抛出 answerCallbackQuery 方法。你能给我举个例子吗?谢谢。

最佳答案

我使用了以下解决方法:

...
var eventEmitter = new events.EventEmitter();


eventEmitter.on('my_fancy_event_1', function(){
...
})

eventEmitter.on('my_fancy_event_2', function(){
...
})

eventEmitter.on('my_fancy_event_3', function(){
...
})


var options = {
polling: true
};

...

var bot = new TelegramBot(token, options);

bot.onText(config.commands.commandStart, function onMessage(msg) {
var options = {
reply_markup: {
inline_keyboard: [
[{text: config.inlineText.addPurchase, callback_data: 'my_fancy_event_1'}],
[{text: config.inlineText.addRevenue, callback_data: 'my_fancy_event_2'}],
[{text: config.inlineText.getReport, callback_data: 'my_fancy_event_3'}]
]
}
};
bot.sendMessage(msg.from.id, "Choose an operation.",options);
});

bot.on('callback_query', function onCallbackQuery(callbackQuery) {
eventEmitter.emit(callbackQuery.data);
bot.answerCallbackQuery(callbackQuery.id, "Hi", false);
});

关于javascript - Telegram Bot - 如何将 InlineKeyboardButton 与 CallbackQuery 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41241308/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com