Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types Reference

ferogram wraps the raw TL layer’s tl::enums::User and tl::enums::Chat variants in typed structs so you never need to pattern-match bare enums.

WrapperUnderlying TL type
Usertl::enums::User (variant User)
Grouptl::types::Chat
Channeltl::types::Channel
ChatUnified enum: Chat::Group or Chat::Channel

All four types are available without any feature flags.


User

User wraps a non-empty tl::enums::User::User variant.

Construction

sync User::from_raw(raw: tl::enums::User) → Option<User>
Returns None for tl::enums::User::Empty, Some(User) otherwise. The raw field is public if you need direct TL access.

Identity

sync user.id() → i64
Telegram user ID. Stable and unique forever.
sync user.access_hash() → Option<i64>
Access hash needed for most API calls targeting this user. May be None for users not in your contact list or not recently seen.
sync user.first_name() → Option<&str>
First name, if set.
sync user.last_name() → Option<&str>
Last name, if set.
sync user.full_name() → String
Concatenates first + last name with a space. Returns an empty string if both are absent.
sync user.username() → Option<&str>
Primary username without the @ prefix.
sync user.usernames() → Vec<&str>
All active usernames (primary + extras for Fragment usernames), without @.
sync user.phone() → Option<&str>
Phone number, if visible to the logged-in account.

Flags

sync user.bot() → bool
true if this is a bot account.
sync user.verified() → bool
true if the account has a blue verification badge.
sync user.premium() → bool
true if the user has Telegram Premium.
sync user.is_self() → bool
true if this is the currently logged-in account.
sync user.deleted() → bool
true if the account has been deleted.
sync user.scam() → bool
true if Telegram has flagged this account as a scam.
sync user.restricted() → bool
true if the account is spam-restricted.
sync user.contact() → bool
true if this user is in the logged-in user's contact list.
sync user.mutual_contact() → bool
true if the logged-in user is also in this user's contact list.
sync user.support() → bool
true if this account belongs to Telegram support staff.

Online & Media

sync user.status() → Option<&tl::enums::UserStatus>
Current online status (Online, Offline, Recently, LastWeek, LastMonth, Empty).
sync user.photo() → Option<&tl::types::UserProfilePhoto>
Profile photo metadata, if set. Use client.iter_profile_photos() to download the actual image.
sync user.lang_code() → Option<&str>
Language code reported by the user's Telegram client.

Bot-specific

sync user.bot_inline_placeholder() → Option<&str>
Placeholder text shown in the compose bar when the user activates this bot's inline mode.
sync user.bot_inline_geo() → bool
true if the bot can be used inline without requiring a location share.
sync user.bot_supports_chats() → bool
true if the bot can be added to groups/channels.

Peer Conversion

sync user.as_peer() → tl::enums::Peer
Convert to a PeerUser for use in API calls.
sync user.as_input_peer() → tl::enums::InputPeer
Convert to an InputPeer. Returns InputPeerUser { user_id, access_hash } when an access hash is available, or InputPeerPeerSelf for the logged-in account.

User also implements Display as "Full Name (@username)" or "Full Name [id]".


Group

Group wraps a basic group (tl::types::Chat). Basic groups have ≤ 200 members; larger groups are supergroups (use Channel with megagroup() == true).

Construction

sync Group::from_raw(raw: tl::enums::Chat) → Option<Group>
Returns None if the raw value is Empty, Forbidden, Channel, or ChannelForbidden. The raw field (tl::types::Chat) is public for direct TL access.

Accessors

sync group.id() → i64
Group ID.
sync group.title() → &str
Group title.
sync group.participants_count() → i32
Current member count.
sync group.creator() → bool
true if the logged-in user is the creator of this group.
sync group.migrated_to() → Option<&tl::enums::InputChannel>
If the group was upgraded to a supergroup, contains the InputChannel of the new supergroup.
sync group.as_peer() → tl::enums::Peer
Convert to PeerChat.
sync group.as_input_peer() → tl::enums::InputPeer
Convert to InputPeerChat.

Group implements Display as "Title [group id]".


Channel

Channel wraps both broadcast channels and supergroups (tl::types::Channel). Use kind() or megagroup() / broadcast() to distinguish them.

Construction

sync Channel::from_raw(raw: tl::enums::Chat) → Option<Channel>
Returns None for non-channel variants. The raw field (tl::types::Channel) is public.

Identity

sync channel.id() → i64
Channel / supergroup ID.
sync channel.access_hash() → Option<i64>
Access hash required for channel-targeted API calls.
sync channel.title() → &str
Channel / supergroup title.
sync channel.username() → Option<&str>
Primary public username without @, if set.
sync channel.usernames() → Vec<&str>
All active usernames (primary + Fragment extras), without @.
sync channel.participants_count() → Option<i32>
Approximate member count. May be None for private channels.

Kind

sync channel.kind() → ChannelKind
VariantDescription
ChannelKind::BroadcastBroadcast channel (posts only)
ChannelKind::MegagroupSupergroup (all members can post)
ChannelKind::GigagroupLarge broadcast group (gigagroup)
sync channel.megagroup() → bool
true for supergroups.
sync channel.broadcast() → bool
true for broadcast channels.

Flags

sync channel.verified() → bool
true if the channel has a verification badge.
sync channel.restricted() → bool
true if the channel is unavailable in certain regions.
sync channel.signatures() → bool
true if post author signatures are shown in the channel.

Rights & Media

sync channel.admin_rights() → Option<&tl::types::ChatAdminRights>
Admin rights granted to the logged-in user in this channel, if any.
sync channel.photo() → Option<&tl::types::ChatPhoto>
Channel profile photo metadata, if set.
sync channel.restriction_reason() → Vec<&tl::enums::RestrictionReason>
Regional restriction reasons (e.g. country codes where the channel is blocked).

Peer Conversion

sync channel.as_peer() → tl::enums::Peer
Convert to PeerChannel.
sync channel.as_input_peer() → tl::enums::InputPeer
Convert to InputPeerChannel { channel_id, access_hash }. Returns InputPeerEmpty if the access hash is absent.
sync channel.as_input_channel() → tl::enums::InputChannel
Convert to InputChannel for channel-specific RPCs (e.g. channels.GetParticipants). Returns InputChannelEmpty if the access hash is absent.

Channel implements Display as "Title (@username)" or "Title [channel id]".


Chat (unified enum)

Chat is a convenience enum that holds either a Group or a Channel. Most client methods return peers as Chat when the type is not known in advance.

#![allow(unused)]
fn main() {
match chat {
    Chat::Group(g) => println!("Basic group: {}", g.title()),
    Chat::Channel(c) => println!("Channel/supergroup: {}", c.title()),
}
}

Construction

sync Chat::from_raw(raw: tl::enums::Chat) → Option<Chat>
Returns None for Empty, Forbidden, and ChannelForbidden variants.

Common Accessors

sync chat.id() → i64
ID regardless of variant.
sync chat.title() → &str
Title regardless of variant.
sync chat.as_peer() → tl::enums::Peer
Convert to the appropriate Peer variant.
sync chat.as_input_peer() → tl::enums::InputPeer
Convert to the appropriate InputPeer variant.

Quick Reference

#![allow(unused)]
fn main() {
use ferogram::{User, Group, Channel, Chat};

// User
if let Some(user) = User::from_raw(raw_user) {
    println!("{} id={}", user.full_name(), user.id());
    if user.bot() { println!("It's a bot"); }
    let peer = user.as_input_peer(); // for API calls
}

// Group
if let Some(group) = Group::from_raw(raw_chat) {
    println!("{} ({} members)", group.title(), group.participants_count());
}

// Channel / Supergroup
if let Some(ch) = Channel::from_raw(raw_chat) {
    match ch.kind() {
        ferogram::ChannelKind::Broadcast => println!("Channel"),
        ferogram::ChannelKind::Megagroup => println!("Supergroup"),
        ferogram::ChannelKind::Gigagroup => println!("Gigagroup"),
    }
}

// Unified
if let Some(chat) = Chat::from_raw(raw_chat) {
    println!("id={} title={}", chat.id(), chat.title());
}
}