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

标签 java telegram-bot

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

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/

相关文章:

telegram - Telegram 嵌入式键盘和键盘

bots - Telegram Bot webhook 真的很慢

java - IllegalArgumentException : Parameter valuefunction. AggregationFunction 与预期类型不匹配 [java.lang.Long (n/a)]

amazon-web-services - AWS Lambda 按顺序处理来自电报机器人的请求并且无法扩展

java - 扫描不适用于 logback.xml

java - 用于 STEP 的 Java API (p21) - 创建符合 STEP 标准的文件

node.js - 如何在点击按钮时显示消息?

json - 电报机器人 : example json, inline_keyboard

java - 通过在小程序中拖放将文本添加到图像上

java - RecyclerView 滚动时扩展项目之间的空间