Merge pull request #144 from teloxide/improve-requests

Improve requests
This commit is contained in:
p0lunin 2020-01-24 22:13:38 +02:00 committed by GitHub
commit 84af1ab0e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 2449 additions and 1053 deletions

View file

@ -15,12 +15,13 @@ tokio-util = { version = "0.2.0", features = ["full"] }
reqwest = { version = "0.10", features = ["json", "stream", "native-tls-vendored"] }
log = "0.4.8"
bytes = "0.5.3"
mime = "0.3.16"
derive_more = "0.99.2"
thiserror = "1.0.9"
async-trait = "0.1.22"
duang = "0.1.2"
futures = "0.3.1"
pin-project = "0.4.6"
serde_with_macros = "1.0.1"
either = "1.5.3"
mime = "0.3.16"

File diff suppressed because it is too large Load diff

View file

@ -9,9 +9,10 @@ use crate::{bot::Bot, net::download_file, DownloadError};
impl Bot {
/// Download a file from Telegram into `destination`.
/// `path` can be obtained from [`get_file`] method.
///
/// For downloading as Stream of Chunks see [`download_file_stream`].
/// `path` can be obtained from [`Bot::get_file`].
///
/// To download as a stream of chunks, see [`Bot::download_file_stream`].
///
/// ## Examples
///
@ -30,8 +31,8 @@ impl Bot {
/// # Ok(()) }
/// ```
///
/// [`get_file`]: crate::Bot::get_file
/// [`download_file_stream`]: crate::Bot::download_file_stream
/// [`Bot::get_file`]: crate::Bot::get_file
/// [`Bot::download_file_stream`]: crate::Bot::download_file_stream
pub async fn download_file<D>(
&self,
path: &str,
@ -45,15 +46,15 @@ impl Bot {
/// Download a file from Telegram.
///
/// `path` can be obtained from the [`get_file`] method.
/// `path` can be obtained from the [`Bot::get_file`].
///
/// For downloading into [`AsyncWrite`] (e.g. [`tokio::fs::File`])
/// see [`download_file`].
/// To download into [`AsyncWrite`] (e.g. [`tokio::fs::File`]), see
/// [`Bot::download_file`].
///
/// [`get_file`]: crate::bot::Bot::get_file
/// [`Bot::get_file`]: crate::bot::Bot::get_file
/// [`AsyncWrite`]: tokio::io::AsyncWrite
/// [`tokio::fs::File`]: tokio::fs::File
/// [`download_file`]: crate::Bot::download_file
/// [`Bot::download_file`]: crate::Bot::download_file
#[cfg(feature = "unstable-stream")]
pub async fn download_file_stream(
&self,

View file

@ -5,29 +5,19 @@ use crate::{
Bot,
};
use super::BotWrapper;
use crate::requests::{Request, ResponseResult};
/// Use this method to add a new sticker to a set created by the bot. Returns
/// True on success.
#[derive(Debug, Clone)]
/// Use this method to add a new sticker to a set created by the bot.
///
/// [The official docs](https://core.telegram.org/bots/api#addstickertoset).
#[derive(PartialEq, Debug, Clone)]
pub struct AddStickerToSet<'a> {
bot: &'a Bot,
/// User identifier of sticker set owner
bot: BotWrapper<'a>,
user_id: i32,
/// Sticker set name
name: String,
/// Png image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. 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 info on Sending Files »
png_sticker: InputFile,
/// One or more emoji corresponding to the sticker
emojis: String,
/// A JSON-serialized object for position where the mask should be placed
/// on faces
mask_position: Option<MaskPosition>,
}
@ -70,7 +60,7 @@ impl<'a> AddStickerToSet<'a> {
E: Into<String>,
{
Self {
bot,
bot: BotWrapper(bot),
user_id,
name: name.into(),
png_sticker,
@ -79,11 +69,13 @@ impl<'a> AddStickerToSet<'a> {
}
}
/// User identifier of sticker set owner.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// Sticker set name.
pub fn name<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -92,11 +84,24 @@ impl<'a> AddStickerToSet<'a> {
self
}
/// **Png** image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
pub fn png_sticker(mut self, val: InputFile) -> Self {
self.png_sticker = val;
self
}
/// One or more emoji corresponding to the sticker.
pub fn emojis<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -105,6 +110,8 @@ impl<'a> AddStickerToSet<'a> {
self
}
/// A JSON-serialized object for position where the mask should be placed on
/// faces.
pub fn mask_position(mut self, val: MaskPosition) -> Self {
self.mask_position = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,36 +8,24 @@ use crate::{
Bot,
};
/// Use 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.Alternatively, the user can be redirected to the specified Game
/// URL. For this option to work, you must first create a game for your bot via
/// @Botfather and accept the terms. Otherwise, you may use links like
/// t.me/your_bot?start=XXXX that open your bot with a parameter.
/// Use 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.
///
/// [The official docs](https://core.telegram.org/bots/api#answercallbackquery).
///
/// [inline keyboards]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct AnswerCallbackQuery<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the query to be answered
bot: BotWrapper<'a>,
callback_query_id: String,
/// Text of the notification. If not specified, nothing will be shown to
/// the user, 0-200 characters
text: Option<String>,
/// If true, an alert will be shown by the client instead of a notification
/// at the top of the chat screen. Defaults to false.
show_alert: Option<bool>,
/// 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.
url: Option<String>,
/// 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.
cache_time: Option<i32>,
}
@ -62,7 +51,7 @@ impl<'a> AnswerCallbackQuery<'a> {
{
let callback_query_id = callback_query_id.into();
Self {
bot,
bot: BotWrapper(bot),
callback_query_id,
text: None,
show_alert: None,
@ -71,6 +60,7 @@ impl<'a> AnswerCallbackQuery<'a> {
}
}
/// Unique identifier for the query to be answered.
pub fn callback_query_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -79,6 +69,8 @@ impl<'a> AnswerCallbackQuery<'a> {
self
}
/// Text of the notification. If not specified, nothing will be shown to the
/// user, 0-200 characters.
pub fn text<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -87,11 +79,24 @@ impl<'a> AnswerCallbackQuery<'a> {
self
}
/// If `true`, an alert will be shown by the client instead of a
/// notification at the top of the chat screen. Defaults to `false`.
pub fn show_alert(mut self, val: bool) -> Self {
self.show_alert = Some(val);
self
}
/// 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.
///
/// [@Botfather]: https://t.me/botfather
/// [`callback_game`]: crate::types::InlineKeyboardButton
/// [`Game`]: crate::types::Game
pub fn url<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -100,6 +105,9 @@ impl<'a> AnswerCallbackQuery<'a> {
self
}
/// 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.
pub fn cache_time(mut self, val: i32) -> Self {
self.cache_time = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,45 +8,22 @@ use crate::{
Bot,
};
/// Use this method to send answers to an inline query. On success, True is
/// returned.No more than 50 results per query are allowed.
/// Use this method to send answers to an inline query.
///
/// No more than **50** results per query are allowed.
///
/// [The official docs](https://core.telegram.org/bots/api#answerinlinequery).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(PartialEq, Debug, Clone, Serialize)]
pub struct AnswerInlineQuery<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the answered query
bot: BotWrapper<'a>,
inline_query_id: String,
/// A JSON-serialized array of results for the inline query
results: Vec<InlineQueryResult>,
/// The maximum amount of time in seconds that the result of the inline
/// query may be cached on the server. Defaults to 300.
cache_time: Option<i32>,
/// 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
is_personal: Option<bool>,
/// 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 dont support pagination. Offset length cant
/// exceed 64 bytes.
next_offset: Option<String>,
/// If passed, clients will display a button with specified text that
/// switches the user to a private chat with the bot and sends the bot a
/// start message with the parameter switch_pm_parameter
switch_pm_text: Option<String>,
/// Deep-linking parameter for the /start message sent to the bot when user
/// presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and -
/// are allowed.Example: An inline bot that sends YouTube videos can ask
/// the user to connect the bot to their YouTube account to adapt search
/// results accordingly. To do this, it displays a Connect your YouTube
/// account button above the results, or even before showing any. The user
/// presses the button, switches to a private chat with the bot and, in
/// doing so, passes a start parameter that instructs the bot to return an
/// oauth link. Once done, the bot can offer a switch_inline button so that
/// the user can easily return to the chat where they wanted to use the
/// bot's inline capabilities.
switch_pm_parameter: Option<String>,
}
@ -77,7 +55,7 @@ impl<'a> AnswerInlineQuery<'a> {
let inline_query_id = inline_query_id.into();
let results = results.into();
Self {
bot,
bot: BotWrapper(bot),
inline_query_id,
results,
cache_time: None,
@ -88,6 +66,7 @@ impl<'a> AnswerInlineQuery<'a> {
}
}
/// Unique identifier for the answered query.
pub fn inline_query_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -96,6 +75,7 @@ impl<'a> AnswerInlineQuery<'a> {
self
}
/// A JSON-serialized array of results for the inline query.
pub fn results<T>(mut self, val: T) -> Self
where
T: Into<Vec<InlineQueryResult>>,
@ -104,17 +84,31 @@ impl<'a> AnswerInlineQuery<'a> {
self
}
/// The maximum amount of time in seconds that the result of the inline
/// query may be cached on the server.
///
/// Defaults to 300.
pub fn cache_time(mut self, val: i32) -> Self {
self.cache_time = Some(val);
self
}
/// 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.
#[allow(clippy::wrong_self_convention)]
pub fn is_personal(mut self, val: bool) -> Self {
self.is_personal = Some(val);
self
}
/// 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 dont
/// support pagination. Offset length cant exceed 64 bytes.
pub fn next_offset<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -123,6 +117,12 @@ impl<'a> AnswerInlineQuery<'a> {
self
}
/// If passed, clients will display a button with specified text that
/// switches the user to a private chat with the bot and sends the bot a
/// start message with the parameter [`switch_pm_parameter`].
///
/// [`switch_pm_parameter`]:
/// crate::requests::AnswerInlineQuery::switch_pm_parameter
pub fn switch_pm_text<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -131,6 +131,22 @@ impl<'a> AnswerInlineQuery<'a> {
self
}
/// [Deep-linking] parameter for the /start message sent to the bot when
/// user presses the switch button. 1-64 characters, only `A-Z`, `a-z`,
/// `0-9`, `_` and `-` are allowed.
///
/// Example: An inline bot that sends YouTube videos can ask the user to
/// connect the bot to their YouTube account to adapt search results
/// accordingly. To do this, it displays a Connect your YouTube account
/// button above the results, or even before showing any. The user presses
/// the button, switches to a private chat with the bot and, in doing so,
/// passes a start parameter that instructs the bot to return an oauth link.
/// Once done, the bot can offer a [`switch_inline`] button so that the user
/// can easily return to the chat where they wanted to use the bot's
/// inline capabilities.
///
/// [Deep-linking]: https://core.telegram.org/bots#deep-linking
/// [`switch_inline`]: crate::types::InlineKeyboardMarkup
pub fn switch_pm_parameter<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,28 +9,21 @@ use crate::{
};
/// 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.
/// 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. Note: The Bot API must receive an answer within 10 seconds after
/// the pre-checkout query was sent.
///
/// [The official docs](https://core.telegram.org/bots/api#answerprecheckoutquery).
///
/// [`Update`]: crate::types::Update
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct AnswerPreCheckoutQuery<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the query to be answered
bot: BotWrapper<'a>,
pre_checkout_query_id: String,
/// Specify True if everything is alright (goods are available, etc.) and
/// the bot is ready to proceed with the order. Use False if there are any
/// problems.
ok: bool,
/// 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.
error_message: Option<String>,
}
@ -59,13 +53,14 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
{
let pre_checkout_query_id = pre_checkout_query_id.into();
Self {
bot,
bot: BotWrapper(bot),
pre_checkout_query_id,
ok,
error_message: None,
}
}
/// Unique identifier for the query to be answered.
pub fn pre_checkout_query_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -74,11 +69,21 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
self
}
/// Specify `true` if everything is alright (goods are available, etc.) and
/// the bot is ready to proceed with the order. Use False if there are any
/// problems.
pub fn ok(mut self, val: bool) -> Self {
self.ok = val;
self
}
/// 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.
pub fn error_message<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,35 +1,28 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
types::{ShippingOption, True},
Bot,
};
/// 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
/// `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.
/// queries.
///
/// [The official docs](https://core.telegram.org/bots/api#answershippingquery).
///
/// [`Update`]: crate::types::Update
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct AnswerShippingQuery<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the query to be answered
bot: BotWrapper<'a>,
shipping_query_id: String,
/// Specify True if delivery to the specified address is possible and False
/// if there are any problems (for example, if delivery to the specified
/// address is not possible)
ok: bool,
/// Required if ok is True. A JSON-serialized array of available shipping
/// options.
shipping_options: Option<Vec<ShippingOption>>,
/// 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.
error_message: Option<String>,
}
@ -55,7 +48,7 @@ impl<'a> AnswerShippingQuery<'a> {
{
let shipping_query_id = shipping_query_id.into();
Self {
bot,
bot: BotWrapper(bot),
shipping_query_id,
ok,
shipping_options: None,
@ -63,6 +56,7 @@ impl<'a> AnswerShippingQuery<'a> {
}
}
/// Unique identifier for the query to be answered.
pub fn shipping_query_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -71,11 +65,16 @@ impl<'a> AnswerShippingQuery<'a> {
self
}
/// Specify `true` if delivery to the specified address is possible and
/// `false` if there are any problems (for example, if delivery to the
/// specified address is not possible).
pub fn ok(mut self, val: bool) -> Self {
self.ok = val;
self
}
/// Required if ok is `true`. A JSON-serialized array of available shipping
/// options.
pub fn shipping_options<T>(mut self, val: T) -> Self
where
T: Into<Vec<ShippingOption>>,
@ -84,6 +83,11 @@ impl<'a> AnswerShippingQuery<'a> {
self
}
/// 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.
pub fn error_message<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -0,0 +1,33 @@
use crate::Bot;
use std::ops::Deref;
/// A wrapper that implements `Clone`, Copy, `PartialEq`, `Eq`, `Debug`, but
/// performs no copying, cloning and comparison.
///
/// Used in the requests bodies.
#[derive(Debug)]
pub struct BotWrapper<'a>(pub &'a Bot);
impl PartialEq for BotWrapper<'_> {
fn eq(&self, other: &BotWrapper<'_>) -> bool {
self.0.token() == other.0.token()
}
}
impl Eq for BotWrapper<'_> {}
impl<'a> Clone for BotWrapper<'a> {
fn clone(&self) -> BotWrapper<'a> {
Self(self.0)
}
}
impl Copy for BotWrapper<'_> {}
impl Deref for BotWrapper<'_> {
type Target = Bot;
fn deref(&self) -> &Bot {
&self.0
}
}

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -6,34 +7,18 @@ use crate::{
};
/// Use this method to create new sticker set owned by a user. The bot will be
/// able to edit the created sticker set. Returns True on success.
#[derive(Debug, Clone)]
/// able to edit the created sticker set.
///
/// [The official docs](https://core.telegram.org/bots/api#createnewstickerset).
#[derive(PartialEq, Debug, Clone)]
pub struct CreateNewStickerSet<'a> {
bot: &'a Bot,
/// User identifier of created sticker set owner
bot: BotWrapper<'a>,
user_id: i32,
/// Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g.,
/// animals). Can contain only english letters, digits and underscores.
/// Must begin with a letter, can't contain consecutive underscores and
/// must end in “_by_<bot username>”. <bot_username> is case insensitive.
/// 1-64 characters.
name: String,
/// Sticker set title, 1-64 characters
title: String,
/// Png image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. 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 info on Sending Files »
png_sticker: InputFile,
/// One or more emoji corresponding to the sticker
emojis: String,
/// Pass True, if a set of mask stickers should be created
contains_masks: Option<bool>,
/// A JSON-serialized object for position where the mask should be placed
/// on faces
mask_position: Option<MaskPosition>,
}
@ -82,7 +67,7 @@ impl<'a> CreateNewStickerSet<'a> {
E: Into<String>,
{
Self {
bot,
bot: BotWrapper(bot),
user_id,
name: name.into(),
title: title.into(),
@ -93,11 +78,18 @@ impl<'a> CreateNewStickerSet<'a> {
}
}
/// User identifier of created sticker set owner.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g.,
/// animals). Can contain only english letters, digits and underscores.
///
/// Must begin with a letter, can't contain consecutive underscores and must
/// end in `_by_<bot username>`. `<bot_username>` is case insensitive.
/// 1-64 characters.
pub fn name<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -106,6 +98,7 @@ impl<'a> CreateNewStickerSet<'a> {
self
}
/// Sticker set title, 1-64 characters.
pub fn title<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -114,11 +107,24 @@ impl<'a> CreateNewStickerSet<'a> {
self
}
/// **Png** image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
pub fn png_sticker(mut self, val: InputFile) -> Self {
self.png_sticker = val;
self
}
/// One or more emoji corresponding to the sticker.
pub fn emojis<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -127,11 +133,14 @@ impl<'a> CreateNewStickerSet<'a> {
self
}
/// Pass `true`, if a set of mask stickers should be created.
pub fn contains_masks(mut self, val: bool) -> Self {
self.contains_masks = Some(val);
self
}
/// A JSON-serialized object for position where the mask should be placed on
/// faces.
pub fn mask_position(mut self, val: MaskPosition) -> Self {
self.mask_position = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -9,15 +10,14 @@ use crate::{
/// 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 admin rights. Returns True on success.
/// must have the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#deletechatphoto).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteChatPhoto<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -42,9 +42,14 @@ impl<'a> DeleteChatPhoto<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,21 @@ use crate::{
Bot,
};
/// 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 admin 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 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 admin rights. Use the field `can_set_sticker_set` optionally
/// returned in [`Bot::get_chat`] requests to check if the bot can use this
/// method.
///
/// [The official docs](https://core.telegram.org/bots/api#deletechatstickerset).
///
/// [`Bot::get_chat`]: crate::Bot::get_chat
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteChatStickerSet<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -44,9 +47,14 @@ impl<'a> DeleteChatStickerSet<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,25 +8,27 @@ use crate::{
Bot,
};
/// 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.- 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 permission in
/// a supergroup or a channel, it can delete any message there.Returns True on
/// success.
/// Use this method to delete a message, including service messages.
///
/// The limitations are:
/// - A message can only be deleted if it was sent less than 48 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 permission in a supergroup or a
/// channel, it can delete any message there.
///
/// [The official docs](https://core.telegram.org/bots/api#deletemessage).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteMessage<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Identifier of the message to delete
message_id: i32,
}
@ -51,12 +54,14 @@ impl<'a> DeleteMessage<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
message_id,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -65,6 +70,7 @@ impl<'a> DeleteMessage<'a> {
self
}
/// Identifier of the message to delete.
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,15 +8,14 @@ use crate::{
Bot,
};
/// Use this method to delete a sticker from a set created by the bot. Returns
/// True on success.
/// Use this method to delete a sticker from a set created by the bot.
///
/// [The official docs](https://core.telegram.org/bots/api#deletestickerfromset).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteStickerFromSet<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// File identifier of the sticker
bot: BotWrapper<'a>,
sticker: String,
}
@ -40,9 +40,13 @@ impl<'a> DeleteStickerFromSet<'a> {
S: Into<String>,
{
let sticker = sticker.into();
Self { bot, sticker }
Self {
bot: BotWrapper(bot),
sticker,
}
}
/// File identifier of the sticker.
pub fn sticker<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,18 +9,23 @@ use crate::{
};
/// Use this method to remove webhook integration if you decide to switch back
/// to getUpdates. Returns True on success. Requires no parameters.
/// to [Bot::get_updates].
///
/// [The official docs](https://core.telegram.org/bots/api#deletewebhook).
///
/// [Bot::get_updates]: crate::Bot::get_updates
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteWebhook<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
}
#[async_trait::async_trait]
impl Request for DeleteWebhook<'_> {
type Output = True;
#[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<True> {
net::request_json(
self.bot.client(),
@ -33,6 +39,8 @@ impl Request for DeleteWebhook<'_> {
impl<'a> DeleteWebhook<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self {
Self { bot }
Self {
bot: BotWrapper(bot),
}
}
}

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,24 +8,24 @@ use crate::{
Bot,
};
/// Use this method to edit captions of messages. On success, if edited message
/// is sent by the bot, the edited Message is returned, otherwise True is
/// returned.
/// Use this method to edit captions of messages.
///
/// On success, if edited message is sent by the bot, the edited [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagecaption).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageCaption<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// New caption of the message
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -49,7 +50,7 @@ impl<'a> EditMessageCaption<'a> {
chat_or_inline_message: ChatOrInlineMessage,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
caption: None,
parse_mode: None,
@ -62,6 +63,7 @@ impl<'a> EditMessageCaption<'a> {
self
}
/// New caption of the message.
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -70,11 +72,21 @@ impl<'a> EditMessageCaption<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// A JSON-serialized object for an [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,24 +8,26 @@ use crate::{
Bot,
};
/// 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 was sent by the
/// bot, the edited Message is returned, otherwise True is returned.
/// 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 was sent by the bot, the edited [`Message`] is returned,
/// otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagelivelocation).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageLiveLocation<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// Latitude of new location
latitude: f32,
/// Longitude of new location
longitude: f32,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -51,7 +54,7 @@ impl<'a> EditMessageLiveLocation<'a> {
longitude: f32,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
latitude,
longitude,
@ -64,16 +67,21 @@ impl<'a> EditMessageLiveLocation<'a> {
self
}
/// Latitude of new location.
pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val;
self
}
/// Longitude of new location.
pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val;
self
}
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -6,21 +7,24 @@ use crate::{
};
/// Use this method to edit animation, audio, document, photo, or video
/// messages. If a message is a part of a message album, then it can be edited
/// only to a photo or a video. Otherwise, message type can be changed
/// arbitrarily. When inline message is edited, new file can't be uploaded. Use
/// previously uploaded file via its file_id or specify a URL. On success, if
/// the edited message was sent by the bot, the edited Message is returned,
/// otherwise True is returned.
#[derive(Debug, Clone)]
/// messages.
///
/// If a message is a part of a message album, then it can be edited only to a
/// photo or a video. Otherwise, message type can be changed arbitrarily. When
/// inline message is edited, new file can't be uploaded. Use previously
/// uploaded file via its `file_id` or specify a URL. On success, if the edited
/// message was sent by the bot, the edited [`Message`] is returned,
/// otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagemedia).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct EditMessageMedia<'a> {
bot: &'a Bot,
bot: BotWrapper<'a>,
chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for a new media content of the message
media: InputMedia,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -70,7 +74,7 @@ impl<'a> EditMessageMedia<'a> {
media: InputMedia,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
media,
reply_markup: None,
@ -82,11 +86,15 @@ impl<'a> EditMessageMedia<'a> {
self
}
/// A JSON-serialized object for a new media content of the message.
pub fn media(mut self, val: InputMedia) -> Self {
self.media = val;
self
}
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,22 @@ use crate::{
Bot,
};
/// Use this method to edit only the reply markup of messages. On success, if
/// edited message is sent by the bot, the edited Message is returned, otherwise
/// True is returned.
/// Use this method to edit only the reply markup of messages.
///
/// On success, if edited message is sent by the bot, the edited [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagereplymarkup).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageReplyMarkup<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -44,7 +48,7 @@ impl<'a> EditMessageReplyMarkup<'a> {
chat_or_inline_message: ChatOrInlineMessage,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
reply_markup: None,
}
@ -55,6 +59,9 @@ impl<'a> EditMessageReplyMarkup<'a> {
self
}
/// A JSON-serialized object for an [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,26 +8,25 @@ use crate::{
Bot,
};
/// Use this method to edit text and game messages. On success, if edited
/// message is sent by the bot, the edited Message is returned, otherwise True
/// is returned.
/// Use this method to edit text and game messages.
///
/// On success, if edited message is sent by the bot, the edited [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagetext).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageText<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// New text of the message
text: String,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in your bot's message.
parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
disable_web_page_preview: Option<bool>,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -55,7 +55,7 @@ impl<'a> EditMessageText<'a> {
T: Into<String>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
text: text.into(),
parse_mode: None,
@ -69,6 +69,7 @@ impl<'a> EditMessageText<'a> {
self
}
/// New text of the message.
pub fn text<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -77,16 +78,26 @@ impl<'a> EditMessageText<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show [bold,
/// italic, fixed-width text or inline URLs] in your bot's message.
///
/// [Markdown]: https://core.telegram.org/bots/api#markdown-style
/// [HTML]: https://core.telegram.org/bots/api#html-style
/// [bold, italic, fixed-width text or inline URLs]: https://core.telegram.org/bots/api#formatting-options
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// Disables link previews for links in this message.
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
self.disable_web_page_preview = Some(val);
self
}
/// A JSON-serialized object for an [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,23 +9,29 @@ use crate::{
};
/// Use this method to generate a new invite link for a chat; any previously
/// generated link is revoked. The bot must be an administrator in the chat for
/// this to work and must have the appropriate admin rights. Returns the new
/// invite link as String on success.Note: Each administrator in a chat
/// generates their own invite links. Bots can't use invite links generated by
/// other administrators. If you want your bot to work with invite links, it
/// will need to generate its own link using exportChatInviteLink after this
/// the link will become available to the bot via the getChat method. If your
/// bot needs to generate a new invite link replacing its previous one, use
/// exportChatInviteLink again.
/// generated link is revoked.
///
/// The bot must be an administrator in the chat for this to work and must have
/// the appropriate admin rights.
///
/// ## Note
/// Each administrator in a chat generates their own invite links. Bots can't
/// use invite links generated by other administrators. If you want your bot to
/// work with invite links, it will need to generate its own link using
/// [`Bot::export_chat_invite_link`] after this the link will become available
/// to the bot via the [`Bot::get_chat`] method. If your bot needs to generate a
/// new invite link replacing its previous one, use
/// [`Bot::export_chat_invite_link`] again.
///
/// [The official docs](https://core.telegram.org/bots/api#exportchatinvitelink).
///
/// [`Bot::export_chat_invite_link`]: crate::Bot::export_chat_invite_link
/// [`Bot::get_chat`]: crate::Bot::get_chat
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct ExportChatInviteLink<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -32,6 +39,7 @@ pub struct ExportChatInviteLink<'a> {
impl Request for ExportChatInviteLink<'_> {
type Output = String;
/// Returns the new invite link as `String` on success.
async fn send(&self) -> ResponseResult<String> {
net::request_json(
self.bot.client(),
@ -49,9 +57,14 @@ impl<'a> ExportChatInviteLink<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,24 +8,17 @@ use crate::{
Bot,
};
/// Use this method to forward messages of any kind. On success, the sent
/// Message is returned.
/// Use this method to forward messages of any kind.
///
/// [`The official docs`](https://core.telegram.org/bots/api#forwardmessage).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct ForwardMessage<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier for the chat where the original message was sent (or
/// channel username in the format @channelusername)
from_chat_id: ChatId,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// Message identifier in the chat specified in from_chat_id
message_id: i32,
}
@ -57,7 +51,7 @@ impl<'a> ForwardMessage<'a> {
let chat_id = chat_id.into();
let from_chat_id = from_chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
from_chat_id,
message_id,
@ -65,6 +59,8 @@ impl<'a> ForwardMessage<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -73,6 +69,8 @@ impl<'a> ForwardMessage<'a> {
self
}
/// Unique identifier for the chat where the original message was sent (or
/// channel username in the format `@channelusername`).
#[allow(clippy::wrong_self_convention)]
pub fn from_chat_id<T>(mut self, val: T) -> Self
where
@ -82,11 +80,18 @@ impl<'a> ForwardMessage<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// Message identifier in the chat specified in [`from_chat_id`].
///
/// [`from_chat_id`]: ForwardMessage::from_chat_id
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -9,15 +10,14 @@ use crate::{
/// Use this method to get up to date information about the chat (current name
/// of the user for one-on-one conversations, current username of a user, group
/// or channel, etc.). Returns a Chat object on success.
/// or channel, etc.).
///
/// [The official docs](https://core.telegram.org/bots/api#getchat).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChat<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -37,9 +37,14 @@ impl<'a> GetChat<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,17 @@ use crate::{
Bot,
};
/// Use this method to get a list of administrators in a chat. On success,
/// returns an Array of ChatMember objects that contains information about all
/// chat administrators except other bots. If the chat is a group or a
/// supergroup and no administrators were appointed, only the creator will be
/// returned.
/// Use this method to get a list of administrators in a chat.
///
/// If the chat is a group or a supergroup and no administrators were appointed,
/// only the creator will be returned.
///
/// [The official docs](https://core.telegram.org/bots/api#getchatadministrators).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChatAdministrators<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -27,6 +26,8 @@ pub struct GetChatAdministrators<'a> {
impl Request for GetChatAdministrators<'_> {
type Output = Vec<ChatMember>;
/// On success, returns an array that contains information about all chat
/// administrators except other bots.
async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
net::request_json(
self.bot.client(),
@ -44,9 +45,14 @@ impl<'a> GetChatAdministrators<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,18 +8,15 @@ use crate::{
Bot,
};
/// Use this method to get information about a member of a chat. Returns a
/// ChatMember object on success.
/// Use this method to get information about a member of a chat.
///
/// [The official docs](https://core.telegram.org/bots/api#getchatmember).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChatMember<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32,
}
@ -44,12 +42,14 @@ impl<'a> GetChatMember<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
user_id,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -58,6 +58,7 @@ impl<'a> GetChatMember<'a> {
self
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,16 +8,14 @@ use crate::{
Bot,
};
/// Use this method to get the number of members in a chat. Returns Int on
/// success.
/// Use this method to get the number of members in a chat.
///
/// [The official docs](https://core.telegram.org/bots/api#getchatmemberscount).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChatMembersCount<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -41,9 +40,14 @@ impl<'a> GetChatMembersCount<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -12,8 +13,6 @@ use crate::{
///
/// 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
@ -24,16 +23,16 @@ use crate::{
/// type. You should save the file's MIME type and name (if available) when the
/// [`File`] object is received.
///
/// [The official docs](https://core.telegram.org/bots/api#getfile).
///
/// [`File`]: crate::types::file
/// [`GetFile`]: self::GetFile
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetFile<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// File identifier to get info about
pub file_id: String,
bot: BotWrapper<'a>,
file_id: String,
}
#[async_trait::async_trait]
@ -52,11 +51,12 @@ impl<'a> GetFile<'a> {
F: Into<String>,
{
Self {
bot,
bot: BotWrapper(bot),
file_id: file_id.into(),
}
}
/// File identifier to get info about.
pub fn file_id<F>(mut self, value: F) -> Self
where
F: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,22 +8,25 @@ use crate::{
Bot,
};
/// Use this method to get data for high score tables. Will return the score of
/// the specified user and several of his neighbors in a game. On success,
/// returns an Array of GameHighScore objects.This method will currently return
/// scores for the target user, plus two of his closest neighbors on each side.
/// Will also return the top three users if the user and his neighbors are not
/// among them. Please note that this behavior is subject to change.
/// Use this method to get data for high score tables.
///
/// Will return the score of the specified user and several of his neighbors in
/// a game.
///
/// ## Note
/// This method will currently return scores for the target user, plus two of
/// his closest neighbors on each side. Will also return the top three users if
/// the user and his neighbors are not among them. Please note that this
/// behavior is subject to change.
///
/// [The official docs](https://core.telegram.org/bots/api#getgamehighscores).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetGameHighScores<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// Target user id
user_id: i32,
}
@ -48,7 +52,7 @@ impl<'a> GetGameHighScores<'a> {
user_id: i32,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
user_id,
}
@ -59,6 +63,7 @@ impl<'a> GetGameHighScores<'a> {
self
}
/// Target user id.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -6,20 +7,20 @@ use crate::{
};
use serde::Serialize;
/// A filter method for testing your bot's auth token. Requires no parameters.
/// Returns basic information about the bot in form of a [`User`] object.
/// A simple method for testing your bot's auth token. Requires no parameters.
///
/// [`User`]: crate::types::User
#[derive(Debug, Clone, Copy, Serialize)]
/// [The official docs](https://core.telegram.org/bots/api#getme).
#[derive(Eq, PartialEq, Debug, Clone, Copy, Serialize)]
pub struct GetMe<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
}
#[async_trait::async_trait]
impl Request for GetMe<'_> {
type Output = User;
/// Returns basic information about the bot.
#[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<User> {
net::request_json(self.bot.client(), self.bot.token(), "getMe", &self)
@ -29,6 +30,8 @@ impl Request for GetMe<'_> {
impl<'a> GetMe<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self {
Self { bot }
Self {
bot: BotWrapper(bot),
}
}
}

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,15 +8,14 @@ use crate::{
Bot,
};
/// Use this method to get a sticker set. On success, a StickerSet object is
/// returned.
/// Use this method to get a sticker set.
///
/// [The official docs](https://core.telegram.org/bots/api#getstickerset).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetStickerSet<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Name of the sticker set
bot: BotWrapper<'a>,
name: String,
}
@ -40,9 +40,13 @@ impl<'a> GetStickerSet<'a> {
N: Into<String>,
{
let name = name.into();
Self { bot, name }
Self {
bot: BotWrapper(bot),
name,
}
}
/// Name of the sticker set.
pub fn name<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,61 +9,24 @@ use crate::{
};
/// Use this method to receive incoming updates using long polling ([wiki]).
/// An array ([`Vec`]) of [`Update`]s is returned.
///
/// **Notes:**
/// 1. This method will not work if an outgoing webhook is set up.
/// 2. In order to avoid getting duplicate updates,
/// recalculate offset after each server response.
///
/// [The official docs](https://core.telegram.org/bots/api#getupdates).
///
/// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling
/// [Update]: crate::types::Update
/// [Vec]: std::alloc::Vec
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetUpdates<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// 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 [`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
/// forgotten.
///
/// [`GetUpdates`]: self::GetUpdates
/// [`offset`]: self::GetUpdates::offset
/// [`id`]: crate::types::Update::id
pub offset: Option<i32>,
/// Limits the number of updates to be retrieved.
/// Values between `1`—`100` are accepted. Defaults to `100`.
pub limit: Option<u8>,
/// 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.
pub timeout: Option<u32>,
/// List the types of updates you want your bot to receive.
/// For example, specify [[`Message`], [`EditedChannelPost`],
/// [`CallbackQuery`]] to only receive updates of these types.
/// See [`AllowedUpdate`] for a complete list of available update types.
///
/// Specify an empty list to receive all updates regardless of type
/// (default). If not specified, the previous setting will be used.
///
/// **Note:**
/// This parameter doesn't affect updates created before the call to the
/// [`GetUpdates`], so unwanted updates may be received for a short period
/// of time.
///
/// [`Message`]: self::AllowedUpdate::Message
/// [`EditedChannelPost`]: self::AllowedUpdate::EditedChannelPost
/// [`CallbackQuery`]: self::AllowedUpdate::CallbackQuery
/// [`AllowedUpdate`]: self::AllowedUpdate
/// [`GetUpdates`]: self::GetUpdates
pub allowed_updates: Option<Vec<AllowedUpdate>>,
bot: BotWrapper<'a>,
pub(crate) offset: Option<i32>,
pub(crate) limit: Option<u8>,
pub(crate) timeout: Option<u32>,
pub(crate) allowed_updates: Option<Vec<AllowedUpdate>>,
}
#[async_trait::async_trait]
@ -83,7 +47,7 @@ impl Request for GetUpdates<'_> {
impl<'a> GetUpdates<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self {
Self {
bot,
bot: BotWrapper(bot),
offset: None,
limit: None,
timeout: None,
@ -91,24 +55,63 @@ impl<'a> GetUpdates<'a> {
}
}
/// 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 [`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 forgotten.
///
/// [`GetUpdates`]: self::GetUpdates
/// [`offset`]: self::GetUpdates::offset
/// [`id`]: crate::types::Update::id
pub fn offset(mut self, value: i32) -> Self {
self.offset = Some(value);
self
}
/// Limits the number of updates to be retrieved.
///
/// Values between `1`—`100` are accepted. Defaults to `100`.
pub fn limit(mut self, value: u8) -> Self {
self.limit = Some(value);
self
}
/// 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.
pub fn timeout(mut self, value: u32) -> Self {
self.timeout = Some(value);
self
}
/// List the types of updates you want your bot to receive.
///
/// For example, specify [[`Message`], [`EditedChannelPost`],
/// [`CallbackQuery`]] to only receive updates of these types.
/// See [`AllowedUpdate`] for a complete list of available update types.
///
/// Specify an empty list to receive all updates regardless of type
/// (default). If not specified, the previous setting will be used.
///
/// **Note:**
/// This parameter doesn't affect updates created before the call to the
/// [`Bot::get_updates`], so unwanted updates may be received for a short
/// period of time.
///
/// [`Message`]: self::AllowedUpdate::Message
/// [`EditedChannelPost`]: self::AllowedUpdate::EditedChannelPost
/// [`CallbackQuery`]: self::AllowedUpdate::CallbackQuery
/// [`AllowedUpdate`]: self::AllowedUpdate
/// [`Bot::get_updates`]: crate::Bot::get_updates
pub fn allowed_updates<T>(mut self, value: T) -> Self
where
T: Into<Vec<AllowedUpdate>>, // TODO: into or other trait?
T: Into<Vec<AllowedUpdate>>,
{
self.allowed_updates = Some(value.into());
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,21 +8,16 @@ use crate::{
Bot,
};
/// Use this method to get a list of profile pictures for a user. Returns a
/// UserProfilePhotos object.
/// Use this method to get a list of profile pictures for a user.
///
/// [The official docs](https://core.telegram.org/bots/api#getuserprofilephotos).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetUserProfilePhotos<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier of the target user
bot: BotWrapper<'a>,
user_id: i32,
/// Sequential number of the first photo to be returned. By default, all
/// photos are returned.
offset: Option<i32>,
/// Limits the number of photos to be retrieved. Values between 1—100 are
/// accepted. Defaults to 100.
limit: Option<i32>,
}
@ -43,23 +39,30 @@ impl Request for GetUserProfilePhotos<'_> {
impl<'a> GetUserProfilePhotos<'a> {
pub(crate) fn new(bot: &'a Bot, user_id: i32) -> Self {
Self {
bot,
bot: BotWrapper(bot),
user_id,
offset: None,
limit: None,
}
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// Sequential number of the first photo to be returned. By default, all
/// photos are returned.
pub fn offset(mut self, val: i32) -> Self {
self.offset = Some(val);
self
}
/// Limits the number of photos to be retrieved. Values between 1—100 are
/// accepted.
///
/// Defaults to 100.
pub fn limit(mut self, val: i32) -> Self {
self.limit = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,25 @@ use crate::{
Bot,
};
/// 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.
#[derive(Debug, Clone, Serialize)]
/// Use this method to get current webhook status.
///
/// If the bot is using [`Bot::get_updates`], will return an object with the url
/// field empty.
///
/// [The official docs](https://core.telegram.org/bots/api#getwebhookinfo).
///
/// [`Bot::get_updates`]: crate::Bot::get_updates
#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetWebhookInfo<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
}
#[async_trait::async_trait]
impl Request for GetWebhookInfo<'_> {
type Output = WebhookInfo;
#[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<WebhookInfo> {
net::request_json(
self.bot.client(),
@ -33,6 +40,8 @@ impl Request for GetWebhookInfo<'_> {
impl<'a> GetWebhookInfo<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self {
Self { bot }
Self {
bot: BotWrapper(bot),
}
}
}

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,25 +8,23 @@ use crate::{
Bot,
};
/// Use this method to kick a user from a group, a supergroup or a channel. In
/// the case of supergroups and channels, the user will not be able to return to
/// the group 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 admin rights. Returns True on success.
/// Use this method to kick a user from a group, a supergroup or a channel.
///
/// In the case of supergroups and channels, the user will not be able to return
/// to the group 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 admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#kickchatmember).
///
/// [unbanned]: crate::Bot::unban_chat_member
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct KickChatMember<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32,
/// 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
until_date: Option<i32>,
}
@ -51,13 +50,15 @@ impl<'a> KickChatMember<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
user_id,
until_date: None,
}
}
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -66,11 +67,16 @@ impl<'a> KickChatMember<'a> {
self
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// 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.
pub fn until_date(mut self, val: i32) -> Self {
self.until_date = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,15 +9,13 @@ use crate::{
};
/// Use this method for your bot to leave a group, supergroup or channel.
/// Returns True on success.
///
/// [The official docs](https://core.telegram.org/bots/api#leavechat).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct LeaveChat<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -41,9 +40,14 @@ impl<'a> LeaveChat<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -130,3 +130,6 @@ pub use stop_poll::*;
pub use unban_chat_member::*;
pub use unpin_chat_message::*;
pub use upload_sticker_file::*;
mod bot_wrapper;
use bot_wrapper::BotWrapper;

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,24 +8,20 @@ use crate::{
Bot,
};
/// Use this method to pin a message in a group, a supergroup, or a channel. The
/// bot must be an administrator in the chat for this to work and must have the
/// can_pin_messages admin right in the supergroup or can_edit_messages
/// admin right in the channel. Returns True on success.
/// Use this method to pin a message in a group, a supergroup, or a channel.
///
/// The bot must be an administrator in the chat for this to work and must have
/// the `can_pin_messages` admin right in the supergroup or `can_edit_messages`
/// admin right in the channel.
///
/// [The official docs](https://core.telegram.org/bots/api#pinchatmessage).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct PinChatMessage<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Identifier of a message to pin
message_id: i32,
/// 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.
disable_notification: Option<bool>,
}
@ -50,13 +47,15 @@ impl<'a> PinChatMessage<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
message_id,
disable_notification: None,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -65,11 +64,16 @@ impl<'a> PinChatMessage<'a> {
self
}
/// Identifier of a message to pin.
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self
}
/// 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.
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,40 +9,26 @@ use crate::{
};
/// 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 admin rights. Pass False for all boolean parameters to
/// demote a user. Returns True on success.
/// demote a user.
///
/// [The official docs](https://core.telegram.org/bots/api#promotechatmember).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct PromoteChatMember<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32,
/// Pass True, if the administrator can change chat title, photo and other
/// settings
can_change_info: Option<bool>,
/// Pass True, if the administrator can create channel posts, channels only
can_post_messages: Option<bool>,
/// Pass True, if the administrator can edit messages of other users and
/// can pin messages, channels only
can_edit_messages: Option<bool>,
/// Pass True, if the administrator can delete messages of other users
can_delete_messages: Option<bool>,
/// Pass True, if the administrator can invite new users to the chat
can_invite_users: Option<bool>,
/// Pass True, if the administrator can restrict, ban or unban chat members
can_restrict_members: Option<bool>,
/// Pass True, if the administrator can pin messages, supergroups only
can_pin_messages: Option<bool>,
/// Pass True, if the administrator can add new administrators with a
/// subset of his own privileges or demote administrators that he has
/// promoted, directly or indirectly (promoted by administrators that were
/// appointed by him)
can_promote_members: Option<bool>,
}
@ -67,7 +54,7 @@ impl<'a> PromoteChatMember<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
user_id,
can_change_info: None,
@ -81,6 +68,8 @@ impl<'a> PromoteChatMember<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -89,46 +78,62 @@ impl<'a> PromoteChatMember<'a> {
self
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// Pass `true`, if the administrator can change chat title, photo and other
/// settings.
pub fn can_change_info(mut self, val: bool) -> Self {
self.can_change_info = Some(val);
self
}
/// Pass `true`, if the administrator can create channel posts, channels
/// only.
pub fn can_post_messages(mut self, val: bool) -> Self {
self.can_post_messages = Some(val);
self
}
/// Pass `true`, if the administrator can edit messages of other users and
/// can pin messages, channels only.
pub fn can_edit_messages(mut self, val: bool) -> Self {
self.can_edit_messages = Some(val);
self
}
/// Pass `true`, if the administrator can delete messages of other users.
pub fn can_delete_messages(mut self, val: bool) -> Self {
self.can_delete_messages = Some(val);
self
}
/// Pass `true`, if the administrator can invite new users to the chat.
pub fn can_invite_users(mut self, val: bool) -> Self {
self.can_invite_users = Some(val);
self
}
/// Pass `true`, if the administrator can restrict, ban or unban chat
/// members.
pub fn can_restrict_members(mut self, val: bool) -> Self {
self.can_restrict_members = Some(val);
self
}
/// Pass `true`, if the administrator can pin messages, supergroups only.
pub fn can_pin_messages(mut self, val: bool) -> Self {
self.can_pin_messages = Some(val);
self
}
/// Pass `true`, if the administrator can add new administrators with a
/// subset of his own privileges or demote administrators that he has
/// promoted, directly or indirectly (promoted by administrators that were
/// appointed by him).
pub fn can_promote_members(mut self, val: bool) -> Self {
self.can_promote_members = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,26 +8,21 @@ use crate::{
Bot,
};
/// 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 admin rights. Pass True for all permissions to lift restrictions
/// from a user. Returns True on success.
/// 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 admin rights. Pass `true` for all permissions to lift
/// restrictions from a user.
///
/// [The official docs](https://core.telegram.org/bots/api#restrictchatmember).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct RestrictChatMember<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32,
/// New user permissions
permissions: ChatPermissions,
/// 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
until_date: Option<i32>,
}
@ -57,7 +53,7 @@ impl<'a> RestrictChatMember<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
user_id,
permissions,
@ -65,6 +61,8 @@ impl<'a> RestrictChatMember<'a> {
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -73,16 +71,22 @@ impl<'a> RestrictChatMember<'a> {
self
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// New user permissions.
pub fn permissions(mut self, val: ChatPermissions) -> Self {
self.permissions = val;
self
}
/// 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.
pub fn until_date(mut self, val: i32) -> Self {
self.until_date = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -8,52 +9,23 @@ use crate::{
/// Use 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.
#[derive(Debug, Clone)]
///
/// [The official docs](https://core.telegram.org/bots/api#sendanimation).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendAnimation<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`)
bot: BotWrapper<'a>,
pub chat_id: ChatId,
/// Animation to send.
pub animation: InputFile,
/// Duration of sent animation in seconds
pub duration: Option<u32>,
/// Animation width
pub width: Option<u32>,
/// Animation height
pub height: Option<u32>,
/// 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 thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// [`InputFile::File`]. Thumbnails cant be reused and can be only
/// uploaded as a new file, with [`InputFile::File`]
///
/// [`InputFile::File`]: crate::types::InputFile::File
pub thumb: Option<InputFile>,
/// Animation caption, `0`-`1024` characters
pub caption: Option<String>,
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
pub disable_notification: Option<bool>,
/// If the message is a reply, [id] of the original message
///
/// [id]: crate::types::Message::id
pub reply_to_message_id: Option<i32>,
/// Additional interface options
pub reply_markup: Option<ReplyMarkup>,
}
@ -101,7 +73,7 @@ impl<'a> SendAnimation<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
animation,
duration: None,
@ -116,6 +88,8 @@ impl<'a> SendAnimation<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, value: T) -> Self
where
T: Into<ChatId>,
@ -124,24 +98,46 @@ impl<'a> SendAnimation<'a> {
self
}
/// Animation to send.
pub fn animation(mut self, val: InputFile) -> Self {
self.animation = val;
self
}
/// Duration of sent animation in seconds.
pub fn duration(mut self, value: u32) -> Self {
self.duration = Some(value);
self
}
/// Animation width.
pub fn width(mut self, value: u32) -> Self {
self.width = Some(value);
self
}
/// Animation height.
pub fn height(mut self, value: u32) -> Self {
self.height = Some(value);
self
}
/// 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
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using [`InputFile::File`]. Thumbnails cant be
/// reused and can be only uploaded as a new file, with
/// [`InputFile::File`].
///
/// [`InputFile::File`]: crate::types::InputFile::File
pub fn thumb(mut self, value: InputFile) -> Self {
self.thumb = Some(value);
self
}
/// Animation caption, `0`-`1024` characters.
pub fn caption<T>(mut self, value: T) -> Self
where
T: Into<String>,
@ -149,18 +145,35 @@ impl<'a> SendAnimation<'a> {
self.caption = Some(value.into());
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, value: ParseMode) -> Self {
self.parse_mode = Some(value);
self
}
/// Sends the message silently. Users will receive a notification with no
/// sound.
pub fn disable_notification(mut self, value: bool) -> Self {
self.disable_notification = Some(value);
self
}
/// If the message is a reply, [id] of the original message.
///
/// [id]: crate::types::Message::id
pub fn reply_to_message_id(mut self, value: i32) -> Self {
self.reply_to_message_id = Some(value);
self
}
/// Additional interface options.
pub fn reply_markup<T>(mut self, value: T) -> Self
where
T: Into<ReplyMarkup>,

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -6,50 +7,29 @@ use crate::{
};
/// 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.
#[derive(Debug, Clone)]
/// them in the music player.
///
/// Your audio must be in the .MP3 or .M4A format. 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 [`Bot::send_voice`] method instead.
///
/// [The official docs](https://core.telegram.org/bots/api#sendaudio).
///
/// [`Bot::send_voice`]: crate::Bot::send_voice
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendAudio<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Audio file to send. Pass a file_id as String to send an audio file that
/// exists on the Telegram servers (recommended), pass an HTTP URL as a
/// String for Telegram to get an audio file from the Internet, or upload a
/// new one using multipart/form-data. More info on Sending Files »
audio: InputFile,
/// Audio caption, 0-1024 characters
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// Duration of the audio in seconds
duration: Option<i32>,
/// Performer
performer: Option<String>,
/// Track name
title: Option<String>,
/// 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 thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant 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 info on Sending Files »
thumb: Option<InputFile>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -97,7 +77,7 @@ impl<'a> SendAudio<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
audio,
caption: None,
@ -112,6 +92,8 @@ impl<'a> SendAudio<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -120,11 +102,24 @@ impl<'a> SendAudio<'a> {
self
}
/// Audio file to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn audio(mut self, val: InputFile) -> Self {
self.audio = val;
self
}
/// Audio caption, 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -133,16 +128,25 @@ impl<'a> SendAudio<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// Duration of the audio in seconds.
pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val);
self
}
/// Performer.
pub fn performer<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -151,6 +155,7 @@ impl<'a> SendAudio<'a> {
self
}
/// Track name.
pub fn title<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -159,21 +164,44 @@ impl<'a> SendAudio<'a> {
self
}
/// 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
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant
/// 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 info on
/// Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options. A JSON-serialized object for an [inline
/// keyboard], [custom reply keyboard], instructions to remove reply
/// keyboard or to force a reply from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,32 +9,35 @@ use crate::{
};
/// 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.Example: The ImageBot needs some time to process a request
/// and upload the image. Instead of sending a text message along the lines of
/// “Retrieving image, please wait…”, the bot may use sendChatAction with action
/// = upload_photo. The user will see a “sending photo” status for the bot.We
/// only recommend using this method when a response from the bot will take a
/// noticeable amount of time to arrive.
/// 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).
///
/// ## Note
/// Example: The [ImageBot] needs some time to process a request and upload the
/// image. Instead of sending a text message along the lines of “Retrieving
/// image, please wait…”, the bot may use [`Bot::send_chat_action`] with `action
/// = upload_photo`. The user will see a `sending photo` status for the bot.
///
/// We only recommend using this method when a response from the bot will take a
/// **noticeable** amount of time to arrive.
///
/// [ImageBot]: https://t.me/imagebot
/// [`Bot::send_chat_action`]: crate::Bot::send_chat_action
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendChatAction<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Type of action to broadcast.
action: SendChatActionKind,
}
/// A type of action used in [`SendChatAction`].
///
/// [`SendChatAction`]: crate::requests::SendChatAction
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SendChatActionKind {
/// For [text messages](crate::Bot::send_message).
@ -92,12 +96,14 @@ impl<'a> SendChatAction<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
action,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -106,6 +112,7 @@ impl<'a> SendChatAction<'a> {
self
}
/// Type of action to broadcast.
pub fn action(mut self, val: SendChatActionKind) -> Self {
self.action = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,33 +8,21 @@ use crate::{
Bot,
};
/// Use this method to send phone contacts. On success, the sent Message is
/// returned.
/// Use this method to send phone contacts.
///
/// [The official docs](https://core.telegram.org/bots/api#sendcontact).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendContact<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Contact's phone number
phone_number: String,
/// Contact's first name
first_name: String,
/// Contact's last name
last_name: Option<String>,
/// Additional data about the contact in the form of a vCard, 0-2048 bytes
vcard: Option<String>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove keyboard or to
/// force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -68,7 +57,7 @@ impl<'a> SendContact<'a> {
let phone_number = phone_number.into();
let first_name = first_name.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
phone_number,
first_name,
@ -80,6 +69,8 @@ impl<'a> SendContact<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -88,6 +79,7 @@ impl<'a> SendContact<'a> {
self
}
/// Contact's phone number.
pub fn phone_number<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -96,6 +88,7 @@ impl<'a> SendContact<'a> {
self
}
/// Contact's first name.
pub fn first_name<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -104,6 +97,7 @@ impl<'a> SendContact<'a> {
self
}
/// Contact's last name.
pub fn last_name<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -112,6 +106,10 @@ impl<'a> SendContact<'a> {
self
}
/// Additional data about the contact in the form of a [vCard], 0-2048
/// bytes.
///
/// [vCard]: https://en.wikipedia.org/wiki/VCard
pub fn vcard<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -120,16 +118,22 @@ impl<'a> SendContact<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -5,44 +6,22 @@ use crate::{
Bot,
};
/// 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.
#[derive(Debug, Clone)]
/// Use this method to send general files.
///
/// Bots can currently send files of any type of up to 50 MB in size, this limit
/// may be changed in the future.
///
/// [The official docs](https://core.telegram.org/bots/api#senddocument).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendDocument<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// File to send. Pass a file_id as String to send a file that exists on
/// the Telegram servers (recommended), 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 info on Sending Files »
document: InputFile,
/// 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 thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant 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 info on Sending Files »
thumb: Option<InputFile>,
/// Document caption (may also be used when resending documents by
/// file_id), 0-1024 characters
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -84,7 +63,7 @@ impl<'a> SendDocument<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
document,
thumb: None,
@ -96,6 +75,8 @@ impl<'a> SendDocument<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -104,16 +85,38 @@ impl<'a> SendDocument<'a> {
self
}
/// File to send.
///
/// Pass a file_id as String to send a file that exists on the
/// Telegram servers (recommended), 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 info on Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn document(mut self, val: InputFile) -> Self {
self.document = val;
self
}
/// 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
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant
/// 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 info on
/// Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
/// Document caption (may also be used when resending documents by
/// `file_id`), 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -122,21 +125,34 @@ impl<'a> SendDocument<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,26 +8,18 @@ use crate::{
Bot,
};
/// Use this method to send a game. On success, the sent Message is returned.
/// Use this method to send a game.
///
/// [The official docs](https://core.telegram.org/bots/api#sendgame).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendGame<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat
bot: BotWrapper<'a>,
chat_id: i32,
/// Short name of the game, serves as the unique identifier for the game.
/// Set up your games via Botfather.
game_short_name: String,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// 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.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -52,7 +45,7 @@ impl<'a> SendGame<'a> {
{
let game_short_name = game_short_name.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
game_short_name,
disable_notification: None,
@ -61,11 +54,16 @@ impl<'a> SendGame<'a> {
}
}
/// Unique identifier for the target chat.
pub fn chat_id(mut self, val: i32) -> Self {
self.chat_id = val;
self
}
/// Short name of the game, serves as the unique identifier for the game.
/// Set up your games via [@Botfather].
///
/// [@Botfather]: https://t.me/botfather
pub fn game_short_name<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -74,16 +72,26 @@ impl<'a> SendGame<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// 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.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,70 +8,36 @@ use crate::{
Bot,
};
/// Use this method to send invoices. On success, the sent Message is returned.
/// Use this method to send invoices.
///
/// [The official docs](https://core.telegram.org/bots/api#sendinvoice).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendInvoice<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target private chat
bot: BotWrapper<'a>,
chat_id: i32,
/// Product name, 1-32 characters
title: String,
/// Product description, 1-255 characters
description: String,
/// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
/// the user, use for your internal processes.
payload: String,
/// Payments provider token, obtained via Botfather
provider_token: String,
/// Unique deep-linking parameter that can be used to generate this invoice
/// when used as a start parameter
start_parameter: String,
/// Three-letter ISO 4217 currency code, see more on currencies
currency: String,
/// Price breakdown, a list of components (e.g. product price, tax,
/// discount, delivery cost, delivery tax, bonus, etc.)
prices: Vec<LabeledPrice>,
/// JSON-encoded 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.
provider_data: 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_url: Option<String>,
/// Photo size
photo_size: Option<i32>,
/// Photo width
photo_width: Option<i32>,
/// Photo height
photo_height: Option<i32>,
/// Pass True, if you require the user's full name to complete the order
need_name: Option<bool>,
/// Pass True, if you require the user's phone number to complete the order
need_phone_number: Option<bool>,
/// Pass True, if you require the user's email address to complete the
/// order
need_email: Option<bool>,
/// Pass True, if you require the user's shipping address to complete the
/// order
need_shipping_address: Option<bool>,
/// Pass True, if user's phone number should be sent to provider
send_phone_number_to_provider: Option<bool>,
/// Pass True, if user's email address should be sent to provider
send_email_to_provider: Option<bool>,
/// Pass True, if the final price depends on the shipping method
is_flexible: Option<bool>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// 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.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -119,7 +86,7 @@ impl<'a> SendInvoice<'a> {
let currency = currency.into();
let prices = prices.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
title,
description,
@ -146,11 +113,13 @@ impl<'a> SendInvoice<'a> {
}
}
/// Unique identifier for the target private chat.
pub fn chat_id(mut self, val: i32) -> Self {
self.chat_id = val;
self
}
/// Product name, 1-32 characters.
pub fn title<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -159,6 +128,7 @@ impl<'a> SendInvoice<'a> {
self
}
/// Product description, 1-255 characters.
pub fn description<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -167,6 +137,8 @@ impl<'a> SendInvoice<'a> {
self
}
/// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
/// the user, use for your internal processes.
pub fn payload<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -175,6 +147,9 @@ impl<'a> SendInvoice<'a> {
self
}
/// Payments provider token, obtained via [@Botfather].
///
/// [@Botfather]: https://t.me/botfather
pub fn provider_token<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -183,6 +158,8 @@ impl<'a> SendInvoice<'a> {
self
}
/// Unique deep-linking parameter that can be used to generate this invoice
/// when used as a start parameter.
pub fn start_parameter<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -191,6 +168,9 @@ impl<'a> SendInvoice<'a> {
self
}
/// Three-letter ISO 4217 currency code, see [more on currencies].
///
/// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies
pub fn currency<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -199,6 +179,8 @@ impl<'a> SendInvoice<'a> {
self
}
/// Price breakdown, a list of components (e.g. product price, tax,
/// discount, delivery cost, delivery tax, bonus, etc.).
pub fn prices<T>(mut self, val: T) -> Self
where
T: Into<Vec<LabeledPrice>>,
@ -207,6 +189,11 @@ impl<'a> SendInvoice<'a> {
self
}
/// JSON-encoded 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.
pub fn provider_data<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -215,6 +202,10 @@ impl<'a> SendInvoice<'a> {
self
}
/// 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.
pub fn photo_url<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -223,67 +214,91 @@ impl<'a> SendInvoice<'a> {
self
}
/// Photo size.
pub fn photo_size(mut self, val: i32) -> Self {
self.photo_size = Some(val);
self
}
/// Photo width.
pub fn photo_width(mut self, val: i32) -> Self {
self.photo_width = Some(val);
self
}
/// Photo height.
pub fn photo_height(mut self, val: i32) -> Self {
self.photo_height = Some(val);
self
}
/// Pass `true`, if you require the user's full name to complete the order.
pub fn need_name(mut self, val: bool) -> Self {
self.need_name = Some(val);
self
}
/// Pass `true`, if you require the user's phone number to complete the
/// order.
pub fn need_phone_number(mut self, val: bool) -> Self {
self.need_phone_number = Some(val);
self
}
/// Pass `true`, if you require the user's email address to complete the
/// order.
pub fn need_email(mut self, val: bool) -> Self {
self.need_email = Some(val);
self
}
/// Pass `true`, if you require the user's shipping address to complete the
/// order.
pub fn need_shipping_address(mut self, val: bool) -> Self {
self.need_shipping_address = Some(val);
self
}
/// Pass `true`, if user's phone number should be sent to provider.
pub fn send_phone_number_to_provider(mut self, val: bool) -> Self {
self.send_phone_number_to_provider = Some(val);
self
}
/// Pass `true`, if user's email address should be sent to provider.
pub fn send_email_to_provider(mut self, val: bool) -> Self {
self.send_email_to_provider = Some(val);
self
}
/// Pass `true`, if the final price depends on the shipping method.
#[allow(clippy::wrong_self_convention)]
pub fn is_flexible(mut self, val: bool) -> Self {
self.is_flexible = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// 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.
///
/// [inlint keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,32 +8,20 @@ use crate::{
Bot,
};
/// Use this method to send point on the map. On success, the sent Message is
/// returned.
/// Use this method to send point on the map.
///
/// [The official docs](https://core.telegram.org/bots/api#sendlocation).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(PartialEq, Debug, Clone, Serialize)]
pub struct SendLocation<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Latitude of the location
latitude: f32,
/// Longitude of the location
longitude: f32,
/// Period in seconds for which the location will be updated (see Live
/// Locations, should be between 60 and 86400.
live_period: Option<i64>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -63,7 +52,7 @@ impl<'a> SendLocation<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
latitude,
longitude,
@ -74,6 +63,8 @@ impl<'a> SendLocation<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -82,31 +73,48 @@ impl<'a> SendLocation<'a> {
self
}
/// Latitude of the location.
pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val;
self
}
/// Longitude of the location.
pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val;
self
}
/// Period in seconds for which the location will be updated (see [Live
/// Locations], should be between 60 and 86400).
///
/// [Live Locations]: https://telegram.org/blog/live-locations
pub fn live_period(mut self, val: i64) -> Self {
self.live_period = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// 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.
///
/// [inlint keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -5,22 +6,15 @@ use crate::{
Bot,
};
/// Use this method to send a group of photos or videos as an album. On success,
/// an array of the sent Messages is returned.
#[derive(Debug, Clone)]
/// Use this method to send a group of photos or videos as an album.
///
/// [The official docs](https://core.telegram.org/bots/api#sendmediagroup).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendMediaGroup<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// A JSON-serialized array describing photos and videos to be sent, must
/// include 210 items
media: Vec<InputMedia>, // TODO: InputMediaPhoto and InputMediaVideo
/// Sends the messages silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the messages are a reply, ID of the original message
reply_to_message_id: Option<i32>,
}
@ -57,7 +51,7 @@ impl<'a> SendMediaGroup<'a> {
let chat_id = chat_id.into();
let media = media.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
media,
disable_notification: None,
@ -65,6 +59,8 @@ impl<'a> SendMediaGroup<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -73,6 +69,8 @@ impl<'a> SendMediaGroup<'a> {
self
}
/// A JSON-serialized array describing photos and videos to be sent, must
/// include 210 items.
pub fn media<T>(mut self, val: T) -> Self
where
T: Into<Vec<InputMedia>>,
@ -81,11 +79,16 @@ impl<'a> SendMediaGroup<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the messages are a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -9,38 +10,18 @@ use crate::{
/// Use this method to send text messages.
///
/// On success, the sent [`Message`] is returned.
///
/// [`Message`]: crate::types::Message
/// [The official docs](https://core.telegram.org/bots/api#sendmessage).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendMessage<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`)
bot: BotWrapper<'a>,
pub chat_id: ChatId,
/// Text of the message to be sent
pub text: String,
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in your bot's message.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
pub disable_web_page_preview: Option<bool>,
/// Sends the message silently.
/// Users will receive a notification with no sound.
pub disable_notification: Option<bool>,
/// If the message is a reply, [id] of the original message
///
/// [id]: crate::types::Message::id
pub reply_to_message_id: Option<i32>,
/// Additional interface options.
pub reply_markup: Option<ReplyMarkup>,
}
@ -66,7 +47,7 @@ impl<'a> SendMessage<'a> {
T: Into<String>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
text: text.into(),
parse_mode: None,
@ -77,6 +58,8 @@ impl<'a> SendMessage<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, value: T) -> Self
where
T: Into<ChatId>,
@ -85,6 +68,7 @@ impl<'a> SendMessage<'a> {
self
}
/// Text of the message to be sent.
pub fn text<T>(mut self, value: T) -> Self
where
T: Into<String>,
@ -93,26 +77,47 @@ impl<'a> SendMessage<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, value: ParseMode) -> Self {
self.parse_mode = Some(value);
self
}
/// Disables link previews for links in this message.
pub fn disable_web_page_preview(mut self, value: bool) -> Self {
self.disable_web_page_preview = Some(value);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, value: bool) -> Self {
self.disable_notification = Some(value);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, value: i32) -> Self {
self.reply_to_message_id = Some(value);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup<T>(mut self, value: T) -> Self
where
T: Into<ReplyMarkup>,

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -5,33 +6,18 @@ use crate::{
Bot,
};
/// Use this method to send photos. On success, the sent Message is returned.
#[derive(Debug, Clone)]
/// Use this method to send photos.
///
/// [The official docs](https://core.telegram.org/bots/api#sendphoto).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendPhoto<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Photo to send. Pass a file_id as String to send a photo that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a photo from the Internet, or upload a new photo using
/// multipart/form-data. More info on Sending Files »
photo: InputFile,
/// Photo caption (may also be used when resending photos by file_id),
/// 0-1024 characters
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -71,7 +57,7 @@ impl<'a> SendPhoto<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
photo,
caption: None,
@ -82,6 +68,8 @@ impl<'a> SendPhoto<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -90,11 +78,25 @@ impl<'a> SendPhoto<'a> {
self
}
/// Photo to send.
///
/// Pass [`InputFile::File`] to send a photo that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn photo(mut self, val: InputFile) -> Self {
self.photo = val;
self
}
///Photo caption (may also be used when resending photos by file_id),
/// 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -103,21 +105,39 @@ impl<'a> SendPhoto<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options. A JSON-serialized object for an [inline
/// keyboard], [custom reply keyboard], instructions to remove reply
/// keyboard or to force a reply from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,29 +9,19 @@ use crate::{
};
/// Use this method to send a native poll. A native poll can't be sent to a
/// private chat. On success, the sent Message is returned.
/// private chat.
///
/// [The official docs](https://core.telegram.org/bots/api#sendpoll).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendPoll<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername). A native poll can't be sent to a
/// private chat.
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Poll question, 1-255 characters
question: String,
/// List of answer options, 2-10 strings 1-100 characters each
options: Vec<String>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -65,7 +56,7 @@ impl<'a> SendPoll<'a> {
let question = question.into();
let options = options.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
question,
options,
@ -75,6 +66,10 @@ impl<'a> SendPoll<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
///
/// A native poll can't be sent to a private chat.
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -83,6 +78,7 @@ impl<'a> SendPoll<'a> {
self
}
/// Poll question, 1-255 characters.
pub fn question<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -91,6 +87,7 @@ impl<'a> SendPoll<'a> {
self
}
/// List of answer options, 2-10 strings 1-100 characters each.
pub fn options<T>(mut self, val: T) -> Self
where
T: Into<Vec<String>>,
@ -99,16 +96,29 @@ impl<'a> SendPoll<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -5,28 +6,18 @@ use crate::{
Bot,
};
/// Use this method to send static .WEBP or animated .TGS stickers. On success,
/// the sent Message is returned.
#[derive(Debug, Clone)]
/// Use this method to send static .WEBP or [animated] .TGS stickers.
///
/// [The official docs](https://core.telegram.org/bots/api#sendsticker).
///
/// [animated]: https://telegram.org/blog/animated-stickers
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendSticker<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Sticker to send. Pass a file_id as String to send a file that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using multipart/form-data. More info on Sending Files »
sticker: InputFile,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -62,7 +53,7 @@ impl<'a> SendSticker<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
sticker,
disable_notification: None,
@ -71,6 +62,8 @@ impl<'a> SendSticker<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -79,21 +72,45 @@ impl<'a> SendSticker<'a> {
self
}
/// Sticker to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn sticker(mut self, val: InputFile) -> Self {
self.sticker = val;
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,39 +8,23 @@ use crate::{
Bot,
};
/// Use this method to send information about a venue. On success, the sent
/// Message is returned.
/// Use this method to send information about a venue.
///
/// [The official docs](https://core.telegram.org/bots/api#sendvenue).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(PartialEq, Debug, Clone, Serialize)]
pub struct SendVenue<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Latitude of the venue
latitude: f32,
/// Longitude of the venue
longitude: f32,
/// Name of the venue
title: String,
/// Address of the venue
address: String,
/// Foursquare identifier of the venue
foursquare_id: Option<String>,
/// Foursquare type of the venue, if known. (For example,
/// “arts_entertainment/default”, “arts_entertainment/aquarium” or
/// “food/icecream”.)
foursquare_type: Option<String>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -76,7 +61,7 @@ impl<'a> SendVenue<'a> {
let title = title.into();
let address = address.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
latitude,
longitude,
@ -90,6 +75,8 @@ impl<'a> SendVenue<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -98,16 +85,19 @@ impl<'a> SendVenue<'a> {
self
}
/// Latitude of the venue.
pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val;
self
}
/// Longitude of the venue.
pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val;
self
}
/// Name of the venue.
pub fn title<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -116,6 +106,7 @@ impl<'a> SendVenue<'a> {
self
}
/// Address of the venue.
pub fn address<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -124,6 +115,7 @@ impl<'a> SendVenue<'a> {
self
}
/// Foursquare identifier of the venue.
pub fn foursquare_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -132,6 +124,10 @@ impl<'a> SendVenue<'a> {
self
}
/// Foursquare type of the venue, if known.
///
/// For example, `arts_entertainment/default`, `arts_entertainment/aquarium`
/// or `food/icecream`.
pub fn foursquare_type<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -140,16 +136,29 @@ impl<'a> SendVenue<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -6,52 +7,26 @@ use crate::{
};
/// Use this method to send video files, Telegram clients support mp4 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
/// (other formats may be sent as Document).
///
/// Bots can currently send video files of up to 50 MB in size, this
/// limit may be changed in the future.
#[derive(Debug, Clone)]
///
/// [The official docs](https://core.telegram.org/bots/api#sendvideo).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendVideo<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Video to send. Pass a file_id as String to send a video that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a video from the Internet, or upload a new video using
/// multipart/form-data. More info on Sending Files »
video: InputFile,
/// Duration of sent video in seconds
duration: Option<i32>,
/// Video width
width: Option<i32>,
/// Video height
height: Option<i32>,
/// 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 thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant 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 info on Sending Files »
thumb: Option<InputFile>,
/// Video caption (may also be used when resending videos by file_id),
/// 0-1024 characters
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// Pass True, if the uploaded video is suitable for streaming
supports_streaming: Option<bool>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -101,7 +76,7 @@ impl<'a> SendVideo<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
video,
duration: None,
@ -117,6 +92,8 @@ impl<'a> SendVideo<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -125,31 +102,58 @@ impl<'a> SendVideo<'a> {
self
}
/// Video to sent.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
pub fn video(mut self, val: InputFile) -> Self {
self.video = val;
self
}
/// Duration of sent video in seconds.
pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val);
self
}
/// Video width.
pub fn width(mut self, val: i32) -> Self {
self.width = Some(val);
self
}
/// Video height.
pub fn height(mut self, val: i32) -> Self {
self.height = Some(val);
self
}
/// 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
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant 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 info on Sending
/// Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
/// Video caption (may also be used when resending videos by file_id),
/// 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -158,26 +162,47 @@ impl<'a> SendVideo<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// Pass `true`, if the uploaded video is suitable for streaming.
pub fn supports_streaming(mut self, val: bool) -> Self {
self.supports_streaming = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -5,42 +6,22 @@ use crate::{
Bot,
};
/// As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1
/// minute long. Use this method to send video messages. On success, the sent
/// Message is returned.
#[derive(Debug, Clone)]
/// As of [v.4.0], Telegram clients support rounded square mp4 videos of up to 1
/// minute long. Use this method to send video messages.
///
/// [The official docs](https://core.telegram.org/bots/api#sendvideonote).
///
/// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendVideoNote<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Video note to send. Pass a file_id as String to send a video note that
/// exists on the Telegram servers (recommended) or upload a new video
/// using multipart/form-data. More info on Sending Files ». Sending video
/// notes by a URL is currently unsupported
video_note: InputFile,
/// Duration of sent video in seconds
duration: Option<i32>,
/// Video width and height, i.e. diameter of the video message
length: Option<i32>,
/// 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 thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant 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 info on Sending Files »
thumb: Option<InputFile>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -86,7 +67,7 @@ impl<'a> SendVideoNote<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
video_note,
duration: None,
@ -98,6 +79,8 @@ impl<'a> SendVideoNote<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -106,36 +89,72 @@ impl<'a> SendVideoNote<'a> {
self
}
/// Video note to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn video_note(mut self, val: InputFile) -> Self {
self.video_note = val;
self
}
/// Duration of sent video in seconds.
pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val);
self
}
/// Video width and height, i.e. diameter of the video message.
pub fn length(mut self, val: i32) -> Self {
self.length = Some(val);
self
}
/// 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
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant
/// 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 info on
/// Sending Files »].
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,3 +1,4 @@
use super::BotWrapper;
use crate::{
net,
requests::{form_builder::FormBuilder, Request, ResponseResult},
@ -6,38 +7,27 @@ use crate::{
};
/// 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 (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
/// the file as a playable voice message.
///
/// For this to work, your audio must be in an .ogg file encoded with OPUS
/// (other formats may be sent as [`Audio`] or [`Document`]). Bots can currently
/// send voice messages of up to 50 MB in size, this limit may be changed in the
/// future.
#[derive(Debug, Clone)]
///
/// [The official docs](https://core.telegram.org/bots/api#sendvoice).
///
/// [`Audio`]: crate::types::Audio
/// [`Document`]: crate::types::Document
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendVoice<'a> {
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Audio file to send. Pass a file_id as String to send a file that exists
/// on the Telegram servers (recommended), 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 info on Sending Files »
voice: InputFile,
/// Voice message caption, 0-1024 characters
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// Duration of the voice message in seconds
duration: Option<i32>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>,
}
@ -79,7 +69,7 @@ impl<'a> SendVoice<'a> {
C: Into<ChatId>,
{
Self {
bot,
bot: BotWrapper(bot),
chat_id: chat_id.into(),
voice,
caption: None,
@ -91,6 +81,8 @@ impl<'a> SendVoice<'a> {
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -99,11 +91,23 @@ impl<'a> SendVoice<'a> {
self
}
/// Audio file to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn voice(mut self, val: InputFile) -> Self {
self.voice = val;
self
}
/// Voice message caption, 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -112,26 +116,47 @@ impl<'a> SendVoice<'a> {
self
}
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
/// Duration of the voice message in seconds.
pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -9,22 +10,16 @@ use crate::{
/// Use this method to set a custom title for an administrator in a supergroup
/// promoted by the bot.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatadministratorcustomtitle).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatAdministratorCustomTitle<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`)
pub chat_id: ChatId,
/// Unique identifier of the target user
pub user_id: i32,
/// New custom title for the administrator; 0-16 characters, emoji are not
/// allowed
pub custom_title: String,
bot: BotWrapper<'a>,
chat_id: ChatId,
user_id: i32,
custom_title: String,
}
#[async_trait::async_trait]
@ -56,13 +51,15 @@ impl<'a> SetChatAdministratorCustomTitle<'a> {
let chat_id = chat_id.into();
let custom_title = custom_title.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
user_id,
custom_title,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -71,11 +68,14 @@ impl<'a> SetChatAdministratorCustomTitle<'a> {
self
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// New custom title for the administrator; 0-16 characters, emoji are not
/// allowed.
pub fn custom_title<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,18 +9,18 @@ use crate::{
};
/// 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 admin rights. Returns True on success.
/// channel.
///
/// The bot must be an administrator in the chat for this to work and must have
/// the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatdescription).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatDescription<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// New chat description, 0-255 characters
description: Option<String>,
}
@ -45,12 +46,14 @@ impl<'a> SetChatDescription<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
description: None,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -59,6 +62,7 @@ impl<'a> SetChatDescription<'a> {
self
}
/// New chat description, 0-255 characters.
pub fn description<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,18 @@ use crate::{
Bot,
};
/// 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 admin rights. Returns True on success.
/// 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 admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatpermissions).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatPermissions<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// New default chat permissions
permissions: ChatPermissions,
}
@ -49,12 +49,14 @@ impl<'a> SetChatPermissions<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
permissions,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -63,6 +65,7 @@ impl<'a> SetChatPermissions<'a> {
self
}
/// New default chat permissions.
pub fn permissions(mut self, val: ChatPermissions) -> Self {
self.permissions = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,20 +8,18 @@ use crate::{
Bot,
};
/// 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 admin rights. Returns True on
/// success.
/// 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 admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatphoto).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatPhoto<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// New chat photo, uploaded using multipart/form-data
photo: InputFile,
}
@ -46,12 +45,14 @@ impl<'a> SetChatPhoto<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
photo,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -60,6 +61,7 @@ impl<'a> SetChatPhoto<'a> {
self
}
/// New chat photo, uploaded using `multipart/form-data`.
pub fn photo(mut self, val: InputFile) -> Self {
self.photo = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,21 +8,19 @@ use crate::{
Bot,
};
/// 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 admin rights. Use the field can_set_sticker_set optionally
/// 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 admin 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.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatstickerset).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatStickerSet<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Name of the sticker set to be set as the group sticker set
sticker_set_name: String,
}
@ -53,12 +52,14 @@ impl<'a> SetChatStickerSet<'a> {
let chat_id = chat_id.into();
let sticker_set_name = sticker_set_name.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
sticker_set_name,
}
}
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -67,6 +68,7 @@ impl<'a> SetChatStickerSet<'a> {
self
}
/// Name of the sticker set to be set as the group sticker set.
pub fn sticker_set_name<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,18 @@ use crate::{
Bot,
};
/// 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 admin rights. Returns True on success.
/// 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 admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchattitle).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatTitle<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// New chat title, 1-255 characters
title: String,
}
@ -47,12 +47,14 @@ impl<'a> SetChatTitle<'a> {
let chat_id = chat_id.into();
let title = title.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
title,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -61,6 +63,7 @@ impl<'a> SetChatTitle<'a> {
self
}
/// New chat title, 1-255 characters.
pub fn title<T>(mut self, val: T) -> Self
where
T: Into<String>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,28 +8,27 @@ use crate::{
Bot,
};
/// Use this method to set the score of the specified user in a game. On
/// success, if the message was sent by the bot, returns the edited Message,
/// otherwise returns True. Returns an error, if the new score is not greater
/// than the user's current score in the chat and force is False.
/// Use this method to set the score of the specified user in a game.
///
/// On success, if the message was sent by the bot, returns the edited
/// [`Message`], otherwise returns [`True`]. Returns an error, if the new score
/// is not greater than the user's current score in the chat and force is
/// `false`.
///
/// [The official docs](https://core.telegram.org/bots/api#setgamescore).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetGameScore<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// User identifier
user_id: i32,
/// New score, must be non-negative
score: i32,
/// Pass True, if the high score is allowed to decrease. This can be useful
/// when fixing mistakes or banning cheaters
force: Option<bool>,
/// Pass True, if the game message should not be automatically edited to
/// include the current scoreboard
disable_edit_message: Option<bool>,
}
@ -55,7 +55,7 @@ impl<'a> SetGameScore<'a> {
score: i32,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
user_id,
score,
@ -69,21 +69,30 @@ impl<'a> SetGameScore<'a> {
self
}
/// User identifier.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// New score, must be non-negative.
pub fn score(mut self, val: i32) -> Self {
self.score = val;
self
}
/// Pass `true`, if the high score is allowed to decrease.
///
/// This can be useful when fixing mistakes or banning cheaters.
pub fn force(mut self, val: bool) -> Self {
self.force = Some(val);
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_edit_message(mut self, val: bool) -> Self {
self.disable_edit_message = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,16 +9,15 @@ use crate::{
};
/// Use this method to move a sticker in a set created by the bot to a specific
/// position . Returns True on success.
/// position.
///
/// [The official docs](https://core.telegram.org/bots/api#setstickerpositioninset).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetStickerPositionInSet<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// File identifier of the sticker
bot: BotWrapper<'a>,
sticker: String,
/// New sticker position in the set, zero-based
position: i32,
}
@ -43,12 +43,13 @@ impl<'a> SetStickerPositionInSet<'a> {
{
let sticker = sticker.into();
Self {
bot,
bot: BotWrapper(bot),
sticker,
position,
}
}
/// File identifier of the sticker.
pub fn sticker<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -57,6 +58,7 @@ impl<'a> SetStickerPositionInSet<'a> {
self
}
/// New sticker position in the set, zero-based.
pub fn position(mut self, val: i32) -> Self {
self.position = val;
self

View file

@ -1,51 +1,38 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
types::{InputFile, True},
types::{AllowedUpdate, InputFile, True},
Bot,
};
/// 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
/// 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, we will give up after a
/// reasonable amount of attempts. Returns True on success. If you'd like to
/// make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else
/// knows your bots token, you can be pretty sure its us.Notes1. You will not
/// be able to receive updates using getUpdates for as long as an outgoing
/// webhook is set up.2. To use a self-signed certificate, you need to upload
/// your public key certificate using certificate parameter. Please upload as
/// InputFile, sending a String will not work.3. Ports currently supported for
/// Webhooks: 443, 80, 88, 8443.NEW! If you're having any trouble setting up
/// webhooks, please check out this amazing guide to Webhooks.
/// [`Update`]. In case of an unsuccessful request, we will give up after a
/// reasonable amount of attempts.
///
/// If you'd like to make sure that the Webhook request comes from Telegram,
/// we recommend using a secret path in the URL, e.g.
/// `https://www.example.com/<token>`. Since nobody else knows your bots
/// token, you can be pretty sure its us.
///
/// [The official docs](https://core.telegram.org/bots/api#setwebhook).
///
/// [`Update`]: crate::types::Update
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetWebhook<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// HTTPS url to send updates to. Use an empty string to remove webhook
/// integration
bot: BotWrapper<'a>,
url: String,
/// Upload your public key certificate so that the root certificate in use
/// can be checked. See our self-signed guide for details.
certificate: Option<InputFile>,
/// 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 bots server, and higher values to increase your bots
/// throughput.
max_connections: Option<i32>,
/// List the types of updates 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 updates
/// regardless of type (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.
allowed_updates: Option<Vec<String>>,
allowed_updates: Option<Vec<AllowedUpdate>>,
}
#[async_trait::async_trait]
@ -70,7 +57,7 @@ impl<'a> SetWebhook<'a> {
{
let url = url.into();
Self {
bot,
bot: BotWrapper(bot),
url,
certificate: None,
max_connections: None,
@ -78,6 +65,9 @@ impl<'a> SetWebhook<'a> {
}
}
/// HTTPS url to send updates to.
///
/// Use an empty string to remove webhook integration.
pub fn url<T>(mut self, val: T) -> Self
where
T: Into<String>,
@ -86,19 +76,50 @@ impl<'a> SetWebhook<'a> {
self
}
/// Upload your public key certificate so that the root certificate in use
/// can be checked.
///
/// See our [self-signed guide] for details.
///
/// [self-signed guide]: https://core.telegram.org/bots/self-signed
pub fn certificate(mut self, val: InputFile) -> Self {
self.certificate = Some(val);
self
}
/// 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 bots server,
/// and higher values to increase your bots throughput.
pub fn max_connections(mut self, val: i32) -> Self {
self.max_connections = Some(val);
self
}
/// List the types of updates you want your bot to receive.
///
/// For example, specify [`AllowedUpdate::Message`],
/// [`AllowedUpdate::EditedChannelPost`], [`AllowedUpdate::CallbackQuery`]
/// to only receive updates of these types. Specify an empty list to receive
/// all updates regardless of type (default). If not specified, the
/// previous setting will be used. See [`AllowedUpdate`] for a complete list
/// of available update types.
///
/// Please note that this parameter doesn't affect updates created before
/// the call to the [`Bot::set_webhook`], so unwanted updates may be
/// received for a short period of time.
///
/// [`Bot::set_webhook`]: crate::Bot::set_webhook
/// [`AllowedUpdate::Message`]: crate::types::AllowedUpdate::Message
/// [`AllowedUpdate::EditedChannelPost`]:
/// crate::types::AllowedUpdate::EditedChannelPost
/// [`AllowedUpdate::CallbackQuery`]:
/// crate::types::AllowedUpdate::CallbackQuery
/// [`AllowedUpdate`]: crate::types::AllowedUpdate
pub fn allowed_updates<T>(mut self, val: T) -> Self
where
T: Into<Vec<String>>,
T: Into<Vec<AllowedUpdate>>,
{
self.allowed_updates = Some(val.into());
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,19 +8,23 @@ use crate::{
Bot,
};
/// Use this method to stop updating a live location message before live_period
/// expires. On success, if the message was sent by the bot, the sent Message is
/// returned, otherwise True is returned.
/// Use this method to stop updating a live location message before
/// `live_period` expires.
///
/// On success, if the message was sent by the bot, the sent [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#stopmessagelivelocation).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct StopMessageLiveLocation<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
bot: BotWrapper<'a>,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -44,7 +49,7 @@ impl<'a> StopMessageLiveLocation<'a> {
chat_or_inline_message: ChatOrInlineMessage,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
chat_or_inline_message,
reply_markup: None,
}
@ -55,6 +60,9 @@ impl<'a> StopMessageLiveLocation<'a> {
self
}
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -7,20 +8,16 @@ use crate::{
Bot,
};
/// Use this method to stop a poll which was sent by the bot. On success, the
/// stopped Poll with the final results is returned.
/// Use this method to stop a poll which was sent by the bot.
///
/// [The official docs](https://core.telegram.org/bots/api#stoppoll).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct StopPoll<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Identifier of the original message with the poll
message_id: i32,
/// A JSON-serialized object for a new message inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -28,6 +25,9 @@ pub struct StopPoll<'a> {
impl Request for StopPoll<'_> {
type Output = Poll;
/// On success, the stopped [`Poll`] with the final results is returned.
///
/// [`Poll`]: crate::types::Poll
async fn send(&self) -> ResponseResult<Poll> {
net::request_json(
self.bot.client(),
@ -45,13 +45,15 @@ impl<'a> StopPoll<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
message_id,
reply_markup: None,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -60,11 +62,15 @@ impl<'a> StopPoll<'a> {
self
}
/// Identifier of the original message with the poll.
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self
}
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,19 +9,17 @@ use crate::{
};
/// Use this method to unban a previously kicked 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. Returns True on success.
/// 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.
///
/// [The official docs](https://core.telegram.org/bots/api#unbanchatmember).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct UnbanChatMember<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format @username)
bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32,
}
@ -46,12 +45,14 @@ impl<'a> UnbanChatMember<'a> {
{
let chat_id = chat_id.into();
Self {
bot,
bot: BotWrapper(bot),
chat_id,
user_id,
}
}
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format `@username`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
@ -60,6 +61,7 @@ impl<'a> UnbanChatMember<'a> {
self
}
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,17 +9,17 @@ use crate::{
};
/// Use this method to unpin a message in a group, a supergroup, or a channel.
///
/// The bot must be an administrator in the chat for this to work and must have
/// the can_pin_messages admin right in the supergroup or can_edit_messages
/// admin right in the channel. Returns True on success.
/// the `can_pin_messages` admin right in the supergroup or `can_edit_messages`
/// admin right in the channel.
///
/// [The official docs](https://core.telegram.org/bots/api#unpinchatmessage).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct UnpinChatMessage<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
bot: BotWrapper<'a>,
chat_id: ChatId,
}
@ -43,9 +44,14 @@ impl<'a> UnpinChatMessage<'a> {
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { bot, chat_id }
Self {
bot: BotWrapper(bot),
chat_id,
}
}
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,

View file

@ -1,5 +1,6 @@
use serde::Serialize;
use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
@ -8,19 +9,19 @@ use crate::{
};
/// Use this method to upload a .png file with a sticker for later use in
/// createNewStickerSet and addStickerToSet methods (can be used multiple
/// times). Returns the uploaded File on success.
/// [`Bot::create_new_sticker_set`] and [`Bot::add_sticker_to_set`] methods (can
/// be used multiple times).
///
/// [The official docs](https://core.telegram.org/bots/api#uploadstickerfile).
///
/// [`Bot::create_new_sticker_set`]: crate::Bot::create_new_sticker_set
/// [`Bot::add_sticker_to_set`]: crate::Bot::add_sticker_to_set
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct UploadStickerFile<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// User identifier of sticker file owner
bot: BotWrapper<'a>,
user_id: i32,
/// Png image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. More info on Sending Files »
png_sticker: InputFile,
}
#[async_trait::async_trait]
@ -45,17 +46,23 @@ impl<'a> UploadStickerFile<'a> {
png_sticker: InputFile,
) -> Self {
Self {
bot,
bot: BotWrapper(bot),
user_id,
png_sticker,
}
}
/// User identifier of sticker file owner.
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
/// **Png** image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. [More info on Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn png_sticker(mut self, val: InputFile) -> Self {
self.png_sticker = val;
self

View file

@ -9,10 +9,10 @@ use super::PassportFile;
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct EncryptedPassportElement {
/// Base64-encoded element hash for using in
/// [`PassportElementErrorUnspecified`].
/// [`PassportElementErrorKind::Unspecified`].
///
/// [`PassportElementErrorUnspecified`]:
/// crate::types::PassportElementErrorUnspecified
/// [`PassportElementErrorKind::Unspecified`]:
/// crate::types::PassportElementErrorKind::Unspecified
pub hash: String,
#[serde(flatten)]