ferogram 0.6.5

A native, elegant, and asynchronous MTProto framework in Rust for Telegram clients, bots, and applications.
Documentation
/*
 * Copyright (c) 2026 Ankit Chaubey <ankitchaubey.dev@gmail.com>
 * https://github.com/ankit-chaubey
 *
 * Project: ferogram
 * Website: https://ferogram.dev
 *
 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
 * This file may not be copied, modified, or distributed except according
 * to those terms.
 */

//! Generate a string session for serverless deployments.
//!
//! Logs in once via a local session file, exports a compact session string,
//! then prints it. Store the string in SESSION_STRING and use it with the
//! serverless_userbot example to connect without a session file.
//!
//! Run:
//!   cargo run --example string_session_gen
//!
//! Keep the string private. It gives full access to your account.

use ferogram::Client;

const API_ID: i32 = 0; // fill in from https://my.telegram.org
const API_HASH: &str = ""; // fill in from https://my.telegram.org

#[tokio::main]
async fn main() {
    if let Err(e) = run().await {
        eprintln!("error: {e}");
        std::process::exit(1);
    }
}

async fn run() -> Result<(), Box<dyn std::error::Error>> {
    if API_ID == 0 || API_HASH.is_empty() {
        eprintln!("Fill in API_ID and API_HASH at the top of string_session_gen.rs");
        std::process::exit(1);
    }

    let (client, _shutdown) = Client::quick_connect("gen.session", API_ID, API_HASH).await?;

    // export_session_string calls get_me() internally
    let session_string = client.export_session_string().await?;

    println!("Your session string:\n");
    println!("{session_string}");
    println!("\nSet SESSION_STRING to this value and run the serverless_userbot example.");
    println!("Keep it private. It gives full access to your account.");

    Ok(())
}