Reputation: 6480
I need to open ReplyKeyboardMarkup
by clicking on InlineKeyboardButton
using library.
In my case, click on Create post
button
And open this type of keyboard
So, I'm trying to click InlineKeyboardButton
and open ReplyKeyboardMarkup
using CallbackQuery
(to handle click) like in this snippet.
When I click on my button, I see only the clock like on the screen (but I have CallbackQuery
to handle this button):
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();
}
}
What I need to correct or add? I appreciate any help.
Upvotes: 2
Views: 2027
Reputation: 363
If I got it right you want to click on one of InlineKeyboardButton
buttons and then open ReplyKeyboardMarkup
. In order to do it you can use code like this:
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
}
}
...
}
Probably this library provides a more convenient way for doing so, but at least this peace of code works.
Upvotes: 3