Skip to content

Commit

Permalink
Bot API 7.6 (#175)
Browse files Browse the repository at this point in the history
* feat: Added PaidMedia classes

* fix: clippy

* feat: add method sendPaidMedia

* fixes

---------

Co-authored-by: Ayrat Badykov <[email protected]>
  • Loading branch information
pxp9 and ayrat555 authored Jul 14, 2024
1 parent a3f9d85 commit 2f94a22
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -876,6 +876,47 @@ pub struct SendVideoNoteParams {
pub reply_markup: Option<ReplyMarkup>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct SendPaidMediaParams {
pub chat_id: ChatId,

pub star_count: u32,

pub media: Vec<InputPaidMedia>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub caption: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub parse_mode: Option<ParseMode>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub caption_entities: Option<Vec<MessageEntity>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub show_caption_above_media: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub disable_notification: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub protect_content: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub reply_parameters: Option<ReplyParameters>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub reply_markup: Option<ReplyMarkup>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendMediaGroupParams {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
8 changes: 8 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -458,6 +459,13 @@ pub trait AsyncTelegramApi {
.await
}

async fn send_paid_media(
&self,
params: SendPaidMediaParams,
) -> Result<MethodResponse<Message>, Self::Error> {
self.request("sendPaidMedia", Some(params)).await
}

async fn send_location(
&self,
params: &SendLocationParams,
Expand Down
8 changes: 8 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MethodResponse<Message>, Self::Error> {
self.request("sendPaidMedia", Some(params))
}

fn send_location(
&self,
params: &SendLocationParams,
Expand Down
90 changes: 90 additions & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ pub struct ChatFullInfo {
#[builder(setter(into, strip_option), default)]
pub permissions: Option<ChatPermissions>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub can_send_paid_media: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub slow_mode_delay: Option<u16>,
Expand Down Expand Up @@ -802,6 +806,10 @@ pub struct Message {
#[builder(setter(into, strip_option), default)]
pub document: Option<Box<Document>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub paid_media: Option<Box<PaidMediaInfo>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub photo: Option<Vec<PhotoSize>>,
Expand Down Expand Up @@ -1096,6 +1104,10 @@ pub struct ExternalReplyInfo {
#[builder(setter(into, strip_option), default)]
pub document: Option<Document>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub paid_media: Option<PaidMediaInfo>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub photo: Option<Vec<PhotoSize>>,
Expand Down Expand Up @@ -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<PaidMedia>,
}

#[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<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub height: Option<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub duration: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PaidMediaPhoto {
pub photo: Vec<PhotoSize>,
}

#[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<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub height: Option<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub duration: Option<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub supports_streaming: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ShippingAddress {
#[builder(setter(into))]
Expand Down

0 comments on commit 2f94a22

Please sign in to comment.