Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn connect( dc_addr: &str, api_id: i32, api_hash: &str, ) -> Result<Self, Error>

Connect fresh: DH + invokeWithLayer(initConnection(GetConfig)).

initConnection wraps GetConfig exactly like grammers’ SenderPoolRunner::connect_sender. The Config response populates our DC address table for future migrations.

Source

pub fn load_or_connect( session_path: impl AsRef<Path>, api_id: i32, api_hash: &str, ) -> Result<Self, Error>

Load saved session or connect fresh.

On a saved session, reuses the auth key — mirrors grammers connect_with_auth. On no session file, defaults to DC2 (same as Telegram’s recommended bootstrap DC).

Source

pub fn save_session(&self, path: impl AsRef<Path>) -> Result<(), Error>

Persist auth key + DC table. Call after successful sign-in.

Source

pub fn is_authorized(&mut self) -> Result<bool, Error>

Returns true if already logged in. Probes with updates.getState — same as grammers.

Source

pub fn request_login_code(&mut self, phone: &str) -> Result<LoginToken, Error>

Send login code. Handles PHONE_MIGRATE_X like grammers: disconnect, reconnect to correct DC, retry.

Source

pub fn sign_in( &mut self, token: &LoginToken, code: &str, ) -> Result<String, SignInError>

Complete sign-in with the received code.

Returns the display name on success. Returns Err(SignInError::PasswordRequired(token)) if 2FA is enabled — pass the token to [check_password].

Handles USER_MIGRATE_X exactly like grammers.

Source

pub fn check_password( &mut self, password_token: PasswordToken, password: impl AsRef<[u8]>, ) -> Result<String, Error>

Complete 2FA login with the user’s password.

password_token comes from Err(SignInError::PasswordRequired(token)). Mirrors grammers check_password.

Source

pub fn send_message(&mut self, peer: &str, text: &str) -> Result<(), Error>

Send a text message to peer. Use "me" for Saved Messages.

Source

pub fn invoke<R: RemoteCall>(&mut self, req: &R) -> Result<R::Return, Error>

Invoke any TL function and return the deserialized response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.