ferogram
A Native & Elegant MTProto Framework for Rust
Built by Ankit Chaubey
This is the main client crate. It talks to Telegram directly over MTProto and handles auth for both bots and user accounts from the same client builder. You get a dispatcher with composable filters, FSM for multi-step conversations, CDN downloads, middleware, MTProxy support and a raw invoke() escape hatch for anything not wrapped yet.
If you're starting fresh, this is the only crate you need. Everything else in the workspace exists to support it and can be pulled in separately if you need a specific layer on its own.
- Installation
- Quick start: bot
- Quick start: user account
- Examples
- Connecting
- Session backends
- Transport and proxy
- Raw API
- Error handling
- Shutdown
- What's covered
- Voice and video calls
- Crates
- Community
- License
Installation
[]
= "0.6.5"
= { = "1.53", = ["full"] }
Quick start: bot
use ;
const API_ID: i32 = 0;
const API_HASH: &str = "";
async
Quick start: user account
use Client;
const API_ID: i32 = 0;
const API_HASH: &str = "";
async
Examples
19 runnable examples covering everything from sending a message to a full FSM order bot.
See examples for the full list with descriptions and notes on when to use quick_connect vs Client::builder().
Connecting
quick_connect is the fast path. For anything more specific, use the builder:
use Client;
let = builder
.api_id
.api_hash
.session
.catch_up
.connect
.await?;
.catch_up(true) replays missed updates after a reconnect, and .retry_policy(...) / .restart_policy(...) let you customize retry and reconnect behavior.
Session backends
builder.session // binary file (default)
builder.in_memory // no persistence
builder.session_string // base64 string
builder.session_backend // sqlite
builder.session_backend // libsql, local file
builder.session_backend // turso, remote only
builder.session_backend // turso, local + synced
The base64 string backend is useful for serverless or containers where writing to disk isn't an option. open_remote and open_replica need the libsql-remote-session feature on top of libsql-session, and can't be combined with sqlite-session (both link a sqlite3 C source). To bring your own backend, implement SessionBackend from ferogram-session.
Transport and proxy
use TransportKind;
builder.transport // default
builder.transport // DPI bypass, plain MTProxy secrets
builder.transport // TLS camouflage, 0xee secrets
// MTProxy from a t.me link
builder.proxy_link
// SOCKS5
builder.socks5
// Race transports, use first to connect
builder.probe_transport
// Fall back through DoH + Telegram special-config if TCP is blocked
builder.resilient_connect
See ferogram-connect for the framing layer underneath.
Raw API
When the high-level API isn't enough, client.invoke() takes any TL function directly (current layer exposed as tl::LAYER). It's the escape hatch, not the normal path, but it's always there:
use tl;
let req = SetBotCommands ;
client.invoke.await?;
client.invoke_on_dc.await?; // target a specific DC
See ferogram-tl-types for all generated types and functions.
Error handling
use ;
match client.send_message.await
FLOOD_WAIT is handled automatically. To disable it:
use NoRetries;
builder.retry_policy
Shutdown
let = builder...connect.await?;
shutdown.cancel; // graceful
client.disconnect; // immediate
What's covered
- Rich Messaging: text, media, albums, polls, dice, games, reactions, scheduled messages
- HTML & Markdown: full parse and generate support for both formats
- Inline & Reply Keyboards: buttons, callbacks, inline mode
- CDN: transparent CDN download handling, no extra calls needed
- Proxy Support: SOCKS5 with optional auth
- MTProxy: Classic, DD, and FakeTLS transports, via link or manual config
- Transport Probing: races transports, connects via whichever is fastest
- Concurrent Transfers: parallel uploads/downloads with pause, resume, cancel, and progress tracking
- Resumable Transfers: checkpointed uploads/downloads that survive crashes
- Session Backends: file, in-memory, string, SQLite, LibSQL
- Router & Dispatcher: composable filters (
&,|,!) for expressive handlers - FSM: type-safe finite state machine for multi-step conversations
- Middleware: rate limiting, tracing, panic recovery
- TgCalls: group calls, P2P calls, conference calls, screen share/presentation, audio and video
- Raw API: full TL coverage via
client.invoke() - Python Bindings: native performance with a clean Python API
...and more features like this throughout the codebase!
See features docs for the full list with method signatures. If something is missing, open a feature request or suggest in @FerogramChat.
Secret chats (end-to-end encrypted) are fully implemented but not published to crates.io yet. The plan is to release once there is enough community demand for it.
Voice and video calls
Group audio, video, and P2P calling are now fully implemented. To get started, check out the tgcalls crate and its examples in the tgcalls repository. It provides seamless integration between ferogram and the official ntgcalls Rust bindings for building Telegram voice and video calling applications.
Crates
Most people only need this crate. But each crate in the workspace is independently publishable if you need just one layer - see ARCHITECTURE for the full breakdown and dependency graph.
Community
- Channel (releases, announcements): @Ferogram
- Chat (questions, discussion): @FerogramChat
- Docs: (docs & guidance): docs.ferogram.dev
- Official Website: (Projects & crates): ferogram.dev
- GitHub: github.com/ankit-chaubey/ferogram
License
This project is licensed under either the MIT License or Apache License 2.0, at your option. See LICENSE-MIT and LICENSE-APACHE for details.
Author: Ankit Chaubey (@ankit-chaubey)