如何定义按下内联按钮以及如何使用pengrad / telegram-bot-api库获取callbackdata?我有这个代码用内联键盘按钮发送消息
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);
}
但是如何处理内联按钮的更新?
答案 0 :(得分:0)
下面的代码段可以帮助您:
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
}