Skip to content

Commit

Permalink
Merge pull request #39 from Desiders/add-support-bot-api-7.9
Browse files Browse the repository at this point in the history
Add support Bot API 7.9
  • Loading branch information
Desiders authored Aug 14, 2024
2 parents 1995e03 + b6b7908 commit 8011828
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 2 deletions.
4 changes: 4 additions & 0 deletions telers/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
100 changes: 100 additions & 0 deletions telers/src/methods/create_chat_subscription_invite_link.rs
Original file line number Diff line number Diff line change
@@ -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
/// <https://core.telegram.org/bots/api#createchatsubscriptioninvitelink>
/// # 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<String>,
/// 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<ChatIdKind>,
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<ChatIdKind>) -> Self {
Self {
chat_id: val.into(),
..self
}
}

#[must_use]
pub fn name(self, val: impl Into<String>) -> 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<impl Into<String>>) -> Self {
Self {
name: val.map(Into::into),
..self
}
}
}

impl TelegramMethod for CreateChatSubscriptionInviteLink {
type Method = Self;
type Return = ChatInviteLink;

fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
Request::new("createChatSubscriptionInviteLink", self, None)
}
}

impl AsRef<CreateChatSubscriptionInviteLink> for CreateChatSubscriptionInviteLink {
fn as_ref(&self) -> &Self {
self
}
}
85 changes: 85 additions & 0 deletions telers/src/methods/edit_chat_subscription_invite_link.rs
Original file line number Diff line number Diff line change
@@ -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
/// <https://core.telegram.org/bots/api#createchatsubscriptioninvitelink>
/// # 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<String>,
}

impl EditChatSubscriptionInviteLink {
#[must_use]
pub fn new(chat_id: impl Into<ChatIdKind>, invite_link: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
invite_link: invite_link.into(),
name: None,
}
}

#[must_use]
pub fn chat_id(self, val: impl Into<ChatIdKind>) -> Self {
Self {
chat_id: val.into(),
..self
}
}

#[must_use]
pub fn invite_link(self, val: impl Into<String>) -> Self {
Self {
invite_link: val.into(),
..self
}
}

#[must_use]
pub fn name(self, val: impl Into<String>) -> Self {
Self {
name: Some(val.into()),
..self
}
}
}

impl EditChatSubscriptionInviteLink {
#[must_use]
pub fn name_option(self, val: Option<impl Into<String>>) -> Self {
Self {
name: val.map(Into::into),
..self
}
}
}

impl TelegramMethod for EditChatSubscriptionInviteLink {
type Method = Self;
type Return = ChatInviteLink;

fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
Request::new("createChatSubscriptionInviteLink", self, None)
}
}

impl AsRef<EditChatSubscriptionInviteLink> for EditChatSubscriptionInviteLink {
fn as_ref(&self) -> &Self {
self
}
}
2 changes: 2 additions & 0 deletions telers/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions telers/src/types/chat_member_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>,
}
32 changes: 31 additions & 1 deletion telers/src/types/reaction_type.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
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
/// <https://core.telegram.org/bots/api#reactiontype>
#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ReactionType {
Emoji(ReactionTypeEmoji),
CustomEmoji(ReactionTypeCustomEmoji),
Paid(ReactionTypePaid),
}

impl ReactionType {
Expand All @@ -24,6 +26,11 @@ impl ReactionType {
pub fn custom_emoji(custom_emoji: impl Into<String>) -> Self {
Self::CustomEmoji(ReactionTypeCustomEmoji::new(custom_emoji))
}

#[must_use]
pub const fn paid() -> Self {
Self::Paid(ReactionTypePaid::new())
}
}

impl From<ReactionTypeEmoji> for ReactionType {
Expand All @@ -40,6 +47,13 @@ impl From<ReactionTypeCustomEmoji> for ReactionType {
}
}

impl From<ReactionTypePaid> for ReactionType {
#[must_use]
fn from(paid: ReactionTypePaid) -> Self {
Self::Paid(paid)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -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":"👍"}"#;
Expand All @@ -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());
}
}
14 changes: 14 additions & 0 deletions telers/src/types/reaction_type_paid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

/// The reaction is paid.
/// # Documentation
/// <https://core.telegram.org/bots/api#reactiontypepaid>
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
pub struct ReactionTypePaid {}

impl ReactionTypePaid {
#[must_use]
pub const fn new() -> Self {
Self {}
}
}
4 changes: 3 additions & 1 deletion telers/src/types/transaction_partner_user.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::User;
use super::{PaidMedia, User};

use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
Expand All @@ -13,4 +13,6 @@ pub struct TransactionPartnerUser {
pub user: User,
/// Bot-specified invoice payload
pub invoice_payload: Option<Box<str>>,
/// Information about the paid media bought by the user
pub paid_media: Option<Box<[PaidMedia]>>,
}

0 comments on commit 8011828

Please sign in to comment.