Invite Links
Full API for creating, editing, revoking, and managing chat invite links, as well as handling join requests.
Create & export
async
client.export_invite_link(peer: impl Into<PeerRef>, expire_date: Option<i32>, usage_limit: Option<i32>, request_needed: bool) → Result<tl::enums::ExportedChatInvite, InvocationError>
Create a new invite link for a chat.
expire_date- Unix timestamp after which the link stops working. PassNonefor no expiry.usage_limit- Maximum number of times the link can be used. PassNonefor unlimited.request_needed- Iftrue, users who join via this link must be approved by an admin before entering.
#![allow(unused)]
fn main() {
// Permanent link, up to 50 uses
let inv = client.export_invite_link(peer.clone(), None, Some(50), false).await?;
// Link that expires in 24 hours, requires approval
let tomorrow = (std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH).unwrap()
.as_secs() + 86400) as i32;
let inv = client.export_invite_link(peer.clone(), Some(tomorrow), None, true).await?;
}
sync
Client::parse_invite_hash(link: &str) → Option<&str>
Extract the raw invite hash from any
t.me/+… or t.me/joinchat/… link format. Returns None if the string is not a valid invite link.
#![allow(unused)]
fn main() {
let hash = Client::parse_invite_hash("https://t.me/+AbCdEfGhIj");
// => Some("AbCdEfGhIj")
}
Revoke & edit
async
client.revoke_invite_link(peer: impl Into<PeerRef>, link: impl Into<String>) → Result<tl::enums::ExportedChatInvite, InvocationError>
Revoke an existing invite link immediately. After revocation the link stops accepting new joins. Returns the updated invite object showing the revoked state. The link is not deleted - it still appears in history and can be deleted with
delete_invite_link.
async
client.edit_invite_link(peer: impl Into<PeerRef>, link: impl Into<String>, expire_date: Option<i32>, usage_limit: Option<i32>, request_needed: bool) → Result<tl::enums::ExportedChatInvite, InvocationError>
Update an existing invite link's properties. Only non-permanent links can be edited. The same fields as
export_invite_link apply.
List & delete
async
client.get_invite_links(peer: impl Into<PeerRef>, admin_id: i64, revoked: bool, limit: i32) → Result<Vec<tl::enums::ExportedChatInvite>, InvocationError>
List invite links created by a specific admin. Pass
revoked: false for active links, true for revoked ones. Maximum limit is 100.
#![allow(unused)]
fn main() {
// All active links created by the logged-in user (user_id from get_me)
let me = client.get_me().await?;
let links = client.get_invite_links(peer.clone(), me.id, false, 100).await?;
}
async
client.delete_invite_link(peer: impl Into<PeerRef>, link: impl Into<String>) → Result<(), InvocationError>
Permanently delete a revoked invite link. The link must already be revoked before it can be deleted.
async
client.delete_revoked_invite_links(peer: impl Into<PeerRef>, admin_id: i64) → Result<(), InvocationError>
Bulk-delete all revoked links created by
admin_id in one call. Useful for cleaning up the invite history.
Join requests
When a link is created with request_needed: true, users who click it appear as pending join requests that an admin must approve or reject.
async
client.approve_join_request(peer: impl Into<PeerRef>, user_id: i64) → Result<(), InvocationError>
Approve a single pending join request. The user is added to the chat immediately.
async
client.reject_join_request(peer: impl Into<PeerRef>, user_id: i64) → Result<(), InvocationError>
Reject and dismiss a single pending join request.
async
client.approve_all_join_requests(peer: impl Into<PeerRef>, link: Option<String>) → Result<(), InvocationError>
Approve all pending join requests at once. If
link is Some(url), only requests submitted via that specific link are approved. Pass None to approve all pending requests regardless of which link they came from.
async
client.reject_all_join_requests(peer: impl Into<PeerRef>, link: Option<String>) → Result<(), InvocationError>
Reject all pending join requests at once, with the same optional link filter as
approve_all_join_requests.
Inspect link usage
async
client.get_invite_link_members(peer: impl Into<PeerRef>, link: Option<String>, requested: bool, limit: i32) → Result<tl::types::messages::ChatInviteImporters, InvocationError>
List members who joined via a specific invite link, or all pending join requesters.
link- the invite URL.Noneto query across all links.requested: false- users who already joined.requested: true- users with a pending join request still awaiting approval.
#![allow(unused)]
fn main() {
// Who is waiting for approval?
let pending = client
.get_invite_link_members(peer.clone(), None, true, 50)
.await?;
}
async
client.get_admins_with_invites(peer: impl Into<PeerRef>) → Result<tl::types::messages::ChatAdminsWithInvites, InvocationError>
Get a breakdown of each admin's invite link counts (active, revoked). Useful for auditing which admins created how many links.
Full example: approval-gated invite
#![allow(unused)]
fn main() {
// Create link that requires admin approval
let inv = client
.export_invite_link(peer.clone(), None, None, true)
.await?;
println!("Share this link: {}", match &inv {
tl::enums::ExportedChatInvite::Invite(i) => &i.link,
_ => "",
});
// Later: check who is waiting
let pending = client
.get_invite_link_members(peer.clone(), None, true, 100)
.await?;
for importer in &pending.importers {
println!("Approving user {}", importer.user_id);
client.approve_join_request(peer.clone(), importer.user_id).await?;
}
}