pengrad / java-telegram-bot-api

Telegram Bot API for Java
https://core.telegram.org/bots
Apache License 2.0
1.78k stars 370 forks source link

callbackQuery's message() is deprecated #395

Closed Donaboyev closed 2 weeks ago

Donaboyev commented 4 weeks ago

I want to get Update -> callbackQuery -> message -> replyMarkup But message() function is deprecated that says use maybeInaccessibleMessage instead. Unfortunately, maybeInaccessibleMessage has not replyMarkup.

The goal is updating message's InlineKeyboardButtons. Or how can I achieve this in another way?

mircoianese commented 4 weeks ago

MaybeInaccessibleMessage is a new class added by telegram because sometimes BOTs may receive callbacks from messages that they can't read.

You can check if the maybeInaccessibleMessage is of type Message, and then cast it. Something like this:

if (update.callbackQuery().maybeInaccessibleMessage() instanceof Message) {
   Message message = (Message)update.callbackQuery().maybeInaccessibleMessage();
}