所以我有这个按钮,我想在单击它后将其删除。 但点击它不会生成更新?
if (Objects.equals(text.toUpperCase(), "TEST")){
String out = link;
try {
SendMessage sendMessage=new SendMessage().setChatId(update.getMessage().getChatId()).setText("JOIN THE CHANNEL!");
InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> rowsInline = new ArrayList<>();
List<InlineKeyboardButton> rowInline = new ArrayList<>();
rowInline.add(new InlineKeyboardButton().setText("JOIN").setCallbackData("JOIN_PREMIUM").setUrl(link));
rowsInline.add(rowInline);
markupInline.setKeyboard(rowsInline);
sendMessage.setReplyMarkup(markupInline);
sendMessage(sendMessage);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
要在按下时决定一个 Action ,我有:
else if (update.hasInlineQuery()||update.hasCallbackQuery()||update.hasChosenInlineQuery()||update.hasPreCheckoutQuery()||update.hasShippingQuery()){
String call_data = update.getCallbackQuery().getData();
System.out.println("CALL DATA: "+call_data);
int message_id = update.getCallbackQuery().getMessage().getMessageId();
long chat_id = update.getCallbackQuery().getMessage().getChatId();
if (Objects.equals(call_data, "JOIN_PREMIUM")){
EditMessageText editMessageText = new EditMessageText().setMessageId(message_id).setChatId(chat_id);
editMessageText.setText("Welcome to the club!");
try {
editMessageText(editMessageText);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
但这没有用,因为它没有提供更新,但应该! 有没有人有解决办法?
最佳答案
InlineKeyboardButton 中的
url 和 callback_data 是可选字段。
You must use exactly one of the optional fields.
documentation for InlineKeyboardButton
所以,问题就在这里:
rowInline.add(new InlineKeyboardButton()
.setText("JOIN")
.setCallbackData("JOIN_PREMIUM")
.setUrl(link));
您应该删除其中一个
.setCallbackData("JOIN_PREMIUM")
或
.setUrl(link)
我还有一点不重要的评论。这一行有很多冗余
else if (update.hasInlineQuery()||update.hasCallbackQuery()||update.hasChosenInlineQuery()||update.hasPreCheckoutQuery()||update.hasShippingQuery())
您可以将其缩短为
else if (update.hasCallbackQuery())
关于java - 电报机器人 java : inline url button does not create an update and thus no callback data to respond on,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49919212/