layer
Async Rust library for the Telegram MTProto protocol. Developed by Ankit Chaubey.
[!NOTE] This project is no longer maintained or supported. Its original purpose for personal SDK/APK experimentation and learning has been fulfilled.
Instead, please use ferogram, which will receive future development and updates. Development may proceed at a slower pace.
Crates
Most users only need layer-client.
| Crate | Description |
|---|---|
layer-client |
High-level async client: auth, messaging, media, bots |
layer-tl-types |
Layer 224 types, functions, enums (2,329 definitions) |
layer-mtproto |
MTProto session, DH exchange, framing, transports |
layer-crypto |
AES-IGE, RSA, SHA, Diffie-Hellman, auth key derivation |
layer-tl-gen |
Build-time code generator from the TL AST |
layer-tl-parser |
Parses .tl schema into an AST |
Installation
[]
= "0.5.0"
= { = "1", = ["full"] }
Get your api_id and api_hash from my.telegram.org.
Optional features:
= { = "0.5.0", = ["sqlite-session"] } # SQLite session
= { = "0.5.0", = ["libsql-session"] } # libsql / Turso
= { = "0.5.0", = ["html"] } # HTML parser
= { = "0.5.0", = ["html5ever"] } # html5ever parser
layer-client re-exports layer_tl_types as layer_client::tl.
Quick Start - Bot
use ;
async
Quick Start - User Account
use ;
async
Session Backends
| Backend | Flag | Notes |
|---|---|---|
BinaryFileBackend |
default | Single-process bots, scripts |
InMemoryBackend |
default | Tests, ephemeral tasks |
StringSessionBackend |
default | Serverless, env-var storage |
SqliteBackend |
sqlite-session |
Multi-session local apps |
LibSqlBackend |
libsql-session |
Turso / distributed storage |
| Custom | - | Implement SessionBackend |
let s = client.export_session_string.await?;
let = with_string_session.await?;
Raw API
Every Layer method is accessible via client.invoke():
use tl;
let req = SetBotCommands ;
client.invoke.await?;
// Target a specific DC
client.invoke_on_dc.await?;
Tests
Integration tests in layer-client/tests/integration.rs use InMemoryBackend and don't need real credentials.
Community
- Channel: t.me/layer_rs
- Chat: t.me/layer_chat
- Guide: layer.ankitchaubey.in
- API docs: docs.rs/layer-client
Contributing
Read CONTRIBUTING.md before opening a PR. Run cargo test --workspace and cargo clippy --workspace locally. Security issues: see SECURITY.md.
Author
Developed by Ankit Chaubey out of curiosity to explore.
Layer is developed as part of exploration, learning, and experimentation with the Telegram MTProto protocol. Use it at your own risk. Its future and stability are not yet guaranteed.
Acknowledgements
Parts of this library are derived from grammers by Lonami, licensed under MIT or Apache-2.0.
AI was used to reduce manual effort on docs, boilerplate, and large rewrites where it made sense. Core library code is written by the author.
License
Licensed under either of, at your option:
- MIT License: see LICENSE-MIT
- Apache License, Version 2.0: see LICENSE-APACHE
Unless you explicitly state otherwise, any contribution submitted for inclusion shall be dual-licensed as above, without any additional terms or conditions.
Telegram Terms of Service
Ensure your usage complies with Telegram's Terms of Service and API Terms of Service. Misuse of the Telegram API, including spam, mass scraping, or automation of normal user accounts, may result in account limitations or permanent bans.