gpt4 book ai didi

java - 如何通过点击InlineKeyboardButton打开ReplyKeyboardMarkup?

转载 作者:行者123 更新时间:2023-11-30 06:02:52 24 4
gpt4 key购买 nike

我需要使用 library 单击 InlineKeyboardButton 打开 ReplyKeyboardMarkup .

就我而言,点击创建帖子按钮 enter image description here

并打开这种类型的键盘 enter image description here

因此,我尝试单击 InlineKeyboardButton 并使用 CallbackQuery (处理点击)打开 ReplyKeyboardMarkup,如下所示 snippet .

当我单击按钮时,我只能看到屏幕上的时钟(但我有 CallbackQuery 来处理此按钮):

enter image description here

   else if (call_data.equals("correcting_post")) {
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow row = new KeyboardRow();
row.add("Clear");
row.add("Preview");
keyboard.add(row);
row = new KeyboardRow();
row.add("Cancel");
row.add("Next");
keyboard.add(row);
keyboardMarkup.setKeyboard(keyboard);
AnswerCallbackQuery a = new AnswerCallbackQuery()
.setCallbackQueryId(update.getCallbackQuery().getId());
try {
execute(a);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}

我需要纠正或添加什么?我感谢任何帮助。

最佳答案

如果我没猜错的话,您需要单击 InlineKeyboardButton 按钮之一,然后打开 ReplyKeyboardMarkup。为此,您可以使用如下代码:

public class YourClass extends TelegramLongPollingBot {

@Override
public void onUpdateReceived(Update update) {
if (update.hasCallbackQuery()) {
String data = update.getCallbackQuery().getData();
if (data.equals("correcting_post")) {
try {
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow row = new KeyboardRow();
row.add("Test button");
keyboard.add(row);
keyboardMarkup.setKeyboard(keyboard);

// Create a message object
SendMessage message = new SendMessage()
.setChatId(update.getCallbackQuery().getMessage().getChatId())
.enableMarkdown(true)
.setText("Message text");
message.setReplyMarkup(keyboardMarkup);
execute(message);
} catch (TelegramApiException e) {
//exception handling
}
}
//Check another options for data
}
}

...
}

也许这个库提供了一种更方便的方法来做到这一点,但至少这种和平的代码是有效的。

关于java - 如何通过点击InlineKeyboardButton打开ReplyKeyboardMarkup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51911740/

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