Profile & Account
Methods for updating your own profile, managing active sessions, and controlling account-level settings.
Profile
async
client.set_profile(first_name: Option<String>, last_name: Option<String>, about: Option<String>) β Result<tl::enums::User, InvocationError>
Change your display name and/or bio. Pass
None for any field you want to leave unchanged. Returns the updated User object.
#![allow(unused)]
fn main() {
// Change just the bio
client.set_profile(None, None, Some("π¦ Rust developer".to_string())).await?;
// Change full name
client.set_profile(
Some("Alice".to_string()),
Some("Smith".to_string()),
None,
).await?;
}
async
client.set_profile("me").username(username: impl Into<String>) β Result<tl::enums::User, InvocationError>
Set or change your @username. Pass an empty string to remove the username. Returns the updated
User object. Telegram will return an error if the username is already taken or violates naming rules.
#![allow(unused)]
fn main() {
client.set_profile("me").username("my_new_handle").send().await?;
client.set_profile("me").username("").send().await?; // remove username
}
async
client.set_presence(true) / set_presence(false) β Result<(), InvocationError>
Manually set your online/offline status. Pass
offline: false to appear online, true to mark yourself as offline. Telegram resets online status automatically after ~5 minutes of inactivity, so call this periodically if you need a persistent "online" appearance.
Profile photo
async
client.set_profile("me").photo(file: UploadedFile) β Result<tl::enums::Photo, InvocationError>
Set or add a new profile photo. Upload the image with
upload_file(path) first.
#![allow(unused)]
fn main() {
let bytes = tokio::fs::read("avatar.jpg").await?;
let uploaded = client.upload_file("avatar.jpg").await?;
let photo = client.set_profile("me").photo(uploaded).send().await?;
}
async
client.delete_profile_photos(photo_ids: Vec<(i64, i64, Vec<u8>)>) β Result<Vec<i64>, InvocationError>
Methods for updating your own profile, managing active sessions, and controlling account-level settings.
Profile
async
client.set_profile(first_name: Option<String>, last_name: Option<String>, about: Option<String>) β Result<tl::enums::User, InvocationError>
Change your display name and/or bio. Pass
None for any field you want to leave unchanged. Returns the updated User object.
#![allow(unused)]
fn main() {
// Change just the bio
client.set_profile(None, None, Some("π¦ Rust developer".to_string())).await?;
// Change full name
client.set_profile(
Some("Alice".to_string()),
Some("Smith".to_string()),
None,
).await?;
}
async
client.set_profile("me").username(username: impl Into<String>) β Result<tl::enums::User, InvocationError>
Set or change your @username. Pass an empty string to remove the username. Returns the updated
User object. Telegram will return an error if the username is already taken or violates naming rules.
#![allow(unused)]
fn main() {
client.set_profile("me").username("my_new_handle").send().await?;
client.set_profile("me").username("").send().await?; // remove username
}
async
client.set_presence(true) / set_presence(false) β Result<(), InvocationError>
Manually set your online/offline status. Pass
offline: false to appear online, true to mark yourself as offline. Telegram resets online status automatically after ~5 minutes of inactivity.
Profile photo
async
client.get_profile_photos(peer: impl Into<PeerRef>, limit: i32) β Result<Vec<tl::enums::Photo>, InvocationError>
Fetch up to
limit profile photos for a user. Only works on user peers; passing a chat or channel returns an error.
#![allow(unused)]
fn main() {
let photos = client.get_profile_photos(peer, 10).await?;
for p in photos {
if let tl::enums::Photo::Photo(photo) = p {
println!("photo id={}", photo.id);
}
}
}
async
client.iter_profile_photos(peer: impl Into<PeerRef>, chunk_size: i32) β ProfilePhotoIter
Returns a lazy iterator over all profile photos for a user.
chunk_size controls how many are fetched per page (pass 0 for the default). Call .total_count() on the iterator to get the total before iterating.
#![allow(unused)]
fn main() {
let mut iter = client.iter_profile_photos(peer, 0).await?;
if let Some(total) = iter.total_count() {
println!("{total} photos total");
}
while let Some(photo) = iter.next(&client).await? {
// handle photo
}
}
async
client.set_profile("me").photo(file: UploadedFile) β Result<tl::enums::Photo, InvocationError>
Set or add a new profile photo. Upload the image with
upload_file(path) first. Returns the new Photo object.
#![allow(unused)]
fn main() {
let bytes = tokio::fs::read("avatar.jpg").await?;
let uploaded = client.upload_file("avatar.jpg").await?;
let photo = client.set_profile("me").photo(uploaded).send().await?;
}
async
client.delete_profile_photos(photo_ids: Vec<(i64, i64, Vec<u8>)>) β Result<Vec<i64>, InvocationError>
Delete one or more profile photos. Each tuple is
(photo_id, access_hash, file_reference) - all three come from a tl::types::Photo. Returns the IDs of successfully deleted photos.
#![allow(unused)]
fn main() {
// Get photos via iter_profile_photos, then delete
let tl::enums::Photo::Photo(p) = photo else { return; };
client.delete_profile_photos(vec![(p.id, p.access_hash, p.file_reference.clone())]).await?;
}
Sessions
async
client.get_authorizations() β Result<Vec<tl::types::Authorization>, InvocationError>
List all active login sessions for this account. Each
Authorization contains:
| Field | Type | Description |
|---|---|---|
hash | i64 | Session identifier - pass to terminate_session |
device_model | String | e.g. "iPhone 15", "Chrome" |
platform | String | e.g. "iOS", "Linux" |
app_name | String | Client app name |
date_created | i32 | Unix timestamp |
date_active | i32 | Last-seen Unix timestamp |
ip | String | IP address of the session |
country | String | Country code |
current | bool | Whether this is the current session |
#![allow(unused)]
fn main() {
let sessions = client.get_authorizations().await?;
for s in &sessions {
println!("{} - {} - active: {}", s.device_model, s.ip, s.date_active);
}
}
async
client.terminate_session(hash: i64) β Result<(), InvocationError>
Revoke a specific session by its
hash from get_authorizations. The device is immediately logged out.
#![allow(unused)]
fn main() {
let sessions = client.get_authorizations().await?;
for s in sessions {
if !s.current && s.app_name.contains("WebK") {
// terminate old web sessions
client.terminate_session(s.hash).await?;
}
}
}
Full example: profile refresh
#![allow(unused)]
fn main() {
// Update name and bio at once
client.set_profile(
Some("Bot".to_string()),
Some("Account".to_string()),
Some("Powered by ferogram π¦".to_string()),
).await?;
// Set a new avatar
let bytes = tokio::fs::read("new_avatar.png").await?;
let f = client.upload_file("avatar.png").await?;
client.set_profile("me").photo(f).send().await?;
// Go offline
client.set_presence(false).await?;
}
Emoji status
Set or clear the animated emoji shown next to the logged-in userβs name (Telegram Premium feature):
#![allow(unused)]
fn main() {
// Set an emoji status using a custom emoji document ID
// (obtain IDs from sticker sets via client.get_sticker_set)
client.set_profile("me").emoji_status(Some(5260885697911948121), None).send().await?;
// Set with an expiry (Unix timestamp)
client.set_profile("me").emoji_status(Some(5260885697911948121), Some(1_800_000_000)).send().await?;
// Clear the current emoji status
client.set_profile("me").emoji_status(None, None).send().await?;
}
document_id is the id field from a tl::types::Document belonging to a custom-emoji sticker. Pass None to remove the status. until is an optional Unix timestamp after which the status expires automatically; pass None for no expiry.