I try to create the telegram bot in Java, and I need to add inline buttons in there. I looked at the official documentation official documentation and everything I made - the button, but they don't work. I also check all GitHub Java examples, but it didn't help. I don't understand how I can obtain the answer of pressing to this button and do something with. For example, If the user presses this button - send him something. Here is my code:
public void sending(Long chatID, File photo) {
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
InlineKeyboardButton button = new InlineKeyboardButton();
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
List<InlineKeyboardButton> buttonList = new ArrayList<>();
button.setText("Just button");
button.setCallbackData("callBack");
buttonList.add(button);
buttons.add(buttonList);
keyboardMarkup.setKeyboard(buttons);
SendPhoto sending = new SendPhoto();
sending.setChatId(chatID.toString());
sending.setNewPhoto(photo);
sending.setReplyMarkup(keyboardMarkup);
try {
sendPhoto(sending);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
Now I have only this error
PM org.telegram.telegrambots.logging.BotLogger severe
SEVERE: BOTSESSION
java.lang.NullPointerException
at mybot.SimpleBot.onUpdateReceived(SimpleBot.java:62)
at org.telegram.telegrambots.updatesreceivers.BotSession$HandlerThread.run(BotSession.java:197)
I would be really appreciated if somebody gives me some tips or simple java code with using callback buttons.