Hello guys. I'm kinda having trouble with learning Bot Api.

Here's the peace of code I wrote in Java
////////////////////////////////////////////
InlineKeyboardButton next;
InlineKeyboardButton previous;
InlineKeyboardButton url;
private InlineKeyboardMarkup keyboardM1;
private InlineKeyboardMarkup keyboardM2;
private boolean screaming;

private Bot() {
screaming = false;
next = InlineKeyboardButton.builder()
.text("Next").callbackData("next")
.build();
previous = InlineKeyboardButton.builder()
.text("Previous").callbackData("previous")
.build();
url = InlineKeyboardButton.builder()
.text("Tutorial")
.url("https://core.telegram.org/bots/api")
.build();
keyboardM1 = InlineKeyboardMarkup.builder()
.keyboardRow(List.of(next))
.build();
keyboardM2 = InlineKeyboardMarkup.builder()
.keyboardRow(List.of(previous))
.keyboardRow(List.of(url))
.build();
}
/////////////////////////////////////////////
@Override
public void onUpdateReceived(Update update) {
var msg = update.getMessage();
var user = msg.getFrom();
if (update.hasCallbackQuery()) {
CallbackQuery callbackQuery = update.getCallbackQuery();
buttonTap(callbackQuery.getFrom().getId(), callbackQuery.getId(), callbackQuery.getData(), msg.getMessageId());
}
}
///////////////////////////////////////////////////////
public void buttonTap(Long id, String queryId, String data, Integer msgId) {
EditMessageText newTxt = EditMessageText.builder()
.chatId(id.toString()).messageId(msgId).text("").build();
EditMessageReplyMarkup newKB = EditMessageReplyMarkup.builder()
.chatId(id.toString()).messageId(msgId).build();

if (data.equals("next")) {
newTxt.setText("Menu 2");
newKB.setReplyMarkup(keyboardM2);
} else if (data.equals("previous")) {
newTxt.setText("Menu 1");
newKB.setReplyMarkup(keyboardM1);
}
AnswerCallbackQuery close = AnswerCallbackQuery.builder()
.callbackQueryId(queryId).build();
try {
execute(close);
execute(newTxt);
execute(newKB);
} catch (TelegramApiException e) {
throw new RuntimeException(e);
}
}
///////////////////////////////////////////////////
for some reason when i hit the button "Next" it's not working or i did something wrong?

6 ответов

25 просмотров

Use pastebin for code samples

Dilshod-Latipov Автор вопроса
Dilshod-Latipov Автор вопроса
Sery
Use pastebin for code samples

Anyway can you help me?

Dilshod-Latipov Автор вопроса
Dilshod Latipov
Anyway can you help me?

If you send a proper pastebin or nekobin link, maybe.

Похожие вопросы

Карта сайта