Create a Telegram Bot with @BotFather: Token Setup and Command Menu
Verify the official BotFather account, create your bot, and store its token securely. Test the token and command menu separately, and replace the token if it leaks.

1. Verify BotFather and create your bot
- Search Telegram for
@BotFather. Open the profile and check both the exact username and the official verification badge. Don’t rely on the avatar, display name, or a contact card forwarded in a group. If in doubt, open BotFather from the official Telegram bot documentation. - In your private chat with BotFather, tap Start and send
/newbot. Enter a display name, such as “Order Lookup Assistant,” then choose a username people can search for. These are separate fields; the display name can include Chinese characters. - For the username, use letters (A–Z), digits, or underscores, and end it with
bot, as inshop_order_bot. If it’s taken, enter another username when prompted; there’s no need to restart. Once BotFather confirms creation, open the bot link in the message and check the display name and username.

2. Store the token and verify it from your backend
- Copy the entire API token from BotFather’s confirmation message, including the colon. The username is public, but the token is a secret: anyone who has it can call the API as your bot without signing in to your personal account.
- In your deployment platform’s secrets settings, create
TELEGRAM_BOT_TOKENand paste the token without quotes or extra spaces. Give the bot service access to the secret at runtime. Keep the token out of source code, frontend code, and startup commands. Redeploy so the service loads the secret. - Before testing, disable debug logging that prints full request URLs, since those URLs contain the token. Use a Telegram bot library on your backend to call
getMe. If the returned username matches the one from step 1, the token works and belongs to the intended bot. This does not test message delivery or replies.

3. Set up the command menu
- Send
/setcommandsto BotFather and select your bot by username. Send the following two lines as a single message, without bullet points:
``` start - Get started help - Show help ``` 2. The command name goes on the left; use only lowercase English letters, digits, or underscores. The description on the right is what users see. Omit the slash when registering a command, but include it in chat: help in BotFather, /help in your bot. Wait for BotFather’s confirmation. 3. Open a private chat with your bot, tap Start, and type / to see the available commands. The menu lists commands but does not implement them. For Show help to return a reply, register a /help handler in your backend and start the service.

4. Troubleshoot by symptom
| Symptom | Check first | What to do |
|---|---|---|
| The menu still shows old commands | Did you edit the right bot? | Verify the username and reopen the private chat. If your code also sets the menu, check whether it overwrites the BotFather settings. |
| Tapping a command gets no reply | Does the backend receive the message? | If not, check your message receiver. If the message arrives, check that the command name matches the registered handler and that the handler sends a reply. |
| The API returns “Unauthorized” | Is the running service using an old token? | Check the deployed secret version, update the environment where the bot actually runs, and restart the service. Never post the token when asking for help. |

5. Replace a leaked token and complete handoff
If the token appears in shared screenshots, a group chat, or a code repository, deleting the exposed copy does not invalidate it. Immediately send /revoke to BotFather, select the affected bot, and obtain a replacement token. Update the secret on every running instance, restart each one, and retest both getMe and /help. Then remove the exposed copies.
- Storage: Keep any backup in a password manager, not in Telegram Saved Messages. Enable two-step verification on the account that manages the bot; see the two-step verification guide.
- Acceptance check: Confirm that
getMereturns the intended username, the command menu appears in a private chat, and tapping/helpproduces the expected reply. - Handoff: Record who is responsible for the bot, where the secret is stored, and how to replace it. Do not include the token itself in the handoff document.