我需要通过使用library单击ReplyKeyboardMarkup
来打开InlineKeyboardButton
。
因此,我试图单击InlineKeyboardButton
并像此snippet一样使用ReplyKeyboardMarkup
打开CallbackQuery
(以处理单击)。
单击按钮时,我只能看到屏幕上的时钟(但是我有CallbackQuery
可以处理此按钮):
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();
}
}
我需要更正或添加什么?感谢您的帮助。
答案 0 :(得分:1)
如果我做对了,您想单击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
}
}
...
}
该库可能提供了一种更方便的方法,但是至少这种代码的和平是可行的。