Skip to content

Commit

Permalink
Bot API 8.0 (#234)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
ayrat555 authored Dec 3, 2024
1 parent 74415e2 commit a9a3ccb
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
38 changes: 38 additions & 0 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@ pub struct GetUserProfilePhotosParams {
pub limit: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SetUserEmojiStatusParams {
pub user_id: u64,
pub emoji_status_custom_emoji_id: Option<String>,
pub emoji_status_expiration_date: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct GetFileParams {
Expand Down Expand Up @@ -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<String>,
pub text_parse_mode: Option<ParseMode>,
pub text_entities: Option<Vec<MessageEntity>>,
}

#[apply(apistruct!)]
pub struct AnswerInlineQueryParams {
pub inline_query_id: String,
Expand Down Expand Up @@ -1277,12 +1295,14 @@ pub struct SendInvoiceParams {
#[apply(apistruct!)]
#[derive(Eq)]
pub struct CreateInvoiceLinkParams {
pub business_connection_id: Option<String>,
pub title: String,
pub description: String,
pub payload: String,
pub provider_token: Option<String>,
pub currency: String,
pub prices: Vec<LabeledPrice>,
pub subscription_period: Option<u32>,
pub max_tip_amount: Option<u32>,
pub suggested_tip_amounts: Option<Vec<u32>>,
pub provider_data: Option<String>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<bool>,
pub allow_bot_chats: Option<bool>,
pub allow_group_chats: Option<bool>,
pub allow_channel_chats: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SetChatMenuButtonParams {
Expand Down
34 changes: 29 additions & 5 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,20 @@ pub struct InputSticker {
pub keywords: Option<Vec<String>>,
}

#[apply(apistruct!)]
pub struct Gift {
pub id: String,
pub stricker: Sticker,
pub star_count: u32,
pub total_count: Option<u32>,
pub remaining_count: Option<u32>,
}

#[apply(apistruct!)]
pub struct Gifts {
pub gifts: Vec<Gift>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Story {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1842,6 +1863,9 @@ pub struct SuccessfulPayment {
pub currency: String,
pub total_amount: u32,
pub invoice_payload: String,
pub subscription_expiration_date: Option<u64>,
pub is_recurring: Option<bool>,
pub is_first_recurring: Option<bool>,
pub shipping_option_id: Option<String>,
pub order_info: Option<OrderInfo>,
pub telegram_payment_charge_id: String,
Expand Down Expand Up @@ -2228,22 +2252,24 @@ 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<TransactionPartnerUser>),
Fragment(TransactionPartnerFragment),
TelegramAds(TransactionPartnerTelegramAds),
TelegramApi(TransactionPartnerTelegramApi),
Other(TransactionPartnerOther),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct TransactionPartnerUser {
pub user: User,
pub invoice_payload: Option<String>,
pub subscription_period: Option<u32>,
pub paid_media: Option<Vec<PaidMedia>>,
pub paid_media_payload: Option<String>,
pub gift: Option<Gift>,
}

#[apply(apistruct!)]
Expand All @@ -2267,7 +2293,6 @@ pub struct TransactionPartnerTelegramApi {
pub struct TransactionPartnerOther {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct StarTransaction {
pub id: String,
pub amount: u32,
Expand All @@ -2277,7 +2302,6 @@ pub struct StarTransaction {
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct StarTransactions {
pub transactions: Vec<StarTransaction>,
}
Expand Down
11 changes: 8 additions & 3 deletions src/trait_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<GameHighScore>);
request!(setMyDefaultAdministratorRights, bool);
request!(getMyDefaultAdministratorRights, ChatAdministratorRights);
request!(answerWebAppQuery, SentWebAppMessage);
request!(savePreparedInlineMessage, PreparedInlineMessage);
request!(setChatMenuButton, bool);
request!(getChatMenuButton, MenuButton);
request!(unpinAllGeneralForumTopicMessages, bool);
Expand Down
11 changes: 8 additions & 3 deletions src/trait_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<GameHighScore>);
request!(setMyDefaultAdministratorRights, bool);
request!(getMyDefaultAdministratorRights, ChatAdministratorRights);
request!(answerWebAppQuery, SentWebAppMessage);
request!(savePreparedInlineMessage, PreparedInlineMessage);
request!(setChatMenuButton, bool);
request!(getChatMenuButton, MenuButton);
request!(unpinAllGeneralForumTopicMessages, bool);
Expand Down

0 comments on commit a9a3ccb

Please sign in to comment.