Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Jul 14, 2024
1 parent c94c448 commit d434196
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 120 deletions.
80 changes: 41 additions & 39 deletions src/api_params.rs
Original file line number Diff line number Diff line change
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 Expand Up @@ -2796,45 +2837,6 @@ pub struct UnpinAllGeneralForumTopicMessagesParams {
pub chat_id: ChatId,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct SendPaidMediaParams {
pub chat_id: ChatId,
pub star_count: i32,
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<String>,

#[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 ReplyParameters {
pub message_id: i32,
Expand Down
14 changes: 7 additions & 7 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,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 Expand Up @@ -1362,13 +1369,6 @@ 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 request_without_body<T: serde::de::DeserializeOwned>(
&self,
method: &str,
Expand Down
14 changes: 7 additions & 7 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,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 Expand Up @@ -1299,13 +1306,6 @@ pub trait TelegramApi {
self.request("unpinAllGeneralForumTopicMessages", Some(params))
}

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

fn request_without_body<T: serde::de::DeserializeOwned>(
&self,
method: &str,
Expand Down
157 changes: 90 additions & 67 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 Expand Up @@ -4172,73 +4262,6 @@ pub struct StarTransactions {
pub transactions: Vec<StarTransaction>,
}

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

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

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

#[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)]
pub struct InputPaidMediaPhoto {
pub media: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct InputPaidMediaVideo {
pub media: String,
pub thumbnail: FileUpload,

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

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

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

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

#[cfg(test)]
mod serde_tests {
use super::*;
Expand Down

0 comments on commit d434196

Please sign in to comment.