rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.69k stars 1.19k forks source link

editMessage usage example #144

Closed drunckoder closed 8 years ago

drunckoder commented 8 years ago

Hey everyone! I'm trying to make a bot with InlineKeyboardMarkup feature and faced an issue while updating the existing chat message.

How do I use the editMessage method? I couldn't find how to get a message ID to pass to setInlineMessageId(String) method.

Is there a working example of such a bot or some kind of explanation?

Thanks in advance!

drunckoder commented 8 years ago

BTW, setInlineMessageId(String.valueOf(update.getCallbackQuery().getMessage().getMessageId())) isn't working with an exception: org.telegram.telegrambots.TelegramApiException: Error at editmessagetext: Bad Request: Wrong inline message identifier specified at org.telegram.telegrambots.bots.AbsSender.sendApiMethod(AbsSender.java:1016) at org.telegram.telegrambots.bots.AbsSender.editMessageText(AbsSender.java:227) at Launcher.onUpdateReceived(Launcher.java:74) at org.telegram.telegrambots.updatesreceivers.BotSession$HandlerThread.run(BotSession.java:197)

Piece of code: EditMessageText editMessage = new EditMessageText(); editMessage.setInlineMessageId(String.valueOf(update.getCallbackQuery().getMessage().getMessageId())); editMessage.setText(update.getCallbackQuery().getMessage().getText()); editMessage.setReplyMarkup(inlineKeyboardMarkup); editMessageText(editMessage);

drunckoder commented 8 years ago

After spending some time, I've got it working: EditMessageText editMessage = new EditMessageText(); editMessage.setChatId(String.valueOf(update.getCallbackQuery().getMessage().getChatId())); editMessage.setMessageId(update.getCallbackQuery().getMessage().getMessageId()); editMessage.setText("text"); editMessageText(editMessage); As the Telegram Bot API docs say, if don't specify the inline_message_id, then I should set chat_id and message_id, and I did so. But the question remains about inline_message_id. Where can I get it?

rubenlagus commented 8 years ago

The inline_message_id is present in the callbackquery itself it the inline button was added to an inline query.

drunckoder commented 8 years ago

Thank you very much!