Skip to content

Commit

Permalink
Bot API 7.0: Chat Boost
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Jan 3, 2024
1 parent a16ab27 commit 8b97179
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 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
71 changes: 71 additions & 0 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 @@ -3598,6 +3602,73 @@ 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>,
}

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

0 comments on commit 8b97179

Please sign in to comment.