All 285 types and 165 methods of the Telegram Bot API β
strongly typed, fully async, automatically kept in sync with every official release.
π¦ Install Β· π Quick Start Β· π Examples Β· π§ API Reference Β· π Auto-Codegen Β· π docs.rs
β¨ Features
π€ Complete API Coverage
- All 285 types β structs, enums, markers
- All 165 methods β fully async
- All 21 union types as Rust enums
- 100 optional params structs with builder pattern
π Auto-Generated & Always Fresh
- Generated from the official spec
- Daily automated check for API updates
- PR auto-opened on every new API version
- Zero manual work to stay up-to-date
π¦ Idiomatic Rust
- Fully
async/awaitwith Tokio Into<ChatId>β acceptsi64or"@username"Into<String>on all text paramsOption<T>for all optional fieldsBox<T>to break recursive type cycles
π‘οΈ Fully Type-Safe
ChatIdβ integer or username, no stringly typingInputFileβ file_id / URL / raw bytesReplyMarkupβ unified enum for all 4 keyboard typesInputMediaβ typed enum for media groups- Compile-time guarantees on every API call
π‘ Flexible HTTP Layer
- Custom API server support (local Bot API)
- Multipart file uploads built-in
- Configurable timeout
- Flood-wait aware error handling
reqwestbackend
π¬ Built-in Polling
- Long-polling dispatcher included
- Spawns a Tokio task per update
- Configurable timeout, limit, allowed_updates
- Clean concurrent update processing
π¦ Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Requirements: Rust
1.75+Β· Tokio async runtime
π Quick Start
use Bot;
async
π Examples
π Echo Bot β Long Polling
The simplest possible bot. Receives every message and echoes it back.
use ;
async
π¬ Formatted Messages
Send HTML or MarkdownV2 formatted messages with optional settings.
use SendMessageParams;
let params = new
.parse_mode
.disable_notification;
bot.send_message.await?;
πΉ Inline Keyboards
Buttons embedded inside messages. Perfect for interactive menus.
use ;
use ;
let keyboard = InlineKeyboardMarkup ;
let params = new
.parse_mode
.reply_markup;
bot.send_message.await?;
β‘ Callback Queries
Handle button taps from inline keyboards. Always acknowledge with answer_callback_query.
use ;
use MaybeInaccessibleMessage;
let handler: UpdateHandler = Boxnew;
β¨οΈ Reply Keyboards
Custom keyboard shown at the bottom of the screen. Great for persistent menu buttons.
use ;
use ;
let keyboard = ReplyKeyboardMarkup ;
let params = new
.reply_markup;
bot.send_message.await?;
πΈ Send Photos & Files
Send files by file_id, URL, or raw bytes from disk.
use ;
let params = new
.caption
.parse_mode;
// Fastest β already on Telegram's servers
bot.send_photo.await?;
// Let Telegram download from a URL
bot.send_photo.await?;
// Upload raw bytes from disk
let data = read.await?;
bot.send_photo.await?;
π¬ Media Groups
Send multiple photos or videos as an album in a single message.
use InputMedia;
use ;
let media = vec!;
bot.send_media_group.await?;
π Polls
Send polls β regular or quiz style.
use SendPollParams;
use InputPollOption;
let options = vec!;
let params = new.is_anonymous;
bot.send_poll.await?;
πͺ Inline Queries
Handle @yourbot query inline mode from any chat.
use ;
let results = vec!;
bot.answer_inline_query.await?;
π Payments & Telegram Stars
Send invoices using Telegram Stars (XTR) or payment providers.
use SendInvoiceParams;
use LabeledPrice;
let prices = vec!;
bot.send_invoice.await?;
π Webhooks
Register a webhook URL so Telegram pushes updates to your server instead of you polling.
use SetWebhookParams;
// Register webhook
let params = new
.max_connections
.allowed_updates
.secret_token;
bot.set_webhook.await?;
Full webhook server with axum:
# Cargo.toml
[]
= "0.7"
use ;
use Arc;
use ;
async
async
For local testing:
ngrok http 8080β use the ngrok URL as your webhook
π Local Bot API Server
Point the bot at a self-hosted Telegram Bot API server for higher file size limits and faster speeds.
let bot = with_api_url.await?;
π οΈ Error Handling
Structured errors with helpers for flood-wait and common API errors.
use BotError;
match bot.send_message.await
π§ API Reference
Bot β Core Struct
| Constructor | Description |
|---|---|
Bot::new(token) |
Create bot, calls getMe, verifies token |
Bot::with_api_url(token, url) |
Create with a custom/local API server |
Bot::new_unverified(token) |
Create without calling getMe |
ChatId β Flexible Chat Identifier
Anywhere ChatId is expected, you can pass any of these:
bot.send_message.await?;
bot.send_message.await?;
bot.send_message.await?;
bot.send_message.await?;
InputFile β File Sending
// Reference a file already on Telegram's servers (fastest)
file_id
// Let Telegram download from a URL
url
// Upload raw bytes directly
let data = read.await?;
memory
ReplyMarkup β All Keyboard Types
// Inline keyboard β buttons inside messages
InlineKeyboard
// Reply keyboard β custom keyboard at bottom of screen
ReplyKeyboard
// Remove the reply keyboard
ReplyKeyboardRemove
// Force the user to reply to a message
ForceReply
Poller β Long Polling Dispatcher
new
.timeout // Seconds to long-poll (0 = short poll)
.limit // Max updates per request (1β100)
.allowed_updates
.start
.await?;
BotError β Error Variants
// Helper methods
error.is_api_error_code // β bool
error.flood_wait_seconds // β Option<i64>
Builder Pattern for Optional Params
Every method with optional parameters has a *Params struct with a fluent builder API:
// Pattern: MethodNameParams::new().field(value).field(value)
let params = new
.parse_mode
.disable_notification
.protect_content
.message_thread_id
.reply_parameters
.reply_markup;
π Coverage Statistics
| Category | Count | Status |
|---|---|---|
| Total Types | 285 | β 100% |
| β³ Struct types | 257 | β |
| β³ Union / Enum types | 21 | β |
| β³ Marker types | 7 | β |
| Total Methods | 165 | β 100% |
β³ set* methods |
30 | β |
β³ get* methods |
29 | β |
β³ send* methods |
22 | β |
β³ edit* methods |
12 | β |
β³ delete* methods |
11 | β |
| β³ Other methods | 61 | β |
| Optional params structs | 100 | β |
| Lines auto-generated | ~11,258 | β |
π Auto-Codegen
tgbotrs is the only Rust Telegram library that automatically stays in sync with the official API spec via GitHub Actions β no manual updates, no lag.
How It Works
Every Day at 08:00 UTC
β
βΌ
βββββββββββββββββββ
β Fetch latest β β github.com/ankit-chaubey/api-spec
β api.json spec β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Compare with βββ No change? βββΊ Stop β
β pinned version β
ββββββββββ¬βββββββββ
β Changed!
βΌ
βββββββββββββββββββ
β diff_spec.py β β Semantic diff (added/removed types & methods)
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β codegen.py β β Pure Python, zero pip dependencies
β β Generates gen_types.rs + gen_methods.rs
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β validate.py β β Verify 100% coverage
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Open PR with β β Rich report: summary table, per-field diff
β full report β New/removed items, checklist
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β On PR merge: β
β β’ Bump semver β
β β’ Git tag β
β β’ GitHub Releaseβ
β β’ crates.io β
βββββββββββββββββββ
Regenerate Manually
# 1. Pull latest spec
# 2. Run codegen (no pip installs needed)
# 3. Rebuild
GitHub Actions Workflows
| Workflow | Trigger | Purpose |
|---|---|---|
auto-regenerate.yml |
β° Daily 08:00 UTC + manual | Spec sync β diff β codegen β PR |
ci.yml |
Every push / PR | Build, test, lint on 3 OS Γ 2 Rust versions |
release.yml |
PR merged β main | Semver bump β tag β crates.io publish |
notify.yml |
After regen | GitHub Issue with full change summary |
π€ Contributing
Contributions are welcome!
Report issues:
- π Bug β open a bug report
- π‘ Feature β open a feature request
- π Security β email ankitchaubey.dev@gmail.com directly
Development workflow:
&&
# Regenerate from latest spec
# Validate 100% coverage
PR guidelines:
- One concern per PR
- Always run
cargo fmtandcargo clippybefore submitting - Never edit
gen_types.rsorgen_methods.rsdirectly β editcodegen.pyinstead - Add examples for any new helpers
π Changelog
See CHANGELOG.md for the full release history.
Developed by Ankit Chaubey
tgbotrs started as a personal tool.
I was constantly running into limitations, missing features, and unsupported things,
so in 2024 I decided to build my own solution.
After using tgbotrs for a long time (2024-26) and refining it along the way,
I felt it could be useful for others too β so I made it public.
If this helps you in any way, feel free to β star it or π΄ fork it π
Developed and maintained by Ankit Chaubey (@ankit-chaubey)
π Thanks & Credits
Special thanks to Paul / PaulSonOfLars β the auto-generation approach at the heart of this library was directly inspired by his excellent Go library gotgbot and api-spec gen. Seeing how clean and maintainable a fully-generated, strongly-typed Telegram library can be was the spark for building tgbotrs.
| Telegram | The Bot API this library implements |
| PaulSonOfLars / gotgbot | Inspiration for the codegen-first approach |
| ankit-chaubey / api-spec | Machine-readable spec used as the codegen source |
π License
MIT License Β© 2026 Ankit Chaubey
If tgbotrs saved you time, a β on GitHub means a lot!