pub struct TelegramClient { /* private fields */ }Expand description
Telegram REST API client
Implementations§
Source§impl TelegramClient
impl TelegramClient
Sourcepub async fn send_message(
&self,
chat_id: i64,
text: &str,
thread_id: Option<i64>,
reply_markup: Option<ReplyMarkup>,
) -> Result<i64, BotError>
pub async fn send_message( &self, chat_id: i64, text: &str, thread_id: Option<i64>, reply_markup: Option<ReplyMarkup>, ) -> Result<i64, BotError>
Send a text message
thread_id targets a forum topic. Returns the id of the message that
was sent.
Sourcepub async fn send_reply(
&self,
chat_id: i64,
reply_to: i64,
text: &str,
) -> Result<i64, BotError>
pub async fn send_reply( &self, chat_id: i64, reply_to: i64, text: &str, ) -> Result<i64, BotError>
Send a text message as a reply to another message
reply_to is the id of the message to quote. Telegram drops the reply
reference rather than failing when the target no longer exists
(allow_sending_without_reply), and posts the reply into the
referenced message’s forum topic. Returns the sent message’s id.
Sourcepub async fn send_reply_markup(
&self,
chat_id: i64,
reply_to: i64,
text: &str,
markup: Option<InlineKeyboardMarkup>,
) -> Result<i64, BotError>
pub async fn send_reply_markup( &self, chat_id: i64, reply_to: i64, text: &str, markup: Option<InlineKeyboardMarkup>, ) -> Result<i64, BotError>
Self::send_reply with an inline keyboard attached.
Sourcepub async fn edit_message_text(
&self,
chat_id: i64,
message_id: i64,
text: &str,
reply_markup: Option<ReplyMarkup>,
) -> Result<(), BotError>
pub async fn edit_message_text( &self, chat_id: i64, message_id: i64, text: &str, reply_markup: Option<ReplyMarkup>, ) -> Result<(), BotError>
Edit a message
Sourcepub async fn edit_message_reply_markup(
&self,
chat_id: i64,
message_id: i64,
reply_markup: Option<InlineKeyboardMarkup>,
) -> Result<(), BotError>
pub async fn edit_message_reply_markup( &self, chat_id: i64, message_id: i64, reply_markup: Option<InlineKeyboardMarkup>, ) -> Result<(), BotError>
Edit only a message’s inline keyboard. Called with None it is the
existence probe: Telegram replies “message is not modified” on a
live message and “message to edit not found” on a dead one.
Sourcepub async fn answer_callback_query(
&self,
callback_query_id: &str,
text: Option<&str>,
show_alert: bool,
) -> Result<(), BotError>
pub async fn answer_callback_query( &self, callback_query_id: &str, text: Option<&str>, show_alert: bool, ) -> Result<(), BotError>
Answer a callback query
Sourcepub async fn delete_webhook(&self) -> Result<(), BotError>
pub async fn delete_webhook(&self) -> Result<(), BotError>
Delete webhook
Sourcepub async fn get_updates(
&self,
offset: Option<i64>,
timeout: Option<u32>,
) -> Result<Vec<Update>, BotError>
pub async fn get_updates( &self, offset: Option<i64>, timeout: Option<u32>, ) -> Result<Vec<Update>, BotError>
Get updates using long polling
Sourcepub async fn send_chat_action(
&self,
chat_id: i64,
action: &str,
thread_id: Option<i64>,
) -> Result<(), BotError>
pub async fn send_chat_action( &self, chat_id: i64, action: &str, thread_id: Option<i64>, ) -> Result<(), BotError>
Send a chat action (typing, uploading, etc.). thread_id targets a
forum topic.
Sourcepub async fn set_message_reaction(
&self,
chat_id: i64,
message_id: i64,
emoji: Option<&str>,
is_big: bool,
) -> Result<(), BotError>
pub async fn set_message_reaction( &self, chat_id: i64, message_id: i64, emoji: Option<&str>, is_big: bool, ) -> Result<(), BotError>
Set the bot’s emoji reaction on a message. None removes the bot’s
reaction; is_big plays the large animation.
Sourcepub async fn delete_message(
&self,
chat_id: i64,
message_id: i64,
) -> Result<(), BotError>
pub async fn delete_message( &self, chat_id: i64, message_id: i64, ) -> Result<(), BotError>
Delete a message — the bot’s own, or any message in a chat where it has delete rights.
Sourcepub async fn pin_message(
&self,
chat_id: i64,
message_id: i64,
notify: bool,
) -> Result<(), BotError>
pub async fn pin_message( &self, chat_id: i64, message_id: i64, notify: bool, ) -> Result<(), BotError>
Pin a message (notify = false pins silently); unpin removes the
pin. Needs pin rights in groups.
Sourcepub async fn unpin_message(
&self,
chat_id: i64,
message_id: i64,
) -> Result<(), BotError>
pub async fn unpin_message( &self, chat_id: i64, message_id: i64, ) -> Result<(), BotError>
See Self::pin_message.
Sourcepub async fn set_my_commands(
&self,
commands: &[BotCommand],
) -> Result<(), BotError>
pub async fn set_my_commands( &self, commands: &[BotCommand], ) -> Result<(), BotError>
Set bot commands for the menu
Registers commands with Telegram so they appear in the command menu.
Sourcepub async fn get_me(&self) -> Result<User, BotError>
pub async fn get_me(&self) -> Result<User, BotError>
The bot’s own identity. id is the user_id owner argument the
sticker-set methods take; username is the mandatory
_by_<bot> suffix for sets the bot creates.
Sourcepub async fn get_file(&self, file_id: &str) -> Result<File, BotError>
pub async fn get_file(&self, file_id: &str) -> Result<File, BotError>
getFile — resolve a file_id to its server-side file_path.
Sourcepub async fn download_file(
&self,
file_path: &str,
limit: usize,
) -> Result<Vec<u8>, BotError>
pub async fn download_file( &self, file_path: &str, limit: usize, ) -> Result<Vec<u8>, BotError>
Download a file’s bytes using the file_path getFile returned.
Telegram serves file content from a separate URL shape
(/file/bot<token>/<path>) and returns raw bytes rather than the
usual JSON envelope. limit caps the buffered size; files larger
than it error instead of truncating.
Sourcepub async fn send_document(
&self,
chat_id: i64,
file: FileSource,
filename: Option<&str>,
caption: Option<&str>,
thread_id: Option<i64>,
) -> Result<i64, BotError>
pub async fn send_document( &self, chat_id: i64, file: FileSource, filename: Option<&str>, caption: Option<&str>, thread_id: Option<i64>, ) -> Result<i64, BotError>
Send a document/file.
Returns the id of the message that was sent.
Sourcepub async fn send_photo(
&self,
chat_id: i64,
file: FileSource,
filename: &str,
caption: Option<&str>,
thread_id: Option<i64>,
) -> Result<i64, BotError>
pub async fn send_photo( &self, chat_id: i64, file: FileSource, filename: &str, caption: Option<&str>, thread_id: Option<i64>, ) -> Result<i64, BotError>
Send a photo (JPEG, PNG, WebP, GIF, …)
Returns the id of the message that was sent.
Sourcepub async fn send_sticker(
&self,
chat_id: i64,
file: FileSource,
filename: &str,
thread_id: Option<i64>,
) -> Result<i64, BotError>
pub async fn send_sticker( &self, chat_id: i64, file: FileSource, filename: &str, thread_id: Option<i64>, ) -> Result<i64, BotError>
Send a native sticker by upload (WebP, TGS, or WebM)
Returns the id of the message that was sent.
Sourcepub async fn send_media(
&self,
chat_id: i64,
kind: MediaKind,
file: FileSource,
filename: &str,
caption: Option<&str>,
thread_id: Option<i64>,
) -> Result<i64, BotError>
pub async fn send_media( &self, chat_id: i64, kind: MediaKind, file: FileSource, filename: &str, caption: Option<&str>, thread_id: Option<i64>, ) -> Result<i64, BotError>
Upload file as the given media kind; returns the sent message’s id.
thread_id targets a forum topic.
Sourcepub async fn send_media_id(
&self,
chat_id: i64,
kind: MediaKind,
file_id: &str,
caption: Option<&str>,
thread_id: Option<i64>,
) -> Result<i64, BotError>
pub async fn send_media_id( &self, chat_id: i64, kind: MediaKind, file_id: &str, caption: Option<&str>, thread_id: Option<i64>, ) -> Result<i64, BotError>
Send media Telegram already hosts by file_id — anything the bot has
seen in a message or holds in a sticker set. thread_id targets a
forum topic. Returns the message id.
Sourcepub async fn get_sticker_set(&self, name: &str) -> Result<StickerSet, BotError>
pub async fn get_sticker_set(&self, name: &str) -> Result<StickerSet, BotError>
Fetch a sticker set by short name.
A missing set fails with a BotError::Api carrying Telegram’s
STICKERSET_INVALID description.
Sourcepub async fn create_sticker_set(
&self,
user_id: i64,
name: &str,
title: &str,
sticker: NewSticker,
) -> Result<(), BotError>
pub async fn create_sticker_set( &self, user_id: i64, name: &str, title: &str, sticker: NewSticker, ) -> Result<(), BotError>
Create a sticker set owned by user_id (the bot itself works) with
sticker as its first entry. name must end in _by_<bot username>.
Sourcepub async fn add_sticker_to_set(
&self,
user_id: i64,
name: &str,
sticker: NewSticker,
) -> Result<(), BotError>
pub async fn add_sticker_to_set( &self, user_id: i64, name: &str, sticker: NewSticker, ) -> Result<(), BotError>
Append sticker to a set the bot owns.
Sourcepub async fn replace_sticker_in_set(
&self,
user_id: i64,
name: &str,
old_file_id: &str,
sticker: NewSticker,
) -> Result<(), BotError>
pub async fn replace_sticker_in_set( &self, user_id: i64, name: &str, old_file_id: &str, sticker: NewSticker, ) -> Result<(), BotError>
Replace the sticker old_file_id points at with sticker, keeping
its position in the set.
Trait Implementations§
Source§impl Clone for TelegramClient
impl Clone for TelegramClient
Source§fn clone(&self) -> TelegramClient
fn clone(&self) -> TelegramClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more