### Client::quick_connect example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Fast path for connecting: one line, handles the session file and prompts for login interactively if needed. Use when you just want to get something running without thinking about connection options. ```rust let (client, _shutdown) = Client::quick_connect("my.session", API_ID, API_HASH).await?; ``` -------------------------------- ### Quick start: send a message with ferogram Source: https://github.com/ankit-chaubey/ferogram/blob/main/README.md Initializes a client with quick_connect and sends a message to 'me'. Requires valid API_ID and API_HASH values. ```rust use ferogram::Client; const API_ID: i32 = 0; const API_HASH: &str = ""; #[tokio::main] async fn main() -> anyhow::Result<()> { let (client, _) = Client::quick_connect("my.session", API_ID, API_HASH).await?; client.send_message("me", "Hello from ferogram!").await?; Ok(()) } ``` -------------------------------- ### Run the example with cargo run Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/quickstart-user.md Run the example with `cargo run`. Fill in API_ID and API_HASH at the top of the file before running. On first run you'll be prompted for your phone number and the code Telegram sends; on subsequent runs the session is reloaded from my.session and login is skipped automatically. ```bash cargo run ``` -------------------------------- ### Complete user account example: connect, send, and stream updates Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/quickstart-user.md A complete working example that connects with Client::quick_connect, sends a message to Saved Messages via send_to_self, and streams incoming updates. Requires API_ID and API_HASH from https://my.telegram.org. On first run, prompts for phone number and code; subsequent runs reload the session from my.session and skip login. ```rust use ferogram::Client; use ferogram::update::Update; const API_ID: i32 = 0; // from https://my.telegram.org const API_HASH: &str = ""; // from https://my.telegram.org #[tokio::main] async fn main() -> Result<(), Box> { let (client, _shutdown) = Client::quick_connect("my.session", API_ID, API_HASH).await?; // Send a message to yourself client.send_to_self("Hello from ferogram! 👋").await?; println!("Message sent to Saved Messages"); // Stream incoming updates println!("Listening for messages… (Ctrl+C to quit)"); let mut updates = client.stream_updates(); while let Some(update) = updates.next().await { match update { Update::NewMessage(msg) if !msg.outgoing() => { let text = msg.text().unwrap_or("(no text)"); let sender = msg.sender_id() .map(|p| format!("{p:?}")) .unwrap_or_else(|| "unknown".into()); println!("📨 [{sender}] {text}"); } Update::MessageEdited(msg) => { println!("✏️ Edited: {}", msg.text().unwrap_or("")); } _ => {} } } Ok(()) } ``` -------------------------------- ### Run showcase_bot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the showcase_bot example, which covers every feature in one place: commands, callbacks, inline queries, media handling, formatting, and more. Uses Client::builder() with all the options. ```bash cargo run --example showcase_bot ``` -------------------------------- ### Install ferogram Python package via pip Source: https://github.com/ankit-chaubey/ferogram/blob/main/README.md Install the pre-built ferogram Python package from PyPI. No Rust toolchain is required. ```bash pip install ferogram ``` -------------------------------- ### Run serverless_userbot example with SESSION_STRING Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Loads a session string from the SESSION_STRING env var, logs in, and sends a message to your Saved Messages to confirm it worked. Uses Client::builder() with .session_string() instead of a file. Run string_session_gen first to get the string. ```bash SESSION_STRING="..." cargo run --example serverless_userbot ``` -------------------------------- ### Run download_media example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Watches for incoming photos and documents and saves them to a downloads/ folder automatically. Useful for building a media archiver. ```bash cargo run --example download_media ``` -------------------------------- ### Run hello_self example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the simplest ferogram example, which logs in and sends 'Hello from ferogram!' to your Saved Messages using quick_connect. Requires api_id and api_hash from my.telegram.org. ```bash cargo run --example hello_self ``` -------------------------------- ### Verify installation by printing Telegram API Layer Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/installation.md Rust example that prints the Telegram API Layer constant from ferogram_tl_types to verify the installation. Expected output is 'Using Telegram API Layer 232'. ```rust use ferogram_tl_types::LAYER; fn main() { println!("Using Telegram API Layer {}", LAYER); // → Using Telegram API Layer 232 } ``` -------------------------------- ### Run filters_showcase example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs an example demonstrating ferogram's filter system, which routes updates to handlers based on conditions like photo, command, or group. Filters compose with &, |, and !. ```bash cargo run --example filters_showcase ``` -------------------------------- ### Run order_bot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the order_bot example, a multi-step conversation bot using FSM (finite state machine) that walks the user through product, quantity, and address before confirming an order. Shows how to handle stateful flows properly. ```bash cargo run --example order_bot ``` -------------------------------- ### Run inline_keyboard example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the inline_keyboard bot example, which sends an inline keyboard on /start and handles button taps via callback queries. ```bash cargo run --example inline_keyboard ``` -------------------------------- ### client.recording_video(peer) Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Shorthand for starting a RecordVideoAction on the given peer. Returns a TypingGuard that cancels when dropped. ```APIDOC ## client.recording_video(peer) ### Description Shorthand for starting a `RecordVideoAction` on the given peer. Returns a `TypingGuard` that cancels when dropped. ### Method async fn ### Parameters - **peer** - The peer to send the recording video action to. ### Returns - `TypingGuard` - RAII guard; drop to cancel. ``` -------------------------------- ### Basic ClientBuilder setup with connect() Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/client-builder.md Shows the minimal fluent setup for a Client connection using Client::builder(). connect() returns Result<(Client, ShutdownToken), BuilderError>; possible errors include MissingApiId, MissingApiHash, or Connect(InvocationError). ```rust use ferogram::Client; #[tokio::main] async fn main() -> anyhow::Result<()> { let (client, _shutdown) = Client::builder() .api_id(12345) .api_hash("abc123") .session("my.session") .catch_up(true) .connect() .await?; Ok(()) } ``` -------------------------------- ### Use LibSqlBackend for local and remote sessions Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/installation.md Rust example showing how to open a LibSqlBackend for local embedded databases and remote Turso cloud databases. Requires the 'libsql-session' feature. ```rust use ferogram::session_backend::LibSqlBackend; // Local let backend = LibSqlBackend::open_local("session.libsql").await?; // Remote (Turso cloud) let backend = LibSqlBackend::open_remote( "libsql://your-db.turso.io", "your-turso-auth-token", ).await?; ``` -------------------------------- ### Client::builder() example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md For when you need control: transport type, proxy, device model, language code, resilient reconnect, string sessions. More code, but more options. ```rust let (client, _shutdown) = Client::builder() .api_id(API_ID) .api_hash(API_HASH) .transport(TransportKind::Abridged) .resilient_connect(true) .connect() .await?; ``` -------------------------------- ### TypingGuard::start_ex(client, peer, action, topic_id, delay) Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Full control variant of start with topic support and custom repeat delay. Returns a TypingGuard that cancels the indicator when dropped. ```APIDOC ## TypingGuard::start_ex(client, peer, action, topic_id, delay) ### Description Full control variant of `start` with topic support and custom repeat delay. Returns a `TypingGuard` that cancels the indicator when dropped. ### Method async fn ### Parameters - **client** - The client instance. - **peer** - The peer to send the action to. - **action** - The `SendMessageAction` to start. - **topic_id** - The forum topic ID. - **delay** - Custom repeat delay in seconds. ### Returns - `TypingGuard` - RAII guard; drop to cancel. ``` -------------------------------- ### Run string_session_gen example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Logs in and prints a session string you can save as an env var. Useful when you can't or don't want to write files to disk (a VPS, a container, CI, etc.). ```bash cargo run --example string_session_gen ``` -------------------------------- ### Run dialogs_list example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Prints every chat in your account, newest first, with unread counts. Requires a personal account via MTProto, not a bot token. ```bash cargo run --example dialogs_list ``` -------------------------------- ### Run inline_query_bot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the inline_query_bot example, which lets users type @your_bot something anywhere in Telegram and see instant results. Requires enabling inline mode in BotFather first (/setinline). ```bash cargo run --example inline_query_bot ``` -------------------------------- ### Run get_participants example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Lists every member of a group or channel with their role (creator, admin, member, banned). Requires being a member and setting PEER. ```bash cargo run --example get_participants ``` -------------------------------- ### Export and restore string session Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/installation.md Rust example showing how to export a session as a base64 string and restore it anywhere. No feature flag is needed for string sessions. ```rust // Export let s = client.export_session_string().await?; // Restore let (client, _shutdown) = Client::builder() .api_id(api_id) .api_hash(api_hash) .session_string(s) .connect() .await?; ``` -------------------------------- ### Quick start user account with ferogram Client Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/README.md Connects a user session using quick_connect and sends a message to 'me'. Requires API_ID and API_HASH constants. ```rust use ferogram::Client; const API_ID: i32 = 0; const API_HASH: &str = ""; #[tokio::main] async fn main() -> anyhow::Result<()> { let (client, _) = Client::quick_connect("my.session", API_ID, API_HASH).await?; client.send_message("me", "Hello from ferogram!").await?; Ok(()) } ``` -------------------------------- ### TypingGuard::start(client, peer, action) Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts any SendMessageAction asynchronously. Returns a TypingGuard that cancels the indicator when dropped. ```APIDOC ## TypingGuard::start(client, peer, action) ### Description Starts any `SendMessageAction` asynchronously. Returns a `TypingGuard` that cancels the indicator when dropped. ### Method async fn ### Parameters - **client** - The client instance. - **peer** - The peer to send the action to. - **action** - The `SendMessageAction` to start. ### Returns - `TypingGuard` - RAII guard; drop to cancel. ``` -------------------------------- ### Load API credentials from environment variables Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/installation.md Shows the recommended way to load api_id and api_hash from environment variables instead of hardcoding them. The 'Good' example uses std::env::var, while the 'Bad' example shows hardcoded values that should never be used in a public repository. ```rust // Good: from environment let api_id: i32 = std::env::var("TG_API_ID")?.parse()?; let api_hash: String = std::env::var("TG_API_HASH")?; // Bad: hardcoded in source let api_id = 12345; let api_hash = "deadbeef..."; // ← never do this in a public repo ``` -------------------------------- ### Common ClientBuilder patterns: standard, low memory, and custom update queue Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/client-builder.md Three common setups in one example: standard credentials, low_memory_mode for constrained hardware, and a power-user configuration with update_queue_capacity and update_overflow_strategy(OverflowStrategy::DropNewest). ```rust use ferogram::Client; // 99% of users - just fill in credentials and go let (client, _) = Client::builder() .api_id(API_ID) .api_hash(API_HASH) .session("bot.session") .connect().await?; // Termux / tiny VPS - running on constrained hardware let (client, _) = Client::builder() .api_id(API_ID) .api_hash(API_HASH) .session("bot.session") .low_memory_mode(true) .connect().await?; // Power user - custom update queue to handle high-traffic bots use ferogram::update_config::OverflowStrategy; let (client, _) = Client::builder() .api_id(API_ID) .api_hash(API_HASH) .session("bot.session") .update_queue_capacity(512) .update_overflow_strategy(OverflowStrategy::DropNewest) .connect().await?; ``` -------------------------------- ### Run admin_log example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Reads the admin action log of a supergroup or channel, showing actions like bans, deletions, and title changes. Requires admin privileges and setting GROUP. ```bash cargo run --example admin_log ``` -------------------------------- ### TypingGuard::start_ex Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a typing indicator with support for forum topics and a custom repeat delay. The indicator is automatically renewed at the specified interval until the guard is dropped. ```APIDOC ## TypingGuard::start_ex ### Description Starts a typing indicator with support for forum topics and a custom repeat delay. The indicator is automatically renewed at the specified interval until the guard is dropped. ### Method start_ex ### Parameters - **client** - The client instance used to send the typing action. - **peer** (tl::enums::Peer) - Required - The peer (already resolved) where the typing indicator is shown. - **action** (tl::enums::SendMessageAction) - Required - The typing action to send (e.g., SendMessageTypingAction). - **top_msg_id** (Option) - Optional - The topic message ID for forum topics; use None for normal chats. - **repeat_delay** (Duration) - Required - The repeat delay for renewing the indicator (≤ 4 seconds recommended). ### Request Example ```rust use std::time::Duration; let _guard = TypingGuard::start_ex( client, peer, // tl::enums::Peer (already resolved) tl::enums::SendMessageAction::SendMessageTypingAction, Some(topic_msg_id), // top_msg_id: None for normal chats Duration::from_secs(4), // repeat delay (≤ 4 s recommended) ).await?; ``` ``` -------------------------------- ### Run poll_bot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the poll_bot example, which creates all four poll types: regular, quiz (with correct answer), multiple choice, and timed. Commands are /poll, /quiz, /multi, /timed. ```bash cargo run --example poll_bot ``` -------------------------------- ### Run userbot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md The full-featured userbot with command handler, message editing, file operations, and more. Uses Client::builder() with custom device model and app version. This is the 'batteries included' reference for a real userbot structure. ```bash cargo run --example userbot ``` -------------------------------- ### Run search_messages example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Performs full-text search across a chat's history by keyword, running server-side. Requires setting PEER and QUERY variables. ```bash cargo run --example search_messages ``` -------------------------------- ### Example /start message received by bot Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/games.md Shows the exact text the bot receives in Message.text when start_param is 'ref_42'. ```plaintext /start ref_42 ``` -------------------------------- ### Use ferogram from GitHub main branch Source: https://github.com/ankit-chaubey/ferogram/blob/main/README.md Points the ferogram dependency to a specific commit on GitHub for development versions. Replace COMMIT_SHA with the actual commit hash. ```toml ferogram = { git = "https://github.com/ankit-chaubey/ferogram", rev = "COMMIT_SHA" } ``` -------------------------------- ### Quick start bot with ferogram Client Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/README.md Connects a bot session using quick_connect, streams updates, and replies to incoming messages. Requires API_ID and API_HASH constants. ```rust use ferogram::{Client, update::Update}; const API_ID: i32 = 0; const API_HASH: &str = ""; #[tokio::main] async fn main() -> anyhow::Result<()> { let (client, _) = Client::quick_connect("bot.session", API_ID, API_HASH).await?; let mut stream = client.stream_updates(); while let Some(upd) = stream.next().await { if let Update::NewMessage(msg) = upd { if !msg.outgoing() { msg.reply(msg.text().unwrap_or_default()).await.ok(); } } } Ok(()) } ``` -------------------------------- ### TypingGuard::start_ex with custom delay Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a typing indicator with a custom repeat delay for forum topics or normal chats. Pass Some(topic_msg_id) for forum topics, None for normal chats. The delay is capped at 4 seconds as recommended. ```rust use std::time::Duration; let _guard = TypingGuard::start_ex( client, peer, // tl::enums::Peer (already resolved) tl::enums::SendMessageAction::SendMessageTypingAction, Some(topic_msg_id), // top_msg_id: None for normal chats Duration::from_secs(4), // repeat delay (≤ 4 s recommended) ).await?; ``` -------------------------------- ### Start a bot programmatically with client.start_bot Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/bot-config.md Sends a /start command with a start parameter as if a user pressed a deep-link button. Equivalent to clicking https://t.me/somebot?start=ref_12345. The start_param is the payload after the link; use an empty string for plain /start. ```rust // bot_user_id: the bot's user ID // peer: the chat where /start is sent // start_param: the payload after the link (empty string for plain /start) client.start_bot( bot_user_id, "@somebot", "ref_12345", ).await?; ``` -------------------------------- ### Run translate_bot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs the translate_bot example, which translates messages using Telegram's built-in translation API when you reply with /tr en (or another language code). No external API key needed. ```bash cargo run --example translate_bot ``` -------------------------------- ### Run schedule_message example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Schedules a message to be sent at a future time, stored and delivered server-side. Requires setting PEER, TEXT, and SEND_IN_SECONDS. ```bash cargo run --example schedule_message ``` -------------------------------- ### Full CDN download example using CdnDownloader Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/advanced/cdn-downloads.md Complete example showing how to connect to a CDN DC and download a file. Steps: detect the CDN redirect from an upload.getFile call, connect to the CDN DC address, then download all bytes. The connect call accepts an optional SOCKS5 proxy (None here). ```rust use ferogram::cdn_download::{CdnDownloader, CDN_CHUNK_SIZE}; // 1. Detect the CDN redirect from an upload.getFile call (raw API) // ... // 2. Connect to the CDN DC let mut cdn = CdnDownloader::connect( "149.154.167.222:443", // CDN DC address from the redirect 5, // CDN DC ID file_token, encryption_key, encryption_iv, None, // no SOCKS5 ).await?; // 3. Download everything let bytes = cdn.download_all(Some(total_size)).await?; println!("Downloaded {} bytes", bytes.len()); ``` -------------------------------- ### Run echo_bot example Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram/examples/README.md Runs a bot that echoes every text message back to the sender. Runs as a bot, not your personal account, so it only sees direct messages. Safe to leave running. ```bash cargo run --example echo_bot ``` -------------------------------- ### start_bot Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/bot-config.md Starts a bot programmatically by sending a /start command with an optional start parameter, equivalent to a user pressing a deep-link button. ```APIDOC ## start_bot ### Description Starts a bot programmatically by sending a /start command with an optional start parameter, equivalent to a user pressing a deep-link button. ### Method start_bot ### Parameters - **bot_user_id** (integer) - Required - The bot's user ID. - **peer** (string) - Required - The chat where /start is sent. - **start_param** (string) - Required - The payload after the link (empty string for plain /start). ### Request Example ```rust client.start_bot( bot_user_id, "@somebot", "ref_12345", ).await?; ``` ``` -------------------------------- ### get_all_stickers(hash) Source: https://github.com/ankit-chaubey/ferogram/blob/main/FEATURES.md Fetches all installed sticker sets. Use this to get all sticker sets. ```APIDOC ## get_all_stickers(hash) ### Description Fetches all installed sticker sets. ### Method Function call ### Parameters - **hash** - Required - The hash for caching. ``` -------------------------------- ### Create LibSqlBackend remote or replica (feature: libsql-remote-session) Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram-session/README.md Creates a `LibSqlBackend` for remote Turso (`open_remote`) or a local replica synced with remote (`open_replica`). Requires `libsql-remote-session` feature on top of `libsql-session`. Reads hit the local replica; writes sync to the remote. ```rust use ferogram_session::LibSqlBackend; // Talk to a remote Turso database directly. let backend = LibSqlBackend::open_remote(url, auth_token)?; // Local file that stays synced with a remote Turso database. // Reads hit the local replica; writes sync to the remote. let backend = LibSqlBackend::open_replica("sessions.db", url, auth_token)?; ``` -------------------------------- ### BinaryFileBackend::path() - get file path Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/authentication/session-backends.md Create a BinaryFileBackend with a filename and print the path where the session will be saved using path().display(). ```rust use ferogram::session_backend::BinaryFileBackend; let backend = BinaryFileBackend::new("bot.session"); println!("Saving to: {}", backend.path().display()); ``` -------------------------------- ### client.uploading_document(peer) Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Shorthand for starting an UploadDocumentAction on the given peer. Returns a TypingGuard that cancels when dropped. ```APIDOC ## client.uploading_document(peer) ### Description Shorthand for starting an `UploadDocumentAction` on the given peer. Returns a `TypingGuard` that cancels when dropped. ### Method async fn ### Parameters - **peer** - The peer to send the uploading document action to. ### Returns - `TypingGuard` - RAII guard; drop to cancel. ``` -------------------------------- ### Create BinaryFileBackend Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram-session/README.md Creates a `BinaryFileBackend` that saves the session as a binary file on disk. This is the default backend. ```rust use ferogram_session::BinaryFileBackend; let backend = BinaryFileBackend::new("ferogram.session"); ``` -------------------------------- ### client.typing(peer) Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Shorthand for starting a TypingAction on the given peer. Returns a TypingGuard that cancels when dropped. ```APIDOC ## client.typing(peer) ### Description Shorthand for starting a `TypingAction` on the given peer. Returns a `TypingGuard` that cancels when dropped. ### Method async fn ### Parameters - **peer** - The peer to send the typing action to. ### Returns - `TypingGuard` - RAII guard; drop to cancel. ``` -------------------------------- ### Complete example: long task with typing Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Shows a full async handler that starts a typing indicator, simulates a slow operation, and sends the result. The indicator is renewed every 4 seconds and cancelled when the guard drops. ```rust use ferogram::{Client, InvocationError}; use ferogram_tl_types as tl; async fn handle_command( client: &Client, peer: tl::enums::Peer, ) -> Result<(), InvocationError> { // Indicator starts immediately, renewed every 4 s let _typing = client.typing(peer.clone()).await?; // Simulate a slow operation let result = compute_answer().await; // _typing drops here → indicator cancelled client .send_message(peer, &result) .await?; Ok(()) } async fn compute_answer() -> String { tokio::time::sleep(std::time::Duration::from_secs(2)).await; "Here is your answer!".into() } ``` -------------------------------- ### TypingGuard::start Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a typing indicator for any SendMessageAction variant. The indicator is automatically cancelled when the returned TypingGuard is dropped. ```APIDOC ## TypingGuard::start ### Description Starts a typing indicator for any SendMessageAction variant. The indicator is automatically cancelled when the returned TypingGuard is dropped. ### Method Rust method ### Parameters - **client** - Required - The client to use. - **peer** - Required - The peer to send the indicator to. - **action** - Required - The SendMessageAction variant to send. ### Returns - **TypingGuard** - A guard that keeps the indicator alive and cancels it when dropped. ### Request Example ```rust let _guard = TypingGuard::start( client, peer.clone(), tl::enums::SendMessageAction::SendMessageRecordAudioAction, ).await?; ``` ``` -------------------------------- ### Create LibSqlBackend local or in-memory (feature: libsql-session) Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram-session/README.md Creates a `LibSqlBackend` using `open_local` for a local file or `in_memory` for tests (no disk). Requires the `libsql-session` feature; no remote server needed. ```rust use ferogram_session::LibSqlBackend; let backend = LibSqlBackend::open_local("sessions.db")?; let backend = LibSqlBackend::in_memory()?; // tests, no disk ``` -------------------------------- ### Client::typing Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a typing indicator for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ```APIDOC ## Client::typing ### Description Starts a "typing…" indicator for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ### Method Rust method ### Parameters - **peer** - Required - The peer to send the typing indicator to. ### Returns - **TypingGuard** - A guard that keeps the indicator alive and cancels it when dropped. ### Request Example ```rust let _typing = client.typing(peer.clone()).await?; ``` ``` -------------------------------- ### Clone, Build, Test, and Lint Ferogram Source: https://github.com/ankit-chaubey/ferogram/blob/main/CONTRIBUTING.md Commands to set up the Ferogram workspace: clone the repository, build the workspace, run tests, build with all optional features, check formatting, and run Clippy with warnings as errors. ```bash # Clone the repository git clone https://github.com/ankit-chaubey/ferogram.git cd ferogram # Build the workspace cargo build --workspace # Run all tests cargo test --workspace # Build with all optional features cargo build -p ferogram --all-features # Check formatting cargo fmt --all -- --check # Run Clippy cargo clippy --workspace --all-features -- -D warnings ``` -------------------------------- ### client.typing_in_topic(peer, topic_id) Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Shorthand for starting a TypingAction inside a forum topic thread. Returns a TypingGuard that cancels when dropped. ```APIDOC ## client.typing_in_topic(peer, topic_id) ### Description Shorthand for starting a `TypingAction` inside a forum topic thread. Returns a `TypingGuard` that cancels when dropped. ### Method async fn ### Parameters - **peer** - The peer to send the typing action to. - **topic_id** - The forum topic ID. ### Returns - `TypingGuard` - RAII guard; drop to cancel. ``` -------------------------------- ### BinaryFileBackend::new Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram-session/README.md Creates a new BinaryFileBackend that saves the session as a binary file on disk. This is the default backend. ```APIDOC ## BinaryFileBackend::new ### Description Creates a new BinaryFileBackend that saves the session as a binary file on disk. This is the default backend. ### Method constructor ### Signature `BinaryFileBackend::new(path)` ### Parameters - **path** (string) - Required - The file path where the session will be saved. ### Request Example ```rust use ferogram_session::BinaryFileBackend; let backend = BinaryFileBackend::new("ferogram.session"); ``` ``` -------------------------------- ### List all installed sticker sets with client.get_all_stickers Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/stickers.md Lists all sticker sets installed for the current account. Pass hash = 0 to always get the full list. Returns None when the server confirms the list is unchanged (hash match for caching). ```rust if let Some(sets) = client.get_all_stickers(0).await? { for s in &sets { println!("{} ({})", s.title, s.short_name); } } ``` -------------------------------- ### Client::typing Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a typing indicator that is automatically renewed every 4 seconds. The indicator is cancelled when the returned guard is dropped. ```APIDOC ## Client::typing ### Description Starts a typing indicator that is automatically renewed every 4 seconds. The indicator is cancelled when the returned guard is dropped. ### Method typing ### Parameters - **peer** (tl::enums::Peer) - Required - The peer where the typing indicator is shown. ### Request Example ```rust use ferogram::{Client, InvocationError}; use ferogram_tl_types as tl; async fn handle_command( client: &Client, peer: tl::enums::Peer, ) -> Result<(), InvocationError> { // Indicator starts immediately, renewed every 4 s let _typing = client.typing(peer.clone()).await?; // Simulate a slow operation let result = compute_answer().await; // _typing drops here → indicator cancelled client .send_message(peer, &result) .await?; Ok(()) } async fn compute_answer() -> String { tokio::time::sleep(std::time::Duration::from_secs(2)).await; "Here is your answer!".into() } ``` ``` -------------------------------- ### Launch a game flow with start_bot Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/games.md Starts a bot with a 'play' parameter to trigger a specific game flow. ```rust // Launch a specific game flow client.start_bot(bot_user_id, bot_user_id, "play").await?; ``` -------------------------------- ### Client::typing_in_topic Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a typing indicator inside a forum topic for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ```APIDOC ## Client::typing_in_topic ### Description Starts a typing indicator inside a forum topic for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ### Method Rust method ### Parameters - **peer** - Required - The peer to send the typing indicator to. - **top_msg_id** - Required - The forum topic ID. ### Returns - **TypingGuard** - A guard that keeps the indicator alive and cancels it when dropped. ### Request Example ```rust let _typing = client.typing_in_topic(peer.clone(), topic_id).await?; ``` ``` -------------------------------- ### Client::recording_video Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts a "recording video…" indicator for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ```APIDOC ## Client::recording_video ### Description Starts a "recording video…" indicator for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ### Method Rust method ### Parameters - **peer** - Required - The peer to send the recording indicator to. ### Returns - **TypingGuard** - A guard that keeps the indicator alive and cancels it when dropped. ### Request Example ```rust let _typing = client.recording_video(peer.clone()).await?; ``` ``` -------------------------------- ### Client::uploading_document Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/typing-guard.md Starts an "uploading document…" indicator for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ```APIDOC ## Client::uploading_document ### Description Starts an "uploading document…" indicator for the given peer. The indicator is automatically cancelled when the returned TypingGuard is dropped. ### Method Rust method ### Parameters - **peer** - Required - The peer to send the uploading indicator to. ### Returns - **TypingGuard** - A guard that keeps the indicator alive and cancels it when dropped. ### Request Example ```rust let _typing = client.uploading_document(peer.clone()).await?; ``` ``` -------------------------------- ### LibSqlBackend::open_local Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram-session/README.md Opens a local LibSQL-backed session backend from a file. Requires the `libsql-session` feature. ```APIDOC ## LibSqlBackend::open_local ### Description Opens a local LibSQL-backed session backend from a file. Requires the `libsql-session` feature. ### Method constructor ### Signature `LibSqlBackend::open_local(path)` ### Parameters - **path** (string) - Required - The path to the local database file. ### Request Example ```rust use ferogram_session::LibSqlBackend; let backend = LibSqlBackend::open_local("sessions.db")?; ``` ``` -------------------------------- ### Create SqliteBackend (feature: sqlite-session) Source: https://github.com/ankit-chaubey/ferogram/blob/main/ferogram-session/README.md Creates a `SqliteBackend` using `open` for a file or `in_memory` for tests (no disk). Requires the `sqlite-session` feature. ```rust use ferogram_session::SqliteBackend; let backend = SqliteBackend::open("sessions.db")?; let backend = SqliteBackend::in_memory()?; // tests, no disk ``` -------------------------------- ### Add ferogram dependency to Cargo.toml Source: https://github.com/ankit-chaubey/ferogram/blob/main/README.md Adds the ferogram crate as a dependency in Cargo.toml. Use the stable version from crates.io for the safe default. ```toml [dependencies] ferogram = "0.6.6" ``` -------------------------------- ### Create a ferogram client and reply to messages Source: https://github.com/ankit-chaubey/ferogram/blob/main/ARCHITECTURE.md Initializes a Client with a session file, API ID, and API hash, registers an on_message handler that replies to incoming messages, and runs the client. The handler is plain Python and can be changed without recompiling. ```python from ferogram import Client client = Client("my.session", api_id=API_ID, api_hash=API_HASH) @client.on_message() async def handler(msg): await msg.reply("Hello from ferogram!") client.run() ``` -------------------------------- ### Basic quick_connect usage Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/quick-connect.md Shows a minimal async main that calls Client::quick_connect with a session file and credentials. The prompt is skipped if already authorized; otherwise it interactively asks for a phone number or bot token, then login code and 2FA if needed. ```rust use ferogram::Client; const API_ID: i32 = 12345; const API_HASH: &str = "your_api_hash"; #[tokio::main] async fn main() -> Result<(), Box> { let (client, _shutdown) = Client::quick_connect("my.session", API_ID, API_HASH).await?; // client is ready to use Ok(()) } ``` -------------------------------- ### Client::builder().socks5() Source: https://github.com/ankit-chaubey/ferogram/blob/main/ARCHITECTURE.md Configures a SOCKS5 proxy for the client connection. ```APIDOC ## Client::builder().socks5() ### Description Configures a SOCKS5 proxy for the client connection. ### Method builder method ### Parameters #### Arguments - **addr** (string) - Required - The SOCKS5 proxy address in host:port format. ### Example ```rust // SOCKS5 Client::builder().socks5("127.0.0.1:1080") ``` ``` -------------------------------- ### client.get_all_stickers(hash: i64) → Result>, InvocationError> Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/stickers.md Lists all sticker sets installed for the current account. Pass hash = 0 to always get the full list. Returns None when the server confirms the list is unchanged (hash match - used for caching). ```APIDOC ## client.get_all_stickers(hash: i64) → Result>, InvocationError> ### Description Lists all sticker sets installed for the current account. Pass `hash = 0` to always get the full list. Returns `None` when the server confirms the list is unchanged (hash match - used for caching). ### Parameters #### Input - **hash** (i64) - Required - Hash for caching; use 0 to force full list. ### Response #### Success Response - **sets** (Option>) - The list of installed sticker sets, or None if unchanged. ### Request Example ```rust if let Some(sets) = client.get_all_stickers(0).await? { for s in &sets { println!("{} ({})", s.title, s.short_name); } } ``` ``` -------------------------------- ### client.get_common_chats(user_id: i64, max_id: i64, limit: i32) → Result, InvocationError> Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/chat-management.md Gets chats shared between the current account and the specified user. Start with max_id = 0; use the last returned chat ID for subsequent pages. Max limit is 100. ```APIDOC ## client.get_common_chats(user_id: i64, max_id: i64, limit: i32) → Result, InvocationError> ### Description Gets chats shared between the current account and the specified user. Start with max_id = 0; use the last returned chat ID for subsequent pages. Max limit is 100. ### Method async ### Signature client.get_common_chats(user_id: i64, max_id: i64, limit: i32) → Result, InvocationError> ### Parameters - **user_id** (i64) - Required - The user to find common chats with. - **max_id** (i64) - Required - Offset for pagination; start with 0. - **limit** (i32) - Required - Maximum number of chats to return; max 100. ### Response #### Success Response - Returns `Result, InvocationError>` - Ok with a list of common chats, or an InvocationError on failure. ``` -------------------------------- ### quick_connect vs ClientBuilder comparison Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/quick-connect.md Compares quick_connect with ClientBuilder configurations for memory-constrained environments and power users. The first block is the default; the second enables low_memory_mode; the third customizes update queue capacity and overflow strategy. ```rust // 99% of users - just works let (client, _) = Client::quick_connect("bot.session", API_ID, API_HASH).await?; ``` ```rust // Termux / tiny VPS - memory-constrained environment let (client, _) = Client::builder() .api_id(API_ID) .api_hash(API_HASH) .session("bot.session") .low_memory_mode(true) .connect().await?; ``` ```rust // Power user with specific needs let (client, _) = Client::builder() .api_id(API_ID) .api_hash(API_HASH) .session("bot.session") .update_queue_capacity(512) .update_overflow_strategy(OverflowStrategy::DropNewest) .connect().await?; ``` -------------------------------- ### Build a client with Client::builder() Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/config.md Shows the recommended way to construct a Config via Client::builder() and connect. All fields except api_id and api_hash have defaults. ```rust use ferogram::{Client, TransportKind}; let (client, _shutdown) = Client::builder() .api_id(12345) .api_hash("your_api_hash") .session("bot.session") // default: "ferogram.session" .transport(TransportKind::Obfuscated { secret: None }) .catch_up(false) .connect() .await?; ``` -------------------------------- ### client.set_admin Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/client.md Sets admin rights. Use AdminRightsBuilder::full_admin() to promote or AdminRightsBuilder::new() to demote. ```APIDOC ## client.set_admin ### Description Set admin rights. Use AdminRightsBuilder::full_admin() to promote or AdminRightsBuilder::new() to demote. ### Method async ### Signature client.set_admin(peer: impl Into, user_id: i64, rights: AdminRightsBuilder) → Result<(), InvocationError> ### Parameters - **peer** (PeerRef) - Required - The chat or channel. - **user_id** (i64) - Required - The ID of the user to set admin rights for. - **rights** (AdminRightsBuilder) - Required - The admin rights to set. ### Response - **Result<(), InvocationError>** - Success or an error. ``` -------------------------------- ### Session backend configuration options Source: https://github.com/ankit-chaubey/ferogram/blob/main/ARCHITECTURE.md Shows all built-in session backends: binary file (default), in-memory, base64 string, SQLite, and LibSQL (local, remote, replica). The base64 string backend suits serverless or containers without disk writes. To bring your own backend, implement `SessionBackend` from `ferogram-session`. ```rust Client::builder().session("bot.session") // binary file (default) Client::builder().in_memory() // no persistence Client::builder().session_string(env::var("SESSION")?) // base64 string Client::builder().session_backend(Arc::new(SqliteBackend::open("s.db")?)) // sqlite Client::builder().session_backend(Arc::new(LibSqlBackend::open_local("s.db")?)) // libsql, local file Client::builder().session_backend(Arc::new(LibSqlBackend::open_remote(url, token)?)) // turso, remote only Client::builder().session_backend(Arc::new(LibSqlBackend::open_replica("s.db", url, token)?)) // turso, local + synced ``` -------------------------------- ### client.download(media: &MessageMedia, dest: impl AsyncWrite + Unpin) → Result Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/api/client.md Download a media file and write it to path. The path argument accepts anything that implements AsRef (e.g. &str, String, PathBuf). DC routing is handled automatically. ```APIDOC ## client.download ### Description Download a media file and write it to `path`. The `path` argument accepts anything that implements `AsRef` (e.g. `&str`, `String`, `PathBuf`). DC routing is handled automatically. ### Method async ### Signature `client.download(media: &MessageMedia, dest: impl AsyncWrite + Unpin) → Result` ### Parameters - **media** (&MessageMedia) - Required - The media to download. - **dest** (impl AsyncWrite + Unpin) - Required - The destination writer. ### Returns - **Result** - Number of bytes written. ``` -------------------------------- ### Configure transport and proxy options Source: https://github.com/ankit-chaubey/ferogram/blob/main/ARCHITECTURE.md Shows how to set the transport kind (Abridged default, Obfuscated for DPI bypass with plain MTProxy secrets, FakeTLS for TLS camouflage with 0xee secrets), configure an MTProxy from a t.me link, use SOCKS5, enable transport racing, and enable resilient connection fallback through DoH and Telegram special-config. ```rust use ferogram::TransportKind; Client::builder().transport(TransportKind::Abridged) // default Client::builder().transport(TransportKind::Obfuscated) // DPI bypass, plain MTProxy secrets Client::builder().transport(TransportKind::FakeTls) // TLS camouflage, 0xee secrets // MTProxy from a t.me link Client::builder().proxy_link("https://t.me/proxy?server=HOST&port=PORT&secret=SECRET") // SOCKS5 Client::builder().socks5("127.0.0.1:1080") // Race transports, use first to connect Client::builder().probe_transport(true) // Fall back through DoH + Telegram special-config if TCP is blocked Client::builder().resilient_connect(true) ``` -------------------------------- ### Callback button data format examples in Rust Source: https://github.com/ankit-chaubey/ferogram/blob/main/docs/src/messaging/keyboards.md Shows compact, parseable formats for callback button data, which is limited to 64 bytes by Telegram. The 'Good' examples are structured and compact, while the 'Bad' example is verbose and should be avoided. ```rust // Good: structured, compact "vote:yes" "page:3" "item:42:delete" "menu:settings:notifications" // Bad: verbose "user_clicked_the_settings_button" ``` -------------------------------- ### toggle_stickers(set, bool) Source: https://github.com/ankit-chaubey/ferogram/blob/main/FEATURES.md Installs or uninstalls a sticker set. Use this to toggle sticker set installation. ```APIDOC ## toggle_stickers(set, bool) ### Description Installs or uninstalls a sticker set. ### Method Function call ### Parameters - **set** - Required - The sticker set. - **bool** - Required - True to install, false to uninstall. ```