Client Methods — Full Reference
All methods on Client. Every method is async and returns Result<T, InvocationError> unless noted.
Connection & Session
async
Client::connect(config: Config) → Result<Client, InvocationError>
Opens a TCP connection to Telegram, performs the full 3-step DH key exchange, and loads any existing session from disk. This is the entry point for all layer usage.
async
client.is_authorized() → Result<bool, InvocationError>
Returns
true if the current session has a logged-in user or bot. Use this to skip the login flow on subsequent runs.
async
client.save_session() → Result<(), InvocationError>
Writes the current session (auth key + DC info + peer cache) to disk. Call this after a successful login.
async
client.sign_out() → Result<bool, InvocationError>
Revokes the auth key on Telegram's servers and deletes the local session file. The returned
bool indicates whether session teardown was confirmed.
Authentication
async
client.request_login_code(phone: &str) → Result<LoginToken, InvocationError>
Sends a verification code to
phone via SMS or Telegram app. Returns a LoginToken that must be passed to sign_in.
async
client.sign_in(token: &LoginToken, code: &str) → Result<String, SignInError>
Submits the verification code. Returns the user's full name on success, or
SignInError::PasswordRequired(PasswordToken) if 2FA is enabled.
async
client.check_password(token: PasswordToken, password: &str) → Result<(), InvocationError>
Completes the SRP 2FA verification. The password is never transmitted — only a zero-knowledge proof.
async
client.bot_sign_in(token: &str) → Result<String, InvocationError>
Logs in using a bot token from @BotFather. Returns the bot's username.
async
client.get_me() → Result<tl::types::User, InvocationError>
Fetches the full
User object for the logged-in account. Contains id, username, first_name, last_name, phone, bot flag, verified flag, and more.Messaging
async
client.send_message(peer: &str, text: &str) → Result<(), InvocationError>
Send a plain-text message.
peer can be "me", "@username", or a numeric ID string. For rich formatting, use send_message_to_peer_ex.
async
client.send_to_self(text: &str) → Result<(), InvocationError>
Sends a message to your own Saved Messages. Shorthand for
send_message("me", text).
async
client.send_message_to_peer(peer: Peer, text: &str) → Result<(), InvocationError>
Send a plain text message to a resolved
tl::enums::Peer.
async
client.send_message_to_peer_ex(peer: Peer, msg: &InputMessage) → Result<(), InvocationError>
Full-featured send with the
InputMessage builder — supports markdown entities, reply-to, inline keyboard, scheduled date, silent flag, and more.
async
client.edit_message(peer: Peer, message_id: i32, new_text: &str) → Result<(), InvocationError>
Edit the text of a previously sent message. Only works on messages sent by the logged-in account.
async
client.delete_messages(ids: Vec<i32>, revoke: bool) → Result<(), InvocationError>
Delete messages by ID.
revoke: true deletes for everyone; false deletes only locally.
async
client.forward_messages(from: Peer, to: Peer, ids: Vec<i32>) → Result<(), InvocationError>
Forward messages from one chat to another.
async
client.get_messages(peer: Peer, limit: i32, offset_id: i32) → Result<Vec<tl::enums::Message>, InvocationError>
Fetch message history.
offset_id = 0 starts from the newest message. Returns up to limit messages in reverse chronological order.
async
client.get_messages_by_id(peer: Peer, ids: Vec<i32>) → Result<Vec<tl::enums::Message>, InvocationError>
Fetch specific messages by their IDs.
async
client.pin_message(peer: Peer, message_id: i32, silent: bool) → Result<(), InvocationError>
Pin a message.
silent: true pins without sending a notification.
async
client.unpin_message(peer: Peer, message_id: i32) → Result<(), InvocationError>
Unpin a specific message.
async
client.unpin_all_messages(peer: Peer) → Result<(), InvocationError>
Remove all pinned messages in a chat.
Search
async
client.search_messages(peer: Peer, query: &str, limit: i32) → Result<Vec<tl::enums::Message>, InvocationError>
Search for messages in a specific chat matching
query.
async
client.search_global(query: &str, limit: i32) → Result<Vec<tl::enums::Message>, InvocationError>
Search across all chats and public channels.
async
client.search_peer(query: &str) → Result<Vec<tl::enums::Peer>, InvocationError>
Search contacts, dialogs, and global results for a username or name prefix.
Dialogs & Chats
async
client.get_dialogs(limit: i32) → Result<Vec<Dialog>, InvocationError>
Returns the most recent
limit dialogs (conversations). Each Dialog has title(), peer(), unread_count(), top_message().
fn
client.iter_dialogs() → DialogIter
Returns a paginating iterator over all dialogs. Call
iter.next(&client).await to get one dialog at a time, automatically fetching more pages.
fn
client.iter_messages(peer: Peer) → MessageIter
Returns a paginating iterator over all messages in a chat from newest to oldest.
async
client.mark_as_read(peer: Peer) → Result<(), InvocationError>
Marks all messages in the chat as read.
async
client.delete_dialog(peer: Peer) → Result<(), InvocationError>
Removes the dialog from the chat list (does not delete messages from the server).
async
client.join_chat(peer: Peer) → Result<(), InvocationError>
Join a public group or channel.
async
client.accept_invite_link(link: &str) → Result<(), InvocationError>
Join via a
t.me/+hash invite link.Bot-specific
async
client.answer_callback_query(query_id: i64, text: Option<&str>, alert: bool) → Result<(), InvocationError>
Must be called in response to every
CallbackQuery. text is the notification shown to the user. alert: true shows it as a modal alert; false shows it as a brief toast.
async
client.answer_inline_query(query_id: i64, results: Vec<InputBotInlineResult>, cache_time: i32, is_personal: bool, next_offset: Option<&str>) → Result<(), InvocationError>
Respond to an
InlineQuery with a list of results. cache_time is seconds to cache results (300 = 5 min). is_personal: true disables shared caching.Reactions & Actions
async
client.send_reaction(peer: Peer, message_id: i32, reaction: &str) → Result<(), InvocationError>
Add a reaction to a message.
reaction is an emoji string like "👍". Pass an empty string to remove your reaction.
async
client.send_chat_action(peer: Peer, action: ChatAction) → Result<(), InvocationError>
Show a typing indicator or other status. Actions:
Typing, UploadPhoto, RecordVideo, UploadVideo, RecordAudio, UploadAudio, UploadDocument, GeoLocation, ChooseContact.Peer Resolution
async
client.resolve_peer(peer: &str) → Result<tl::enums::Peer, InvocationError>
Resolve a string to a
Peer. Supported formats:
"me"— your own account"@username"— any public username"123456789"— numeric user/chat/channel ID
Raw API
async
client.invoke<R: RemoteCall>(req: &R) → Result<R::Return, InvocationError>
Call any Telegram API function directly.
R is a struct from layer_tl_types::functions. See Raw API Access.Updates
fn
client.stream_updates() → UpdateStream
Returns an
UpdateStream. Call .next().await to receive the next Update. The stream never ends unless the connection is dropped.