Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ferogram

Crates.io docs.rs TL Layer License

ferogram is an async Rust library for Telegram’s MTProto protocol. It works for user accounts and bots, and talks to Telegram directly over MTProto with no Bot API HTTP proxy in the middle.

Everything in the workspace is written from scratch: the .tl schema parser, the TL code generator, AES-IGE crypto, the DH key exchange, MTProto framing, the session layer, and the high-level client on top. Each piece is its own crate so you can pull in just what you need.

Why it exists

I was already using other MTProto libraries and kept running into cases where I needed things to work a bit differently than they allowed. So I wrote my own.

The goal was to cover the major use cases first, and it does. If something’s missing for you, drop by t.me/FerogramChat. I genuinely like hearing what people are building with it.

Crates

Most people only need ferogram. But each crate is independently published if you need a specific layer on its own.

CrateWhat it does
ferogramHigh-level client. Auth, messaging, media, dispatcher, FSM, middleware.
ferogram-sessionSession types and pluggable storage backends (file, memory, SQLite, LibSQL, base64).
ferogram-fsmFSM state storage and context. StateStorage trait, MemoryStorage, StateContext.
ferogram-parsersTelegram Markdown and HTML entity parsers.
ferogram-derive#[derive(FsmState)] proc macro.
ferogram-mtsenderDC connection pool and retry policy. AutoSleep, NoRetries, CircuitBreaker.
ferogram-connectRaw TCP, MTProto framing, obfuscation, SOCKS5, MTProxy, gzip.
ferogram-mtprotoMTProto 2.0 session, DH key exchange, message framing, PFS key binding.
ferogram-cryptoAES-IGE, RSA, SHA, Diffie-Hellman, PQ factorization, auth key derivation.
ferogram-tl-typesAuto-generated TL types, functions, and enums for Layer 225.
ferogram-tl-genBuild-time code generator from TL AST to Rust source.
ferogram-tl-parserParses .tl schema text into a Definition AST.

The rough dependency chain:

ferogram
└ ferogram-mtsender
  └ ferogram-connect
    ├ ferogram-mtproto
    │ ├ ferogram-tl-types
    │ │ └ (build) ferogram-tl-gen
    │ │   └ (build) ferogram-tl-parser
    │ └ ferogram-crypto
    └ ferogram-crypto

Quick install

[dependencies]
ferogram = "0.5.0"
tokio    = { version = "1", features = ["full"] }

Get api_id and api_hash from my.telegram.org. That’s all you need to get started.

Where to go next

Python

Python support is live via ferogram-py. Pre-built wheels, no Rust toolchain needed.

pip install ferogram

Community

License

MIT OR Apache-2.0.

Usage must comply with Telegram’s API Terms of Service.