The complete Rust
Telegram Bot library
tgbotrs gives you every Telegram Bot API method and type — fully typed, fully async, auto-generated from the official spec. Built with Tokio. Lowest supported: v0.1.4.
🚀 Quick Start
Get your first bot running in under 2 minutes.
[dependencies]
tgbotrs = "0.1.4"
tokio = { version = "1", features = ["full"] }use tgbotrs::{Bot, Poller, UpdateHandler};
#[tokio::main]
async fn main() {
let bot = Bot::new("YOUR_BOT_TOKEN").await.unwrap();
let handler: UpdateHandler = Box::new(|bot, update| {
Box::pin(async move {
let Some(msg) = update.message else { return };
let Some(text) = msg.text else { return };
let reply = match text.as_str() {
"/start" => "👋 Hello! Powered by tgbotrs 🦀".to_string(),
other => format!("Echo: {}", other),
};
let _ = bot.send_message(msg.chat.id, reply, None).await;
})
});
Poller::new(bot, handler).timeout(30).start().await.unwrap();
}cargo run📦 Installation
Minimum supported: v0.1.4
[dependencies]
tgbotrs = "0.1.4"
tokio = { version = "1", features = ["full"] }[dependencies]
tgbotrs = { version = "0.1.4", features = ["webhook"] }
tokio = { version = "1", features = ["full"] }✅ serde + serde_json
✅ tokio
✅ thiserror
🔌 axum (webhook only)
let token = std::env::var("BOT_TOKEN").expect("BOT_TOKEN not set");
let bot = Bot::new(token).await?;✨ Features
Everything you need to build powerful Telegram bots in Rust.
.parse_mode("HTML").Bot::with_api_url() to point at your own server.🔄 Long Polling
Simplest way to receive updates — no external server needed.
use tgbotrs::{Bot, Poller, UpdateHandler};
use tgbotrs::gen_methods::{SendMessageParams, AnswerCallbackQueryParams};
use tgbotrs::types::{InlineKeyboardMarkup, InlineKeyboardButton};
use tgbotrs::ReplyMarkup;
#[tokio::main]
async fn main() {
let bot = Bot::new("YOUR_BOT_TOKEN").await.unwrap();
let handler: UpdateHandler = Box::new(|bot, update| {
Box::pin(async move {
if let Some(msg) = update.message {
if msg.text.as_deref() == Some("/start") {
let keyboard = ReplyMarkup::InlineKeyboard(InlineKeyboardMarkup {
inline_keyboard: vec![vec![InlineKeyboardButton {
text: "🔵 Click me".into(),
callback_data: Some("btn1".into()),
..Default::default()
}]]
});
let params = SendMessageParams::new().reply_markup(keyboard);
let _ = bot.send_message(msg.chat.id, "Pick a button 👇", Some(params)).await;
}
}
if let Some(cq) = update.callback_query {
let _ = bot.answer_callback_query(cq.id,
Some(AnswerCallbackQueryParams::new().text("Clicked! ✅".to_string()))
).await;
}
})
});
Poller::new(bot, handler).timeout(30).limit(100).start().await.unwrap();
}
🪝 Webhook Server
Production-ready webhook server powered by Axum.
use tgbotrs::{Bot, UpdateHandler, WebhookServer};
#[tokio::main]
async fn main() {
let bot = Bot::new("YOUR_BOT_TOKEN").await.unwrap();
let handler: UpdateHandler = Box::new(|bot, update| {
Box::pin(async move {
if let Some(msg) = update.message {
let _ = bot.send_message(msg.chat.id, "pong! 🏓", None).await;
}
})
});
WebhookServer::new(bot, handler)
.port(8080).path("/webhook")
.secret_token("my_secret").max_connections(40)
.start("https://yourdomain.com").await.unwrap();
}
Sending Messages
22Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
SendAnimationParams19 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| duration | Option<i64> | Duration of sent animation in seconds |
| width | Option<i64> | Animation width |
| height | Option<i64> | Animation height |
| thumbnail | Option<InputFileOrString> | Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files: https://core.telegram.org/bots/api#sending-files |
| caption | Option<String> | Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the animation caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| show_caption_above_media | Option<bool> | Pass True, if the caption must be shown above the message media |
| has_spoiler | Option<bool> | Pass True if the animation needs to be covered with a spoiler animation |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendAnimationParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let animation = todo!();
// Optional parameters
let params = SendAnimationParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.duration(None)
.width(None)
// ... +14 more optional fields;
let result = bot.send_animation(
chat_id,
animation,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. /// For sending voice messages, use the sendVoice method instead.
SendAudioParams17 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| caption | Option<String> | Audio caption, 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the audio caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| duration | Option<i64> | Duration of the audio in seconds |
| performer | Option<String> | Performer |
| title | Option<String> | Track name |
| thumbnail | Option<InputFileOrString> | Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files: https://core.telegram.org/bots/api#sending-files |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendAudioParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let audio = todo!();
// Optional parameters
let params = SendAudioParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.caption(None)
.parse_mode(None)
// ... +12 more optional fields;
let result = bot.send_audio(
chat_id,
audio,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. /// We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
SendChatActionParams2 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the action will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread or topic of a forum; for supergroups and private chats of bots with forum topic mode enabled only |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendChatActionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let action = "example";
// Optional parameters
let params = SendChatActionParams::new()
.business_connection_id(None)
.message_thread_id(None);
let result = bot.send_chat_action(
chat_id,
action,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send a checklist on behalf of a connected business account. On success, the sent Message is returned.
SendChecklistParams5 fields| Field | Type | Description |
|---|---|---|
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message |
| reply_parameters | Option<Box<ReplyParameters>> | A JSON-serialized object for description of the message to reply to |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for an inline keyboard |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendChecklistParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let chat_id = 123456789i64;
let checklist = InputChecklist::default();
// Optional parameters
let params = SendChecklistParams::new()
.disable_notification(None)
.protect_content(None)
.message_effect_id(None)
.reply_parameters(None)
.reply_markup(None);
let result = bot.send_checklist(
business_connection_id,
chat_id,
checklist,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send phone contacts. On success, the sent Message is returned.
SendContactParams12 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| last_name | Option<String> | Contact's last name |
| vcard | Option<String> | Additional data about the contact in the form of a vCard, 0-2048 bytes |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendContactParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let phone_number = "example";
let first_name = "my_name";
// Optional parameters
let params = SendContactParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.last_name(None)
.vcard(None)
// ... +7 more optional fields;
let result = bot.send_contact(
chat_id,
phone_number,
first_name,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
SendDiceParams11 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| emoji | Option<String> | Emoji on which the dice throw animation is based. Currently, must be one of "🎲", "🎯", "🏀", "⚽", "🎳", or "🎰". Dice can have values 1-6 for "🎲", "🎯" and "🎳", values 1-5 for "🏀" and "⚽", and values 1-64 for "🎰". Defaults to "🎲" |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendDiceParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
// Optional parameters
let params = SendDiceParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.emoji(None)
.disable_notification(None)
// ... +6 more optional fields;
let result = bot.send_dice(
chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
SendDocumentParams15 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| thumbnail | Option<InputFileOrString> | Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files: https://core.telegram.org/bots/api#sending-files |
| caption | Option<String> | Document caption (may also be used when resending documents by file_id), 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the document caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| disable_content_type_detection | Option<bool> | Disables automatic server-side content type detection for files uploaded using multipart/form-data |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendDocumentParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let document = todo!();
// Optional parameters
let params = SendDocumentParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.thumbnail(None)
.caption(None)
// ... +10 more optional fields;
let result = bot.send_document(
chat_id,
document,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send a game. On success, the sent Message is returned.
SendGameParams8 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for an inline keyboard. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendGameParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let game_short_name = "my_name";
// Optional parameters
let params = SendGameParams::new()
.business_connection_id(None)
.message_thread_id(None)
.disable_notification(None)
.protect_content(None)
.allow_paid_broadcast(None)
// ... +3 more optional fields;
let result = bot.send_game(
chat_id,
game_short_name,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Sends a gift to the given user or channel chat. The gift can't be converted to Telegram Stars by the receiver. Returns True on success.
SendGiftParams6 fields| Field | Type | Description |
|---|---|---|
| user_id | Option<i64> | Required if chat_id is not specified. Unique identifier of the target user who will receive the gift. |
| chat_id | Option<ChatId> | Required if user_id is not specified. Unique identifier for the chat or username of the channel (in the format @channelusername) that will receive the gift. |
| pay_for_upgrade | Option<bool> | Pass True to pay for the gift upgrade from the bot's balance, thereby making the upgrade free for the receiver |
| text | Option<String> | Text that will be shown along with the gift; 0-128 characters |
| text_parse_mode | Option<String> | Mode for parsing entities in the text. See formatting options for more details. Entities other than "bold", "italic", "underline", "strikethrough", "spoiler", and "custom_emoji" are ignored. |
| text_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than "bold", "italic", "underline", "strikethrough", "spoiler", and "custom_emoji" are ignored. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendGiftParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let gift_id = "example";
// Optional parameters
let params = SendGiftParams::new()
.user_id(None)
.chat_id(None)
.pay_for_upgrade(None)
.text(None)
.text_parse_mode(None)
// ... +1 more optional fields;
let result = bot.send_gift(
gift_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send invoices. On success, the sent Message is returned.
SendInvoiceParams25 fields| Field | Type | Description |
|---|---|---|
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| provider_token | Option<String> | Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. |
| max_tip_amount | Option<i64> | The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars. |
| suggested_tip_amounts | Option<Vec<i64>> | A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. |
| start_parameter | Option<String> | Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter |
| provider_data | Option<String> | JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. |
| photo_url | Option<String> | URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for. |
| photo_size | Option<i64> | Photo size in bytes |
| photo_width | Option<i64> | Photo width |
| photo_height | Option<i64> | Photo height |
| need_name | Option<bool> | Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars. |
| need_phone_number | Option<bool> | Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars. |
| need_email | Option<bool> | Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars. |
| need_shipping_address | Option<bool> | Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars. |
| send_phone_number_to_provider | Option<bool> | Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars. |
| send_email_to_provider | Option<bool> | Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars. |
| is_flexible | Option<bool> | Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars. |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendInvoiceParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let title = "example";
let description = "example";
let payload = "example";
let currency = "example";
let prices = vec![] // Vec<LabeledPrice>;
// Optional parameters
let params = SendInvoiceParams::new()
.message_thread_id(None)
.direct_messages_topic_id(None)
.provider_token(None)
.max_tip_amount(None)
.suggested_tip_amounts(None)
// ... +20 more optional fields;
let result = bot.send_invoice(
chat_id,
title,
description,
payload,
currency,
prices,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send point on the map. On success, the sent Message is returned.
SendLocationParams14 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| horizontal_accuracy | Option<f64> | The radius of uncertainty for the location, measured in meters; 0-1500 |
| live_period | Option<i64> | Period in seconds during which the location will be updated (see Live Locations, should be between 60 and 86400, or 0x7FFFFFFF for live locations that can be edited indefinitely. |
| heading | Option<i64> | For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. |
| proximity_alert_radius | Option<i64> | For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendLocationParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let latitude = 0.0;
let longitude = 0.0;
// Optional parameters
let params = SendLocationParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.horizontal_accuracy(None)
.live_period(None)
// ... +9 more optional fields;
let result = bot.send_location(
chat_id,
latitude,
longitude,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Message objects that were sent is returned.
SendMediaGroupParams8 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the messages will be sent; required if the messages are sent to a direct messages chat |
| disable_notification | Option<bool> | Sends messages silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent messages from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendMediaGroupParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let media = todo!();
// Optional parameters
let params = SendMediaGroupParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.disable_notification(None)
.protect_content(None)
// ... +3 more optional fields;
let result = bot.send_media_group(
chat_id,
media,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send text messages. On success, the sent Message is returned.
SendMessageParams13 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| parse_mode | Option<String> | Mode for parsing entities in the message text. See formatting options for more details. |
| entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode |
| link_preview_options | Option<Box<LinkPreviewOptions>> | Link preview generation options for the message |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendMessageParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let text = "Hello from tgbotrs! 🦀";
// Optional parameters
let params = SendMessageParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.parse_mode(None)
.entities(None)
// ... +8 more optional fields;
let result = bot.send_message(
chat_id,
text,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to stream a partial message to a user while the message is being generated; supported only for bots with forum topic mode enabled. Returns True on success.
SendMessageDraftParams3 fields| Field | Type | Description |
|---|---|---|
| message_thread_id | Option<i64> | Unique identifier for the target message thread |
| parse_mode | Option<String> | Mode for parsing entities in the message text. See formatting options for more details. |
| entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendMessageDraftParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let draft_id = 0i64;
let text = "Hello from tgbotrs! 🦀";
// Optional parameters
let params = SendMessageDraftParams::new()
.message_thread_id(None)
.parse_mode(None)
.entities(None);
let result = bot.send_message_draft(
chat_id,
draft_id,
text,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send paid media. On success, the sent Message is returned.
SendPaidMediaParams14 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| payload | Option<String> | Bot-defined paid media payload, 0-128 bytes. This will not be displayed to the user, use it for your internal processes. |
| caption | Option<String> | Media caption, 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the media caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| show_caption_above_media | Option<bool> | Pass True, if the caption must be shown above the message media |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendPaidMediaParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let star_count = 0i64;
let media = vec![] // Vec<InputPaidMedia>;
// Optional parameters
let params = SendPaidMediaParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.payload(None)
.caption(None)
// ... +9 more optional fields;
let result = bot.send_paid_media(
chat_id,
star_count,
media,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send photos. On success, the sent Message is returned.
SendPhotoParams15 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| caption | Option<String> | Photo caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the photo caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| show_caption_above_media | Option<bool> | Pass True, if the caption must be shown above the message media |
| has_spoiler | Option<bool> | Pass True if the photo needs to be covered with a spoiler animation |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendPhotoParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let photo = todo!();
// Optional parameters
let params = SendPhotoParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.caption(None)
.parse_mode(None)
// ... +10 more optional fields;
let result = bot.send_photo(
chat_id,
photo,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send a native poll. On success, the sent Message is returned.
SendPollParams19 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| question_parse_mode | Option<String> | Mode for parsing entities in the question. See formatting options for more details. Currently, only custom emoji entities are allowed |
| question_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the poll question. It can be specified instead of question_parse_mode |
| is_anonymous | Option<bool> | True, if the poll needs to be anonymous, defaults to True |
| allows_multiple_answers | Option<bool> | True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False |
| correct_option_id | Option<i64> | 0-based identifier of the correct answer option, required for polls in quiz mode |
| explanation | Option<String> | Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing |
| explanation_parse_mode | Option<String> | Mode for parsing entities in the explanation. See formatting options for more details. |
| explanation_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the poll explanation. It can be specified instead of explanation_parse_mode |
| open_period | Option<i64> | Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date. |
| close_date | Option<i64> | Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period. |
| is_closed | Option<bool> | Pass True if the poll needs to be immediately closed. This can be useful for poll preview. |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendPollParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let question = "example";
let options = vec![] // Vec<InputPollOption>;
// Optional parameters
let params = SendPollParams::new()
.business_connection_id(None)
.message_thread_id(None)
.question_parse_mode(None)
.question_entities(None)
.is_anonymous(None)
// ... +14 more optional fields;
let result = bot.send_poll(
chat_id,
question,
options,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned.
SendStickerParams11 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| emoji | Option<String> | Emoji associated with the sticker; only for just uploaded stickers |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendStickerParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let sticker = todo!();
// Optional parameters
let params = SendStickerParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.emoji(None)
.disable_notification(None)
// ... +6 more optional fields;
let result = bot.send_sticker(
chat_id,
sticker,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send information about a venue. On success, the sent Message is returned.
SendVenueParams14 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| foursquare_id | Option<String> | Foursquare identifier of the venue |
| foursquare_type | Option<String> | Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) |
| google_place_id | Option<String> | Google Places identifier of the venue |
| google_place_type | Option<String> | Google Places type of the venue. (See supported types.) |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendVenueParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let latitude = 0.0;
let longitude = 0.0;
let title = "example";
let address = "example";
// Optional parameters
let params = SendVenueParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.foursquare_id(None)
.foursquare_type(None)
// ... +9 more optional fields;
let result = bot.send_venue(
chat_id,
latitude,
longitude,
title,
address,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
SendVideoParams22 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| duration | Option<i64> | Duration of sent video in seconds |
| width | Option<i64> | Video width |
| height | Option<i64> | Video height |
| thumbnail | Option<InputFileOrString> | Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files: https://core.telegram.org/bots/api#sending-files |
| cover | Option<InputFileOrString> | Cover for the video in the message. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>" to upload a new one using multipart/form-data under <file_attach_name> name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files |
| start_timestamp | Option<i64> | Start timestamp for the video in the message |
| caption | Option<String> | Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the video caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| show_caption_above_media | Option<bool> | Pass True, if the caption must be shown above the message media |
| has_spoiler | Option<bool> | Pass True if the video needs to be covered with a spoiler animation |
| supports_streaming | Option<bool> | Pass True if the uploaded video is suitable for streaming |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendVideoParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let video = todo!();
// Optional parameters
let params = SendVideoParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.duration(None)
.width(None)
// ... +17 more optional fields;
let result = bot.send_video(
chat_id,
video,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.
SendVideoNoteParams13 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| duration | Option<i64> | Duration of sent video in seconds |
| length | Option<i64> | Video width and height, i.e. diameter of the video message |
| thumbnail | Option<InputFileOrString> | Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files: https://core.telegram.org/bots/api#sending-files |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendVideoNoteParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let video_note = todo!();
// Optional parameters
let params = SendVideoNoteParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.duration(None)
.length(None)
// ... +8 more optional fields;
let result = bot.send_video_note(
chat_id,
video_note,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
SendVoiceParams14 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be sent |
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| caption | Option<String> | Voice message caption, 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the voice message caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| duration | Option<i64> | Duration of the voice message in seconds |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; for private chats only |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SendVoiceParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let voice = todo!();
// Optional parameters
let params = SendVoiceParams::new()
.business_connection_id(None)
.message_thread_id(None)
.direct_messages_topic_id(None)
.caption(None)
.parse_mode(None)
// ... +9 more optional fields;
let result = bot.send_voice(
chat_id,
voice,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Getting Info
29Returns the list of gifts that can be sent by the bot to users and channel chats. Requires no parameters. Returns a Gifts object.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.get_available_gifts().await?;
println!("Result: {result:?}");
Ok(())
}
Returns the gifts received and owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns OwnedGifts on success.
GetBusinessAccountGiftsParams10 fields| Field | Type | Description |
|---|---|---|
| exclude_unsaved | Option<bool> | Pass True to exclude gifts that aren't saved to the account's profile page |
| exclude_saved | Option<bool> | Pass True to exclude gifts that are saved to the account's profile page |
| exclude_unlimited | Option<bool> | Pass True to exclude gifts that can be purchased an unlimited number of times |
| exclude_limited_upgradable | Option<bool> | Pass True to exclude gifts that can be purchased a limited number of times and can be upgraded to unique |
| exclude_limited_non_upgradable | Option<bool> | Pass True to exclude gifts that can be purchased a limited number of times and can't be upgraded to unique |
| exclude_unique | Option<bool> | Pass True to exclude unique gifts |
| exclude_from_blockchain | Option<bool> | Pass True to exclude gifts that were assigned from the TON blockchain and can't be resold or transferred in Telegram |
| sort_by_price | Option<bool> | Pass True to sort results by gift price instead of send date. Sorting is applied before pagination. |
| offset | Option<String> | Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results |
| limit | Option<i64> | The maximum number of gifts to be returned; 1-100. Defaults to 100 |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetBusinessAccountGiftsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
// Optional parameters
let params = GetBusinessAccountGiftsParams::new()
.exclude_unsaved(None)
.exclude_saved(None)
.exclude_unlimited(None)
.exclude_limited_upgradable(None)
.exclude_limited_non_upgradable(None)
// ... +5 more optional fields;
let result = bot.get_business_account_gifts(
business_connection_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns StarAmount on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let result = bot.get_business_account_star_balance(
business_connection_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let result = bot.get_business_connection(
business_connection_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get up-to-date information about the chat. Returns a ChatFullInfo object on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.get_chat(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of ChatMember objects.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.get_chat_administrators(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Returns the gifts owned by a chat. Returns OwnedGifts on success.
GetChatGiftsParams10 fields| Field | Type | Description |
|---|---|---|
| exclude_unsaved | Option<bool> | Pass True to exclude gifts that aren't saved to the chat's profile page. Always True, unless the bot has the can_post_messages administrator right in the channel. |
| exclude_saved | Option<bool> | Pass True to exclude gifts that are saved to the chat's profile page. Always False, unless the bot has the can_post_messages administrator right in the channel. |
| exclude_unlimited | Option<bool> | Pass True to exclude gifts that can be purchased an unlimited number of times |
| exclude_limited_upgradable | Option<bool> | Pass True to exclude gifts that can be purchased a limited number of times and can be upgraded to unique |
| exclude_limited_non_upgradable | Option<bool> | Pass True to exclude gifts that can be purchased a limited number of times and can't be upgraded to unique |
| exclude_from_blockchain | Option<bool> | Pass True to exclude gifts that were assigned from the TON blockchain and can't be resold or transferred in Telegram |
| exclude_unique | Option<bool> | Pass True to exclude unique gifts |
| sort_by_price | Option<bool> | Pass True to sort results by gift price instead of send date. Sorting is applied before pagination. |
| offset | Option<String> | Offset of the first entry to return as received from the previous request; use an empty string to get the first chunk of results |
| limit | Option<i64> | The maximum number of gifts to be returned; 1-100. Defaults to 100 |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetChatGiftsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
// Optional parameters
let params = GetChatGiftsParams::new()
.exclude_unsaved(None)
.exclude_saved(None)
.exclude_unlimited(None)
.exclude_limited_upgradable(None)
.exclude_limited_non_upgradable(None)
// ... +5 more optional fields;
let result = bot.get_chat_gifts(
chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat. Returns a ChatMember object on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
let result = bot.get_chat_member(
chat_id,
user_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the number of members in a chat. Returns Int on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.get_chat_member_count(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let custom_emoji_ids = vec![] // Vec<String>;
let result = bot.get_custom_emoji_stickers(
custom_emoji_ids
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. /// Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let file_id = "example";
let result = bot.get_file(
file_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.get_forum_topic_icon_stickers().await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects.
GetGameHighScoresParams3 fields| Field | Type | Description |
|---|---|---|
| chat_id | Option<i64> | Required if inline_message_id is not specified. Unique identifier for the target chat |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the sent message |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetGameHighScoresParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
// Optional parameters
let params = GetGameHighScoresParams::new()
.chat_id(None)
.message_id(None)
.inline_message_id(None);
let result = bot.get_game_high_scores(
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.get_me().await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned.
GetMyCommandsParams2 fields| Field | Type | Description |
|---|---|---|
| scope | Option<Box<BotCommandScope>> | A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault. |
| language_code | Option<String> | A two-letter ISO 639-1 language code or an empty string |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetMyCommandsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetMyCommandsParams::new()
.scope(None)
.language_code(None);
let result = bot.get_my_commands(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
GetMyDefaultAdministratorRightsParams1 fields| Field | Type | Description |
|---|---|---|
| for_channels | Option<bool> | Pass True to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetMyDefaultAdministratorRightsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetMyDefaultAdministratorRightsParams::new()
.for_channels(None);
let result = bot.get_my_default_administrator_rights(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the current bot description for the given user language. Returns BotDescription on success.
GetMyDescriptionParams1 fields| Field | Type | Description |
|---|---|---|
| language_code | Option<String> | A two-letter ISO 639-1 language code or an empty string |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetMyDescriptionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetMyDescriptionParams::new()
.language_code(None);
let result = bot.get_my_description(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the current bot name for the given user language. Returns BotName on success.
GetMyNameParams1 fields| Field | Type | Description |
|---|---|---|
| language_code | Option<String> | A two-letter ISO 639-1 language code or an empty string |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetMyNameParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetMyNameParams::new()
.language_code(None);
let result = bot.get_my_name(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.
GetMyShortDescriptionParams1 fields| Field | Type | Description |
|---|---|---|
| language_code | Option<String> | A two-letter ISO 639-1 language code or an empty string |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetMyShortDescriptionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetMyShortDescriptionParams::new()
.language_code(None);
let result = bot.get_my_short_description(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
A method to get the current Telegram Stars balance of the bot. Requires no parameters. On success, returns a StarAmount object.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.get_my_star_balance().await?;
println!("Result: {result:?}");
Ok(())
}
Returns the bot's Telegram Star transactions in chronological order. On success, returns a StarTransactions object.
GetStarTransactionsParams2 fields| Field | Type | Description |
|---|---|---|
| offset | Option<i64> | Number of transactions to skip in the response |
| limit | Option<i64> | The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetStarTransactionsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetStarTransactionsParams::new()
.offset(None)
.limit(None);
let result = bot.get_star_transactions(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get a sticker set. On success, a StickerSet object is returned.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let name = "my_name";
let result = bot.get_sticker_set(
name
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to receive incoming updates using long polling (wiki). Returns an Array of Update objects.
GetUpdatesParams4 fields| Field | Type | Description |
|---|---|---|
| offset | Option<i64> | Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will be forgotten. |
| limit | Option<i64> | Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100. |
| timeout | Option<i64> | Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only. |
| allowed_updates | Option<Vec<String>> | A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to getUpdates, so unwanted updates may be received for a short period of time. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetUpdatesParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = GetUpdatesParams::new()
.offset(None)
.limit(None)
.timeout(None)
.allowed_updates(None);
let result = bot.get_updates(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
let result = bot.get_user_chat_boosts(
chat_id,
user_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Returns the gifts owned and hosted by a user. Returns OwnedGifts on success.
GetUserGiftsParams8 fields| Field | Type | Description |
|---|---|---|
| exclude_unlimited | Option<bool> | Pass True to exclude gifts that can be purchased an unlimited number of times |
| exclude_limited_upgradable | Option<bool> | Pass True to exclude gifts that can be purchased a limited number of times and can be upgraded to unique |
| exclude_limited_non_upgradable | Option<bool> | Pass True to exclude gifts that can be purchased a limited number of times and can't be upgraded to unique |
| exclude_from_blockchain | Option<bool> | Pass True to exclude gifts that were assigned from the TON blockchain and can't be resold or transferred in Telegram |
| exclude_unique | Option<bool> | Pass True to exclude unique gifts |
| sort_by_price | Option<bool> | Pass True to sort results by gift price instead of send date. Sorting is applied before pagination. |
| offset | Option<String> | Offset of the first entry to return as received from the previous request; use an empty string to get the first chunk of results |
| limit | Option<i64> | The maximum number of gifts to be returned; 1-100. Defaults to 100 |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetUserGiftsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
// Optional parameters
let params = GetUserGiftsParams::new()
.exclude_unlimited(None)
.exclude_limited_upgradable(None)
.exclude_limited_non_upgradable(None)
.exclude_from_blockchain(None)
.exclude_unique(None)
// ... +3 more optional fields;
let result = bot.get_user_gifts(
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get a list of profile audios for a user. Returns a UserProfileAudios object.
GetUserProfileAudiosParams2 fields| Field | Type | Description |
|---|---|---|
| offset | Option<i64> | Sequential number of the first audio to be returned. By default, all audios are returned. |
| limit | Option<i64> | Limits the number of audios to be retrieved. Values between 1-100 are accepted. Defaults to 100. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetUserProfileAudiosParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
// Optional parameters
let params = GetUserProfileAudiosParams::new()
.offset(None)
.limit(None);
let result = bot.get_user_profile_audios(
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
GetUserProfilePhotosParams2 fields| Field | Type | Description |
|---|---|---|
| offset | Option<i64> | Sequential number of the first photo to be returned. By default, all photos are returned. |
| limit | Option<i64> | Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{GetUserProfilePhotosParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
// Optional parameters
let params = GetUserProfilePhotosParams::new()
.offset(None)
.limit(None);
let result = bot.get_user_profile_photos(
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.get_webhook_info().await?;
println!("Result: {result:?}");
Ok(())
}
Editing
12Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a ChatInviteLink object.
EditChatInviteLinkParams4 fields| Field | Type | Description |
|---|---|---|
| name | Option<String> | Invite link name; 0-32 characters |
| expire_date | Option<i64> | Point in time (Unix timestamp) when the link will expire |
| member_limit | Option<i64> | The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 |
| creates_join_request | Option<bool> | True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditChatInviteLinkParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let invite_link = "example";
// Optional parameters
let params = EditChatInviteLinkParams::new()
.name(None)
.expire_date(None)
.member_limit(None)
.creates_join_request(None);
let result = bot.edit_chat_invite_link(
chat_id,
invite_link,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
EditChatSubscriptionInviteLinkParams1 fields| Field | Type | Description |
|---|---|---|
| name | Option<String> | Invite link name; 0-32 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditChatSubscriptionInviteLinkParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let invite_link = "example";
// Optional parameters
let params = EditChatSubscriptionInviteLinkParams::new()
.name(None);
let result = bot.edit_chat_subscription_invite_link(
chat_id,
invite_link,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit name and icon of a topic in a forum supergroup chat or a private chat with a user. In the case of a supergroup chat the bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
EditForumTopicParams2 fields| Field | Type | Description |
|---|---|---|
| name | Option<String> | New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept |
| icon_custom_emoji_id | Option<String> | New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditForumTopicParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_thread_id = 0i64;
// Optional parameters
let params = EditForumTopicParams::new()
.name(None)
.icon_custom_emoji_id(None);
let result = bot.edit_forum_topic(
chat_id,
message_thread_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let name = "my_name";
let result = bot.edit_general_forum_topic(
chat_id,
name
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit captions of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
EditMessageCaptionParams9 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| chat_id | Option<ChatId> | Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the message to edit |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
| caption | Option<String> | New caption of the message, 0-1024 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the message caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| show_caption_above_media | Option<bool> | Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages. |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for an inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditMessageCaptionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = EditMessageCaptionParams::new()
.business_connection_id(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None)
.caption(None)
// ... +4 more optional fields;
let result = bot.edit_message_caption(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit a checklist on behalf of a connected business account. On success, the edited Message is returned.
EditMessageChecklistParams1 fields| Field | Type | Description |
|---|---|---|
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for the new inline keyboard for the message |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditMessageChecklistParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let chat_id = 123456789i64;
let message_id = 0i64;
let checklist = InputChecklist::default();
// Optional parameters
let params = EditMessageChecklistParams::new()
.reply_markup(None);
let result = bot.edit_message_checklist(
business_connection_id,
chat_id,
message_id,
checklist,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
EditMessageLiveLocationParams9 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| chat_id | Option<ChatId> | Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the message to edit |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
| live_period | Option<i64> | New period in seconds during which the location can be updated, starting from the message send date. If 0x7FFFFFFF is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current live_period by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then live_period remains unchanged |
| horizontal_accuracy | Option<f64> | The radius of uncertainty for the location, measured in meters; 0-1500 |
| heading | Option<i64> | Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. |
| proximity_alert_radius | Option<i64> | The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for a new inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditMessageLiveLocationParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let latitude = 0.0;
let longitude = 0.0;
// Optional parameters
let params = EditMessageLiveLocationParams::new()
.business_connection_id(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None)
.live_period(None)
// ... +4 more optional fields;
let result = bot.edit_message_live_location(
latitude,
longitude,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
EditMessageMediaParams5 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| chat_id | Option<ChatId> | Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the message to edit |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for a new inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditMessageMediaParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let media = todo!();
// Optional parameters
let params = EditMessageMediaParams::new()
.business_connection_id(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None)
.reply_markup(None);
let result = bot.edit_message_media(
media,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
EditMessageReplyMarkupParams5 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| chat_id | Option<ChatId> | Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the message to edit |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for an inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditMessageReplyMarkupParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = EditMessageReplyMarkupParams::new()
.business_connection_id(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None)
.reply_markup(None);
let result = bot.edit_message_reply_markup(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
EditMessageTextParams8 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| chat_id | Option<ChatId> | Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the message to edit |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
| parse_mode | Option<String> | Mode for parsing entities in the message text. See formatting options for more details. |
| entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode |
| link_preview_options | Option<Box<LinkPreviewOptions>> | Link preview generation options for the message |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for an inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditMessageTextParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let text = "Hello from tgbotrs! 🦀";
// Optional parameters
let params = EditMessageTextParams::new()
.business_connection_id(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None)
.parse_mode(None)
// ... +3 more optional fields;
let result = bot.edit_message_text(
text,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Edits a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.
EditStoryParams4 fields| Field | Type | Description |
|---|---|---|
| caption | Option<String> | Caption of the story, 0-2048 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the story caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| areas | Option<Vec<StoryArea>> | A JSON-serialized list of clickable areas to be shown on the story |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{EditStoryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let story_id = 0i64;
let content = InputStoryContent::default();
// Optional parameters
let params = EditStoryParams::new()
.caption(None)
.parse_mode(None)
.caption_entities(None)
.areas(None);
let result = bot.edit_story(
business_connection_id,
story_id,
content,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let telegram_payment_charge_id = "example";
let is_canceled = true;
let result = bot.edit_user_star_subscription(
user_id,
telegram_payment_charge_id,
is_canceled
).await?;
println!("Result: {result:?}");
Ok(())
}
Deletion
11Delete messages on behalf of a business account. Requires the can_delete_sent_messages business bot right to delete messages sent by the bot itself, or the can_delete_all_messages business bot right to delete any message. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let message_ids = vec![] // Vec<i64>;
let result = bot.delete_business_messages(
business_connection_id,
message_ids
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.delete_chat_photo(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.delete_chat_sticker_set(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete a forum topic along with all its messages in a forum supergroup chat or a private chat with a user. In the case of a supergroup chat the bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_thread_id = 0i64;
let result = bot.delete_forum_topic(
chat_id,
message_thread_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete a message, including service messages, with the following limitations: /// - A message can only be deleted if it was sent less than 48 hours ago. /// - Service messages about a supergroup, channel, or forum topic creation can't be deleted. /// - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago. /// - Bots can delete outgoing messages in private chats, groups, and supergroups. /// - Bots can delete incoming messages in private chats. /// - Bots granted can_post_messages permissions can delete outgoing messages in channels. /// - If the bot is an administrator of a group, it can delete any message there. /// - If the bot has can_delete_messages administrator right in a supergroup or a channel, it can delete any message there. /// - If the bot has can_manage_direct_messages administrator right in a channel, it can delete any message in the corresponding direct messages chat. /// Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_id = 0i64;
let result = bot.delete_message(
chat_id,
message_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete multiple messages simultaneously. If some of the specified messages can't be found, they are skipped. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_ids = vec![] // Vec<i64>;
let result = bot.delete_messages(
chat_id,
message_ids
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success.
DeleteMyCommandsParams2 fields| Field | Type | Description |
|---|---|---|
| scope | Option<Box<BotCommandScope>> | A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault. |
| language_code | Option<String> | A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{DeleteMyCommandsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = DeleteMyCommandsParams::new()
.scope(None)
.language_code(None);
let result = bot.delete_my_commands(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete a sticker from a set created by the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let sticker = "example";
let result = bot.delete_sticker_from_set(
sticker
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to delete a sticker set that was created by the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let name = "my_name";
let result = bot.delete_sticker_set(
name
).await?;
println!("Result: {result:?}");
Ok(())
}
Deletes a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let story_id = 0i64;
let result = bot.delete_story(
business_connection_id,
story_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.
DeleteWebhookParams1 fields| Field | Type | Description |
|---|---|---|
| drop_pending_updates | Option<bool> | Pass True to drop all pending updates |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{DeleteWebhookParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = DeleteWebhookParams::new()
.drop_pending_updates(None);
let result = bot.delete_webhook(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Forwarding & Copying
4Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
CopyMessageParams14 fields| Field | Type | Description |
|---|---|---|
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat |
| video_start_timestamp | Option<i64> | New start timestamp for the copied video in the message |
| caption | Option<String> | New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept |
| parse_mode | Option<String> | Mode for parsing entities in the new caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parse_mode |
| show_caption_above_media | Option<bool> | Pass True, if the caption must be shown above the message media. Ignored if a new caption isn't specified. |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent message from forwarding and saving |
| allow_paid_broadcast | Option<bool> | Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; only available when copying to private chats |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined. |
| reply_parameters | Option<Box<ReplyParameters>> | Description of the message to reply to |
| reply_markup | Option<ReplyMarkup> | Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CopyMessageParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let from_chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = CopyMessageParams::new()
.message_thread_id(None)
.direct_messages_topic_id(None)
.video_start_timestamp(None)
.caption(None)
.parse_mode(None)
// ... +9 more optional fields;
let result = bot.copy_message(
chat_id,
from_chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
CopyMessagesParams5 fields| Field | Type | Description |
|---|---|---|
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the messages will be sent; required if the messages are sent to a direct messages chat |
| disable_notification | Option<bool> | Sends the messages silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the sent messages from forwarding and saving |
| remove_caption | Option<bool> | Pass True to copy the messages without their captions |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CopyMessagesParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let from_chat_id = 123456789i64;
let message_ids = vec![] // Vec<i64>;
// Optional parameters
let params = CopyMessagesParams::new()
.message_thread_id(None)
.direct_messages_topic_id(None)
.disable_notification(None)
.protect_content(None)
.remove_caption(None);
let result = bot.copy_messages(
chat_id,
from_chat_id,
message_ids,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned.
ForwardMessageParams7 fields| Field | Type | Description |
|---|---|---|
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the message will be forwarded; required if the message is forwarded to a direct messages chat |
| video_start_timestamp | Option<i64> | New start timestamp for the forwarded video in the message |
| disable_notification | Option<bool> | Sends the message silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the forwarded message from forwarding and saving |
| message_effect_id | Option<String> | Unique identifier of the message effect to be added to the message; only available when forwarding to private chats |
| suggested_post_parameters | Option<Box<SuggestedPostParameters>> | A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{ForwardMessageParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let from_chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = ForwardMessageParams::new()
.message_thread_id(None)
.direct_messages_topic_id(None)
.video_start_timestamp(None)
.disable_notification(None)
.protect_content(None)
// ... +2 more optional fields;
let result = bot.forward_message(
chat_id,
from_chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned.
ForwardMessagesParams4 fields| Field | Type | Description |
|---|---|---|
| message_thread_id | Option<i64> | Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only |
| direct_messages_topic_id | Option<i64> | Identifier of the direct messages topic to which the messages will be forwarded; required if the messages are forwarded to a direct messages chat |
| disable_notification | Option<bool> | Sends the messages silently. Users will receive a notification with no sound. |
| protect_content | Option<bool> | Protects the contents of the forwarded messages from forwarding and saving |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{ForwardMessagesParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let from_chat_id = 123456789i64;
let message_ids = vec![] // Vec<i64>;
// Optional parameters
let params = ForwardMessagesParams::new()
.message_thread_id(None)
.direct_messages_topic_id(None)
.disable_notification(None)
.protect_content(None);
let result = bot.forward_messages(
chat_id,
from_chat_id,
message_ids,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Answering Queries
5Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.
AnswerCallbackQueryParams4 fields| Field | Type | Description |
|---|---|---|
| text | Option<String> | Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters |
| show_alert | Option<bool> | If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. |
| url | Option<String> | URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from a callback_game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter. |
| cache_time | Option<i64> | The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{AnswerCallbackQueryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let callback_query_id = "example";
// Optional parameters
let params = AnswerCallbackQueryParams::new()
.text(None)
.show_alert(None)
.url(None)
.cache_time(None);
let result = bot.answer_callback_query(
callback_query_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to send answers to an inline query. On success, True is returned. /// No more than 50 results per query are allowed.
AnswerInlineQueryParams4 fields| Field | Type | Description |
|---|---|---|
| cache_time | Option<i64> | The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300. |
| is_personal | Option<bool> | Pass True if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query. |
| next_offset | Option<String> | Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes. |
| button | Option<Box<InlineQueryResultsButton>> | A JSON-serialized object describing a button to be shown above inline query results |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{AnswerInlineQueryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let inline_query_id = "example";
let results = vec![] // Vec<InlineQueryResult>;
// Optional parameters
let params = AnswerInlineQueryParams::new()
.cache_time(None)
.is_personal(None)
.next_offset(None)
.button(None);
let result = bot.answer_inline_query(
inline_query_id,
results,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
AnswerPreCheckoutQueryParams1 fields| Field | Type | Description |
|---|---|---|
| error_message | Option<String> | Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{AnswerPreCheckoutQueryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let pre_checkout_query_id = "example";
let ok = true;
// Optional parameters
let params = AnswerPreCheckoutQueryParams::new()
.error_message(None);
let result = bot.answer_pre_checkout_query(
pre_checkout_query_id,
ok,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
AnswerShippingQueryParams2 fields| Field | Type | Description |
|---|---|---|
| shipping_options | Option<Vec<ShippingOption>> | Required if ok is True. A JSON-serialized array of available shipping options. |
| error_message | Option<String> | Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable"). Telegram will display this message to the user. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{AnswerShippingQueryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let shipping_query_id = "example";
let ok = true;
// Optional parameters
let params = AnswerShippingQueryParams::new()
.shipping_options(None)
.error_message(None);
let result = bot.answer_shipping_query(
shipping_query_id,
ok,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let web_app_query_id = "example";
let result = InlineQueryResult::default();
let result = bot.answer_web_app_query(
web_app_query_id,
result
).await?;
println!("Result: {result:?}");
Ok(())
}
Chat Administration
6Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
BanChatMemberParams2 fields| Field | Type | Description |
|---|---|---|
| until_date | Option<i64> | Date when the user will be unbanned; Unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only. |
| revoke_messages | Option<bool> | Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{BanChatMemberParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
// Optional parameters
let params = BanChatMemberParams::new()
.until_date(None)
.revoke_messages(None);
let result = bot.ban_chat_member(
chat_id,
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let sender_chat_id = 123456789i64;
let result = bot.ban_chat_sender_chat(
chat_id,
sender_chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Pass False for all boolean parameters to demote a user. Returns True on success.
PromoteChatMemberParams16 fields| Field | Type | Description |
|---|---|---|
| is_anonymous | Option<bool> | Pass True if the administrator's presence in the chat is hidden |
| can_manage_chat | Option<bool> | Pass True if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages, ignore slow mode, and send messages to the chat without paying Telegram Stars. Implied by any other administrator privilege. |
| can_delete_messages | Option<bool> | Pass True if the administrator can delete messages of other users |
| can_manage_video_chats | Option<bool> | Pass True if the administrator can manage video chats |
| can_restrict_members | Option<bool> | Pass True if the administrator can restrict, ban or unban chat members, or access supergroup statistics. For backward compatibility, defaults to True for promotions of channel administrators |
| can_promote_members | Option<bool> | Pass True if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by him) |
| can_change_info | Option<bool> | Pass True if the administrator can change chat title, photo and other settings |
| can_invite_users | Option<bool> | Pass True if the administrator can invite new users to the chat |
| can_post_stories | Option<bool> | Pass True if the administrator can post stories to the chat |
| can_edit_stories | Option<bool> | Pass True if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive |
| can_delete_stories | Option<bool> | Pass True if the administrator can delete stories posted by other users |
| can_post_messages | Option<bool> | Pass True if the administrator can post messages in the channel, approve suggested posts, or access channel statistics; for channels only |
| can_edit_messages | Option<bool> | Pass True if the administrator can edit messages of other users and can pin messages; for channels only |
| can_pin_messages | Option<bool> | Pass True if the administrator can pin messages; for supergroups only |
| can_manage_topics | Option<bool> | Pass True if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only |
| can_manage_direct_messages | Option<bool> | Pass True if the administrator can manage direct messages within the channel and decline suggested posts; for channels only |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{PromoteChatMemberParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
// Optional parameters
let params = PromoteChatMemberParams::new()
.is_anonymous(None)
.can_manage_chat(None)
.can_delete_messages(None)
.can_manage_video_chats(None)
.can_restrict_members(None)
// ... +11 more optional fields;
let result = bot.promote_chat_member(
chat_id,
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.
RestrictChatMemberParams2 fields| Field | Type | Description |
|---|---|---|
| use_independent_chat_permissions | Option<bool> | Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission. |
| until_date | Option<i64> | Date when restrictions will be lifted for the user; Unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{RestrictChatMemberParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
let permissions = ChatPermissions::default();
// Optional parameters
let params = RestrictChatMemberParams::new()
.use_independent_chat_permissions(None)
.until_date(None);
let result = bot.restrict_chat_member(
chat_id,
user_id,
permissions,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to unban a previously banned user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don't want this, use the parameter only_if_banned. Returns True on success.
UnbanChatMemberParams1 fields| Field | Type | Description |
|---|---|---|
| only_if_banned | Option<bool> | Do nothing if the user is not banned |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{UnbanChatMemberParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
// Optional parameters
let params = UnbanChatMemberParams::new()
.only_if_banned(None);
let result = bot.unban_chat_member(
chat_id,
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let sender_chat_id = 123456789i64;
let result = bot.unban_chat_sender_chat(
chat_id,
sender_chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Invite & Membership
10Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
let result = bot.approve_chat_join_request(
chat_id,
user_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to approve a suggested post in a direct messages chat. The bot must have the 'can_post_messages' administrator right in the corresponding channel chat. Returns True on success.
ApproveSuggestedPostParams1 fields| Field | Type | Description |
|---|---|---|
| send_date | Option<i64> | Point in time (Unix timestamp) when the post is expected to be published; omit if the date has already been specified when the suggested post was created. If specified, then the date must be not more than 2678400 seconds (30 days) in the future |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{ApproveSuggestedPostParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = ApproveSuggestedPostParams::new()
.send_date(None);
let result = bot.approve_suggested_post(
chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
CreateChatInviteLinkParams4 fields| Field | Type | Description |
|---|---|---|
| name | Option<String> | Invite link name; 0-32 characters |
| expire_date | Option<i64> | Point in time (Unix timestamp) when the link will expire |
| member_limit | Option<i64> | The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 |
| creates_join_request | Option<bool> | True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CreateChatInviteLinkParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
// Optional parameters
let params = CreateChatInviteLinkParams::new()
.name(None)
.expire_date(None)
.member_limit(None)
.creates_join_request(None);
let result = bot.create_chat_invite_link(
chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
CreateChatSubscriptionInviteLinkParams1 fields| Field | Type | Description |
|---|---|---|
| name | Option<String> | Invite link name; 0-32 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CreateChatSubscriptionInviteLinkParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let subscription_period = 0i64;
let subscription_price = 0i64;
// Optional parameters
let params = CreateChatSubscriptionInviteLinkParams::new()
.name(None);
let result = bot.create_chat_subscription_invite_link(
chat_id,
subscription_period,
subscription_price,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to create a topic in a forum supergroup chat or a private chat with a user. In the case of a supergroup chat the bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator right. Returns information about the created topic as a ForumTopic object.
CreateForumTopicParams2 fields| Field | Type | Description |
|---|---|---|
| icon_color | Option<i64> | Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) |
| icon_custom_emoji_id | Option<String> | Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CreateForumTopicParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let name = "my_name";
// Optional parameters
let params = CreateForumTopicParams::new()
.icon_color(None)
.icon_custom_emoji_id(None);
let result = bot.create_forum_topic(
chat_id,
name,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to create a link for an invoice. Returns the created invoice link as String on success.
CreateInvoiceLinkParams17 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the link will be created. For payments in Telegram Stars only. |
| provider_token | Option<String> | Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. |
| subscription_period | Option<i64> | The number of seconds the subscription will be active for before the next payment. The currency must be set to "XTR" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must no exceed 10000 Telegram Stars. |
| max_tip_amount | Option<i64> | The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars. |
| suggested_tip_amounts | Option<Vec<i64>> | A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. |
| provider_data | Option<String> | JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. |
| photo_url | Option<String> | URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. |
| photo_size | Option<i64> | Photo size in bytes |
| photo_width | Option<i64> | Photo width |
| photo_height | Option<i64> | Photo height |
| need_name | Option<bool> | Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars. |
| need_phone_number | Option<bool> | Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars. |
| need_email | Option<bool> | Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars. |
| need_shipping_address | Option<bool> | Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars. |
| send_phone_number_to_provider | Option<bool> | Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars. |
| send_email_to_provider | Option<bool> | Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars. |
| is_flexible | Option<bool> | Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CreateInvoiceLinkParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let title = "example";
let description = "example";
let payload = "example";
let currency = "example";
let prices = vec![] // Vec<LabeledPrice>;
// Optional parameters
let params = CreateInvoiceLinkParams::new()
.business_connection_id(None)
.provider_token(None)
.subscription_period(None)
.max_tip_amount(None)
.suggested_tip_amounts(None)
// ... +12 more optional fields;
let result = bot.create_invoice_link(
title,
description,
payload,
currency,
prices,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. Returns True on success.
CreateNewStickerSetParams2 fields| Field | Type | Description |
|---|---|---|
| sticker_type | Option<String> | Type of stickers in the set, pass "regular", "mask", or "custom_emoji". By default, a regular sticker set is created. |
| needs_repainting | Option<bool> | Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{CreateNewStickerSetParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let name = "my_name";
let title = "example";
let stickers = vec![] // Vec<InputSticker>;
// Optional parameters
let params = CreateNewStickerSetParams::new()
.sticker_type(None)
.needs_repainting(None);
let result = bot.create_new_sticker_set(
user_id,
name,
title,
stickers,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
let result = bot.decline_chat_join_request(
chat_id,
user_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to decline a suggested post in a direct messages chat. The bot must have the 'can_manage_direct_messages' administrator right in the corresponding channel chat. Returns True on success.
DeclineSuggestedPostParams1 fields| Field | Type | Description |
|---|---|---|
| comment | Option<String> | Comment for the creator of the suggested post; 0-128 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{DeclineSuggestedPostParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = DeclineSuggestedPostParams::new()
.comment(None);
let result = bot.decline_suggested_post(
chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let invite_link = "example";
let result = bot.revoke_chat_invite_link(
chat_id,
invite_link
).await?;
println!("Result: {result:?}");
Ok(())
}
Pinning
5Use this method to add a message to the list of pinned messages in a chat. In private chats and channel direct messages chats, all non-service messages can be pinned. Conversely, the bot must be an administrator with the 'can_pin_messages' right or the 'can_edit_messages' right to pin messages in groups and channels respectively. Returns True on success.
PinChatMessageParams2 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be pinned |
| disable_notification | Option<bool> | Pass True if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{PinChatMessageParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = PinChatMessageParams::new()
.business_connection_id(None)
.disable_notification(None);
let result = bot.pin_chat_message(
chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to clear the list of pinned messages in a chat. In private chats and channel direct messages chats, no additional rights are required to unpin all pinned messages. Conversely, the bot must be an administrator with the 'can_pin_messages' right or the 'can_edit_messages' right to unpin all pinned messages in groups and channels respectively. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.unpin_all_chat_messages(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to clear the list of pinned messages in a forum topic in a forum supergroup chat or a private chat with a user. In the case of a supergroup chat the bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_thread_id = 0i64;
let result = bot.unpin_all_forum_topic_messages(
chat_id,
message_thread_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.unpin_all_general_forum_topic_messages(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to remove a message from the list of pinned messages in a chat. In private chats and channel direct messages chats, all messages can be unpinned. Conversely, the bot must be an administrator with the 'can_pin_messages' right or the 'can_edit_messages' right to unpin messages in groups and channels respectively. Returns True on success.
UnpinChatMessageParams2 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message will be unpinned |
| message_id | Option<i64> | Identifier of the message to unpin. Required if business_connection_id is specified. If not specified, the most recent pinned message (by sending date) will be unpinned. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{UnpinChatMessageParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
// Optional parameters
let params = UnpinChatMessageParams::new()
.business_connection_id(None)
.message_id(None);
let result = bot.unpin_chat_message(
chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Configuration
30Changes the bio of a managed business account. Requires the can_change_bio business bot right. Returns True on success.
SetBusinessAccountBioParams1 fields| Field | Type | Description |
|---|---|---|
| bio | Option<String> | The new value of the bio for the business account; 0-140 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetBusinessAccountBioParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
// Optional parameters
let params = SetBusinessAccountBioParams::new()
.bio(None);
let result = bot.set_business_account_bio(
business_connection_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Changes the privacy settings pertaining to incoming gifts in a managed business account. Requires the can_change_gift_settings business bot right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let show_gift_button = true;
let accepted_gift_types = AcceptedGiftTypes::default();
let result = bot.set_business_account_gift_settings(
business_connection_id,
show_gift_button,
accepted_gift_types
).await?;
println!("Result: {result:?}");
Ok(())
}
Changes the first and last name of a managed business account. Requires the can_change_name business bot right. Returns True on success.
SetBusinessAccountNameParams1 fields| Field | Type | Description |
|---|---|---|
| last_name | Option<String> | The new value of the last name for the business account; 0-64 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetBusinessAccountNameParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let first_name = "my_name";
// Optional parameters
let params = SetBusinessAccountNameParams::new()
.last_name(None);
let result = bot.set_business_account_name(
business_connection_id,
first_name,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.
SetBusinessAccountProfilePhotoParams1 fields| Field | Type | Description |
|---|---|---|
| is_public | Option<bool> | Pass True to set the public photo, which will be visible even if the main photo is hidden by the business account's privacy settings. An account can have only one public photo. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetBusinessAccountProfilePhotoParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let photo = InputProfilePhoto::default();
// Optional parameters
let params = SetBusinessAccountProfilePhotoParams::new()
.is_public(None);
let result = bot.set_business_account_profile_photo(
business_connection_id,
photo,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Changes the username of a managed business account. Requires the can_change_username business bot right. Returns True on success.
SetBusinessAccountUsernameParams1 fields| Field | Type | Description |
|---|---|---|
| username | Option<String> | The new value of the username for the business account; 0-32 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetBusinessAccountUsernameParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
// Optional parameters
let params = SetBusinessAccountUsernameParams::new()
.username(None);
let result = bot.set_business_account_username(
business_connection_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let user_id = 123456789i64;
let custom_title = "example";
let result = bot.set_chat_administrator_custom_title(
chat_id,
user_id,
custom_title
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
SetChatDescriptionParams1 fields| Field | Type | Description |
|---|---|---|
| description | Option<String> | New chat description, 0-255 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetChatDescriptionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
// Optional parameters
let params = SetChatDescriptionParams::new()
.description(None);
let result = bot.set_chat_description(
chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
SetChatPermissionsParams1 fields| Field | Type | Description |
|---|---|---|
| use_independent_chat_permissions | Option<bool> | Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetChatPermissionsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let permissions = ChatPermissions::default();
// Optional parameters
let params = SetChatPermissionsParams::new()
.use_independent_chat_permissions(None);
let result = bot.set_chat_permissions(
chat_id,
permissions,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let photo = InputFile::default();
let result = bot.set_chat_photo(
chat_id,
photo
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let sticker_set_name = "my_name";
let result = bot.set_chat_sticker_set(
chat_id,
sticker_set_name
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let title = "example";
let result = bot.set_chat_title(
chat_id,
title
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success.
SetCustomEmojiStickerSetThumbnailParams1 fields| Field | Type | Description |
|---|---|---|
| custom_emoji_id | Option<String> | Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetCustomEmojiStickerSetThumbnailParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let name = "my_name";
// Optional parameters
let params = SetCustomEmojiStickerSetThumbnailParams::new()
.custom_emoji_id(None);
let result = bot.set_custom_emoji_sticker_set_thumbnail(
name,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set the score of the specified user in a game message. On success, if the message is not an inline message, the Message is returned, otherwise True is returned. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
SetGameScoreParams5 fields| Field | Type | Description |
|---|---|---|
| force | Option<bool> | Pass True if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters |
| disable_edit_message | Option<bool> | Pass True if the game message should not be automatically edited to include the current scoreboard |
| chat_id | Option<i64> | Required if inline_message_id is not specified. Unique identifier for the target chat |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the sent message |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetGameScoreParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let score = 0i64;
// Optional parameters
let params = SetGameScoreParams::new()
.force(None)
.disable_edit_message(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None);
let result = bot.set_game_score(
user_id,
score,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the chosen reactions on a message. Service messages of some types can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
SetMessageReactionParams2 fields| Field | Type | Description |
|---|---|---|
| reaction | Option<Vec<ReactionType>> | A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots. |
| is_big | Option<bool> | Pass True to set the reaction with a big animation |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetMessageReactionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = SetMessageReactionParams::new()
.reaction(None)
.is_big(None);
let result = bot.set_message_reaction(
chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the list of the bot's commands. See this manual for more details about bot commands. Returns True on success.
SetMyCommandsParams2 fields| Field | Type | Description |
|---|---|---|
| scope | Option<Box<BotCommandScope>> | A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault. |
| language_code | Option<String> | A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetMyCommandsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let commands = vec![] // Vec<BotCommand>;
// Optional parameters
let params = SetMyCommandsParams::new()
.scope(None)
.language_code(None);
let result = bot.set_my_commands(
commands,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are free to modify the list before adding the bot. Returns True on success.
SetMyDefaultAdministratorRightsParams2 fields| Field | Type | Description |
|---|---|---|
| rights | Option<Box<ChatAdministratorRights>> | A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared. |
| for_channels | Option<bool> | Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetMyDefaultAdministratorRightsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = SetMyDefaultAdministratorRightsParams::new()
.rights(None)
.for_channels(None);
let result = bot.set_my_default_administrator_rights(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. Returns True on success.
SetMyDescriptionParams2 fields| Field | Type | Description |
|---|---|---|
| description | Option<String> | New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language. |
| language_code | Option<String> | A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetMyDescriptionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = SetMyDescriptionParams::new()
.description(None)
.language_code(None);
let result = bot.set_my_description(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the bot's name. Returns True on success.
SetMyNameParams2 fields| Field | Type | Description |
|---|---|---|
| name | Option<String> | New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language. |
| language_code | Option<String> | A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetMyNameParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = SetMyNameParams::new()
.name(None)
.language_code(None);
let result = bot.set_my_name(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Changes the profile photo of the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let photo = InputProfilePhoto::default();
let result = bot.set_my_profile_photo(
photo
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. Returns True on success.
SetMyShortDescriptionParams2 fields| Field | Type | Description |
|---|---|---|
| short_description | Option<String> | New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language. |
| language_code | Option<String> | A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetMyShortDescriptionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = SetMyShortDescriptionParams::new()
.short_description(None)
.language_code(None);
let result = bot.set_my_short_description(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success. /// Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let errors = vec![] // Vec<PassportElementError>;
let result = bot.set_passport_data_errors(
user_id,
errors
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let sticker = "example";
let emoji_list = vec![] // Vec<String>;
let result = bot.set_sticker_emoji_list(
sticker,
emoji_list
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.
SetStickerKeywordsParams1 fields| Field | Type | Description |
|---|---|---|
| keywords | Option<Vec<String>> | A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetStickerKeywordsParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let sticker = "example";
// Optional parameters
let params = SetStickerKeywordsParams::new()
.keywords(None);
let result = bot.set_sticker_keywords(
sticker,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success.
SetStickerMaskPositionParams1 fields| Field | Type | Description |
|---|---|---|
| mask_position | Option<Box<MaskPosition>> | A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetStickerMaskPositionParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let sticker = "example";
// Optional parameters
let params = SetStickerMaskPositionParams::new()
.mask_position(None);
let result = bot.set_sticker_mask_position(
sticker,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let sticker = "example";
let position = 0i64;
let result = bot.set_sticker_position_in_set(
sticker,
position
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set. Returns True on success.
SetStickerSetThumbnailParams1 fields| Field | Type | Description |
|---|---|---|
| thumbnail | Option<InputFileOrString> | A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animation-requirements for animated sticker technical requirements), or a .WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetStickerSetThumbnailParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let name = "my_name";
let user_id = 123456789i64;
let format = "example";
// Optional parameters
let params = SetStickerSetThumbnailParams::new()
.thumbnail(None);
let result = bot.set_sticker_set_thumbnail(
name,
user_id,
format,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to set the title of a created sticker set. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let name = "my_name";
let title = "example";
let result = bot.set_sticker_set_title(
name,
title
).await?;
println!("Result: {result:?}");
Ok(())
}
Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. Returns True on success.
SetUserEmojiStatusParams2 fields| Field | Type | Description |
|---|---|---|
| emoji_status_custom_emoji_id | Option<String> | Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status. |
| emoji_status_expiration_date | Option<i64> | Expiration date of the emoji status, if any |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetUserEmojiStatusParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
// Optional parameters
let params = SetUserEmojiStatusParams::new()
.emoji_status_custom_emoji_id(None)
.emoji_status_expiration_date(None);
let result = bot.set_user_emoji_status(
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to specify a URL and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. In case of an unsuccessful request (a request with response HTTP status code different from 2XY), we will repeat the request and give up after a reasonable amount of attempts. Returns True on success. /// If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter secret_token. If specified, the request will contain a header "X-Telegram-Bot-Api-Secret-Token" with the secret token as content.
SetWebhookParams6 fields| Field | Type | Description |
|---|---|---|
| certificate | Option<InputFile> | Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details. |
| ip_address | Option<String> | The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS |
| max_connections | Option<i64> | The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. |
| allowed_updates | Option<Vec<String>> | A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. |
| drop_pending_updates | Option<bool> | Pass True to drop all pending updates |
| secret_token | Option<String> | A secret token to be sent in a header "X-Telegram-Bot-Api-Secret-Token" in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SetWebhookParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let url = "https://example.com";
// Optional parameters
let params = SetWebhookParams::new()
.certificate(None)
.ip_address(None)
.max_connections(None)
.allowed_updates(None)
.drop_pending_updates(None)
// ... +1 more optional fields;
let result = bot.set_webhook(
url,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Updates & Webhook
1Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.close().await?;
println!("Result: {result:?}");
Ok(())
}
Stickers
3Use this method to add a new sticker to a set created by the bot. Emoji sticker sets can have up to 200 stickers. Other sticker sets can have up to 120 stickers. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let name = "my_name";
let sticker = InputSticker::default();
let result = bot.add_sticker_to_set(
user_id,
name,
sticker
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let name = "my_name";
let old_sticker = "example";
let sticker = InputSticker::default();
let result = bot.replace_sticker_in_set(
user_id,
name,
old_sticker,
sticker
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to upload a file with a sticker for later use in the createNewStickerSet, addStickerToSet, or replaceStickerInSet methods (the file can be used multiple times). Returns the uploaded File on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let sticker = InputFile::default();
let sticker_format = "example";
let result = bot.upload_sticker_file(
user_id,
sticker,
sticker_format
).await?;
println!("Result: {result:?}");
Ok(())
}
Forum Topics
6Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_thread_id = 0i64;
let result = bot.close_forum_topic(
chat_id,
message_thread_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.close_general_forum_topic(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed if it was open. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.hide_general_forum_topic(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_thread_id = 0i64;
let result = bot.reopen_forum_topic(
chat_id,
message_thread_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.reopen_general_forum_topic(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.unhide_general_forum_topic(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Payments & Stars
6Converts a given regular gift to Telegram Stars. Requires the can_convert_gifts_to_stars business bot right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let owned_gift_id = "example";
let result = bot.convert_gift_to_stars(
business_connection_id,
owned_gift_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Refunds a successful payment in Telegram Stars. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let telegram_payment_charge_id = "example";
let result = bot.refund_star_payment(
user_id,
telegram_payment_charge_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Transfers Telegram Stars from the business account balance to the bot's balance. Requires the can_transfer_stars business bot right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let star_count = 0i64;
let result = bot.transfer_business_account_stars(
business_connection_id,
star_count
).await?;
println!("Result: {result:?}");
Ok(())
}
Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right. Requires can_transfer_stars business bot right if the transfer is paid. Returns True on success.
TransferGiftParams1 fields| Field | Type | Description |
|---|---|---|
| star_count | Option<i64> | The amount of Telegram Stars that will be paid for the transfer from the business account balance. If positive, then the can_transfer_stars business bot right is required. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{TransferGiftParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let owned_gift_id = "example";
let new_owner_chat_id = 123456789i64;
// Optional parameters
let params = TransferGiftParams::new()
.star_count(None);
let result = bot.transfer_gift(
business_connection_id,
owned_gift_id,
new_owner_chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right. Additionally requires the can_transfer_stars business bot right if the upgrade is paid. Returns True on success.
UpgradeGiftParams2 fields| Field | Type | Description |
|---|---|---|
| keep_original_details | Option<bool> | Pass True to keep the original gift text, sender and receiver in the upgraded gift |
| star_count | Option<i64> | The amount of Telegram Stars that will be paid for the upgrade from the business account balance. If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required and gift.upgrade_star_count must be passed. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{UpgradeGiftParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let owned_gift_id = "example";
// Optional parameters
let params = UpgradeGiftParams::new()
.keep_original_details(None)
.star_count(None);
let result = bot.upgrade_gift(
business_connection_id,
owned_gift_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Stories
2Posts a story on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.
PostStoryParams6 fields| Field | Type | Description |
|---|---|---|
| caption | Option<String> | Caption of the story, 0-2048 characters after entities parsing |
| parse_mode | Option<String> | Mode for parsing entities in the story caption. See formatting options for more details. |
| caption_entities | Option<Vec<MessageEntity>> | A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode |
| areas | Option<Vec<StoryArea>> | A JSON-serialized list of clickable areas to be shown on the story |
| post_to_chat_page | Option<bool> | Pass True to keep the story accessible after it expires |
| protect_content | Option<bool> | Pass True if the content of the story must be protected from forwarding and screenshotting |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{PostStoryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let content = InputStoryContent::default();
let active_period = 0i64;
// Optional parameters
let params = PostStoryParams::new()
.caption(None)
.parse_mode(None)
.caption_entities(None)
.areas(None)
.post_to_chat_page(None)
// ... +1 more optional fields;
let result = bot.post_story(
business_connection_id,
content,
active_period,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Reposts a story on behalf of a business account from another business account. Both business accounts must be managed by the same bot, and the story on the source account must have been posted (or reposted) by the bot. Requires the can_manage_stories business bot right for both business accounts. Returns Story on success.
RepostStoryParams2 fields| Field | Type | Description |
|---|---|---|
| post_to_chat_page | Option<bool> | Pass True to keep the story accessible after it expires |
| protect_content | Option<bool> | Pass True if the content of the story must be protected from forwarding and screenshotting |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{RepostStoryParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let from_chat_id = 123456789i64;
let from_story_id = 0i64;
let active_period = 0i64;
// Optional parameters
let params = RepostStoryParams::new()
.post_to_chat_page(None)
.protect_content(None);
let result = bot.repost_story(
business_connection_id,
from_chat_id,
from_story_id,
active_period,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Business
2Marks incoming message as read on behalf of a business account. Requires the can_read_messages business bot right. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
let chat_id = 123456789i64;
let message_id = 0i64;
let result = bot.read_business_message(
business_connection_id,
chat_id,
message_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.
RemoveBusinessAccountProfilePhotoParams1 fields| Field | Type | Description |
|---|---|---|
| is_public | Option<bool> | Pass True to remove the public photo, which is visible even if the main photo is hidden by the business account's privacy settings. After the main photo is removed, the previous profile photo (if present) becomes the main photo. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{RemoveBusinessAccountProfilePhotoParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let business_connection_id = "example";
// Optional parameters
let params = RemoveBusinessAccountProfilePhotoParams::new()
.is_public(None);
let result = bot.remove_business_account_profile_photo(
business_connection_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Other
11Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the new invite link as String on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.export_chat_invite_link(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.leave_chat(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success. Requires no parameters.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.log_out().await?;
println!("Result: {result:?}");
Ok(())
}
Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let result = bot.remove_chat_verification(
chat_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Removes the profile photo of the bot. Requires no parameters. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let result = bot.remove_my_profile_photo().await?;
println!("Result: {result:?}");
Ok(())
}
Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.
use tgbotrs::{Bot, BotError};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let result = bot.remove_user_verification(
user_id
).await?;
println!("Result: {result:?}");
Ok(())
}
Stores a message that can be sent by a user of a Mini App. Returns a PreparedInlineMessage object.
SavePreparedInlineMessageParams4 fields| Field | Type | Description |
|---|---|---|
| allow_user_chats | Option<bool> | Pass True if the message can be sent to private chats with users |
| allow_bot_chats | Option<bool> | Pass True if the message can be sent to private chats with bots |
| allow_group_chats | Option<bool> | Pass True if the message can be sent to group and supergroup chats |
| allow_channel_chats | Option<bool> | Pass True if the message can be sent to channel chats |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{SavePreparedInlineMessageParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
let result = InlineQueryResult::default();
// Optional parameters
let params = SavePreparedInlineMessageParams::new()
.allow_user_chats(None)
.allow_bot_chats(None)
.allow_group_chats(None)
.allow_channel_chats(None);
let result = bot.save_prepared_inline_message(
user_id,
result,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
StopMessageLiveLocationParams5 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| chat_id | Option<ChatId> | Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
| message_id | Option<i64> | Required if inline_message_id is not specified. Identifier of the message with live location to stop |
| inline_message_id | Option<String> | Required if chat_id and message_id are not specified. Identifier of the inline message |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for a new inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{StopMessageLiveLocationParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
// Optional parameters
let params = StopMessageLiveLocationParams::new()
.business_connection_id(None)
.chat_id(None)
.message_id(None)
.inline_message_id(None)
.reply_markup(None);
let result = bot.stop_message_live_location(
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.
StopPollParams2 fields| Field | Type | Description |
|---|---|---|
| business_connection_id | Option<String> | Unique identifier of the business connection on behalf of which the message to be edited was sent |
| reply_markup | Option<Box<InlineKeyboardMarkup>> | A JSON-serialized object for a new message inline keyboard. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{StopPollParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
let message_id = 0i64;
// Optional parameters
let params = StopPollParams::new()
.business_connection_id(None)
.reply_markup(None);
let result = bot.stop_poll(
chat_id,
message_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Verifies a chat on behalf of the organization which is represented by the bot. Returns True on success.
VerifyChatParams1 fields| Field | Type | Description |
|---|---|---|
| custom_description | Option<String> | Custom description for the verification; 0-70 characters. Must be empty if the organization isn't allowed to provide a custom verification description. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{VerifyChatParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let chat_id = 123456789i64;
// Optional parameters
let params = VerifyChatParams::new()
.custom_description(None);
let result = bot.verify_chat(
chat_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.
VerifyUserParams1 fields| Field | Type | Description |
|---|---|---|
| custom_description | Option<String> | Custom description for the verification; 0-70 characters. Must be empty if the organization isn't allowed to provide a custom verification description. |
use tgbotrs::{Bot, BotError};
use tgbotrs::gen_methods::{VerifyUserParams};
#[tokio::main]
async fn main() -> Result<(), BotError> {
let bot = Bot::new("YOUR_BOT_TOKEN").await?;
let user_id = 123456789i64;
// Optional parameters
let params = VerifyUserParams::new()
.custom_description(None);
let result = bot.verify_user(
user_id,
Some(params)
).await?;
println!("Result: {result:?}");
Ok(())
}
📐 Types Reference
All 257 Telegram types — every field shown. See docs.rs for full rustdoc.
Accepts numeric IDs or username strings.
bot.send_message(123456789i64, "text", None).await?;
bot.send_message("@mychannel", "text", None).await?;Flexible file input — path, URL, or bytes.
use tgbotrs::InputFile;
let by_path = InputFile::path("photo.jpg");
let by_url = InputFile::url("https://example.com/photo.jpg");
let by_bytes = InputFile::bytes("photo.jpg", std::fs::read("photo.jpg").unwrap());⚠️ Error Handling
All calls return Result<T, BotError>
match bot.send_message(chat_id, text, None).await {
Ok(msg) => println!("Sent #{}", msg.message_id),
Err(BotError::Api { code: 403, .. }) => println!("Bot was blocked"),
Err(BotError::Api { code: 429, retry_after: Some(secs), .. }) => {
tokio::time::sleep(std::time::Duration::from_secs(secs as u64)).await;
}
Err(e) => eprintln!("Error: {}", e),
}