gpt4 book ai didi

java - 电报机器人 java : inline url button does not create an update and thus no callback data to respond on

转载 作者:行者123 更新时间:2023-12-02 11:21:05 26 4
gpt4 key购买 nike

所以我有这个按钮,我想在单击它后将其删除。但点击它不会生成更新?

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 中的

urlcallback_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/

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