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

Chat Management

Full reference for creating, editing, and deleting groups and channels. All methods are async and return Result<_, InvocationError>.

For invite link management see Invite Links. For forum topics see Forum Topics.


Join & leave

async client.join_chat(peer: impl Into<PeerRef>) → Result<(), InvocationError>
Join a public group or channel by peer reference (username, ID, or t.me link).
async client.join_link(link: &str) → Result<(), InvocationError>
Accept a t.me/+hash or t.me/joinchat/hash invite link and join the chat.
async client.leave_chat(peer: impl Into<PeerRef>) → Result<(), InvocationError>
Leave a channel or supergroup. For basic groups, use kick on yourself or delete_dialog to hide it.

Create

async client.create_group(title: impl Into<String>, user_ids: Vec<i64>) → Result<tl::enums::Chat, InvocationError>
Create a new legacy basic group with an initial member list. Basic groups support up to 200 members. To go larger, call migrate_chat to upgrade to a supergroup.
#![allow(unused)]
fn main() {
let chat = client.create_group("Dev Team", vec![user_a, user_b]).await?;
}
async client.create_channel(title: impl Into<String>, about: impl Into<String>, broadcast: bool) → Result<tl::enums::Chat, InvocationError>
Create a new channel (broadcast = true) or supergroup (broadcast = false).
#![allow(unused)]
fn main() {
// Supergroup
let sg = client.create_channel("My Community", "A place to chat", false).await?;

// Broadcast channel
let ch = client.create_channel("My News", "Daily updates", true).await?;
}

Delete & migrate

async client.delete_chat(peer: impl Into<PeerRef>) → Result<(), InvocationError>
Permanently delete a channel or supergroup. Only the creator can do this. Irreversible - all messages are lost.
async client.delete_chat(chat_id: i64) → Result<(), InvocationError>
Delete a legacy basic group by its raw numeric chat ID. Only the creator can do this. For supergroups and channels use delete_chat.
async client.migrate_chat(chat_id: i64) → Result<tl::enums::Chat, InvocationError>
Upgrade a legacy basic group to a supergroup. Returns the new channel peer. The original chat_id becomes invalid after migration; update any stored references.

Edit

async client.set_profile(peer).title(: impl Into<PeerRef>, title: impl Into<String>) → Result<(), InvocationError>
Rename a chat, group, channel, or supergroup.
async client.set_profile(peer).bio(: impl Into<PeerRef>, about: impl Into<String>) → Result<(), InvocationError>
Set or update the description/about text. Works for all chat types.
async client.set_profile(peer).chat_photo(peer: impl Into<PeerRef>, photo: tl::enums::InputChatPhoto) → Result<(), InvocationError>
Change the group/channel photo. Pass InputChatPhoto::Empty to remove it.
#![allow(unused)]
fn main() {
// Set a new photo (upload first)
let uploaded = client.upload_file("photo.jpg").await?;
client.set_profile(peer).chat_photo(
    peer.clone(),
    tl::enums::InputChatPhoto::InputChatUploadedPhoto(
        tl::types::InputChatUploadedPhoto {
            video: false, video_emoji_markup: None,
            file: Some(uploaded.into_input_file()),
        }
    ),
).await?;

// Remove photo
client.set_profile(peer).chat_photo(peer.clone(), tl::enums::InputChatPhoto::Empty).await?;
}
async client.edit_chat_default_banned_rights(peer: impl Into<PeerRef>, build: impl FnOnce(BannedRightsBuilder) → BannedRightsBuilder) → Result<(), InvocationError>
Set default permissions for all members via a closure on BannedRightsBuilder. Passing true to a method restricts that action.
#![allow(unused)]
fn main() {
// Read-only group: members can only read
client.edit_chat_default_banned_rights(peer.clone(), |b| {
    b.send_messages(true)
     .send_media(true)
     .send_polls(true)
}).await?;

// Restore all defaults
client.edit_chat_default_banned_rights(peer.clone(), |b| b).await?;
}
async client.set_chat_theme(peer: impl Into<PeerRef>, emoticon: impl Into<String>) → Result<(), InvocationError>
Set the emoji colour theme for a chat. Pass a single emoji (e.g. "🌈") to apply it, or an empty string to reset to the default.
async client.set_chat_reactions(peer: impl Into<PeerRef>, reactions: tl::enums::ChatReactions) → Result<(), InvocationError>
Control which reactions members can use. See Client Methods § Chat management for the three variant forms.

Members & info

async client.invite_users(peer: impl Into<PeerRef>, user_ids: Vec<i64>) → Result<(), InvocationError>
Add one or more users to a chat. For channels all users are added in a single request; for basic groups each user is added individually.
async client.get_chat_full(peer: impl Into<PeerRef>) → Result<tl::enums::messages::ChatFull, InvocationError>
Fetch the full info object for any chat. Contains description, pinned message ID, linked channel, member count, slow mode delay, call info, and more.
async client.get_online_count(peer: impl Into<PeerRef>) → Result<i32, InvocationError>
Get the approximate number of members currently online in a group or channel.
async client.get_common_chats(user_id: i64, max_id: i64, limit: i32) → Result<Vec<tl::enums::Chat>, InvocationError>
Get chats shared between the current account and user_id. Start with max_id = 0; use the last returned chat ID for subsequent pages. Max limit is 100.

Moderation settings

async client.toggle_no_forwards(peer: impl Into<PeerRef>, enabled: bool) → Result<(), InvocationError>
Enable or disable the no-forwards restriction. When on, members cannot forward messages out of this chat.
async client.set_history_ttl(peer: impl Into<PeerRef>, period: i32) → Result<(), InvocationError>
Set the auto-delete timer for messages. period is in seconds - common values: 86400 (1 day), 604800 (1 week), 2678400 (1 month). Pass 0 to disable.
async client.toggle_forum(peer: impl Into<PeerRef>, enabled: bool) → Result<(), InvocationError>
Enable or disable forum (topics) mode on a supergroup. See Forum Topics for full topic management after enabling.

Quick-start recipe

#![allow(unused)]
fn main() {
// 1. Create a supergroup
let chat = client.create_channel("My Group", "Welcome!", false).await?;

// 2. Add members
client.invite_users(chat.clone(), vec![user_a, user_b]).await?;

// 3. Set description and lock down media for all
client.set_profile(chat.clone()).bio("Read the rules before posting.").send().await?;
client.edit_chat_default_banned_rights(chat.clone(), |b| {
    b.send_media(true).send_polls(true)
}).await?;

// 4. Enable auto-delete (1 week)
client.set_history_ttl(chat.clone(), 604_800).await?;

// 5. Generate an approval-gated invite link
let inv = client.export_invite_link(chat.clone(), None, None, true).await?;
println!("Invite: {}", match &inv {
    tl::enums::ExportedChatInvite::Invite(i) => &i.link,
    _ => "",
});
}

Transfer ownership

Transfer ownership of a basic group to another member. The calling user must be the current owner and must supply their 2FA SRP credential.

#![allow(unused)]
fn main() {
use ferogram_tl_types as tl;

// For a no-password account, use InputCheckPasswordEmpty
let password_check = tl::enums::InputCheckPasswordSrp::Empty(
    tl::types::InputCheckPasswordEmpty {}
);

client.transfer_chat_ownership(
    "@mygroup",
    new_owner_user_id,
    password_check,
).await?;
}

Use Client::compute_password_check to build the SRP object when 2FA is enabled.

Note: For channels and supergroups, ownership transfer uses channels.editCreator on the Telegram layer, which is not yet wrapped by a dedicated helper. Use the raw API for that case.


Linked channel

A broadcast channel can have a linked discussion supergroup and vice-versa. Retrieve the linked chat’s ID:

#![allow(unused)]
fn main() {
if let Some(linked_id) = client.get_linked_channel("@mychannel").await? {
    println!("Linked chat ID: {linked_id}");
}
}

Returns None when no linked chat is configured. Works for both directions - pass a channel to get its discussion group, or pass a supergroup to get its linked broadcast channel.


History, albums, and identity

async client.delete_chat_history(peer: impl Into<PeerRef>, max_id: i32, revoke: bool) → Result<(), InvocationError>
Delete the current user's message history in a chat up to max_id. When revoke is true, deletes for all members (only possible if you are an admin).
async client.get_media_group(peer: impl Into<PeerRef>, msg_id: i32) → Result<Vec<IncomingMessage>, InvocationError>
Fetch all messages that belong to the same grouped media album as msg_id.
async client.get_send_as_peers(peer: impl Into<PeerRef>) → Result<Vec<tl::enums::Peer>, InvocationError>
List the identities the current user can send messages as in peer. Returns the user's own account plus any channels they manage that are allowed as send-as identities in this chat.
async client.set_default_send_as(peer: impl Into<PeerRef>, send_as: impl Into<PeerRef>) → Result<(), InvocationError>
Set the default send-as identity for peer. send_as must be one of the peers returned by get_send_as_peers.
#![allow(unused)]
fn main() {
// Delete own history up to message 500
client.delete_chat_history("@peer", 500, false).await?;

// Fetch all messages in an album
let album = client.get_media_group("@channel", msg_id).await?;

// List send-as identities
let identities = client.get_send_as_peers("@group").await?;

// Set default send-as
client.set_default_send_as("@group", "@mychannel").await?;
}