Telegram bot Java, как сделать счётчик чисел в Inlinekeyboard
В данной части кода не получается сделать счётчик чисел. Нужно сделать чтобы при нажатии кнопки число увеличивалось на 1, при повторном нажатии ещё на 1 и т.д.
else if (update.hasCallbackQuery()) {
// Set variables
String call_data = update.getCallbackQuery().getData();
long message_id =update.getCallbackQuery().getMessage( ).getMessageId();
long chat_id = update.getCallbackQuery().getMessage().getChatId();
String inline_message_id = update.getCallbackQuery().getInlineMessageId();
if (call_data.equals("update_msg_text")) {
double i = 0;
double a = 1;
String answer = String.valueOf(i + a);
EditMessageText new_message = new EditMessageText();
new_message.setChatId(String.valueOf(chat_id));
new_message.setMessageId(toIntExact(message_id));
new_message.setInlineMessageId(inline_message_id);
new_message.setText(answer);
List<List<InlineKeyboardButton>> buttons3 = new ArrayList<>();
buttons3.add(
Collections.singletonList(
InlineKeyboardButton.builder().text("Number of clicks " + answer).callbackData("update_msg_text").build()));
try {
execute(EditMessageReplyMarkup.builder()
.chatId(new_message.getChatId())
.messageId(new_message.getMessageId())
.replyMarkup(InlineKeyboardMarkup.builder().keyboard(buttons3).build())
.build());
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
Error editing message reply markup: [400] Bad Request:
message is not modified: specified new message content and reply
markup are exactly the same as a current content and reply markup of the message
at org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageReplyMarkup.deserializeResponse(EditMessageReplyMarkup.java:76)
at org.telegram.telegrambots.bots.DefaultAbsSender.sendApiMethod(DefaultAbsSender.java:1039)
at org.telegram.telegrambots.meta.bots.AbsSender.execute(AbsSender.java:64)
at io.proj3ct.SpringDemoBot.service.TelegramBot.onUpdateReceived(TelegramBot.java:229)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.telegram.telegrambots.meta.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27)
at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:317)