Creating a custom menu in a Telegram bot: How to implement buttons like this?

I’m trying to add a special menu to my Telegram bot. It’s like a button that shows up below the chat input box when you click on something else. I’ve seen it in other bots but I’m not sure what it’s called or how to make it.

I’ve looked through the Telegram API docs but couldn’t find anything about this feature. Maybe I’m using the wrong keywords? Can anyone point me in the right direction or explain how to set this up?

Here’s what I’m trying to do:

  1. Have a main button (let’s call it the trigger)
  2. When the user taps the trigger, a set of new buttons appear below the chat input
  3. These new buttons offer different options or actions

Has anyone implemented something like this before? Any tips or code examples would be super helpful! I’m pretty new to Telegram bot development, so even basic explanations would be great. Thanks!

I’ve actually implemented something similar in one of my bots recently. What you’re describing is indeed an inline keyboard, as Bob mentioned. But there’s a bit more to it for the specific behavior you want.

To get buttons below the chat input, you’ll need to use what’s called a ‘keyboard markup’ instead. It’s slightly different from inline keyboards. Look for ‘ReplyKeyboardMarkup’ in the API docs.

The tricky part is making it appear only when needed. You’ll want to send a message with the keyboard when the user triggers it, then remove it later with ‘ReplyKeyboardRemove’.

One gotcha: these keyboards are persistent until removed, so make sure to handle that properly in your code. Otherwise, users might get stuck with buttons they can’t get rid of.

Hope this helps point you in the right direction. Let me know if you need any clarification on implementing it.

hey, i think what ur looking for is called an inline keyboard. its part of the telegram bot api. u can create custom buttons that appear under messages or in the chat input area. check out the ‘InlineKeyboardMarkup’ in the api docs. itll let u make those clickable buttons u want. good luck with ur bot!

I’ve worked with Telegram bots before, and what you’re describing sounds like a combination of inline keyboards and reply keyboards. For the main trigger button, you’ll want to use an inline keyboard attached to a message. When users tap it, you can then send a new message with a ReplyKeyboardMarkup to display those custom buttons below the chat input.

Keep in mind that reply keyboards are persistent until removed, so you’ll need to implement a way to hide them when they’re no longer needed. You can do this by sending a ReplyKeyboardRemove when appropriate.

One approach I’ve found effective is to use a state machine to manage the different stages of user interaction. This helps keep track of when to show or hide the custom keyboard based on user actions.

Remember to handle edge cases, like users trying to access the menu out of sequence. Good error handling will make your bot more robust and user-friendly.