pub struct Client { /* private fields */ }Expand description
The main Telegram client. Cheap to clone: internally Arc-wrapped.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn bot_sign_in(&self, token: &str) -> Result<String, InvocationError>
pub async fn bot_sign_in(&self, token: &str) -> Result<String, InvocationError>
Sign in as a bot.
Sourcepub async fn request_login_code(
&self,
phone: &str,
) -> Result<LoginToken, InvocationError>
pub async fn request_login_code( &self, phone: &str, ) -> Result<LoginToken, InvocationError>
Request a login code for a user account.
Sourcepub async fn sign_in(
&self,
token: &LoginToken,
code: &str,
) -> Result<String, SignInError>
pub async fn sign_in( &self, token: &LoginToken, code: &str, ) -> Result<String, SignInError>
Complete sign-in with the code sent to the phone.
Sourcepub async fn check_password(
&self,
token: PasswordToken,
password: impl AsRef<[u8]>,
) -> Result<String, InvocationError>
pub async fn check_password( &self, token: PasswordToken, password: impl AsRef<[u8]>, ) -> Result<String, InvocationError>
Complete 2FA login.
Sourcepub async fn sign_out(&self) -> Result<bool, InvocationError>
pub async fn sign_out(&self) -> Result<bool, InvocationError>
Sign out and invalidate the current session.
Sourcepub async fn get_users_by_id(
&self,
ids: &[i64],
) -> Result<Vec<Option<User>>, InvocationError>
pub async fn get_users_by_id( &self, ids: &[i64], ) -> Result<Vec<Option<User>>, InvocationError>
Fetch user info by ID. Returns None for each ID that is not found.
Used internally by update::IncomingMessage::sender_user.
Sourcepub async fn get_user_from_message(
&self,
peer: InputPeer,
msg_id: i32,
user_id: i64,
) -> Result<Option<User>, InvocationError>
pub async fn get_user_from_message( &self, peer: InputPeer, msg_id: i32, user_id: i64, ) -> Result<Option<User>, InvocationError>
Resolve a user by message context (no access_hash required).
Returns None if Telegram returns no matching user.
Sourcepub fn my_id(&self) -> Option<i64>
pub fn my_id(&self) -> Option<i64>
The logged-in account’s numeric user ID, if already known.
This is a cheap, synchronous, no-network lookup of a value captured
automatically the first time a User object with is_self == true
was cached (sign-in, get_me(), etc.). Returns None only if neither
has happened yet in this session - call my_id_or_fetch() for a
version that falls back to a network call in that case.
Sourcepub async fn my_id_or_fetch(&self) -> Result<i64, InvocationError>
pub async fn my_id_or_fetch(&self) -> Result<i64, InvocationError>
Like my_id, but performs a one-time get_me() call
to populate the cache if it isn’t already known.
Sourcepub async fn get_me(&self) -> Result<User, InvocationError>
pub async fn get_me(&self) -> Result<User, InvocationError>
Fetch information about the logged-in user.
Sourcepub async fn export_login_token(
&self,
) -> Result<(Vec<u8>, i32), InvocationError>
pub async fn export_login_token( &self, ) -> Result<(Vec<u8>, i32), InvocationError>
Generate a QR-code login token.
Returns (token_bytes, expires_unix_ts). Encode token_bytes as a
tg://login?token=<base64url> URL and present as a QR code.
Call import_qr_token once the user scans it, then poll until you
receive Update::Raw with updateLoginToken (constructor 0x564fe691),
or call export_login_token again to check.
§Example
let (token, expires) = client.export_login_token().await?;
// base64url-encode `token` and make a QR codeSourcepub async fn check_qr_login(
&self,
token: Vec<u8>,
) -> Result<Option<String>, InvocationError>
pub async fn check_qr_login( &self, token: Vec<u8>, ) -> Result<Option<String>, InvocationError>
Check whether a QR-code token has been scanned.
Returns Some(username) if the user has scanned and confirmed the QR
code, or None if still pending.
Source§impl Client
impl Client
Sourcepub async fn open_mini_app(
&self,
peer: impl Into<PeerRef>,
app: MiniApp,
) -> Result<MiniAppSession, InvocationError>
pub async fn open_mini_app( &self, peer: impl Into<PeerRef>, app: MiniApp, ) -> Result<MiniAppSession, InvocationError>
Open a Telegram Mini App (a web app) in peer’s context and get back
a session you can use to interact with it. app picks whether you’re
opening the bot’s main app or a specific URL it registered.
Sourcepub async fn answer_callback_query(
&self,
query_id: i64,
text: Option<&str>,
alert: bool,
) -> Result<bool, InvocationError>
pub async fn answer_callback_query( &self, query_id: i64, text: Option<&str>, alert: bool, ) -> Result<bool, InvocationError>
Respond to a button tap from an inline keyboard. With alert: true,
text shows as a popup the user has to dismiss; otherwise it’s a brief
toast. You should call this for every callback query you get, even
with no text, or the button stays stuck in a loading state.
Sourcepub async fn answer_inline_query(
&self,
query_id: i64,
results: Vec<InputBotInlineResult>,
cache_time: i32,
is_personal: bool,
next_offset: Option<String>,
) -> Result<bool, InvocationError>
pub async fn answer_inline_query( &self, query_id: i64, results: Vec<InputBotInlineResult>, cache_time: i32, is_personal: bool, next_offset: Option<String>, ) -> Result<bool, InvocationError>
Send results back for an @your_bot query inline query. next_offset
lets the client ask for more results when the user scrolls, by passing
it back to you as the next query’s offset.
Sourcepub async fn start_bot(
&self,
bot_user_id: i64,
peer: impl Into<PeerRef>,
start_param: impl Into<String>,
) -> Result<(), InvocationError>
pub async fn start_bot( &self, bot_user_id: i64, peer: impl Into<PeerRef>, start_param: impl Into<String>, ) -> Result<(), InvocationError>
Send /start to a bot with a deep-link parameter, as if the user
tapped a t.me/bot?start=... link.
Sourcepub async fn set_game_score(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
user_id: i64,
score: i32,
force: bool,
edit_message: bool,
) -> Result<(), InvocationError>
pub async fn set_game_score( &self, peer: impl Into<PeerRef>, msg_id: i32, user_id: i64, score: i32, force: bool, edit_message: bool, ) -> Result<(), InvocationError>
Set a user’s score for the game in a sent game message. With
force: true, the score is set even if it’s lower than the user’s
current one; with edit_message: true, the message’s scoreboard is
updated in place.
Sourcepub async fn get_game_high_scores(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
user_id: i64,
) -> Result<Vec<HighScore>, InvocationError>
pub async fn get_game_high_scores( &self, peer: impl Into<PeerRef>, msg_id: i32, user_id: i64, ) -> Result<Vec<HighScore>, InvocationError>
Get the high score table for the game in a sent game message,
centered around user_id.
Sourcepub async fn edit_inline_message(
&self,
id: InputBotInlineMessageId,
new_text: &str,
reply_markup: Option<ReplyMarkup>,
) -> Result<bool, InvocationError>
pub async fn edit_inline_message( &self, id: InputBotInlineMessageId, new_text: &str, reply_markup: Option<ReplyMarkup>, ) -> Result<bool, InvocationError>
Edit a message that was sent via inline mode (one identified by an
InputBotInlineMessageId, not a regular message ID).
Sourcepub async fn set_bot_commands(
&self,
commands: &[(&str, &str)],
scope: Option<BotCommandScope>,
lang_code: &str,
) -> Result<bool, InvocationError>
pub async fn set_bot_commands( &self, commands: &[(&str, &str)], scope: Option<BotCommandScope>, lang_code: &str, ) -> Result<bool, InvocationError>
Set the bot’s command list - the menu users see when they tap the
/ icon. scope controls where it applies (everywhere, a specific
chat, just admins, etc); None means the default scope.
Sourcepub async fn delete_bot_commands(
&self,
scope: Option<BotCommandScope>,
lang_code: &str,
) -> Result<bool, InvocationError>
pub async fn delete_bot_commands( &self, scope: Option<BotCommandScope>, lang_code: &str, ) -> Result<bool, InvocationError>
Clear the bot’s command list for a scope, falling back to whatever the next broader scope defines.
Sourcepub async fn set_bot_info(
&self,
bot: Option<impl Into<PeerRef>>,
name: Option<&str>,
about: Option<&str>,
description: Option<&str>,
lang_code: &str,
) -> Result<bool, InvocationError>
pub async fn set_bot_info( &self, bot: Option<impl Into<PeerRef>>, name: Option<&str>, about: Option<&str>, description: Option<&str>, lang_code: &str, ) -> Result<bool, InvocationError>
Set bot profile info.
bot: pass the bot’s peer when calling from a userbot that owns the
bot. Pass None when calling from the bot session itself.
All text fields are optional; only the ones you supply are changed.
§Examples
// From a bot session: edit self.
client.set_bot_info(None::<&str>, Some("My Bot"), Some("Short about."), Some("Start page text."), "en").await?;
// From a userbot: edit an owned bot.
client.set_bot_info(Some("@MyBot"), Some("My Bot"), None, None, "en").await?;Sourcepub async fn get_bot_info(
&self,
bot: Option<impl Into<PeerRef>>,
lang_code: &str,
) -> Result<BotInfo, InvocationError>
pub async fn get_bot_info( &self, bot: Option<impl Into<PeerRef>>, lang_code: &str, ) -> Result<BotInfo, InvocationError>
Get bot profile info.
bot: pass the bot’s peer when calling from a userbot. Pass None
when calling from the bot session itself.
Source§impl Client
impl Client
Sourcepub async fn delete_chat(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn delete_chat( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Delete a chat or channel. Dispatches to channels.deleteChannel for channels/supergroups
and messages.deleteChat for legacy basic groups.
Only the creator can delete. This action is irreversible.
Sourcepub async fn leave_chat(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn leave_chat( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Leave a channel or supergroup.
For basic groups, kick yourself or use
Client::delete_dialog to just hide it.
Sourcepub async fn migrate_chat(&self, chat_id: i64) -> Result<Chat, InvocationError>
pub async fn migrate_chat(&self, chat_id: i64) -> Result<Chat, InvocationError>
Upgrade a legacy group to a supergroup (megagroup).
Returns the new channel/supergroup peer. The original chat ID becomes invalid after migration.
Sourcepub async fn get_chat_full(
&self,
peer: impl Into<PeerRef>,
) -> Result<ChatFull, InvocationError>
pub async fn get_chat_full( &self, peer: impl Into<PeerRef>, ) -> Result<ChatFull, InvocationError>
Get the full info for a chat - description, pinned message, slow-mode delay, and other fields the basic chat object doesn’t carry.
Sourcepub async fn delete_chat_history(
&self,
peer: impl Into<PeerRef>,
max_id: i32,
revoke: bool,
) -> Result<(), InvocationError>
pub async fn delete_chat_history( &self, peer: impl Into<PeerRef>, max_id: i32, revoke: bool, ) -> Result<(), InvocationError>
Delete messages up to max_id from a chat’s history on your side.
With revoke: true on a group/channel you admin, it deletes for
everyone instead of just you.
Sourcepub async fn create_group(
&self,
title: impl Into<String>,
user_ids: Vec<i64>,
) -> Result<Chat, InvocationError>
pub async fn create_group( &self, title: impl Into<String>, user_ids: Vec<i64>, ) -> Result<Chat, InvocationError>
Create a basic group chat with title and the given members. This is
the small, old-style group with a low member cap - use
Self::create_channel for a supergroup if you need more room or
admin tooling.
Sourcepub async fn create_channel(
&self,
title: impl Into<String>,
about: impl Into<String>,
broadcast: bool,
) -> Result<Chat, InvocationError>
pub async fn create_channel( &self, title: impl Into<String>, about: impl Into<String>, broadcast: bool, ) -> Result<Chat, InvocationError>
Create a channel or supergroup. broadcast: true makes a broadcast
channel (only admins post); false makes a supergroup (everyone can,
by default).
Sourcepub async fn edit_chat_default_banned_rights(
&self,
peer: impl Into<PeerRef>,
build: impl FnOnce(BannedRightsBuilder) -> BannedRightsBuilder,
) -> Result<(), InvocationError>
pub async fn edit_chat_default_banned_rights( &self, peer: impl Into<PeerRef>, build: impl FnOnce(BannedRightsBuilder) -> BannedRightsBuilder, ) -> Result<(), InvocationError>
Set the default permissions for non-admin members of a chat, using a
builder closure over crate::participants::BannedRightsBuilder.
Sourcepub async fn invite_users(
&self,
peer: impl Into<PeerRef>,
user_ids: &[i64],
) -> Result<(), InvocationError>
pub async fn invite_users( &self, peer: impl Into<PeerRef>, user_ids: &[i64], ) -> Result<(), InvocationError>
Add one or more users to a chat by user ID.
Sourcepub async fn set_history_ttl(
&self,
peer: impl Into<PeerRef>,
period: i32,
) -> Result<(), InvocationError>
pub async fn set_history_ttl( &self, peer: impl Into<PeerRef>, period: i32, ) -> Result<(), InvocationError>
Set the auto-delete timer for new messages in a chat, in seconds.
Pass 0 to turn it off.
Sourcepub async fn get_common_chats(
&self,
user_id: i64,
max_id: i64,
limit: i32,
) -> Result<Vec<Chat>, InvocationError>
pub async fn get_common_chats( &self, user_id: i64, max_id: i64, limit: i32, ) -> Result<Vec<Chat>, InvocationError>
List the group chats you have in common with a user. max_id/limit
page through results if there are a lot.
Sourcepub async fn get_chat_administrators(
&self,
peer: impl Into<PeerRef>,
) -> Result<Vec<Participant>, InvocationError>
pub async fn get_chat_administrators( &self, peer: impl Into<PeerRef>, ) -> Result<Vec<Participant>, InvocationError>
List the admins of a chat.
Sourcepub async fn transfer_chat_ownership(
&self,
peer: impl Into<PeerRef>,
new_owner_id: i64,
password: InputCheckPasswordSrp,
) -> Result<(), InvocationError>
pub async fn transfer_chat_ownership( &self, peer: impl Into<PeerRef>, new_owner_id: i64, password: InputCheckPasswordSrp, ) -> Result<(), InvocationError>
Transfer ownership of a channel or supergroup to another user. You’ll
need their confirmation on Telegram’s end too - this just starts the
transfer. password is your 2FA password, required by Telegram for
this regardless of whether you’d normally need it to log in.
Sourcepub async fn get_linked_channel(
&self,
peer: impl Into<PeerRef>,
) -> Result<Option<i64>, InvocationError>
pub async fn get_linked_channel( &self, peer: impl Into<PeerRef>, ) -> Result<Option<i64>, InvocationError>
Get the ID of the discussion group linked to a broadcast channel, or
None if it doesn’t have one.
Sourcepub async fn get_admin_log(
&self,
peer: impl Into<PeerRef>,
query: impl Into<String>,
limit: i32,
max_id: i64,
min_id: i64,
) -> Result<Vec<ChannelAdminLogEvent>, InvocationError>
pub async fn get_admin_log( &self, peer: impl Into<PeerRef>, query: impl Into<String>, limit: i32, max_id: i64, min_id: i64, ) -> Result<Vec<ChannelAdminLogEvent>, InvocationError>
Read the admin action log for a supergroup or channel: who banned
who, what got deleted, title changes, and so on. You need to be an
admin of peer to call this. query filters by text, and
max_id/min_id page through results - pass 0 for both to start
from the most recent event.
Sourcepub async fn toggle_no_forwards(
&self,
peer: impl Into<PeerRef>,
enabled: bool,
) -> Result<(), InvocationError>
pub async fn toggle_no_forwards( &self, peer: impl Into<PeerRef>, enabled: bool, ) -> Result<(), InvocationError>
Turn content protection on or off for a chat - when enabled, members can’t forward or save media from it.
Sourcepub async fn set_chat_theme(
&self,
peer: impl Into<PeerRef>,
emoticon: impl Into<String>,
) -> Result<(), InvocationError>
pub async fn set_chat_theme( &self, peer: impl Into<PeerRef>, emoticon: impl Into<String>, ) -> Result<(), InvocationError>
Set the emoji theme for a chat. emoticon must be one of the emoji
Telegram’s official clients offer in the chat theme picker, not
arbitrary text.
Sourcepub async fn set_chat_reactions(
&self,
peer: impl Into<PeerRef>,
reactions: ChatReactions,
) -> Result<(), InvocationError>
pub async fn set_chat_reactions( &self, peer: impl Into<PeerRef>, reactions: ChatReactions, ) -> Result<(), InvocationError>
Set which reactions are allowed in a chat - all of them, none, or a specific list.
Sourcepub async fn get_send_as_peers(
&self,
peer: impl Into<PeerRef>,
) -> Result<Vec<Peer>, InvocationError>
pub async fn get_send_as_peers( &self, peer: impl Into<PeerRef>, ) -> Result<Vec<Peer>, InvocationError>
List the identities you can post as in a chat - your own account, or any channel you admin that’s linked to it.
Sourcepub async fn set_default_send_as(
&self,
peer: impl Into<PeerRef>,
send_as_peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn set_default_send_as( &self, peer: impl Into<PeerRef>, send_as_peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Set which identity you post as in a chat by default, from the options
Self::get_send_as_peers returns.
Source§impl Client
impl Client
Sourcepub async fn get_dialogs(
&self,
limit: i32,
) -> Result<Vec<Dialog>, InvocationError>
pub async fn get_dialogs( &self, limit: i32, ) -> Result<Vec<Dialog>, InvocationError>
Fetch up to limit dialogs, most recent first. Populates entity/message.
Sourcepub async fn delete_dialog(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn delete_dialog( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Remove a dialog from your chat list, clearing its history on your side. For a group or channel this also makes you leave it.
Sourcepub async fn mark_read(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn mark_read( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Mark all messages in a chat as read.
Sourcepub async fn clear_mentions(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn clear_mentions( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Clear unread mention markers.
Sourcepub async fn join_chat(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn join_chat( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Join a public chat or channel by username/peer.
Sourcepub fn parse_invite_hash(link: &str) -> Option<&str>
pub fn parse_invite_hash(link: &str) -> Option<&str>
Extract hash from https://t.me/+HASH or https://t.me/joinchat/HASH.
Sourcepub fn iter_dialogs(&self) -> DialogIter
pub fn iter_dialogs(&self) -> DialogIter
Returns a DialogIter that can be advanced with DialogIter::next.
Lets you page through all dialogs without loading them all at once.
§Example
let mut iter = client.iter_dialogs();
while let Some(dialog) = iter.next(&client).await? {
println!("{}", dialog.title());
}Sourcepub fn iter_messages(&self, peer: impl Into<PeerRef>) -> MessageIter
pub fn iter_messages(&self, peer: impl Into<PeerRef>) -> MessageIter
Fetch messages from a peer, page by page.
Returns a MessageIter that can be advanced with MessageIter::next.
§Example
let mut iter = client.iter_messages(peer);
while let Some(msg) = iter.next(&client).await? {
println!("{:?}", msg.text());
}Sourcepub async fn sync_drafts(&self) -> Result<(), InvocationError>
pub async fn sync_drafts(&self) -> Result<(), InvocationError>
Fetch all saved drafts across all chats.
The server responds with an Updates containing updateDraftMessage
entries; this method triggers that push and returns immediately.
Sourcepub async fn clear_all_drafts(&self) -> Result<(), InvocationError>
pub async fn clear_all_drafts(&self) -> Result<(), InvocationError>
Delete all saved drafts across all chats.
Sourcepub async fn pin_dialog(
&self,
peer: impl Into<PeerRef>,
pin: bool,
) -> Result<(), InvocationError>
pub async fn pin_dialog( &self, peer: impl Into<PeerRef>, pin: bool, ) -> Result<(), InvocationError>
Pin or unpin a dialog. pin: true pins, pin: false unpins.
Sourcepub async fn archive(
&self,
peer: impl Into<PeerRef>,
archive: bool,
) -> Result<(), InvocationError>
pub async fn archive( &self, peer: impl Into<PeerRef>, archive: bool, ) -> Result<(), InvocationError>
Archive or unarchive a dialog. archive: true moves to folder 1 (archive), false moves back to folder 0.
Sourcepub async fn get_pinned_dialogs(
&self,
folder_id: i32,
) -> Result<Vec<Dialog>, InvocationError>
pub async fn get_pinned_dialogs( &self, folder_id: i32, ) -> Result<Vec<Dialog>, InvocationError>
List the pinned dialogs in a folder. folder_id is 0 for the main
list, 1 for the Archive folder.
Sourcepub async fn mark_dialog_unread(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn mark_dialog_unread( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Mark a dialog as unread, the way “Mark as unread” in the app does - independent of whether it actually has unread messages.
Source§impl Client
impl Client
Sourcepub async fn upload_sequential(
&self,
path: impl AsRef<Path>,
handle: Option<&TransferHandle>,
) -> Result<UploadedFile, InvocationError>
pub async fn upload_sequential( &self, path: impl AsRef<Path>, handle: Option<&TransferHandle>, ) -> Result<UploadedFile, InvocationError>
Upload a file from disk one chunk at a time, without ever loading the full file into memory.
Reads and sends each part sequentially with no concurrency. RAM usage stays flat at
roughly one chunk size regardless of how large the file is. Good for constrained
environments or when you want predictable memory, but slower than upload_file
on a fast connection.
MIME type is sniffed from the first bytes of the file so you do not need to specify it manually.
Pass a TransferHandle if you want to pause, resume, or cancel mid-transfer.
Pass None to skip progress tracking entirely.
§Example
use ferogram::{Client, TransferHandle};
let handle = TransferHandle::new();
let uploaded = client.upload_sequential("big_video.mp4", Some(&handle)).await?;
// Then attach to a message:
// client.send_message(chat, InputMessage::text("").document(uploaded)).await?;Sourcepub async fn download(
&self,
media: &MessageMedia,
dest: impl AsyncWrite + Unpin,
handle: Option<&TransferHandle>,
) -> Result<u64, InvocationError>
pub async fn download( &self, media: &MessageMedia, dest: impl AsyncWrite + Unpin, handle: Option<&TransferHandle>, ) -> Result<u64, InvocationError>
Download message media to any writable sink: a Vec<u8>, a file handle, a socket, etc.
Streams data directly to dest without buffering the entire file in memory first.
Returns the total number of bytes written.
If the media is on a different DC than the current connection, ferogram reconnects transparently. You do not need to handle DC switching yourself.
Pass a TransferHandle to track progress, pause, or cancel. Pass None to
skip progress tracking.
§Example
// Download to an in-memory buffer
let mut buf = Vec::new();
client.download(msg.media().unwrap(), &mut buf, None).await.unwrap();
// Stream directly to a file on disk
let mut file = tokio::fs::File::create("photo.jpg").await.unwrap();
client.download(msg.media().unwrap(), &mut file, None).await.unwrap();Sourcepub fn download_file<'a>(
&'a self,
media: &'a MessageMedia,
path: impl AsRef<Path>,
) -> DownloadFile<'a>
pub fn download_file<'a>( &'a self, media: &'a MessageMedia, path: impl AsRef<Path>, ) -> DownloadFile<'a>
Download message media and save it directly to a file at path.
Creates the file if it does not exist, or truncates it if it does. Data is streamed to disk without loading everything into memory first.
For large files (over 10 MB) this uses concurrent workers automatically, which is significantly faster than the sequential path. You do not need to configure anything; ferogram picks the worker count based on file size.
Returns the number of bytes written.
By default no progress tracking happens. Chain .handle(&handle) before
.await if you want to track progress, pause, or cancel the transfer:
let handle = TransferHandle::new();
client.download_file(msg.media().unwrap(), "downloaded.mp4")
.handle(&handle)
.await?;§Example
client.download_file(msg.media().unwrap(), "downloaded.mp4").await?;Sourcepub fn iter_download(&self, media: &MessageMedia) -> Option<DownloadIter>
pub fn iter_download(&self, media: &MessageMedia) -> Option<DownloadIter>
Return a lazy chunk iterator for media.
Useful when you want to process file bytes as they arrive instead of waiting
for the full download to complete. Each call to DownloadIter::next fetches
the next chunk from Telegram and returns it as a bytes::Bytes slice.
Returns None if the media does not have a downloadable location (for example,
a contact card or a venue).
§Example
if let Some(mut iter) = client.iter_download(msg.media().unwrap()) {
while let Some(chunk) = iter.next().await? {
// process chunk bytes
}
}Sourcepub fn upload<'a, R>(&'a self, source: R, name: &str) -> Upload<'a, R>
pub fn upload<'a, R>(&'a self, source: R, name: &str) -> Upload<'a, R>
Upload from any tokio::io::AsyncRead source: a file handle, a network stream,
a cursor over bytes in memory, etc.
Reads the entire source into memory first, then uploads using the optimal part size. If the data is larger than 10 MB, concurrent workers are used automatically.
If you already have a path on disk, prefer upload_file instead. It stats the
file before opening it and avoids the in-memory buffer for large files.
By default no progress tracking happens. Chain .handle(&handle) before
.await if you want to track progress, pause, or cancel the transfer:
let handle = TransferHandle::new();
let bytes = b"hello world".to_vec();
let uploaded = client.upload(std::io::Cursor::new(bytes), "note.txt")
.handle(&handle)
.await?;§Example
use ferogram::Client;
let bytes = b"hello world".to_vec();
let uploaded = client.upload(std::io::Cursor::new(bytes), "note.txt").await?;Sourcepub fn upload_file<'a>(&'a self, path: impl AsRef<Path>) -> UploadFile<'a>
pub fn upload_file<'a>(&'a self, path: impl AsRef<Path>) -> UploadFile<'a>
Upload a file from disk by path. This is the standard upload method for most use cases.
Stats the file first so ferogram can pick the right part size without reading the entire file upfront. For large files (over 10 MB) it streams from disk with concurrent workers, keeping RAM usage low even for multi-gigabyte files.
For strict sequential uploads with a fixed memory ceiling, use upload_sequential.
MIME type is detected automatically from the file name and content.
By default no progress tracking happens. Chain .handle(&handle) before
.await if you want to track progress, pause, or cancel the transfer:
let handle = TransferHandle::new();
let uploaded = client.upload_file("photo.jpg")
.handle(&handle)
.await?;§Example
use ferogram::Client;
let uploaded = client.upload_file("photo.jpg").await?;
// Then send it as a photo:
// client.send_message(chat, InputMessage::text("").photo(uploaded)).await?;Sourcepub async fn get_media_group(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn get_media_group( &self, peer: impl Into<PeerRef>, msg_id: i32, ) -> Result<Vec<IncomingMessage>, InvocationError>
Get every message in the same media group (album) as msg_id, given
any one message from that group.
Source§impl Client
impl Client
Sourcepub async fn get_forum_topics(
&self,
peer: impl Into<PeerRef>,
query: Option<String>,
limit: i32,
offset_date: i32,
offset_id: i32,
offset_topic: i32,
) -> Result<Vec<ForumTopic>, InvocationError>
pub async fn get_forum_topics( &self, peer: impl Into<PeerRef>, query: Option<String>, limit: i32, offset_date: i32, offset_id: i32, offset_topic: i32, ) -> Result<Vec<ForumTopic>, InvocationError>
List a forum group’s topics, optionally filtered by query. Page
through results with offset_date/offset_id/offset_topic from
the last topic you saw - all 0 to start from the most recent.
Sourcepub async fn get_forum_topics_by_id(
&self,
peer: impl Into<PeerRef>,
topic_ids: Vec<i32>,
) -> Result<Vec<ForumTopic>, InvocationError>
pub async fn get_forum_topics_by_id( &self, peer: impl Into<PeerRef>, topic_ids: Vec<i32>, ) -> Result<Vec<ForumTopic>, InvocationError>
Look up specific topics in a forum group by their topic IDs.
Sourcepub async fn create_forum_topic(
&self,
peer: impl Into<PeerRef>,
title: impl Into<String>,
icon_color: Option<i32>,
icon_emoji_id: Option<i64>,
) -> Result<(), InvocationError>
pub async fn create_forum_topic( &self, peer: impl Into<PeerRef>, title: impl Into<String>, icon_color: Option<i32>, icon_emoji_id: Option<i64>, ) -> Result<(), InvocationError>
Create a new topic in a forum group. icon_color/icon_emoji_id are
both optional - leave them None for Telegram’s default icon.
Sourcepub async fn edit_forum_topic(
&self,
peer: impl Into<PeerRef>,
topic_id: i32,
title: Option<String>,
icon_emoji_id: Option<i64>,
closed: Option<bool>,
hidden: Option<bool>,
) -> Result<(), InvocationError>
pub async fn edit_forum_topic( &self, peer: impl Into<PeerRef>, topic_id: i32, title: Option<String>, icon_emoji_id: Option<i64>, closed: Option<bool>, hidden: Option<bool>, ) -> Result<(), InvocationError>
Edit a topic’s title, icon, or open/closed and hidden state. Pass
None for any field you don’t want to change.
Sourcepub async fn delete_forum_topic_history(
&self,
peer: impl Into<PeerRef>,
top_msg_id: i32,
) -> Result<(), InvocationError>
pub async fn delete_forum_topic_history( &self, peer: impl Into<PeerRef>, top_msg_id: i32, ) -> Result<(), InvocationError>
Delete every message in a topic. Telegram only deletes a batch at a time, so this keeps calling through until nothing’s left.
Sourcepub async fn toggle_forum(
&self,
peer: impl Into<PeerRef>,
enabled: bool,
) -> Result<(), InvocationError>
pub async fn toggle_forum( &self, peer: impl Into<PeerRef>, enabled: bool, ) -> Result<(), InvocationError>
Turn Topics mode on or off for a supergroup.
Source§impl Client
impl Client
Sourcepub async fn export_invite_link(
&self,
peer: impl Into<PeerRef>,
expire_date: Option<i32>,
usage_limit: Option<i32>,
request_needed: bool,
title: Option<String>,
) -> Result<ExportedChatInvite, InvocationError>
pub async fn export_invite_link( &self, peer: impl Into<PeerRef>, expire_date: Option<i32>, usage_limit: Option<i32>, request_needed: bool, title: Option<String>, ) -> Result<ExportedChatInvite, InvocationError>
Create a new invite link for a chat. expire_date/usage_limit cap
when it stops working; request_needed: true makes joins go through
admin approval instead of being instant.
Sourcepub async fn revoke_invite_link(
&self,
peer: impl Into<PeerRef>,
link: impl Into<String>,
) -> Result<ExportedChatInvite, InvocationError>
pub async fn revoke_invite_link( &self, peer: impl Into<PeerRef>, link: impl Into<String>, ) -> Result<ExportedChatInvite, InvocationError>
Revoke an invite link so it stops working.
Sourcepub async fn edit_invite_link(
&self,
peer: impl Into<PeerRef>,
link: impl Into<String>,
expire_date: Option<i32>,
usage_limit: Option<i32>,
request_needed: Option<bool>,
title: Option<String>,
) -> Result<ExportedChatInvite, InvocationError>
pub async fn edit_invite_link( &self, peer: impl Into<PeerRef>, link: impl Into<String>, expire_date: Option<i32>, usage_limit: Option<i32>, request_needed: Option<bool>, title: Option<String>, ) -> Result<ExportedChatInvite, InvocationError>
Change an existing invite link’s expiry, usage limit, approval
requirement, or title. Fields left None are unchanged.
Sourcepub async fn get_invite_links(
&self,
peer: impl Into<PeerRef>,
admin_id: i64,
revoked: bool,
limit: i32,
offset_date: Option<i32>,
offset_link: Option<String>,
) -> Result<Vec<ExportedChatInvite>, InvocationError>
pub async fn get_invite_links( &self, peer: impl Into<PeerRef>, admin_id: i64, revoked: bool, limit: i32, offset_date: Option<i32>, offset_link: Option<String>, ) -> Result<Vec<ExportedChatInvite>, InvocationError>
List invite links for a chat created by a specific admin. Set
revoked: true to see revoked links instead of active ones;
offset_date/offset_link page through results.
Sourcepub async fn delete_invite_link(
&self,
peer: impl Into<PeerRef>,
link: impl Into<String>,
) -> Result<(), InvocationError>
pub async fn delete_invite_link( &self, peer: impl Into<PeerRef>, link: impl Into<String>, ) -> Result<(), InvocationError>
Permanently delete a revoked invite link. Active links need
Self::revoke_invite_link first.
Sourcepub async fn delete_revoked_invite_links(
&self,
peer: impl Into<PeerRef>,
admin_id: i64,
) -> Result<(), InvocationError>
pub async fn delete_revoked_invite_links( &self, peer: impl Into<PeerRef>, admin_id: i64, ) -> Result<(), InvocationError>
Delete every revoked invite link a specific admin created for a chat, in one go.
Sourcepub async fn join_request(
&self,
peer: impl Into<PeerRef>,
user_id: i64,
approve: bool,
) -> Result<(), InvocationError>
pub async fn join_request( &self, peer: impl Into<PeerRef>, user_id: i64, approve: bool, ) -> Result<(), InvocationError>
Approve or decline a single pending join request.
Sourcepub async fn all_join_requests(
&self,
peer: impl Into<PeerRef>,
approve: bool,
link: Option<String>,
) -> Result<(), InvocationError>
pub async fn all_join_requests( &self, peer: impl Into<PeerRef>, approve: bool, link: Option<String>, ) -> Result<(), InvocationError>
Approve or decline every pending join request for a chat at once.
Pass link to only act on requests that came through that specific
invite link.
Sourcepub async fn get_invite_link_members(
&self,
peer: impl Into<PeerRef>,
link: Option<String>,
requested: bool,
limit: i32,
offset_date: i32,
offset_user_id: i64,
) -> Result<Vec<ChatInviteImporter>, InvocationError>
pub async fn get_invite_link_members( &self, peer: impl Into<PeerRef>, link: Option<String>, requested: bool, limit: i32, offset_date: i32, offset_user_id: i64, ) -> Result<Vec<ChatInviteImporter>, InvocationError>
List the people who joined (or requested to join) through a chat’s
invite links. Pass link to filter to one specific link, or None
for all of them. Set requested: true to list pending join requests
instead of people who already joined.
Sourcepub async fn get_admins_with_invites(
&self,
peer: impl Into<PeerRef>,
) -> Result<ChatAdminsWithInvites, InvocationError>
pub async fn get_admins_with_invites( &self, peer: impl Into<PeerRef>, ) -> Result<ChatAdminsWithInvites, InvocationError>
List the admins who have invite links for a chat, with how many people joined through each admin’s links.
Source§impl Client
impl Client
Sourcepub fn search(&self, peer: impl Into<PeerRef>, query: &str) -> SearchBuilder
pub fn search(&self, peer: impl Into<PeerRef>, query: &str) -> SearchBuilder
Fluent search builder for in-chat message search.
Sourcepub fn search_global(&self, query: &str) -> GlobalSearchBuilder
pub fn search_global(&self, query: &str) -> GlobalSearchBuilder
Fluent builder for global cross-chat search.
Sourcepub async fn send_message(
&self,
peer: impl Into<PeerRef>,
msg: impl Into<InputMessage>,
) -> Result<IncomingMessage, InvocationError>
pub async fn send_message( &self, peer: impl Into<PeerRef>, msg: impl Into<InputMessage>, ) -> Result<IncomingMessage, InvocationError>
Send a message to a peer.
If msg carries attached media (set via InputMessage::copy_media),
this dispatches through messages.SendMedia instead of messages.SendMessage,
since the latter has no media field and would silently drop it.
Sourcepub async fn send_to_self(
&self,
msg: impl Into<InputMessage>,
) -> Result<IncomingMessage, InvocationError>
pub async fn send_to_self( &self, msg: impl Into<InputMessage>, ) -> Result<IncomingMessage, InvocationError>
Send a message to your own Saved Messages. A quick way to test that a connection works, or to leave yourself a note.
Sourcepub async fn edit_message(
&self,
peer: impl Into<PeerRef>,
message_id: i32,
new_text: impl Into<InputMessage>,
) -> Result<(), InvocationError>
pub async fn edit_message( &self, peer: impl Into<PeerRef>, message_id: i32, new_text: impl Into<InputMessage>, ) -> Result<(), InvocationError>
Edit the text of an existing message.
Sourcepub async fn forward_messages(
&self,
destination: impl Into<PeerRef>,
message_ids: &[i32],
source: impl Into<PeerRef>,
opts: ForwardOptions,
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn forward_messages( &self, destination: impl Into<PeerRef>, message_ids: &[i32], source: impl Into<PeerRef>, opts: ForwardOptions, ) -> Result<Vec<IncomingMessage>, InvocationError>
Forward one or more messages from source to destination. Forwards
keep the “Forwarded from” attribution by default; set opts to
strip it or to reply to an existing message in the destination.
Sourcepub async fn delete_messages(
&self,
message_ids: &[i32],
revoke: bool,
) -> Result<(), InvocationError>
pub async fn delete_messages( &self, message_ids: &[i32], revoke: bool, ) -> Result<(), InvocationError>
Delete messages by ID from a regular chat or DM. Channel posts need
channel-aware deletion instead, which isn’t wired up on this path.
With revoke: true, deletes for the other side too, not just you.
Sourcepub async fn get_messages(
&self,
peer: impl Into<PeerRef>,
ids: &[i32],
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn get_messages( &self, peer: impl Into<PeerRef>, ids: &[i32], ) -> Result<Vec<IncomingMessage>, InvocationError>
Fetch a single message by ID.
Sourcepub async fn get_pinned_message(
&self,
peer: impl Into<PeerRef>,
) -> Result<Option<IncomingMessage>, InvocationError>
pub async fn get_pinned_message( &self, peer: impl Into<PeerRef>, ) -> Result<Option<IncomingMessage>, InvocationError>
Get the currently pinned message in a chat, or None if nothing’s
pinned. If a chat has multiple pins, this returns only the latest one.
Sourcepub async fn pin_message(
&self,
peer: impl Into<PeerRef>,
id: i32,
pin: bool,
) -> Result<(), InvocationError>
pub async fn pin_message( &self, peer: impl Into<PeerRef>, id: i32, pin: bool, ) -> Result<(), InvocationError>
Pin or unpin a message. pin: true pins, pin: false unpins.
Sourcepub async fn unpin_all_messages(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn unpin_all_messages( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Unpin every pinned message in a chat at once.
Sourcepub async fn get_scheduled_messages(
&self,
peer: impl Into<PeerRef>,
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn get_scheduled_messages( &self, peer: impl Into<PeerRef>, ) -> Result<Vec<IncomingMessage>, InvocationError>
List a chat’s scheduled messages - the ones queued to send later, not sent yet.
Sourcepub async fn delete_scheduled_messages(
&self,
peer: impl Into<PeerRef>,
ids: &[i32],
) -> Result<(), InvocationError>
pub async fn delete_scheduled_messages( &self, peer: impl Into<PeerRef>, ids: &[i32], ) -> Result<(), InvocationError>
Cancel scheduled messages before they send.
Sourcepub async fn get_message_history(
&self,
peer: impl Into<PeerRef>,
limit: i32,
offset_id: i32,
add_offset: i32,
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn get_message_history( &self, peer: impl Into<PeerRef>, limit: i32, offset_id: i32, add_offset: i32, ) -> Result<Vec<IncomingMessage>, InvocationError>
Fetch message history for a peer, newest first.
recent message). add_offset additionally skips this many messages
past that anchor, which is what makes simple limit-based pagination
possible without having to track the exact last-seen message ID
yourself: e.g. get_message_history(peer, 20, 0, 0) for the first
page, then get_message_history(peer, 20, 0, 20) for the second,
add_offset: 40 for the third, and so on. The server still has to
walk past the skipped messages internally, so this does not scale
well to very deep pagination - prefer Client::iter_messages for
walking large histories.
Sourcepub async fn send_chat_action(
&self,
peer: impl Into<PeerRef>,
action: SendMessageAction,
) -> Result<(), InvocationError>
pub async fn send_chat_action( &self, peer: impl Into<PeerRef>, action: SendMessageAction, ) -> Result<(), InvocationError>
Show a chat action like “typing…” in a chat. Telegram clears it automatically after a few seconds, so call this again if the action is still ongoing.
Sourcepub async fn send_dice(
&self,
peer: impl Into<PeerRef>,
emoticon: impl Into<String>,
) -> Result<IncomingMessage, InvocationError>
pub async fn send_dice( &self, peer: impl Into<PeerRef>, emoticon: impl Into<String>, ) -> Result<IncomingMessage, InvocationError>
Send a dice/dart/basketball/etc animated emoji and return the sent message.
The rolled value is in the returned message’s media:
let msg = client.send_dice(123456789, "🎲").await?;
if let Some(tl::enums::MessageMedia::Dice(d)) = msg.media() {
println!("rolled {}", d.value);
}Sourcepub async fn save_draft(
&self,
peer: impl Into<PeerRef>,
text: impl Into<String>,
) -> Result<(), InvocationError>
pub async fn save_draft( &self, peer: impl Into<PeerRef>, text: impl Into<String>, ) -> Result<(), InvocationError>
Save text as the draft for a chat, the way an unsent typed message shows up when you reopen it.
Sourcepub async fn send_scheduled_now(
&self,
peer: impl Into<PeerRef>,
ids: &[i32],
) -> Result<(), InvocationError>
pub async fn send_scheduled_now( &self, peer: impl Into<PeerRef>, ids: &[i32], ) -> Result<(), InvocationError>
Send scheduled messages immediately instead of waiting for their scheduled time.
Sourcepub async fn get_message_read_participants(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
) -> Result<Vec<ReadParticipantDate>, InvocationError>
pub async fn get_message_read_participants( &self, peer: impl Into<PeerRef>, msg_id: i32, ) -> Result<Vec<ReadParticipantDate>, InvocationError>
List who has read a message and when, in a small group. Telegram doesn’t track this for everything - large chats or old enough messages just come back empty.
Sourcepub async fn get_replies(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
limit: i32,
offset_id: i32,
add_offset: i32,
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn get_replies( &self, peer: impl Into<PeerRef>, msg_id: i32, limit: i32, offset_id: i32, add_offset: i32, ) -> Result<Vec<IncomingMessage>, InvocationError>
Fetch replies in a discussion thread. Same add_offset pagination
trick as Client::get_message_history: skip this many messages
past offset_id (which can stay 0) to jump straight to a given page.
Sourcepub async fn get_discussion_message(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
) -> Result<DiscussionMessage, InvocationError>
pub async fn get_discussion_message( &self, peer: impl Into<PeerRef>, msg_id: i32, ) -> Result<DiscussionMessage, InvocationError>
Get the discussion-group message linked to a channel post, for channels that have comments enabled.
Sourcepub async fn read_discussion(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
read_max_id: i32,
) -> Result<(), InvocationError>
pub async fn read_discussion( &self, peer: impl Into<PeerRef>, msg_id: i32, read_max_id: i32, ) -> Result<(), InvocationError>
Mark a discussion thread as read up to read_max_id.
Sourcepub async fn get_web_page_preview(
&self,
text: impl Into<String>,
) -> Result<MessageMedia, InvocationError>
pub async fn get_web_page_preview( &self, text: impl Into<String>, ) -> Result<MessageMedia, InvocationError>
Generate a link preview for text without sending it anywhere -
handy for showing a preview before the user actually sends.
Sourcepub async fn translate_messages(
&self,
peer: impl Into<PeerRef>,
msg_ids: Vec<i32>,
to_lang: impl Into<String>,
) -> Result<Vec<TextWithEntities>, InvocationError>
pub async fn translate_messages( &self, peer: impl Into<PeerRef>, msg_ids: Vec<i32>, to_lang: impl Into<String>, ) -> Result<Vec<TextWithEntities>, InvocationError>
Translate one or more existing messages to to_lang (an ISO language
code like "en").
Sourcepub async fn transcribe_audio(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
) -> Result<TranscribedAudio, InvocationError>
pub async fn transcribe_audio( &self, peer: impl Into<PeerRef>, msg_id: i32, ) -> Result<TranscribedAudio, InvocationError>
Transcribe a voice message to text.
Sourcepub async fn toggle_peer_translations(
&self,
peer: impl Into<PeerRef>,
disabled: bool,
) -> Result<(), InvocationError>
pub async fn toggle_peer_translations( &self, peer: impl Into<PeerRef>, disabled: bool, ) -> Result<(), InvocationError>
Turn the “Translate” button on or off for a chat.
Sourcepub async fn export_message_link(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
kind: LinkKind,
) -> Result<String, InvocationError>
pub async fn export_message_link( &self, peer: impl Into<PeerRef>, msg_id: i32, kind: LinkKind, ) -> Result<String, InvocationError>
Get a t.me link to a specific message. kind picks whether it
points at the single message, its whole media group, or its comment
thread.
Source§impl Client
impl Client
Sourcepub async fn answer_precheckout_query(
&self,
query_id: i64,
ok: bool,
error_message: Option<String>,
) -> Result<(), InvocationError>
pub async fn answer_precheckout_query( &self, query_id: i64, ok: bool, error_message: Option<String>, ) -> Result<(), InvocationError>
Approve or decline a checkout right before payment is charged.
Set ok: false with an error_message to tell the user why it
can’t go through (e.g. out of stock).
Sourcepub async fn answer_shipping_query(
&self,
query_id: i64,
error: Option<String>,
shipping_options: Option<Vec<ShippingOption>>,
) -> Result<(), InvocationError>
pub async fn answer_shipping_query( &self, query_id: i64, error: Option<String>, shipping_options: Option<Vec<ShippingOption>>, ) -> Result<(), InvocationError>
Respond to a shipping query with available shipping options, or an
error if you can’t ship to the address the user gave.
Sourcepub async fn send_invoice(
&self,
peer: impl Into<PeerRef>,
title: impl Into<String>,
description: impl Into<String>,
payload: impl Into<String>,
options: InvoiceOptions,
) -> Result<IncomingMessage, InvocationError>
pub async fn send_invoice( &self, peer: impl Into<PeerRef>, title: impl Into<String>, description: impl Into<String>, payload: impl Into<String>, options: InvoiceOptions, ) -> Result<IncomingMessage, InvocationError>
Send a payment invoice message. payload is your own opaque string
for tracking the order - it isn’t shown to the user.
Source§impl Client
impl Client
Sourcepub async fn send_poll(
&self,
peer: impl Into<PeerRef>,
poll: PollBuilder,
) -> Result<(), InvocationError>
pub async fn send_poll( &self, peer: impl Into<PeerRef>, poll: PollBuilder, ) -> Result<(), InvocationError>
Send a poll, built with crate::poll::PollBuilder.
Sourcepub async fn send_vote(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
options: Vec<Vec<u8>>,
) -> Result<(), InvocationError>
pub async fn send_vote( &self, peer: impl Into<PeerRef>, msg_id: i32, options: Vec<Vec<u8>>, ) -> Result<(), InvocationError>
Vote on a poll. options are the option byte identifiers from the
poll’s own answer list, not their text or index - pass more than one
only if the poll allows multiple choice.
Sourcepub async fn poll_results(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
) -> Result<PollStats, InvocationError>
pub async fn poll_results( &self, peer: impl Into<PeerRef>, msg_id: i32, ) -> Result<PollStats, InvocationError>
Get statistics for a poll message.
Sourcepub async fn get_poll_votes(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
option: Option<Vec<u8>>,
limit: i32,
offset: Option<String>,
) -> Result<VotesList, InvocationError>
pub async fn get_poll_votes( &self, peer: impl Into<PeerRef>, msg_id: i32, option: Option<Vec<u8>>, limit: i32, offset: Option<String>, ) -> Result<VotesList, InvocationError>
List who voted for what on a poll. Pass option to filter to one
specific answer, or None for everyone; offset/limit page
through results.
Source§impl Client
impl Client
Sourcepub async fn get_privacy(
&self,
key: InputPrivacyKey,
) -> Result<Vec<PrivacyRule>, InvocationError>
pub async fn get_privacy( &self, key: InputPrivacyKey, ) -> Result<Vec<PrivacyRule>, InvocationError>
Get your privacy rules for one setting - who can see your phone number, add you to groups, call you, and so on.
Sourcepub async fn set_privacy(
&self,
key: InputPrivacyKey,
rules: Vec<InputPrivacyRule>,
) -> Result<Vec<PrivacyRule>, InvocationError>
pub async fn set_privacy( &self, key: InputPrivacyKey, rules: Vec<InputPrivacyRule>, ) -> Result<Vec<PrivacyRule>, InvocationError>
Replace your privacy rules for one setting. This overwrites the
whole rule set for key, not just one rule in it.
Sourcepub async fn get_notify_settings(
&self,
peer: impl Into<PeerRef>,
) -> Result<PeerNotifySettings, InvocationError>
pub async fn get_notify_settings( &self, peer: impl Into<PeerRef>, ) -> Result<PeerNotifySettings, InvocationError>
Get notification settings for a chat - muted, sound, and so on.
Sourcepub async fn update_notify_settings(
&self,
peer: impl Into<PeerRef>,
settings: InputPeerNotifySettings,
) -> Result<(), InvocationError>
pub async fn update_notify_settings( &self, peer: impl Into<PeerRef>, settings: InputPeerNotifySettings, ) -> Result<(), InvocationError>
Change notification settings for a chat.
Source§impl Client
impl Client
Sourcepub async fn get_reactions(
&self,
peer: impl Into<PeerRef>,
msg_ids: Vec<i32>,
) -> Result<(), InvocationError>
pub async fn get_reactions( &self, peer: impl Into<PeerRef>, msg_ids: Vec<i32>, ) -> Result<(), InvocationError>
Tell Telegram you’ve seen the reactions on these messages, so it stops marking them as new/unread.
Sourcepub async fn delete_reaction(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
participant: impl Into<PeerRef>,
) -> Result<bool, InvocationError>
pub async fn delete_reaction( &self, peer: impl Into<PeerRef>, msg_id: i32, participant: impl Into<PeerRef>, ) -> Result<bool, InvocationError>
Report (and request removal of) a specific user’s reaction on a message.
Sourcepub async fn iter_reaction_users(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
reaction: Option<Reaction>,
limit: i32,
offset: Option<String>,
) -> Result<MessageReactionsList, InvocationError>
pub async fn iter_reaction_users( &self, peer: impl Into<PeerRef>, msg_id: i32, reaction: Option<Reaction>, limit: i32, offset: Option<String>, ) -> Result<MessageReactionsList, InvocationError>
List who reacted to a message, and with what. Pass reaction to
filter to one specific reaction, or None for all of them; offset
pages through results.
Sourcepub async fn send_paid_reaction(
&self,
peer: impl Into<PeerRef>,
msg_id: i32,
count: i32,
) -> Result<(), InvocationError>
pub async fn send_paid_reaction( &self, peer: impl Into<PeerRef>, msg_id: i32, count: i32, ) -> Result<(), InvocationError>
Send count Star reactions on a message - the paid reaction type,
not a regular emoji one.
Source§impl Client
impl Client
Sourcepub async fn resolve<P: Into<PeerRef>>(
&self,
peer: P,
) -> Result<Peer, InvocationError>
pub async fn resolve<P: Into<PeerRef>>( &self, peer: P, ) -> Result<Peer, InvocationError>
Resolve any peer reference to a tl::enums::Peer.
Accepts everything PeerRef accepts:
&str/String:"@username","me","self", numeric string,t.me/URL, invite link, E.164 phonei64/i32: Bot-API encoded numeric IDtl::enums::Peer: returned as-is (zero cost)tl::enums::InputPeer: hash cached, then stripped toPeer
Resolution is cache-first; an RPC is only made on a genuine cache miss.
Sourcepub async fn join_link(&self, link: &str) -> Result<InputPeer, InvocationError>
pub async fn join_link(&self, link: &str) -> Result<InputPeer, InvocationError>
Join a chat by invite link and return its InputPeer.
Calls messages.importChatInvite, caches all returned entities, and
returns the InputPeer of the joined chat.
Join a chat or channel via an invite link.
Sourcepub async fn check_invite(
&self,
link: &str,
) -> Result<ChatInvite, InvocationError>
pub async fn check_invite( &self, link: &str, ) -> Result<ChatInvite, InvocationError>
Peek at an invite link without joining.
Returns the title and participant count of the chat the link points to.
Source§impl Client
impl Client
Sourcepub async fn read_reactions(
&self,
peer: impl Into<PeerRef>,
) -> Result<(), InvocationError>
pub async fn read_reactions( &self, peer: impl Into<PeerRef>, ) -> Result<(), InvocationError>
Mark all unread reactions in a chat as read.
Sourcepub async fn clear_recent_reactions(&self) -> Result<(), InvocationError>
pub async fn clear_recent_reactions(&self) -> Result<(), InvocationError>
Clear the recent reactions list shown in the reaction picker.
Sourcepub async fn get_online_count(
&self,
peer: impl Into<PeerRef>,
) -> Result<i32, InvocationError>
pub async fn get_online_count( &self, peer: impl Into<PeerRef>, ) -> Result<i32, InvocationError>
Get the approximate number of online members in a group or channel.
Source§impl Client
impl Client
Sourcepub async fn get_sticker_set(
&self,
stickerset: InputStickerSet,
) -> Result<StickerSet, InvocationError>
pub async fn get_sticker_set( &self, stickerset: InputStickerSet, ) -> Result<StickerSet, InvocationError>
Get a sticker set’s contents - title, stickers, and so on.
Sourcepub async fn toggle_stickers(
&self,
stickerset: InputStickerSet,
install: bool,
) -> Result<Option<StickerSetInstallResult>, InvocationError>
pub async fn toggle_stickers( &self, stickerset: InputStickerSet, install: bool, ) -> Result<Option<StickerSetInstallResult>, InvocationError>
Install or uninstall a sticker set. install: true installs, install: false uninstalls.
Sourcepub async fn get_all_stickers(
&self,
hash: i64,
) -> Result<Option<Vec<StickerSet>>, InvocationError>
pub async fn get_all_stickers( &self, hash: i64, ) -> Result<Option<Vec<StickerSet>>, InvocationError>
List every sticker set you have installed. Pass the hash from a
previous call to get back None cheaply when nothing’s changed,
instead of the full list again; 0 always gets the full list.
Sourcepub async fn get_custom_emoji_documents(
&self,
document_ids: Vec<i64>,
) -> Result<Vec<Document>, InvocationError>
pub async fn get_custom_emoji_documents( &self, document_ids: Vec<i64>, ) -> Result<Vec<Document>, InvocationError>
Look up custom emoji by their document IDs, to get the actual emoji documents (image/animation data) behind them.
Source§impl Client
impl Client
Sourcepub async fn get_contacts(&self) -> Result<Vec<User>, InvocationError>
pub async fn get_contacts(&self) -> Result<Vec<User>, InvocationError>
Fetch the full contact list of the current user.
Returns an empty list when the server reports no changes since the last fetch.
Sourcepub async fn delete_contacts(
&self,
user_ids: &[i64],
) -> Result<(), InvocationError>
pub async fn delete_contacts( &self, user_ids: &[i64], ) -> Result<(), InvocationError>
Remove one or more users from the contact list.
Sourcepub async fn block(
&self,
peer: impl Into<PeerRef>,
block: bool,
) -> Result<(), InvocationError>
pub async fn block( &self, peer: impl Into<PeerRef>, block: bool, ) -> Result<(), InvocationError>
Block or unblock a user or peer. block: true blocks, block: false unblocks.
Sourcepub async fn set_presence(&self, online: bool) -> Result<(), InvocationError>
pub async fn set_presence(&self, online: bool) -> Result<(), InvocationError>
Set presence status. online: true appears online, online: false appears offline.
Sourcepub async fn terminate_session(&self, hash: i64) -> Result<(), InvocationError>
pub async fn terminate_session(&self, hash: i64) -> Result<(), InvocationError>
Terminate a specific session by its hash (obtained from Self::get_authorizations).
Sourcepub async fn add_contact(
&self,
user_id: i64,
first_name: impl Into<String>,
last_name: impl Into<String>,
phone: impl Into<String>,
add_phone_privacy_exception: bool,
) -> Result<(), InvocationError>
pub async fn add_contact( &self, user_id: i64, first_name: impl Into<String>, last_name: impl Into<String>, phone: impl Into<String>, add_phone_privacy_exception: bool, ) -> Result<(), InvocationError>
Add a user to your contacts. With add_phone_privacy_exception: true,
they’ll be able to see your phone number even if your privacy
settings would normally hide it from them.
Sourcepub async fn import_contacts(
&self,
contacts: &[(&str, &str, &str)],
) -> Result<ImportedContacts, InvocationError>
pub async fn import_contacts( &self, contacts: &[(&str, &str, &str)], ) -> Result<ImportedContacts, InvocationError>
Add several contacts at once, each given as (phone, first_name, last_name).
Sourcepub async fn get_blocked_users(
&self,
offset: i32,
limit: i32,
) -> Result<Vec<Peer>, InvocationError>
pub async fn get_blocked_users( &self, offset: i32, limit: i32, ) -> Result<Vec<Peer>, InvocationError>
List the users you’ve blocked. offset/limit page through results.
Sourcepub async fn search_contacts(
&self,
query: impl Into<String>,
limit: i32,
) -> Result<Vec<Peer>, InvocationError>
pub async fn search_contacts( &self, query: impl Into<String>, limit: i32, ) -> Result<Vec<Peer>, InvocationError>
Search your contacts and the global user directory by name or
username for query.
Sourcepub async fn delete_profile_photos(
&self,
photo_ids: Vec<(i64, i64, Vec<u8>)>,
) -> Result<Vec<i64>, InvocationError>
pub async fn delete_profile_photos( &self, photo_ids: Vec<(i64, i64, Vec<u8>)>, ) -> Result<Vec<i64>, InvocationError>
Delete profile photos by (id, access_hash, file_reference). Returns
the IDs that were actually deleted.
Sourcepub fn set_profile(&self, peer: impl Into<PeerRef>) -> SetProfileBuilder
pub fn set_profile(&self, peer: impl Into<PeerRef>) -> SetProfileBuilder
Update user or chat profile fields via a builder.
Call .send().await to apply. Unset fields are left unchanged.
§Example
client.set_profile("me").name("Alice", "").bio("Hello!").send().await.unwrap();List your active sessions - every device currently logged into this account.
Sourcepub async fn get_user_full(
&self,
user_id: i64,
) -> Result<UserFull, InvocationError>
pub async fn get_user_full( &self, user_id: i64, ) -> Result<UserFull, InvocationError>
Get full info for a user - bio, common chats count, blocked status, and other fields the basic user object doesn’t carry.
Sourcepub async fn stats(
&self,
peer: impl Into<PeerRef>,
) -> Result<ChannelStats, InvocationError>
pub async fn stats( &self, peer: impl Into<PeerRef>, ) -> Result<ChannelStats, InvocationError>
Retrieve channel or supergroup statistics.
Auto-dispatches to stats.getBroadcastStats for channels and
stats.getMegagroupStats for supergroups.
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Return a fluent crate::ClientBuilder for constructing and connecting a client.
§Example
let (client, _shutdown) = Client::builder()
.api_id(12345)
.api_hash("abc123")
.session("my.session")
.catch_up(true)
.connect().await?;Sourcepub async fn connect(
config: Config,
) -> Result<(Self, ShutdownToken), InvocationError>
pub async fn connect( config: Config, ) -> Result<(Self, ShutdownToken), InvocationError>
Connect to Telegram and log in (or resume an existing session) using
config. This is the first thing you call - it returns your Client
plus a ShutdownToken you can use to disconnect cleanly later.
Sourcepub async fn save_session(&self) -> Result<(), InvocationError>
pub async fn save_session(&self) -> Result<(), InvocationError>
Persist the current session to the configured crate::SessionBackend.
Sourcepub async fn export_session_string(&self) -> Result<String, InvocationError>
pub async fn export_session_string(&self) -> Result<String, InvocationError>
Export the session as a compact string (V2 format).
Encodes dc_id, ip, port, user_id, and auth key. Store in an env var
or secret manager and pass back to crate::ClientBuilder::session_string
to resume without re-authenticating.
Calls get_me() internally to obtain the user_id.
Sourcepub async fn export_native_session_string(
&self,
) -> Result<String, InvocationError>
pub async fn export_native_session_string( &self, ) -> Result<String, InvocationError>
Export the full native session string (DC table, update state, peer cache).
Use this when you need to resume update processing from exactly where
you left off (PTS, QTS, seq, peer cache intact). Pass the result back
to crate::ClientBuilder::session_string which auto-detects the format.
Sourcepub async fn media_dc_addr(&self, dc_id: i32) -> Option<String>
pub async fn media_dc_addr(&self, dc_id: i32) -> Option<String>
Return the media-only DC address for the given DC id, if known.
Media DCs (media_only = true in DcOption) are preferred for file
uploads and downloads because they are not subject to the API rate
limits applied to the main DC connection.
Sourcepub async fn best_media_dc_addr(&self) -> Option<(i32, String)>
pub async fn best_media_dc_addr(&self) -> Option<(i32, String)>
Return the best media DC address for the current home DC (falls back to any known media DC if no home-DC media entry exists).
Returns true if the client is already authorized.
Sourcepub fn stream_updates(&self) -> UpdateStream
pub fn stream_updates(&self) -> UpdateStream
Return an UpdateStream that yields incoming crate::Updates.
The reader task sends all updates to inner.update_tx. This method
proxies those updates into a caller-owned channel, applying the
overflow strategy from UpdateConfig:
DropOldest(default) - aVecDequering buffer ofqueue_capacityslots is maintained in the proxy task. When it is full, the stalest Ephemeral update (typing, online status) is evicted first; if there are none, the oldest Normal update is evicted. The incoming update is always accepted.DropNewest- the incoming update is dropped if the channel is full (originaltry_sendbehaviour).
In both cases, internal MTProto state (pts, qts, getDifference) is never touched here. It runs exclusively in the reader task.
Sourcepub fn signal_network_restored(&self)
pub fn signal_network_restored(&self)
Signal that network connectivity has been restored.
Call this from platform network-change callbacks: Android’s
ConnectivityManager, iOS NWPathMonitor, or any other OS hook
to make the client attempt an immediate reconnect instead of waiting
for the exponential backoff timer to expire.
Safe to call at any time: if the connection is healthy the hint is silently ignored by the reader task; if it is in a backoff loop it wakes up and tries again right away.
Sourcepub async fn invoke<R: RemoteCall>(
&self,
req: &R,
) -> Result<R::Return, InvocationError>
pub async fn invoke<R: RemoteCall>( &self, req: &R, ) -> Result<R::Return, InvocationError>
Invoke any TL function directly, handling flood-wait retries.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Gracefully shut down the client.
Signals the reader task to exit cleanly. Same as cancelling the
ShutdownToken returned from Client::connect.
In-flight RPCs will receive a Dropped error. Call save_session()
before this if you want to persist the current auth state.
Sourcepub async fn channel_kind_of(&self, channel_id: i64) -> Option<ChannelKind>
pub async fn channel_kind_of(&self, channel_id: i64) -> Option<ChannelKind>
Look up the cached crate::ChannelKind for a raw channel ID.
Returns None if the channel is not in the peer cache yet. The cache is
populated automatically as updates arrive, or you can warm it explicitly
with warm_peer_cache_from_dialogs.
Sourcepub async fn warm_peer_cache_from_dialogs(&self) -> Result<(), InvocationError>
pub async fn warm_peer_cache_from_dialogs(&self) -> Result<(), InvocationError>
Fetch the first page of dialogs purely to populate the peer cache
with their users/chats. Called automatically on a cache-miss burst
(see bulk_peer_hydration); exposed publicly so callers can
also warm it up-front instead of waiting for the first miss.
Sourcepub async fn resolve_to_input_peer(
&self,
peer: &Peer,
) -> Result<InputPeer, InvocationError>
pub async fn resolve_to_input_peer( &self, peer: &Peer, ) -> Result<InputPeer, InvocationError>
Try to resolve a peer to InputPeer, returning an error if the access_hash is unknown (i.e. the peer has not been seen in any prior API call).
Sourcepub async fn invoke_on_dc<R: RemoteCall>(
&self,
dc_id: i32,
req: &R,
) -> Result<R::Return, InvocationError>
pub async fn invoke_on_dc<R: RemoteCall>( &self, dc_id: i32, req: &R, ) -> Result<R::Return, InvocationError>
Invoke a request on a specific DC, using the pool.
If the target DC has no auth key yet, one is acquired via DH and then
authorized via auth.exportAuthorization / auth.importAuthorization
so the worker DC can serve user-account requests too.
Source§impl Client
impl Client
Sourcepub async fn upload_file_concurrent(
&self,
data: Arc<Vec<u8>>,
name: &str,
mime_type: &str,
handle: Option<&TransferHandle>,
) -> Result<UploadedFile, InvocationError>
pub async fn upload_file_concurrent( &self, data: Arc<Vec<u8>>, name: &str, mime_type: &str, handle: Option<&TransferHandle>, ) -> Result<UploadedFile, InvocationError>
Upload bytes with parallel worker sessions.
Parallel upload using per-worker connections. Worker count scales with file size. Part size: 32 KB for tiny files, 512 KB otherwise.
- Files < 10 MB ->
upload.saveFilePart(small-file API) - Files >= 10 MB ->
upload.saveBigFilePart(big-file API)
Sourcepub async fn send_file(
&self,
peer: impl Into<PeerRef>,
media: impl Into<InputMedia>,
msg: &InputMessage,
) -> Result<IncomingMessage, InvocationError>
pub async fn send_file( &self, peer: impl Into<PeerRef>, media: impl Into<InputMedia>, msg: &InputMessage, ) -> Result<IncomingMessage, InvocationError>
Send a file as a document or photo to a chat.
Sourcepub async fn send_album(
&self,
peer: impl Into<PeerRef>,
items: Vec<AlbumItem>,
) -> Result<Vec<IncomingMessage>, InvocationError>
pub async fn send_album( &self, peer: impl Into<PeerRef>, items: Vec<AlbumItem>, ) -> Result<Vec<IncomingMessage>, InvocationError>
Send multiple files as an album.
Each AlbumItem carries its own media, caption, entities (formatting),
and optional reply_to message ID.
use ferogram::media::AlbumItem;
let msgs = client.send_album(peer.clone(), vec![
AlbumItem::new(photo_media).caption_html("<b>First photo</b>"),
AlbumItem::new(video_media).caption("Second item").reply_to(Some(42)),
]).await?;
// Shorthand: legacy tuple API still works via From impl
client.send_album(peer, vec![
(photo_media2, "caption".to_string()).into(),
]).await?;Source§impl Client
impl Client
Sourcepub async fn get_participants(
&self,
peer: impl Into<PeerRef>,
limit: i32,
) -> Result<Vec<Participant>, InvocationError>
pub async fn get_participants( &self, peer: impl Into<PeerRef>, limit: i32, ) -> Result<Vec<Participant>, InvocationError>
Fetch all participants of a chat, group or channel.
For channels this uses channels.getParticipants; for basic groups it
uses messages.getFullChat.
Returns up to limit participants; pass 0 for the default (200 for channels).
Sourcepub async fn kick(
&self,
peer: impl Into<PeerRef>,
user_id: i64,
) -> Result<(), InvocationError>
pub async fn kick( &self, peer: impl Into<PeerRef>, user_id: i64, ) -> Result<(), InvocationError>
Kick a user from a group chat or channel.
For basic groups, this removes the user immediately. For channels and supergroups, it bans then unbans them (a Telegram kick).
Sourcepub async fn ban(
&self,
channel: impl Into<PeerRef>,
user_id: i64,
until: Option<i32>,
) -> Result<(), InvocationError>
pub async fn ban( &self, channel: impl Into<PeerRef>, user_id: i64, until: Option<i32>, ) -> Result<(), InvocationError>
Ban a user from a channel or supergroup.
until: None is a permanent ban; until: Some(ts) bans until the Unix timestamp.
Sourcepub async fn get_profile_photos(
&self,
peer: impl Into<PeerRef>,
limit: i32,
) -> Result<Vec<Photo>, InvocationError>
pub async fn get_profile_photos( &self, peer: impl Into<PeerRef>, limit: i32, ) -> Result<Vec<Photo>, InvocationError>
Iterate profile photos of a user or channel.
Returns a list of photo objects (up to limit).
Sourcepub async fn iter_profile_photos(
&self,
peer: impl Into<PeerRef>,
chunk_size: i32,
) -> Result<ProfilePhotoIter, InvocationError>
pub async fn iter_profile_photos( &self, peer: impl Into<PeerRef>, chunk_size: i32, ) -> Result<ProfilePhotoIter, InvocationError>
Stream profile photos of a user lazily, one page at a time.
Returns a ProfilePhotoIter that fetches photos in pages of
chunk_size and exposes them one-by-one via .next().await.
Set chunk_size to 0 to use the default (100).
Only works for users: channels use messages.search with a photo
filter instead.
§Example
let mut iter = client.iter_profile_photos(peer, 0).await?;
while let Some(photo) = iter.next().await? {
println!("{photo:?}");
}Sourcepub async fn search_peer(
&self,
query: &str,
) -> Result<Vec<Peer>, InvocationError>
pub async fn search_peer( &self, query: &str, ) -> Result<Vec<Peer>, InvocationError>
Search for a peer (user, group, or channel) by name prefix.
Searches contacts, dialogs, and globally. Returns combined results.
Source§impl Client
impl Client
Sourcepub async fn restrict(
&self,
channel: impl Into<PeerRef>,
user_id: i64,
build: impl FnOnce(BannedRightsBuilder) -> BannedRightsBuilder,
) -> Result<(), InvocationError>
pub async fn restrict( &self, channel: impl Into<PeerRef>, user_id: i64, build: impl FnOnce(BannedRightsBuilder) -> BannedRightsBuilder, ) -> Result<(), InvocationError>
Apply granular ban rights to a user in a channel or supergroup.
Use BannedRightsBuilder to specify which rights to restrict.
Sourcepub async fn set_admin(
&self,
channel: impl Into<PeerRef>,
user_id: i64,
build: impl FnOnce(AdminRightsBuilder) -> AdminRightsBuilder,
) -> Result<(), InvocationError>
pub async fn set_admin( &self, channel: impl Into<PeerRef>, user_id: i64, build: impl FnOnce(AdminRightsBuilder) -> AdminRightsBuilder, ) -> Result<(), InvocationError>
Apply granular admin rights to a user in a channel or supergroup.
Use AdminRightsBuilder to specify which rights to grant.
Sourcepub async fn get_participants_filtered(
&self,
peer: impl Into<PeerRef>,
filter: Option<ChannelParticipantsFilter>,
limit: i32,
) -> Result<Vec<Participant>, InvocationError>
pub async fn get_participants_filtered( &self, peer: impl Into<PeerRef>, filter: Option<ChannelParticipantsFilter>, limit: i32, ) -> Result<Vec<Participant>, InvocationError>
Fetch participants with an optional filter, paginated.
filter defaults to ChannelParticipantsRecent when None.
Sourcepub async fn get_permissions(
&self,
channel: impl Into<PeerRef>,
user_id: i64,
) -> Result<ParticipantPermissions, InvocationError>
pub async fn get_permissions( &self, channel: impl Into<PeerRef>, user_id: i64, ) -> Result<ParticipantPermissions, InvocationError>
Get the effective permissions of a specific user in a channel.
Source§impl Client
impl Client
Sourcepub async fn quick_connect(
session: impl AsRef<Path>,
api_id: i32,
api_hash: &str,
) -> Result<(Client, ShutdownToken), QuickConnectError>
pub async fn quick_connect( session: impl AsRef<Path>, api_id: i32, api_hash: &str, ) -> Result<(Client, ShutdownToken), QuickConnectError>
Connect and authenticate in a single call.
Prompts interactively (stdin) for a phone number or bot token, then drives the full auth flow - login code and 2FA password if required. If the session is already authorized the prompt is skipped entirely.
For advanced options (proxy, custom transport, PFS, catch-up, etc.)
use Client::builder() instead.
§Example
use ferogram::Client;
const API_ID: i32 = 0;
const API_HASH: &str = "";
let (client, _) = Client::quick_connect("my.session", API_ID, API_HASH).await?;Source§impl Client
impl Client
Sourcepub fn iter_inline_queries(&self) -> InlineQueryIter
pub fn iter_inline_queries(&self) -> InlineQueryIter
Return an iterator that yields every incoming inline query (bot side).
The internal channel is bounded to 256 entries.
If the consumer stops calling InlineQueryIter::next and the backlog
fills, the feed task exits and the stream ends rather than growing memory
without bound.
Sourcepub async fn inline_query(
&self,
bot: Peer,
query: &str,
) -> Result<InlineResultIter, InvocationError>
pub async fn inline_query( &self, bot: Peer, query: &str, ) -> Result<InlineResultIter, InvocationError>
Query a bot’s inline mode and return a paginated InlineResultIter.
Equivalent to typing @bot_username query in a Telegram app.
§Example
let mut iter = client.inline_query(bot, "hello").await?;
while let Some(r) = iter.next().await? {
println!("{}", r.title().unwrap_or("(no title)"));
}Source§impl Client
impl Client
Sourcepub async fn typing(
&self,
peer: impl Into<PeerRef>,
) -> Result<TypingGuard, InvocationError>
pub async fn typing( &self, peer: impl Into<PeerRef>, ) -> Result<TypingGuard, InvocationError>
Start a scoped typing indicator that auto-cancels when dropped.
A convenience wrapper around TypingGuard::start.
Sourcepub async fn typing_in_topic(
&self,
peer: impl Into<PeerRef>,
topic_id: i32,
) -> Result<TypingGuard, InvocationError>
pub async fn typing_in_topic( &self, peer: impl Into<PeerRef>, topic_id: i32, ) -> Result<TypingGuard, InvocationError>
Start a scoped typing indicator in a forum topic thread.
topic_id is the top_msg_id of the forum topic.
Sourcepub async fn uploading_document(
&self,
peer: impl Into<PeerRef>,
) -> Result<TypingGuard, InvocationError>
pub async fn uploading_document( &self, peer: impl Into<PeerRef>, ) -> Result<TypingGuard, InvocationError>
Start a scoped “uploading document” action that auto-cancels when dropped.
Sourcepub async fn recording_video(
&self,
peer: impl Into<PeerRef>,
) -> Result<TypingGuard, InvocationError>
pub async fn recording_video( &self, peer: impl Into<PeerRef>, ) -> Result<TypingGuard, InvocationError>
Start a scoped “recording video” action that auto-cancels when dropped.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more