๐ค layer-client
High-level async Telegram client for Rust.
The friendly face of the layer stack โ connect, authenticate, send messages, and stream updates with a clean async API.
๐ฆ Installation
[]
= "0.1.2"
= { = "1", = ["full"] }
โจ What It Does
layer-client wraps the raw MTProto machinery into a clean, ergonomic async API. You don't need to know anything about TL schemas, DH handshakes, or message framing โ just connect and go.
- ๐ User auth โ phone code + optional 2FA (SRP)
- ๐ค Bot auth โ bot token login
- ๐ฌ Messaging โ send, delete, fetch message history
- ๐ก Update stream โ typed async events (NewMessage, CallbackQuery, etc.)
- ๐ FLOOD_WAIT retries โ automatic with configurable policy
- ๐ DC migration โ handled transparently
- ๐พ Session persistence โ survive restarts without re-login
- ๐ง Raw API access โ
client.invoke(req)for any TL function
๐ Quick Start โ User Account
use ;
async
๐ค Quick Start โ Bot
use ;
async
๐ API Reference
Connection
// Connect and load/create session
let client = connect.await?;
// Check if already logged in
let authed = client.is_authorized.await?;
// Save session to disk
client.save_session.await?;
// Sign out
client.sign_out.await?;
Authentication
// Phone login
let token = client.request_login_code.await?;
client.sign_in.await?;
// 2FA
client.check_password.await?;
// Bot login
client.bot_sign_in.await?;
Messaging
// By username, "me", or numeric ID
client.send_message.await?;
client.send_message.await?;
client.send_to_self.await?;
// By resolved peer
client.send_message_to_peer.await?;
// Delete messages
client.delete_messages.await?;
// Fetch history
let msgs = client.get_messages.await?;
Updates
let mut stream = client.stream_updates;
while let Some = stream.next.await
IncomingMessage
msg.id // โ i32
msg.text // โ Option<&str>
msg.peer_id // โ Option<&Peer>
msg.sender_id // โ Option<&Peer>
msg.outgoing // โ bool
msg.reply.await?;
Bots
// Answer callback query
client.answer_callback_query.await?;
// Answer with alert popup
client.answer_callback_query.await?;
// Answer inline query
client.answer_inline_query.await?;
Peer Resolution
// Supported formats
client.resolve_peer.await?;
client.resolve_peer.await?;
client.resolve_peer.await?;
Raw API
// Invoke any TL function directly
let result = client.invoke.await?;
โ๏ธ Configuration
Config
Retry Policies
// Auto-sleep on FLOOD_WAIT (default)
retry_policy: new
// Never retry โ propagate all errors immediately
retry_policy: new
// Custom policy
;
๐ Part of the layer stack
layer-client โ you are here
โโโ layer-mtproto (session, DH, framing)
โโโ layer-tl-types (generated API types)
โโโ layer-crypto (AES, RSA, SHA)
๐ License
Licensed under either of, at your option:
- MIT License โ see LICENSE-MIT
- Apache License, Version 2.0 โ see LICENSE-APACHE
๐ค Author
Ankit Chaubey github.com/ankit-chaubey ยท ankitchaubey.in ยท ankitchaubey.dev@gmail.com