如何使用 Telegram java TdApi 在 replyMarkup 上回答?

How to answer on replyMarkup using Telegram java TdApi?

我正在使用 https://github.com/tdlib/td/tree/master/example/java 中的代码在 java 上制作电报客户端 我需要从我的应用程序与电报机器人进行通信。 Bot 发送带有附加 InlineKeyboardButtons 的消息。如果我点击了按钮,我该如何发送这些消息的回复?

TdApi 有 class "AnswerInlineQuery" 但我不明白如何根据我的代码调整它以及我应该在何处获取参数来制作此答案对象。 我尝试使用 "sendMessage" 函数和 "replyToMessageId" 参数进行回复。

这是接收到的消息的结构

UpdateNewMessage { message = Message {
    id = 969932800
    senderUserId = 0
    chatId = -1001418532179
    sendingState = null
    isOutgoing = false
    canBeEdited = false
    canBeForwarded = true
    canBeDeletedOnlyForSelf = false
    canBeDeletedForAllUsers = false
    isChannelPost = true
    containsUnreadMention = false
    date = 1562509621
    editDate = 0
    forwardInfo = null
    replyToMessageId = 0
    ttl = 0
    ttlExpiresIn = 0.000000
    viaBotUserId = 0
    authorSignature = ""
    views = 1
    mediaAlbumId = 0
    content = MessageText {
      text = FormattedText {
        text = "опрос"
        entities = Array[0] {
        }
      }
      webPage = null
    }
    replyMarkup = ReplyMarkupInlineKeyboard {
      rows = Array[1] {
        Array[3] {
          InlineKeyboardButton {
            text = "1"
            type = InlineKeyboardButtonTypeCallback {
              data = bytes [15] { 73 65 6E 64 5F 72 65 61 63 74 69 6F 6E 5F 30 }
            }
          }
          InlineKeyboardButton {
            text = "2"
            type = InlineKeyboardButtonTypeCallback {
              data = bytes [15] { 73 65 6E 64 5F 72 65 61 63 74 69 6F 6E 5F 31 }
            }
          }
          InlineKeyboardButton {
            text = "3"
            type = InlineKeyboardButtonTypeCallback {
              data = bytes [15] { 73 65 6E 64 5F 72 65 61 63 74 69 6F 6E 5F 32 }
            }
          }
        }
      }
    }
  }
}

我在这里收到消息

        @Override
        public void onResult(TdApi.Object object) {
            switch (object.getConstructor()) {
                case TdApi.UpdateNewMessage.CONSTRUCTOR:
                    TdApi.UpdateNewMessage updateNewMessage = (TdApi.UpdateNewMessage) object;
                    TdApi.ReplyMarkupInlineKeyboard buttons = (TdApi.ReplyMarkupInlineKeyboard) updateNewMessage.message.replyMarkup;
                    if (buttons.rows[0][0].text.compareTo("1") == 0) {
                        System.out.println("found button");
                        TdApi.InlineKeyboardButton btn = buttons.rows[0][0];
                        TdApi.InlineKeyboardButtonTypeCallback resp = 
    (TdApi.InlineKeyboardButtonTypeCallback) btn.type;
                    }
                    // TdApi.MessageText messageText = 
    (TdApi.MessageText)updateNewMessage.message.content;
                    // System.out.println(messageText.text.text);
                    break;

我应该使用哪个函数和什么参数来发送回复?

GetCallbackQueryAnswer 方法可以将回调查询发送到机器人 CallbackQueryPayloadData 并将来自按钮的数据作为有效负载。 我对这个方法的使用:

private static void replyMessage( long chatId, long messageId, byte[] data) {
    TdApi.CallbackQueryPayloadData payloadData = new TdApi.CallbackQueryPayloadData(data);
    TdApi.GetCallbackQueryAnswer answer = new TdApi.GetCallbackQueryAnswer(chatId,messageId, payloadData);
    client.send(answer, defaultHandler);
}

其中 data 是来自 InlineKeyboardButtonTypeCallback

的字节