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

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

VariantControls
InputPrivacyKey::StatusTimestampLast seen / online status
InputPrivacyKey::ChatInviteWho can add you to groups
InputPrivacyKey::CallWho can call you
InputPrivacyKey::ProfilePhotoWho sees your profile photo
InputPrivacyKey::PhoneNumberWho sees your phone number
InputPrivacyKey::ForwardedMessagesWho can link forwards to your account
InputPrivacyKey::PhoneCallWho can voice-call you
InputPrivacyKey::PhoneP2PPeer-to-peer call mode
InputPrivacyKey::VoicesVoice messages
InputPrivacyKey::AboutWho 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

VariantMeaning
InputPrivacyValueAllowAllAllow everyone
InputPrivacyValueAllowContactsAllow contacts only
InputPrivacyValueAllowUsers { users }Allow specific users
InputPrivacyValueDisallowAllBlock everyone
InputPrivacyValueDisallowContactsBlock 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

FieldTypeDescription
mute_untilOption<i32>Unix timestamp to mute until. Some(i32::MAX) = forever. Some(0) = unmute.
soundOption<NotificationSound>Sound to play
show_previewsOption<bool>Show message preview in notification
silentOption<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?;
}