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
t.me/+hash or t.me/joinchat/hash invite link and join the chat.kick on yourself or delete_dialog to hide it.Create
migrate_chat to upgrade to a supergroup.
#![allow(unused)]
fn main() {
let chat = client.create_group("Dev Team", vec![user_a, user_b]).await?;
}
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
delete_chat.chat_id becomes invalid after migration; update any stored references.Edit
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?;
}
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?;
}
"🌈") to apply it, or an empty string to reset to the default.Members & info
user_id. Start with max_id = 0; use the last returned chat ID for subsequent pages. Max limit is 100.Moderation settings
period is in seconds - common values: 86400 (1 day), 604800 (1 week), 2678400 (1 month). Pass 0 to disable.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.editCreatoron 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
max_id. When revoke is true, deletes for all members (only possible if you are an admin).msg_id.peer. Returns the user's own account plus any channels they manage that are allowed as send-as identities in this chat.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?;
}