Lesson 6. Inline keyboards and editing message's text

I published poll in our Telegram chat about next lesson. So, as you are reading this, Bots API 2.0 won.

Our chat

On April 9, 2016, Telegram released Bot API 2.0 which allows you to edit message's text and send new Inline Keyboards. So, let's implement it to your bot and see how its beautiful. Now as always open IntelliJ Idea, within src folder create files Main.java and BotApi20.java. First look:

src/BotApi20.java

src/Main.java

I recommend you always look in the Bot API description so you know every method and type. Okey, lets make bot answer to the /start command:

And now lets add Inline Keyboard to this message:

It looks like this now:

Inline Keyboard

We want to edit message text right? Let's do it when user press our button. Add a Callback Query handler to your bot:

So if update has Callback query, it call this else if operator. Moving forward:

Now when user press our button it will change it's text:

editMessageText

Source:

src/Main.java

src/BotApi20.java

You can also find all source code to all of my lessons at GitHub.

Thank you for reading this! Now you can send Inline Keyboards and edit message's text and extra: handle callback queries. I hope you liked this lesson. Next time I will show how to create users database using MongoDB. Bye!

Last updated

Was this helpful?