Ferogram Rust API Layer 225

Raw Telegram MTProto API reference for Layer 225, with Rust code examples using ferogram. Use the search box above or browse by section.

What is ferogram?

ferogram is an async Rust Telegram MTProto client. It talks to Telegram directly over MTProto with no Bot API proxy, works for both bots and user accounts, and gives you full access to the raw TL API through client.invoke().

How to invoke a raw method

use ferogram::tl::{enums, functions};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let (client, _) = ferogram::Client::quick_connect(
        "my.session", 12345, "0123456789abcdef0123456789abcdef",
    ).await?;

    let result = client.invoke(&functions::messages::GetHistory {
        peer: enums::InputPeer::Empty,
        offset_id: 0,
        offset_date: 0,
        add_offset: 0,
        limit: 100,
        max_id: 0,
        min_id: 0,
        hash: 0,
    }).await?;

    println!("{result:?}");
    Ok(())
}
use ferogram::{Client, update::Update};
use ferogram::tl::{enums, functions};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let (client, _) = ferogram::Client::quick_connect(
        "my.session", 12345, "0123456789abcdef0123456789abcdef",
    ).await?;

    let mut stream = client.stream_updates();
    while let Some(upd) = stream.next().await {
        if let Update::NewMessage(msg) = upd {
            // Use client inside the handler loop
            let result = client.invoke(&functions::messages::GetHistory {
                peer: enums::InputPeer::Empty,
                offset_id: 0, offset_date: 0, add_offset: 0,
                limit: 10, max_id: 0, min_id: 0, hash: 0,
            }).await?;
            println!("{result:?}");
        }
    }
    Ok(())
}

Core types

TL primitives map to Rust types as follows:

inti3232-bit signed integer.
longi6464-bit signed integer.
int128[u8; 16]128-bit value as a byte array.
int256[u8; 32]256-bit value as a byte array.
doublef6464-bit float.
stringStringUTF-8 owned string.
bytesVec<u8>Arbitrary binary data.
Bool / trueboolflags.N?true fields are plain bool in Rust. Other optional fields are Option<T>.
datei32Unix timestamp.
Vector<T>Vec<T>Rust Vec of the element type.

Module layout

All generated types live under ferogram::tl (re-exported from ferogram-tl-types):

ferogram::tl::functionsRPC function structs implementing RemoteCall. Pass a reference to client.invoke().
ferogram::tl::typesConcrete constructor structs (bare types). Used as enum variant payloads.
ferogram::tl::enumsBoxed abstract types as Rust enums. Pattern-match on these to get the inner types::* struct.