Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

How to Add a Command Menu to a Telegram Bot with Python

A Telegram bot can recognize commands without displaying them in the client. However, users should not have to memorize every available command. Registering a command menu lets Telegram show a list when someone taps the menu button or types / . In this tutorial, we will create /start , /help , and /status handlers, register them through the Bot API, and display different command menus in private…

Registering a command menu in Telegram allows users to access a list of available commands without having to remember each one. In this tutorial, we will add three command handlers - /start, /help, and /status - and register them through the Bot API. These handlers will display different responses when called.

First, we create a file called bot.py and import necessary libraries. The bot.py file will contain the code for our command handlers. We import os to access environment variables, telegram modules for updates and command handling, and python-telegram-bot specific classes.

Next, we define our command handlers as async functions. The start function welcomes the user and prompts them to use /help to view available commands. The help_command function lists all available commands: /start, /help, and /status. Finally, the status function informs the user that the service is running normally.

In the main function, we retrieve the bot token from the environment variable TELEGRAM_BOT_TOKEN. We use this token to initialize the Application object, which handles incoming updates and messages. We then add the command handlers to the application using CommandHandler, specifying the command name and corresponding function.

Finally, we run the application in polling mode, which continuously checks for new updates and messages. When executed, the bot should respond to /start, /help, and /status commands. However, the command menu may still appear empty. To fix this, we need to register the commands using BotFather.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

20 Native macOS Apps That Replaced My Electron Bloat for Good

I opened Activity Monitor last year on a Thursday afternoon, just to check something quick. Slack was sitting at 780MB. Discord was at 410MB. Notion was at 490MB. Spotify was lurking at 280MB.

  • Electron framework causes high RAM usage in popular macOS apps
  • Mimestream, Zed, Craft, and Reeder are faster alternatives
  • Native apps are more integrated with macOS than Electron apps

Feedly attributes weeklong slowdown to bug, not its AI pivot

Feedly says a bug is behind the performance issues that have made its web app nearly "unusable" for some users, while complaints about its mobile apps and customer support are adding to frustrations.

  • Feedly experienced a weeklong slowdown due to a bug, not AI pivot
  • Web app issues caused frustration, rendering browsing feeds unusable
  • CEO assured RSS priority, fix released Friday, investigating all user issues

More from Monday 17 August →