Search code examples
pythontelegramtelegram-bottelethon

Is there a bot menu in Telethon?


I'm building an app with Telethon and almost finished it. Now there is some beauty left to be made and I found out that there is no good explanation in the internet (and docs too) how to make bot's menu.

Year or two ago I have built another bot with TeleBot and It provides a good solution for it using types.ReplyKeyboardMarkup. I can see how Telethon documentaion mentions ReplyKeyboardMarkup but still I can't get my bot's menu done.

Just to be clear, what I want to do look like this:


Solution

  • Oh, I've found out that I was using wrong Button's type (inline instead of text). Working code:

    from telethon import events, Button
    
    bot = ...
    
    @bot.on(events.NewMessage(pattern='/start'))
    async def handle_start_command(event):
        markup = event.client.build_reply_markup([
            [Button.text('First button')],
            [Button.text('Second button')]
        ])
        await event.respond("Hello!", buttons=markup)
    

    Result looks like this:

    Documentation says that:

    You can use inline, switch_inline, url and auth together to create inline buttons (under the message).

    You can use text, request_location, request_phone and request_poll together to create a reply markup (replaces the user keyboard).