首页 文章

Telegram Bot,内联按钮

提问于
浏览
1

如何定义内联按钮被按下以及如何使用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);
}

但如何处理内联按钮的更新?

1 回答

  • 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
    }
    

相关问题