Files
lukaszraczylo ac7cae8fa7 Initial release of go-telegram
A fully-generated, strongly-typed Go client for the Telegram Bot API.

* 176 methods + 301 types generated from Bot API v10.0
* 1408 auto-generated tests (8 scenarios per method)
* Typed unions throughout — no 'any' in the public surface
* Pluggable HTTP transport and JSON codec (default goccy/go-json)
* Built-in retry middleware honouring Telegram's retry_after
* Generic dispatcher with filters and conversation handlers
* Self-verifying codegen pipeline (regen → audit → emit → run tests)
* 14 example bots covering common patterns
2026-05-09 13:09:27 +01:00

41 lines
1.3 KiB
Markdown

# admin
Authentication middleware that restricts the bot to an allowlist of Telegram user IDs.
## What it shows
- `router.Use(...)` to install a global `Middleware[*api.Update]`
- Parsing `ALLOWED_USERS` env var into a `map[int64]bool` lookup 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:
```go
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
```bash
export TELEGRAM_BOT_TOKEN=123456:ABC...
export ALLOWED_USERS=111111,222222
go run ./examples/admin
```