From a9a3ccb5cd12d2bfef7a7b0c3d65ec547ccd296e Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 3 Dec 2024 12:13:04 +0200 Subject: [PATCH] Bot API 8.0 (#234) * Bot API 8.0 - Star Subscriptions * editUserStarSubscription * Bot API 8.0 - Emoji Status (#235) * Bot API 8.0 - Media Sharing and File Downloads (#236) * Bot API 8.0 - Gifts (#237) --- src/api_params.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/objects.rs | 34 +++++++++++++++++++++++++++++----- src/trait_async.rs | 11 ++++++++--- src/trait_sync.rs | 11 ++++++++--- 4 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 44a8524..ce581d6 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -622,6 +622,14 @@ pub struct GetUserProfilePhotosParams { pub limit: Option, } +#[apply(apistruct!)] +#[derive(Eq)] +pub struct SetUserEmojiStatusParams { + pub user_id: u64, + pub emoji_status_custom_emoji_id: Option, + pub emoji_status_expiration_date: Option, +} + #[apply(apistruct!)] #[derive(Eq)] pub struct GetFileParams { @@ -1222,6 +1230,16 @@ pub struct DeleteStickerSetParams { pub name: String, } +#[apply(apistruct!)] +#[derive(Eq)] +pub struct SendGiftParams { + pub user_id: u64, + pub gift_id: String, + pub text: Option, + pub text_parse_mode: Option, + pub text_entities: Option>, +} + #[apply(apistruct!)] pub struct AnswerInlineQueryParams { pub inline_query_id: String, @@ -1277,12 +1295,14 @@ pub struct SendInvoiceParams { #[apply(apistruct!)] #[derive(Eq)] pub struct CreateInvoiceLinkParams { + pub business_connection_id: Option, pub title: String, pub description: String, pub payload: String, pub provider_token: Option, pub currency: String, pub prices: Vec, + pub subscription_period: Option, pub max_tip_amount: Option, pub suggested_tip_amounts: Option>, pub provider_data: Option, @@ -1331,6 +1351,14 @@ pub struct RefundStarPaymentParams { pub telegram_payment_charge_id: String, } +#[apply(apistruct!)] +#[derive(Eq)] +pub struct EditUserStarSubscriptionParams { + pub user_id: u64, + pub telegram_payment_charge_id: String, + pub is_canceled: bool, +} + #[apply(apistruct!)] #[derive(Eq)] pub struct SetPassportDataErrorsParams { @@ -1459,6 +1487,16 @@ pub struct AnswerWebAppQueryParams { pub result: InlineQueryResult, } +#[apply(apistruct!)] +pub struct SavePreparedInlineMessageParams { + pub user_id: u64, + pub result: InlineQueryResult, + pub allow_user_chats: Option, + pub allow_bot_chats: Option, + pub allow_group_chats: Option, + pub allow_channel_chats: Option, +} + #[apply(apistruct!)] #[derive(Eq)] pub struct SetChatMenuButtonParams { diff --git a/src/objects.rs b/src/objects.rs index b3fa242..f926fc2 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1335,6 +1335,20 @@ pub struct InputSticker { pub keywords: Option>, } +#[apply(apistruct!)] +pub struct Gift { + pub id: String, + pub stricker: Sticker, + pub star_count: u32, + pub total_count: Option, + pub remaining_count: Option, +} + +#[apply(apistruct!)] +pub struct Gifts { + pub gifts: Vec, +} + #[apply(apistruct!)] #[derive(Eq)] pub struct Story { @@ -1732,6 +1746,13 @@ pub struct ChosenInlineResult { pub query: String, } +#[apply(apistruct!)] +#[derive(Eq)] +pub struct PreparedInlineMessage { + pub id: String, + pub expiration_date: u64, +} + #[apply(apistruct!)] #[derive(Eq)] pub struct LabeledPrice { @@ -1842,6 +1863,9 @@ pub struct SuccessfulPayment { pub currency: String, pub total_amount: u32, pub invoice_payload: String, + pub subscription_expiration_date: Option, + pub is_recurring: Option, + pub is_first_recurring: Option, pub shipping_option_id: Option, pub order_info: Option, pub telegram_payment_charge_id: String, @@ -2228,10 +2252,10 @@ pub struct RevenueWithdrawalStateSucceeded { #[derive(Eq)] pub struct RevenueWithdrawalStateFailed {} -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(tag = "type", rename_all = "snake_case")] pub enum TransactionPartner { - User(TransactionPartnerUser), + User(Box), Fragment(TransactionPartnerFragment), TelegramAds(TransactionPartnerTelegramAds), TelegramApi(TransactionPartnerTelegramApi), @@ -2239,11 +2263,13 @@ pub enum TransactionPartner { } #[apply(apistruct!)] -#[derive(Eq)] pub struct TransactionPartnerUser { pub user: User, pub invoice_payload: Option, + pub subscription_period: Option, pub paid_media: Option>, + pub paid_media_payload: Option, + pub gift: Option, } #[apply(apistruct!)] @@ -2267,7 +2293,6 @@ pub struct TransactionPartnerTelegramApi { pub struct TransactionPartnerOther {} #[apply(apistruct!)] -#[derive(Eq)] pub struct StarTransaction { pub id: String, pub amount: u32, @@ -2277,7 +2302,6 @@ pub struct StarTransaction { } #[apply(apistruct!)] -#[derive(Eq)] pub struct StarTransactions { pub transactions: Vec, } diff --git a/src/trait_async.rs b/src/trait_async.rs index c1a0fa4..7a819b1 100644 --- a/src/trait_async.rs +++ b/src/trait_async.rs @@ -9,9 +9,9 @@ use crate::api_params::{ use crate::objects::{ BotCommand, BotDescription, BotName, BotShortDescription, BusinessConnection, ChatAdministratorRights, ChatFullInfo, ChatInviteLink, ChatMember, File as FileObject, - ForumTopic, GameHighScore, InputSticker, MenuButton, Message, MessageId, Poll, - SentWebAppMessage, StarTransactions, Sticker, StickerSet, Update, User, UserChatBoosts, - UserProfilePhotos, WebhookInfo, + ForumTopic, GameHighScore, Gifts, InputSticker, MenuButton, Message, MessageId, Poll, + PreparedInlineMessage, SentWebAppMessage, StarTransactions, Sticker, StickerSet, Update, User, + UserChatBoosts, UserProfilePhotos, WebhookInfo, }; use crate::response::{MessageOrBool, MethodResponse}; @@ -314,6 +314,7 @@ where request!(sendChatAction, bool); request!(setMessageReaction, bool); request!(getUserProfilePhotos, UserProfilePhotos); + request!(setUserEmojiStatus, bool); request!(getFile, FileObject); request!(banChatMember, bool); request!(unbanChatMember, bool); @@ -625,18 +626,22 @@ where request!(setCustomEmojiStickerSetThumbnail, bool); request!(deleteStickerSet, bool); + request_nb!(getAvailableGifts, Gifts); + request!(sendGift, bool); request!(sendInvoice, Message); request!(createInvoiceLink, String); request!(answerShippingQuery, bool); request!(answerPreCheckoutQuery, bool); request!(getStarTransactions, StarTransactions); request!(refundStarPayment, bool); + request!(editUserStarSubscription, bool); request!(sendGame, Message); request!(setGameScore, MessageOrBool); request!(getGameHighScores, Vec); request!(setMyDefaultAdministratorRights, bool); request!(getMyDefaultAdministratorRights, ChatAdministratorRights); request!(answerWebAppQuery, SentWebAppMessage); + request!(savePreparedInlineMessage, PreparedInlineMessage); request!(setChatMenuButton, bool); request!(getChatMenuButton, MenuButton); request!(unpinAllGeneralForumTopicMessages, bool); diff --git a/src/trait_sync.rs b/src/trait_sync.rs index f81047c..28e33f2 100644 --- a/src/trait_sync.rs +++ b/src/trait_sync.rs @@ -9,9 +9,9 @@ use crate::api_params::{ use crate::objects::{ BotCommand, BotDescription, BotName, BotShortDescription, BusinessConnection, ChatAdministratorRights, ChatFullInfo, ChatInviteLink, ChatMember, File as FileObject, - ForumTopic, GameHighScore, InputSticker, MenuButton, Message, MessageId, Poll, - SentWebAppMessage, StarTransactions, Sticker, StickerSet, Update, User, UserChatBoosts, - UserProfilePhotos, WebhookInfo, + ForumTopic, GameHighScore, Gifts, InputSticker, MenuButton, Message, MessageId, Poll, + PreparedInlineMessage, SentWebAppMessage, StarTransactions, Sticker, StickerSet, Update, User, + UserChatBoosts, UserProfilePhotos, WebhookInfo, }; use crate::response::{MessageOrBool, MethodResponse}; @@ -286,6 +286,7 @@ pub trait TelegramApi { request!(sendChatAction, bool); request!(setMessageReaction, bool); request!(getUserProfilePhotos, UserProfilePhotos); + request!(setUserEmojiStatus, bool); request!(getFile, FileObject); request!(banChatMember, bool); request!(unbanChatMember, bool); @@ -591,18 +592,22 @@ pub trait TelegramApi { request!(setCustomEmojiStickerSetThumbnail, bool); request!(deleteStickerSet, bool); + request_nb!(getAvailableGifts, Gifts); + request!(sendGift, bool); request!(sendInvoice, Message); request!(createInvoiceLink, String); request!(answerShippingQuery, bool); request!(answerPreCheckoutQuery, bool); request!(getStarTransactions, StarTransactions); request!(refundStarPayment, bool); + request!(editUserStarSubscription, bool); request!(sendGame, Message); request!(setGameScore, MessageOrBool); request!(getGameHighScores, Vec); request!(setMyDefaultAdministratorRights, bool); request!(getMyDefaultAdministratorRights, ChatAdministratorRights); request!(answerWebAppQuery, SentWebAppMessage); + request!(savePreparedInlineMessage, PreparedInlineMessage); request!(setChatMenuButton, bool); request!(getChatMenuButton, MenuButton); request!(unpinAllGeneralForumTopicMessages, bool);