Tg Bot ошибка при нажатии на кнопки
Столкнулся с проблемой, что нет ответа от CallBackQuery. Уже все перетыкал, не могу разобраться :( Может кто опытный подсказать?
В консоли update.hasCallbackQuery() = false. А как указать путь не могу понять.
@SneakyThrows
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
String messageText = update.getMessage().getText();
long chatId = update.getMessage().getChatId();
switch (messageText) {
case "/start":
registerUser(update.getMessage());
try {
startCommand(chatId, update.getMessage().getChat().getFirstName());
break;
} catch (TelegramApiException e) {
throw new RuntimeException(e);
}
case "/command1":
//sendRows(chatId, "Выберите место");
break;
case "/command2":
if (messageText.equals("/command2")) {
// buttonsMash(chatId, "Выберите место");
SendMessage message = new SendMessage();
message.setChatId(chatId);
message.setText("Выберите место");
message.setParseMode(ParseMode.MARKDOWN);
InlineKeyboardMarkup markupInLine = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> rowsInLine = new ArrayList<>();
List<InlineKeyboardButton> rowInLine = new ArrayList<>();
InlineKeyboardButton firstSlot = new InlineKeyboardButton();
InlineKeyboardButton secondSlot = new InlineKeyboardButton();
InlineKeyboardButton thirdSlot = new InlineKeyboardButton();
InlineKeyboardButton fourthSlot = new InlineKeyboardButton();
InlineKeyboardButton fifthSlot = new InlineKeyboardButton();
firstSlot.setText("1 место");
firstSlot.setCallbackData("first");
secondSlot.setText("2 место");
secondSlot.setCallbackData("TWO_SLOT");
thirdSlot.setText("3 место");
thirdSlot.setCallbackData("THREE_SLOT");
fourthSlot.setText("4 место");
fourthSlot.setCallbackData("FOUR_SLOT");
fifthSlot.setText("5 место");
fifthSlot.setCallbackData("FIVE_SLOT");
rowInLine.add(firstSlot);
rowInLine.add(secondSlot);
rowInLine.add(thirdSlot);
rowInLine.add(fourthSlot);
rowInLine.add(fifthSlot);
rowsInLine.add(rowInLine);
markupInLine.setKeyboard(rowsInLine);
message.setReplyMarkup(markupInLine);
execute(message);
System.out.println(update.hasCallbackQuery());
System.out.println(update.getCallbackQuery());
}
if (update.hasCallbackQuery()) {
CallbackQuery callbackQuery = update.getCallbackQuery();
String data = callbackQuery.getData();
SendMessage sendMessage = new SendMessage();
sendMessage.setParseMode(ParseMode.MARKDOWN);
sendMessage.setChatId(update.getCallbackQuery().getMessage().getChatId());
if (data.equals("THREE_SLOT")) {
sendMessage.setText("22364679641");
execute(sendMessage);
}
}
break;
case "/command3":
sendMessage(chatId, "Свободно: " + totalParkingPlaces + "мест");
break;
case "/command4":
final String HELP_TEXT = "Этот бот создан для учета парковки на Акуловской 2Д";
sendMessage(chatId, HELP_TEXT);
break;
case "/command5":
break;
default:
sendMessage(chatId, "Ну извини, еще не умею");
}
}
}