Skip to content

Commit

Permalink
Bot API 7.0: Request for multiple users (#132)
Browse files Browse the repository at this point in the history
* Bot API 7.0: Request for multiple users

* change type

* Bot API 7.0: Chat Boost (#133)

* Bot API 7.0: Chat Boost

* Bot API 7.0: Giveaway (#134)

* Bot API 7.0: Giveaway

* Bot API 7.0: Other changes (#135)
  • Loading branch information
ayrat555 authored Jan 6, 2024
1 parent e30eb11 commit 5dbcf67
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 29 deletions.
8 changes: 8 additions & 0 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,14 @@ pub struct AnswerCallbackQueryParams {
pub cache_time: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GetUserChatBoostsParams {
#[builder(setter(into))]
pub chat_id: ChatId,

pub user_id: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetMyCommandsParams {
pub commands: Vec<BotCommand>,
Expand Down
9 changes: 9 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserChatBoostsParams;
use crate::api_params::GetUserProfilePhotosParams;
use crate::api_params::HideGeneralForumTopicParams;
use crate::api_params::InputMedia;
Expand Down Expand Up @@ -134,6 +135,7 @@ use crate::objects::SentWebAppMessage;
use crate::objects::StickerSet;
use crate::objects::Update;
use crate::objects::User;
use crate::objects::UserChatBoosts;
use crate::objects::UserProfilePhotos;
use crate::objects::WebhookInfo;
use crate::Sticker;
Expand Down Expand Up @@ -815,6 +817,13 @@ pub trait AsyncTelegramApi {
self.request("answerCallbackQuery", Some(params)).await
}

async fn get_user_chat_boosts(
&self,
params: &GetUserChatBoostsParams,
) -> Result<MethodResponse<UserChatBoosts>, Self::Error> {
self.request("getUserChatBoosts", Some(params)).await
}

async fn get_my_commands(
&self,
params: &GetMyCommandsParams,
Expand Down
9 changes: 9 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserChatBoostsParams;
use crate::api_params::GetUserProfilePhotosParams;
use crate::api_params::HideGeneralForumTopicParams;
use crate::api_params::InputMedia;
Expand Down Expand Up @@ -133,6 +134,7 @@ use crate::objects::SentWebAppMessage;
use crate::objects::StickerSet;
use crate::objects::Update;
use crate::objects::User;
use crate::objects::UserChatBoosts;
use crate::objects::UserProfilePhotos;
use crate::objects::WebhookInfo;
use crate::GetCustomEmojiStickersParams;
Expand Down Expand Up @@ -770,6 +772,13 @@ pub trait TelegramApi {
self.request("answerCallbackQuery", Some(params))
}

fn get_user_chat_boosts(
&self,
params: &GetUserChatBoostsParams,
) -> Result<MethodResponse<UserChatBoosts>, Self::Error> {
self.request("getUserChatBoosts", Some(params))
}

fn get_my_commands(
&self,
params: &GetMyCommandsParams,
Expand Down
180 changes: 151 additions & 29 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ pub enum UpdateContent {
MyChatMember(ChatMemberUpdated),
ChatMember(ChatMemberUpdated),
ChatJoinRequest(ChatJoinRequest),
ChatBoost(ChatBoost),
RemovedChatBoost(ChatBoostRemoved),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -416,6 +418,8 @@ pub enum AllowedUpdate {
MyChatMember,
ChatMember,
ChatJoinRequest,
ChatBoost,
RemovedChatBoost,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -499,6 +503,22 @@ pub struct Chat {
#[builder(setter(into, strip_option), default)]
pub available_reactions: Option<Vec<ReactionType>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub accent_color_id: Option<u16>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub background_custom_emoji_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub profile_accent_color_id: Option<u16>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub profile_background_custom_emoji_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub emoji_status_custom_emoji_id: Option<String>,
Expand Down Expand Up @@ -563,6 +583,10 @@ pub struct Chat {
#[builder(setter(into, strip_option), default)]
pub has_protected_content: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub has_visible_history: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub sticker_set_name: Option<String>,
Expand Down Expand Up @@ -603,27 +627,7 @@ pub struct Message {

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub forward_from: Option<Box<User>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub forward_from_chat: Option<Box<Chat>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub forward_from_message_id: Option<i32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub forward_signature: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub forward_sender_name: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub forward_date: Option<u64>,
pub forward_origin: Option<Box<MessageOrigin>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand Down Expand Up @@ -795,7 +799,7 @@ pub struct Message {

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub pinned_message: Option<Box<Message>>,
pub pinned_message: Option<Box<MaybeInaccessibleMessage>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand All @@ -807,7 +811,7 @@ pub struct Message {

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub user_shared: Option<Box<UserShared>>,
pub users_shared: Option<Box<UsersShared>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand Down Expand Up @@ -853,6 +857,22 @@ pub struct Message {
#[builder(setter(into, strip_option), default)]
pub general_forum_topic_unhidden: Option<Box<GeneralForumTopicUnhidden>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub giveaway_created: Option<GiveawayCreated>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub giveaway: Option<Giveaway>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub giveaway_winners: Option<GiveawayWinners>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub giveaway_completed: Option<GiveawayCompleted>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub video_chat_started: Option<Box<VideoChatStarted>>,
Expand Down Expand Up @@ -1460,17 +1480,17 @@ pub struct GeneralForumTopicHidden {}
pub struct GeneralForumTopicUnhidden {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct UserShared {
pub struct UsersShared {
pub request_id: i32,

pub user_id: u64,
pub user_ids: Vec<u64>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatShared {
pub request_id: i32,

pub user_id: u64,
pub chat_id: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1556,7 +1576,7 @@ pub struct KeyboardButton {

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub request_user: Option<KeyboardButtonRequestUser>,
pub request_users: Option<KeyboardButtonRequestUsers>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand All @@ -1580,7 +1600,7 @@ pub struct KeyboardButton {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct KeyboardButtonRequestUser {
pub struct KeyboardButtonRequestUsers {
pub request_id: i32,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -1590,6 +1610,10 @@ pub struct KeyboardButtonRequestUser {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub user_is_premium: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub max_quantity: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1737,7 +1761,7 @@ pub struct CallbackQuery {

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub message: Option<Message>,
pub message: Option<MaybeInaccessibleMessage>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand Down Expand Up @@ -3460,6 +3484,9 @@ pub struct GameHighScore {
pub score: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct GiveawayCreated {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct Giveaway {
pub chats: Vec<Chat>,
Expand Down Expand Up @@ -3526,6 +3553,19 @@ pub struct GiveawayWinners {
pub prize_description: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct GiveawayCompleted {
pub winner_count: u32,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub unclaimed_prize_count: Option<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub giveaway_message: Option<Box<Message>>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatAdministratorRights {
pub is_anonymous: bool,
Expand Down Expand Up @@ -3594,6 +3634,88 @@ pub struct WebAppData {
pub button_text: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "source", rename_all = "snake_case")]
pub enum ChatBoostSource {
Premium(ChatBoostSourcePremium),
GiftCode(ChatBoostSourceGiftCode),
Giveaway(ChatBoostSourceGiveaway),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatBoostSourcePremium {
pub user: User,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatBoostSourceGiftCode {
pub user: User,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatBoostSourceGiveaway {
pub giveaway_message_id: i32,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub user: Option<User>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub is_unclaimed: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatBoost {
#[builder(setter(into))]
pub boost_id: String,

pub add_date: u64,

pub expiration_date: u64,

pub source: ChatBoostSource,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct ChatBoostUpdated {
pub chat: Chat,

pub boost: ChatBoost,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct ChatBoostRemoved {
pub chat: Chat,

#[builder(setter(into))]
pub boost_id: String,

pub remove_date: u64,

pub source: ChatBoostSource,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct UserChatBoosts {
pub boosts: Vec<ChatBoost>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum MaybeInaccessibleMessage {
Message(Message),
InaccessibleMessage(InaccessibleMessage),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct InaccessibleMessage {
pub chat: Chat,

pub message_id: i32,

pub date: u64,
}

#[cfg(test)]
mod serde_tests {
use super::*;
Expand Down

0 comments on commit 5dbcf67

Please sign in to comment.