From eb45a67826c6b7e0e0b052090c83b10c0136354a Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 3 Dec 2024 11:57:28 +0200 Subject: [PATCH] Bot API 8.0 - Media Sharing and File Downloads (#236) * Bot API 8.0 - Media Sharing and File Downloads * Bot API 8.0 - Gifts (#237) --- src/api_params.rs | 20 ++++++++++++++++++++ src/objects.rs | 30 +++++++++++++++++++++++++----- src/trait_async.rs | 9 ++++++--- src/trait_sync.rs | 9 ++++++--- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 5d078b0..ce581d6 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -1230,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, @@ -1477,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 5b672d6..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 { @@ -2231,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), @@ -2242,12 +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!)] @@ -2271,7 +2293,6 @@ pub struct TransactionPartnerTelegramApi { pub struct TransactionPartnerOther {} #[apply(apistruct!)] -#[derive(Eq)] pub struct StarTransaction { pub id: String, pub amount: u32, @@ -2281,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 b0708fc..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}; @@ -626,6 +626,8 @@ where request!(setCustomEmojiStickerSetThumbnail, bool); request!(deleteStickerSet, bool); + request_nb!(getAvailableGifts, Gifts); + request!(sendGift, bool); request!(sendInvoice, Message); request!(createInvoiceLink, String); request!(answerShippingQuery, bool); @@ -639,6 +641,7 @@ where 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 c8d6430..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}; @@ -592,6 +592,8 @@ 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); @@ -605,6 +607,7 @@ pub trait TelegramApi { request!(setMyDefaultAdministratorRights, bool); request!(getMyDefaultAdministratorRights, ChatAdministratorRights); request!(answerWebAppQuery, SentWebAppMessage); + request!(savePreparedInlineMessage, PreparedInlineMessage); request!(setChatMenuButton, bool); request!(getChatMenuButton, MenuButton); request!(unpinAllGeneralForumTopicMessages, bool);