How to define that inline button is pressed and how to get callbackdata using pengrad/telegram-bot-api library? I have this code to send message with inline keyboard button
private void approveAdmin(User u){
User admin = userService.findByUserRole("ROLE_ADMIN");
SendMessage sm = new SendMessage(admin.getChatId(),
"Do you approve user: "+u.getfName()+" "+u.getlName()+" as admin?");
sm.replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton[]
{new InlineKeyboardButton("Approve user.").callbackData(u.getIdUser().toString())}));
BOT.execute(sm);
}
but how to handle update from inline button?
below snippet may helps you:
GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates());
List<Update> updates = updatesResponse.updates();
for (Update update : updates) {
CallbackQuery callbackQuery = update.callbackQuery();
if (callbackQuery != null) {
//use the callbackQuery object peroperties to provide the appropriate response
}
//to make the update handler fully functional, make sure to check other types of messages
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With