How to create a three dashes menu on a Telegram bot?
Asked Answered
L

3

10

How could I create a three-dashes menus on a Telegram bot, similarly to what they do to the Jobs bot? It should be similar to this:

How do we call this kind of menu?

Leyba answered 13/9, 2021 at 7:28 Comment(3)
Does this answer your question? Show an additional (/) button in the input field?Licko
It is not really the same thing.Leyba
Tell botFather what commands are available, then the button will appear.Pozsony
B
2

In java case with this library.

if the commands already was created, so simply in the class that extends TelegramLongPollingBot:

 this.execute(new GetMyCommands());

In other case:

  1. Create new List BotCommand

    List<> commandsList = new ArrayList();

  2. Adding BotCommand to the list with name and description

    commandsList.add(new BotCommand("commandName", "description"));

  3. Create a new SetMyCommands whit the botCommandList and executed

    this.execute(new SetMyCommands(commands));

more information about: https://telegram.org/blog/animated-backgrounds#bot-menu

Bax answered 20/9, 2021 at 15:50 Comment(3)
Since OP didn't specify a programming language, he's probably looking for a generic solution. A Java only solution, based on same random library won't help OP.Pozsony
ok, understand. Sorry, I am very new and I can't ask him in a comment. Maybe the last link help. telegram.org/blog/animated-backgrounds#bot-menu Thank you for the feedback 0stone0Bax
Actually this answers my question. Even if the answer was in Java, at least I can navigate my way to the implementation in Python, which is the one I wanna use. Thanks @Federremu!Leyba
H
10

You can add your commands which will be displayed on the menu using the Bot father commands.

I followed the below steps:

  • Open BotFather send command /setcommand
  • BotFather will ask for the bot you want to set the command
  • Provide the command name along with the description in "command - description" format

Now open your bot and the command you send will be displayed on the Menu.

Hope this helps.

Homeostasis answered 25/5, 2022 at 16:18 Comment(4)
but it does not work. maybe need something else?Sirrah
In which step are you getting failure?Homeostasis
I removed my bot and created again. After it everything works :)Sirrah
That's great..!!!Homeostasis
B
2

In java case with this library.

if the commands already was created, so simply in the class that extends TelegramLongPollingBot:

 this.execute(new GetMyCommands());

In other case:

  1. Create new List BotCommand

    List<> commandsList = new ArrayList();

  2. Adding BotCommand to the list with name and description

    commandsList.add(new BotCommand("commandName", "description"));

  3. Create a new SetMyCommands whit the botCommandList and executed

    this.execute(new SetMyCommands(commands));

more information about: https://telegram.org/blog/animated-backgrounds#bot-menu

Bax answered 20/9, 2021 at 15:50 Comment(3)
Since OP didn't specify a programming language, he's probably looking for a generic solution. A Java only solution, based on same random library won't help OP.Pozsony
ok, understand. Sorry, I am very new and I can't ask him in a comment. Maybe the last link help. telegram.org/blog/animated-backgrounds#bot-menu Thank you for the feedback 0stone0Bax
Actually this answers my question. Even if the answer was in Java, at least I can navigate my way to the implementation in Python, which is the one I wanna use. Thanks @Federremu!Leyba
I
1

If you are looking for a solution using python-telegram-bot, here is a simple code reference:


from telegram import BotCommand
from telegram.ext import ApplicationBuilder, Application, CommandHandler

config = dotenv_values(".env")

command_info = [
    BotCommand("hello", "Say hello to the bot"),
]
command_handlers = [
    CommandHandler("hello", hello),
]


async def post_init(application: Application) -> None:
    bot = application.bot
    await bot.set_my_commands(commands=command_info)


if __name__ == "__main__":
    log("Starting bot...")
    app = (
        ApplicationBuilder()
        .token(config["BOT_TOKEN"])
        .post_init(post_init)
        .build()
    )
    app.add_handlers(command_handlers)
    log("Bot started!")
    app.run_polling()

References:

Ildaile answered 20/5, 2023 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.