Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API 7.0: Chat Boost #133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
164 changes: 141 additions & 23 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 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 @@ -1741,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 @@ -3464,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 @@ -3530,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 @@ -3598,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