Files
go-telegram/examples
lukaszraczylo 9c363f470a chore(api): regenerate from Telegram Bot API v10.2
Snapshot taken 2026-07-21. Notable shape change: ReplyParameters.MessageID
becomes optional (*int64) because Bot API 10.2 allows a reply to target
ephemeral_message_id instead. This breaks callers that set MessageID by value,
so examples/echo passes the address now.

New surface includes the ephemeral message methods, sendRichMessage with
InputRichMessageMedia, and the Community service messages.
2026-07-21 22:52:20 +01:00
..
2026-05-09 13:09:27 +01:00
2026-05-09 13:09:27 +01:00
2026-05-09 13:09:27 +01:00
2026-05-09 13:09:27 +01:00
2026-05-09 13:09:27 +01:00
2026-05-09 13:09:27 +01:00
2026-05-09 13:09:27 +01:00

Examples

Each subdirectory contains a self-contained sample bot demonstrating one feature area.

Example What it shows
echo Long-poll bot that echoes text back to the sender
webhook Webhook delivery with secret-token verification
callback Inline keyboard with callback queries and counter state
conversation Multi-step conversation flow with dispatch/conversation
files Upload and download files via api.DownloadFile
inline Inline-mode bot returning search-style results
middleware Custom middleware chains via Router.Use
stateful Per-user state managed via closures
welcome Greet new chat members; detect and log departures
moderation /kick, /ban, /mute, /warn with admin permission checks
polls Create polls and tally answers via OnPollAnswer
payments Telegram Payments: sendInvoice → pre_checkout_query → successful_payment
pagination Multi-page inline keyboard with stateless prev/next navigation
admin Auth middleware allowlisting specific user IDs via Router.Use

Running

All examples follow the same pattern:

export TELEGRAM_BOT_TOKEN=123456:ABC...
go run ./examples/<name>

Webhook examples need a public HTTPS endpoint (use Cloudflare Tunnel, ngrok, or similar).

Common patterns

Retry-safe HTTP — every example wraps the HTTP client with client.NewRetryDoer, which automatically honours Telegram's retry_after field on 429 responses.

Graceful shutdown — all examples use signal.NotifyContext so the bot drains cleanly on SIGINT/SIGTERM.

Structured logging — for production, wire a logger via client.WithLogger and wrap the process in supervision (systemd unit, k8s liveness probe, etc.).