Lesson 2 of 9 · 21m
Bot Identity, Commands, and Permission Boundaries
Configure the bot's public surface, command menu, group behavior, administrator rights, and deep-link onboarding before writing business logic.
A Telegram bot is not just an HTTP endpoint. It is an identity inside a social product: it has a username, a profile, group membership, privacy behavior, command menus, and sometimes administrator rights. Teams that treat identity setup as cosmetic end up confused when users cannot trigger the bot, groups leak too much traffic, or commands appear in one client but not another.
Configure identity with the abuse case in mind
@BotFather can set name, username, description, about text, commands, profile picture, and group privacy. The username becomes a trust signal. Choose something users can recognize under pressure, because phishing bots often rely on visually similar names. Do not put temporary environment names into the production identity.
Useful command metadata is not decoration. Telegram clients render it as a menu:
curl -sS -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setMyCommands" -H 'content-type: application/json' -d '{"commands":[
{"command":"start","description":"Connect your account"},
{"command":"status","description":"Show current service status"},
{"command":"support","description":"Open a support request"}
]}'Command descriptions shape user behavior. If /status is only for administrators, do not advertise it globally without thinking through authorization failure noise.
Group privacy is a security boundary
By default, bots in groups often operate in privacy mode: they receive commands, replies, service events, and messages directed at them, not all ordinary chatter. This is a feature. Turning privacy off because 'we did not see messages' may massively increase ingest volume and data exposure. First understand the update types you actually need. If the bot must moderate a group, it may need administrator rights. Request the minimum:
delete messages only if moderation requires deletion
ban users only for enforcement actions
invite users usually unnecessary
pin messages only for announcement workflows
manage topics only for forum-style supergroupsAdministrator rights are not a vague 'make it work' checkbox. Every granted permission becomes a liability if the token or application logic is compromised.
Commands are routing hints, not authorization
A user can type any command manually. /admin is only text. Authorization still belongs in your handler:
if update.effective_user.id not in settings.admin_user_ids:
await update.message.reply_text("This command is not available for your account.")
returnUse stable internal account mapping rather than trusting display names or usernames. Telegram user IDs are the durable identifier; usernames can change and display names are freely chosen.
Deep links carry onboarding state
Telegram deep links are the correct way to connect an external account or pass a signed onboarding context:
https://t.me/SudoSecurityOpsBot?start=connect_9f31abThe bot receives /start connect_9f31ab. Treat that payload as untrusted input. It should reference a short-lived server-side token, not encode mutable authorization facts such as user_id=42&admin=true. Expire onboarding links, bind them to the intended account, and consume them once where replay would be harmful.
Design the command surface like an API
Keep commands few and boring. Users remember flows better than syntax. Prefer conversational state and buttons for structured choices. Reserve commands for entry points, global actions, and recovery: /start, /help, /status, /cancel. Anything more complex deserves a keyboard or a web flow.
Field notes
- Telegram usernames are not immutable and should never be the primary key in your database.
- Bot commands are case-sensitive in user perception even when routing code lowercases them; document one form.
setMyCommandscan be scoped. Admin commands do not need to appear in every user's menu.- Group administrator rights can be changed after deployment; monitor permission drift.
- Do not use deep-link payloads as signed permission grants unless you designed the cryptographic binding deliberately.
Was this lesson helpful?