Privacy & Notifications
Methods for reading and writing Telegram account privacy rules and per-chat notification settings.
Privacy rules
Privacy rules control who can see your phone number, last seen, profile photo, etc.
async
client.get_privacy(key: tl::enums::InputPrivacyKey) → Result<Vec<tl::enums::PrivacyRule>, InvocationError>
Fetch the current privacy rules for a specific setting identified by
key.
Privacy keys
| Variant | Controls |
|---|---|
InputPrivacyKey::StatusTimestamp | Last seen / online status |
InputPrivacyKey::ChatInvite | Who can add you to groups |
InputPrivacyKey::Call | Who can call you |
InputPrivacyKey::ProfilePhoto | Who sees your profile photo |
InputPrivacyKey::PhoneNumber | Who sees your phone number |
InputPrivacyKey::ForwardedMessages | Who can link forwards to your account |
InputPrivacyKey::PhoneCall | Who can voice-call you |
InputPrivacyKey::PhoneP2P | Peer-to-peer call mode |
InputPrivacyKey::Voices | Voice messages |
InputPrivacyKey::About | Who sees your bio |
#![allow(unused)]
fn main() {
let rules = client.get_privacy(
tl::enums::InputPrivacyKey::StatusTimestamp
).await?;
for rule in &rules {
println!("{rule:?}");
}
}
async
client.set_privacy(key: tl::enums::InputPrivacyKey, rules: Vec<tl::enums::InputPrivacyRule>) → Result<Vec<tl::enums::PrivacyRule>, InvocationError>
Update the privacy rules for a key. Rules are evaluated in order - the first matching rule wins.
Rule variants
| Variant | Meaning |
|---|---|
InputPrivacyValueAllowAll | Allow everyone |
InputPrivacyValueAllowContacts | Allow contacts only |
InputPrivacyValueAllowUsers { users } | Allow specific users |
InputPrivacyValueDisallowAll | Block everyone |
InputPrivacyValueDisallowContacts | Block contacts |
InputPrivacyValueDisallowUsers { users } | Block specific users |
#![allow(unused)]
fn main() {
use tl::enums::{InputPrivacyKey, InputPrivacyRule};
// Last seen: contacts only
client.set_privacy(
InputPrivacyKey::StatusTimestamp,
vec![
InputPrivacyRule::InputPrivacyValueAllowContacts,
InputPrivacyRule::InputPrivacyValueDisallowAll,
],
).await?;
// Phone: nobody
client.set_privacy(
InputPrivacyKey::PhoneNumber,
vec![InputPrivacyRule::InputPrivacyValueDisallowAll],
).await?;
// Profile photo: everyone
client.set_privacy(
InputPrivacyKey::ProfilePhoto,
vec![InputPrivacyRule::InputPrivacyValueAllowAll],
).await?;
}
Notification settings
async
client.get_notify_settings(peer: impl Into<PeerRef>) → Result<tl::enums::PeerNotifySettings, InvocationError>
Get the notification settings for a specific chat.
#![allow(unused)]
fn main() {
let settings = client.get_notify_settings(peer.clone()).await?;
if let tl::enums::PeerNotifySettings::PeerNotifySettings(s) = settings {
println!("muted until: {:?}", s.mute_until);
println!("sound: {:?}", s.sound);
println!("show_previews: {:?}", s.show_previews);
}
}
async
client.update_notify_settings(peer: impl Into<PeerRef>, settings: tl::enums::InputPeerNotifySettings) → Result<(), InvocationError>
Update notification settings for a chat. Only the fields you set are changed on the server; unset
Option fields are left as-is.
InputPeerNotifySettings fields
| Field | Type | Description |
|---|---|---|
mute_until | Option<i32> | Unix timestamp to mute until. Some(i32::MAX) = forever. Some(0) = unmute. |
sound | Option<NotificationSound> | Sound to play |
show_previews | Option<bool> | Show message preview in notification |
silent | Option<bool> | Deliver silently without sound |
#![allow(unused)]
fn main() {
use tl::enums::InputPeerNotifySettings;
use tl::types::InputPeerNotifySettings as S;
// Mute a chat for 1 hour
let until = (std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH).unwrap()
.as_secs() + 3600) as i32;
client.update_notify_settings(
peer.clone(),
tl::enums::InputPeerNotifySettings::InputPeerNotifySettings(S {
show_previews: None,
silent: None,
mute_until: Some(until),
sound: None,
stories_muted: None,
stories_hide_sender: None,
stories_sound: None,
}),
).await?;
// Unmute
client.update_notify_settings(
peer.clone(),
tl::enums::InputPeerNotifySettings::InputPeerNotifySettings(S {
mute_until: Some(0),
show_previews: None, silent: None, sound: None,
stories_muted: None, stories_hide_sender: None, stories_sound: None,
}),
).await?;
}
Common privacy recipes
#![allow(unused)]
fn main() {
// "Ghost mode" - hide everything from non-contacts
use tl::enums::{InputPrivacyKey as Key, InputPrivacyRule as Rule};
let ghost = vec![Rule::InputPrivacyValueAllowContacts, Rule::InputPrivacyValueDisallowAll];
client.set_privacy(Key::StatusTimestamp, ghost.clone()).await?;
client.set_privacy(Key::ProfilePhoto, ghost.clone()).await?;
client.set_privacy(Key::PhoneNumber, vec![Rule::InputPrivacyValueDisallowAll]).await?;
client.set_privacy(Key::ChatInvite, ghost.clone()).await?;
}