From 2242990050f07333a3f58bef68f36d7638212148 Mon Sep 17 00:00:00 2001 From: Desiders Date: Thu, 15 Aug 2024 01:18:27 +0300 Subject: [PATCH 1/4] Add `paid_media` to `TransactionPartnerUser` type --- telers/src/types/transaction_partner_user.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telers/src/types/transaction_partner_user.rs b/telers/src/types/transaction_partner_user.rs index 4e00223..dcd83d4 100644 --- a/telers/src/types/transaction_partner_user.rs +++ b/telers/src/types/transaction_partner_user.rs @@ -1,4 +1,4 @@ -use super::User; +use super::{PaidMedia, User}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; @@ -13,4 +13,6 @@ pub struct TransactionPartnerUser { pub user: User, /// Bot-specified invoice payload pub invoice_payload: Option>, + /// Information about the paid media bought by the user + pub paid_media: Option>, } From ee1fa06f675c43411c1601a07b4faf2e60d9eb68 Mon Sep 17 00:00:00 2001 From: Desiders Date: Thu, 15 Aug 2024 01:32:39 +0300 Subject: [PATCH 2/4] Add `CreateChatSubscriptionInviteLink` and `EditChatSubscriptionInviteLink` methods --- telers/src/methods.rs | 4 + .../create_chat_subscription_invite_link.rs | 100 ++++++++++++++++++ .../edit_chat_subscription_invite_link.rs | 85 +++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 telers/src/methods/create_chat_subscription_invite_link.rs create mode 100644 telers/src/methods/edit_chat_subscription_invite_link.rs diff --git a/telers/src/methods.rs b/telers/src/methods.rs index 0261a2e..02623fd 100644 --- a/telers/src/methods.rs +++ b/telers/src/methods.rs @@ -39,6 +39,7 @@ pub mod close_general_forum_topic; pub mod copy_message; pub mod copy_messages; pub mod create_chat_invite_link; +pub mod create_chat_subscription_invite_link; pub mod create_forum_topic; pub mod create_invoice_link; pub mod create_new_sticker_set; @@ -52,6 +53,7 @@ pub mod delete_my_commands; pub mod delete_sticker_from_set; pub mod delete_sticker_set; pub mod edit_chat_invite_link; +pub mod edit_chat_subscription_invite_link; pub mod edit_forum_topic; pub mod edit_general_forum_topic; pub mod edit_message_caption; @@ -160,6 +162,7 @@ pub use close_general_forum_topic::CloseGeneralForumTopic; pub use copy_message::CopyMessage; pub use copy_messages::CopyMessages; pub use create_chat_invite_link::CreateChatInviteLink; +pub use create_chat_subscription_invite_link::CreateChatSubscriptionInviteLink; pub use create_forum_topic::CreateForumTopic; pub use create_invoice_link::CreateInvoiceLink; pub use create_new_sticker_set::CreateNewStickerSet; @@ -173,6 +176,7 @@ pub use delete_my_commands::DeleteMyCommands; pub use delete_sticker_from_set::DeleteStickerFromSet; pub use delete_sticker_set::DeleteStickerSet; pub use edit_chat_invite_link::EditChatInviteLink; +pub use edit_chat_subscription_invite_link::EditChatSubscriptionInviteLink; pub use edit_forum_topic::EditForumTopic; pub use edit_general_forum_topic::EditGeneralForumTopic; pub use edit_message_caption::EditMessageCaption; diff --git a/telers/src/methods/create_chat_subscription_invite_link.rs b/telers/src/methods/create_chat_subscription_invite_link.rs new file mode 100644 index 0000000..c6be983 --- /dev/null +++ b/telers/src/methods/create_chat_subscription_invite_link.rs @@ -0,0 +1,100 @@ +use super::base::{Request, TelegramMethod}; + +use crate::{ + client::Bot, + types::{ChatIdKind, ChatInviteLink}, +}; + +use serde::Serialize; +use serde_with::skip_serializing_none; + +/// Use this method to create a [`subscription invite link`](https://telegram.org/blog/superchannels-star-reactions-subscriptions#star-subscriptions) for a channel chat. The bot must have the `can_invite_users` administrator rights. The link can be edited using the method [`EditChatSubscriptionInviteLink`](super::EditChatSubscriptionInviteLink) or revoked using the method [`RevokeChatInviteLink`](super::RevokeChatInviteLink). +/// # Documentation +/// +/// # Returns +/// Returns the new invite link as a [`ChatInviteLink`] object +#[skip_serializing_none] +#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)] +pub struct CreateChatSubscriptionInviteLink { + /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) + pub chat_id: ChatIdKind, + /// Invite link name; 0-32 characters + pub name: Option, + /// The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days). + pub subscription_period: i64, + /// The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500 + pub subscription_price: i64, +} + +impl CreateChatSubscriptionInviteLink { + #[must_use] + pub fn new( + chat_id: impl Into, + subscription_period: i64, + subscription_price: i64, + ) -> Self { + Self { + chat_id: chat_id.into(), + name: None, + subscription_period, + subscription_price, + } + } + + #[must_use] + pub fn chat_id(self, val: impl Into) -> Self { + Self { + chat_id: val.into(), + ..self + } + } + + #[must_use] + pub fn name(self, val: impl Into) -> Self { + Self { + name: Some(val.into()), + ..self + } + } + + #[must_use] + pub fn subscription_period(self, val: i64) -> Self { + Self { + subscription_period: val, + ..self + } + } + + #[must_use] + pub fn subscription_price(self, val: i64) -> Self { + Self { + subscription_price: val, + ..self + } + } +} + +impl CreateChatSubscriptionInviteLink { + #[must_use] + pub fn name_option(self, val: Option>) -> Self { + Self { + name: val.map(Into::into), + ..self + } + } +} + +impl TelegramMethod for CreateChatSubscriptionInviteLink { + type Method = Self; + type Return = ChatInviteLink; + + fn build_request(&self, _bot: &Bot) -> Request { + Request::new("createChatSubscriptionInviteLink", self, None) + } +} + +impl AsRef for CreateChatSubscriptionInviteLink { + fn as_ref(&self) -> &Self { + self + } +} diff --git a/telers/src/methods/edit_chat_subscription_invite_link.rs b/telers/src/methods/edit_chat_subscription_invite_link.rs new file mode 100644 index 0000000..f8f4504 --- /dev/null +++ b/telers/src/methods/edit_chat_subscription_invite_link.rs @@ -0,0 +1,85 @@ +use super::base::{Request, TelegramMethod}; + +use crate::{ + client::Bot, + types::{ChatIdKind, ChatInviteLink}, +}; + +use serde::Serialize; +use serde_with::skip_serializing_none; + +/// Use this method to create a [`subscription invite link`](https://telegram.org/blog/superchannels-star-reactions-subscriptions#star-subscriptions) for a channel chat. The bot must have the `can_invite_users` administrator rights. The link can be edited using the method [`EditChatSubscriptionInviteLink`](super::EditChatSubscriptionInviteLink) or revoked using the method [`RevokeChatInviteLink`](super::RevokeChatInviteLink). +/// # Documentation +/// +/// # Returns +/// Returns the new invite link as a [`ChatInviteLink`] object +#[skip_serializing_none] +#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)] +pub struct EditChatSubscriptionInviteLink { + /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) + pub chat_id: ChatIdKind, + /// The invite link to edit + pub invite_link: String, + /// Invite link name; 0-32 characters + pub name: Option, +} + +impl EditChatSubscriptionInviteLink { + #[must_use] + pub fn new(chat_id: impl Into, invite_link: impl Into) -> Self { + Self { + chat_id: chat_id.into(), + invite_link: invite_link.into(), + name: None, + } + } + + #[must_use] + pub fn chat_id(self, val: impl Into) -> Self { + Self { + chat_id: val.into(), + ..self + } + } + + #[must_use] + pub fn invite_link(self, val: impl Into) -> Self { + Self { + invite_link: val.into(), + ..self + } + } + + #[must_use] + pub fn name(self, val: impl Into) -> Self { + Self { + name: Some(val.into()), + ..self + } + } +} + +impl EditChatSubscriptionInviteLink { + #[must_use] + pub fn name_option(self, val: Option>) -> Self { + Self { + name: val.map(Into::into), + ..self + } + } +} + +impl TelegramMethod for EditChatSubscriptionInviteLink { + type Method = Self; + type Return = ChatInviteLink; + + fn build_request(&self, _bot: &Bot) -> Request { + Request::new("createChatSubscriptionInviteLink", self, None) + } +} + +impl AsRef for EditChatSubscriptionInviteLink { + fn as_ref(&self) -> &Self { + self + } +} From 0547ef787fc66e8c2dd204ae68eb40a92cf9fa47 Mon Sep 17 00:00:00 2001 From: Desiders Date: Thu, 15 Aug 2024 01:34:25 +0300 Subject: [PATCH 3/4] Add `until_date` to `ChatMemberMember` type --- telers/src/types/chat_member_member.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/telers/src/types/chat_member_member.rs b/telers/src/types/chat_member_member.rs index 745f259..5059304 100644 --- a/telers/src/types/chat_member_member.rs +++ b/telers/src/types/chat_member_member.rs @@ -9,4 +9,6 @@ use serde::{Deserialize, Serialize}; pub struct ChatMemberMember { /// Information about the user pub user: User, + /// Date when the user's subscription will expire; Unix time + pub until_date: Option, } From b6b79084db1de8cc6823b67d4c56aec35fc61b27 Mon Sep 17 00:00:00 2001 From: Desiders Date: Thu, 15 Aug 2024 01:48:18 +0300 Subject: [PATCH 4/4] Add `ReactionTypePaid` type --- telers/src/types.rs | 2 ++ telers/src/types/reaction_type.rs | 32 +++++++++++++++++++++++++- telers/src/types/reaction_type_paid.rs | 14 +++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 telers/src/types/reaction_type_paid.rs diff --git a/telers/src/types.rs b/telers/src/types.rs index 78a2501..2ba5daf 100644 --- a/telers/src/types.rs +++ b/telers/src/types.rs @@ -218,6 +218,7 @@ pub mod reaction_count; pub mod reaction_type; pub mod reaction_type_custom_emoji; pub mod reaction_type_emoji; +pub mod reaction_type_paid; pub mod refunded_payment; pub mod reply_keyboard_markup; pub mod reply_keyboard_remove; @@ -522,6 +523,7 @@ pub use reaction_count::ReactionCount; pub use reaction_type::ReactionType; pub use reaction_type_custom_emoji::ReactionTypeCustomEmoji; pub use reaction_type_emoji::ReactionTypeEmoji; +pub use reaction_type_paid::ReactionTypePaid; pub use refunded_payment::RefundedPayment; pub use reply_keyboard_markup::ReplyKeyboardMarkup; pub use reply_keyboard_remove::ReplyKeyboardRemove; diff --git a/telers/src/types/reaction_type.rs b/telers/src/types/reaction_type.rs index abf223d..ee8ccdf 100644 --- a/telers/src/types/reaction_type.rs +++ b/telers/src/types/reaction_type.rs @@ -1,10 +1,11 @@ -use super::{ReactionTypeCustomEmoji, ReactionTypeEmoji}; +use super::{ReactionTypeCustomEmoji, ReactionTypeEmoji, ReactionTypePaid}; use serde::{Deserialize, Serialize}; /// This object describes the type of a reaction. Currently, it can be one of /// - [`ReactionTypeEmoji`] /// - [`ReactionTypeCustomEmoji`] +/// - [`ReactionTypePaid`] /// # Documentation /// #[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)] @@ -12,6 +13,7 @@ use serde::{Deserialize, Serialize}; pub enum ReactionType { Emoji(ReactionTypeEmoji), CustomEmoji(ReactionTypeCustomEmoji), + Paid(ReactionTypePaid), } impl ReactionType { @@ -24,6 +26,11 @@ impl ReactionType { pub fn custom_emoji(custom_emoji: impl Into) -> Self { Self::CustomEmoji(ReactionTypeCustomEmoji::new(custom_emoji)) } + + #[must_use] + pub const fn paid() -> Self { + Self::Paid(ReactionTypePaid::new()) + } } impl From for ReactionType { @@ -40,6 +47,13 @@ impl From for ReactionType { } } +impl From for ReactionType { + #[must_use] + fn from(paid: ReactionTypePaid) -> Self { + Self::Paid(paid) + } +} + #[cfg(test)] mod tests { use super::*; @@ -60,6 +74,14 @@ mod tests { assert_eq!(json, r#"{"type":"custom_emoji","custom_emoji":"123"}"#); } + #[test] + fn serialize_paid_emoji() { + let data = ReactionType::paid(); + let json = serde_json::to_string(&data).unwrap(); + + assert_eq!(json, r#"{"type":"paid"}"#); + } + #[test] fn deserialize_emoji() { let data = r#"{"type":"emoji","emoji":"👍"}"#; @@ -75,4 +97,12 @@ mod tests { assert_eq!(custom_emoji, ReactionType::custom_emoji("123")); } + + #[test] + fn deserialize_paid() { + let data = r#"{"type":"paid"}"#; + let paid: ReactionType = serde_json::from_str(data).unwrap(); + + assert_eq!(paid, ReactionType::paid()); + } } diff --git a/telers/src/types/reaction_type_paid.rs b/telers/src/types/reaction_type_paid.rs new file mode 100644 index 0000000..4547f98 --- /dev/null +++ b/telers/src/types/reaction_type_paid.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +/// The reaction is paid. +/// # Documentation +/// +#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)] +pub struct ReactionTypePaid {} + +impl ReactionTypePaid { + #[must_use] + pub const fn new() -> Self { + Self {} + } +}