mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-11-30 07:15:38 +00:00
* chore(api): regenerate for BotFullInfo and optional chat_id Telegram split BotFullInfo out of User and getMe now returns it, and chat_id is optional in the methods that accept an ephemeral callback reply. Regenerate the API, make MeCache cache BotFullInfo, and wrap the now-optional chat_id arguments in the examples. This is the output of make regen, so the weekly regen job no longer fails its api test. * chore(api): pin the 2026-11-29 API snapshot the regen used codegen-clean regenerates from testdata/html/latest.html, so the new BotFullInfo output needs a matching snapshot.
admin
Authentication middleware that restricts the bot to an allowlist of Telegram user IDs.
What it shows
router.Use(...)to install a globalMiddleware[*api.Update]- Parsing
ALLOWED_USERSenv var into amap[int64]boollookup set - Extracting sender ID from multiple update types in one helper
- Silent drop pattern for unauthorized updates (no error, no reply)
Environment variables
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Yes | Bot token from @BotFather |
ALLOWED_USERS |
No | Comma-separated numeric user IDs, e.g. 123456,789012. If unset, all users are permitted. |
Finding your user ID
Send /whoami to the bot — it replies with your numeric Telegram user ID. Add that ID to ALLOWED_USERS to restrict the bot to you.
Extending
Combine with examples/moderation to ensure only group admins can invoke moderation commands:
router.Use(allowlistMiddleware(adminIDs))
router.OnCommand("/ban", banHandler)
For group-context admin checks (verify the sender is an admin of that specific group), use api.GetChatAdministrators and check the result dynamically rather than a static ID list.
Running
export TELEGRAM_BOT_TOKEN=123456:ABC...
export ALLOWED_USERS=111111,222222
go run ./examples/admin