docs.rs failed to build layer-client-0.4.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
layer-client-0.4.2
๐ค 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.4.4"
= { = "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.markdown_text // โ Option<String> (text with entities as Markdown)
msg.html_text // โ Option<String> (text with entities as HTML)
msg.date // โ i32
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?;
Reactions, Admin & Participants
// Send a reaction
client.send_reaction.await?;
// Promote a user
use AdminRightsBuilder;
client.set_admin_rights.await?;
// Restrict a user
use BanRights;
client.set_banned_rights.await?;
// Iterate participants
let mut iter = client.iter_participants;
while let Some = iter.next.await?
// Profile photos
let photos = client.get_profile_photos.await?;
// Effective permissions
let perms = client.get_permissions.await?;
Search
// Per-peer search
let results = client
.search_messages
.query
.limit
.collect
.await?;
// Global search
let results = client
.search_global
.query
.limit
.collect
.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