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:
| int | i32 | 32-bit signed integer. |
| long | i64 | 64-bit signed integer. |
| int128 | [u8; 16] | 128-bit value as a byte array. |
| int256 | [u8; 32] | 256-bit value as a byte array. |
| double | f64 | 64-bit float. |
| string | String | UTF-8 owned string. |
| bytes | Vec<u8> | Arbitrary binary data. |
| Bool / true | bool | flags.N?true fields are plain bool in Rust. Other optional fields are Option<T>. |
| date | i32 | Unix 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::functions | RPC function structs implementing RemoteCall. Pass a reference to client.invoke(). |
ferogram::tl::types | Concrete constructor structs (bare types). Used as enum variant payloads. |
ferogram::tl::enums | Boxed abstract types as Rust enums. Pattern-match on these to get the inner types::* struct. |