From 2f94a226cddeb5bb50f6421457c8c72f9c6e6170 Mon Sep 17 00:00:00 2001 From: Pmarquez <48651252+pxp9@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:10:00 +0200 Subject: [PATCH] Bot API 7.6 (#175) * feat: Added PaidMedia classes * fix: clippy * feat: add method sendPaidMedia * fixes --------- Co-authored-by: Ayrat Badykov --- src/api_params.rs | 49 +++++++++++++-- src/api_traits/async_telegram_api.rs | 8 +++ src/api_traits/telegram_api.rs | 8 +++ src/objects.rs | 90 ++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 4 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 2db49c2..07e80cd 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -7,10 +7,10 @@ use crate::objects::{ InlineQueryResultCachedVoice, InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultGame, InlineQueryResultGif, InlineQueryResultLocation, InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVenue, - InlineQueryResultVideo, InlineQueryResultVoice, InputPollOption, InputSticker, LabeledPrice, - LinkPreviewOptions, MaskPosition, MenuButton, MessageEntity, PassportElementErrorDataField, - PassportElementErrorFile, PassportElementErrorFiles, PassportElementErrorFrontSide, - PassportElementErrorReverseSide, PassportElementErrorSelfie, + InlineQueryResultVideo, InlineQueryResultVoice, InputPaidMedia, InputPollOption, InputSticker, + LabeledPrice, LinkPreviewOptions, MaskPosition, MenuButton, MessageEntity, + PassportElementErrorDataField, PassportElementErrorFile, PassportElementErrorFiles, + PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorTranslationFile, PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType, ReactionType, ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, StickerFormat, StickerType, WebAppInfo, @@ -876,6 +876,47 @@ pub struct SendVideoNoteParams { pub reply_markup: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct SendPaidMediaParams { + pub chat_id: ChatId, + + pub star_count: u32, + + pub media: Vec, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub caption: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub parse_mode: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub caption_entities: Option>, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub show_caption_above_media: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub disable_notification: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub protect_content: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub reply_parameters: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub reply_markup: Option, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct SendMediaGroupParams { #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/api_traits/async_telegram_api.rs b/src/api_traits/async_telegram_api.rs index ce956d6..01cb6dd 100644 --- a/src/api_traits/async_telegram_api.rs +++ b/src/api_traits/async_telegram_api.rs @@ -81,6 +81,7 @@ use crate::api_params::SendInvoiceParams; use crate::api_params::SendLocationParams; use crate::api_params::SendMediaGroupParams; use crate::api_params::SendMessageParams; +use crate::api_params::SendPaidMediaParams; use crate::api_params::SendPhotoParams; use crate::api_params::SendPollParams; use crate::api_params::SendStickerParams; @@ -458,6 +459,13 @@ pub trait AsyncTelegramApi { .await } + async fn send_paid_media( + &self, + params: SendPaidMediaParams, + ) -> Result, Self::Error> { + self.request("sendPaidMedia", Some(params)).await + } + async fn send_location( &self, params: &SendLocationParams, diff --git a/src/api_traits/telegram_api.rs b/src/api_traits/telegram_api.rs index a908643..24aa058 100644 --- a/src/api_traits/telegram_api.rs +++ b/src/api_traits/telegram_api.rs @@ -80,6 +80,7 @@ use crate::api_params::SendInvoiceParams; use crate::api_params::SendLocationParams; use crate::api_params::SendMediaGroupParams; use crate::api_params::SendMessageParams; +use crate::api_params::SendPaidMediaParams; use crate::api_params::SendPhotoParams; use crate::api_params::SendPollParams; use crate::api_params::SendStickerParams; @@ -433,6 +434,13 @@ pub trait TelegramApi { self.request_with_possible_form_data(method_name, params, files) } + fn send_paid_media( + &self, + params: SendPaidMediaParams, + ) -> Result, Self::Error> { + self.request("sendPaidMedia", Some(params)) + } + fn send_location( &self, params: &SendLocationParams, diff --git a/src/objects.rs b/src/objects.rs index e3bb466..c97db5e 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -640,6 +640,10 @@ pub struct ChatFullInfo { #[builder(setter(into, strip_option), default)] pub permissions: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub can_send_paid_media: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub slow_mode_delay: Option, @@ -802,6 +806,10 @@ pub struct Message { #[builder(setter(into, strip_option), default)] pub document: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub paid_media: Option>, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub photo: Option>, @@ -1096,6 +1104,10 @@ pub struct ExternalReplyInfo { #[builder(setter(into, strip_option), default)] pub document: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub paid_media: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub photo: Option>, @@ -3510,6 +3522,84 @@ pub struct Invoice { pub total_amount: u32, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct PaidMediaInfo { + pub start_count: u32, + + pub paid_media: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(tag = "type", rename_all = "snake_case")] +pub enum PaidMedia { + Preview(PaidMediaPreview), + Photo(PaidMediaPhoto), + Video(PaidMediaVideo), +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct PaidMediaPreview { + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub width: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub height: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub duration: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PaidMediaPhoto { + pub photo: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PaidMediaVideo { + pub video: Video, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(tag = "type", rename_all = "snake_case")] +pub enum InputPaidMedia { + Photo(InputPaidMediaPhoto), + Video(InputPaidMediaVideo), +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct InputPaidMediaPhoto { + #[builder(setter(into))] + pub media: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct InputPaidMediaVideo { + #[builder(setter(into))] + pub media: String, + + #[builder(setter(into))] + pub thumbnail: String, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub width: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub height: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub duration: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub supports_streaming: Option, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct ShippingAddress { #[builder(setter(into))]