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.2 - Mixed-Format Sticker Packs #158

Merged
merged 4 commits into from
Apr 19, 2024
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
2 changes: 1 addition & 1 deletion src/api/telegram_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ mod tests {

#[test]
fn get_sticker_set_success() {
let response_string = "{\"ok\":true,\"result\":{\"name\":\"unocards\",\"title\":\"UNO Bot\",\"sticker_type\":\"regular\",\"is_animated\":false,\"is_video\":false,\"contains_masks\":false,\"stickers\":[{\"file_id\":\"CAACAgQAAxUAAWCDxAQVJ6X7FGiBD5NyjN5DDvgfAALZAQACX1eZAAEqnpNt3SpG_x8E\",\"file_unique_id\":\"AgAD2QEAAl9XmQAB\",\"type\":\"regular\",\"width\":342,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumbnail\":{\"file_id\":\"AAMCBAADFQABYIPEBBUnpfsUaIEPk3KM3kMO-B8AAtkBAAJfV5kAASqek23dKkb_P75BGQAEAQAHbQADBBEAAh8E\",\"file_unique_id\":\"AQADP75BGQAEBBEAAg\",\"width\":85,\"height\":128,\"file_size\":2452},\"emoji\":\"dd\",\"set_name\":\"unocards\",\"file_size\":8898}]}}";
let response_string = "{\"ok\":true,\"result\":{\"name\":\"unocards\",\"title\":\"UNO Bot\",\"sticker_type\":\"regular\",\"contains_masks\":false,\"stickers\":[{\"file_id\":\"CAACAgQAAxUAAWCDxAQVJ6X7FGiBD5NyjN5DDvgfAALZAQACX1eZAAEqnpNt3SpG_x8E\",\"file_unique_id\":\"AgAD2QEAAl9XmQAB\",\"type\":\"regular\",\"width\":342,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumbnail\":{\"file_id\":\"AAMCBAADFQABYIPEBBUnpfsUaIEPk3KM3kMO-B8AAtkBAAJfV5kAASqek23dKkb_P75BGQAEAQAHbQADBBEAAh8E\",\"file_unique_id\":\"AQADP75BGQAEBBEAAg\",\"width\":85,\"height\":128,\"file_size\":2452},\"emoji\":\"dd\",\"set_name\":\"unocards\",\"file_size\":8898}]}}";

let params = GetStickerSetParams::builder().name("unocards").build();
let mut server = mockito::Server::new();
Expand Down
17 changes: 15 additions & 2 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1983,8 +1983,6 @@ pub struct CreateNewStickerSetParams {

pub stickers: Vec<InputSticker>,

pub sticker_format: StickerFormat,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option))]
pub sticker_type: Option<StickerType>,
Expand Down Expand Up @@ -2024,6 +2022,19 @@ pub struct DeleteStickerFromSetParams {
pub sticker: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct ReplaceStickerInSetParams {
pub user_id: u64,

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

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

pub sticker: InputSticker,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetStickerEmojiListParams {
#[builder(setter(into))]
Expand Down Expand Up @@ -2071,6 +2082,8 @@ pub struct SetStickerSetThumbnailParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub thumbnail: Option<FileUpload>,

pub format: StickerFormat,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down
8 changes: 8 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use crate::api_params::PinChatMessageParams;
use crate::api_params::PromoteChatMemberParams;
use crate::api_params::ReopenForumTopicParams;
use crate::api_params::ReopenGeneralForumTopicParams;
use crate::api_params::ReplaceStickerInSetParams;
use crate::api_params::RestrictChatMemberParams;
use crate::api_params::RevokeChatInviteLinkParams;
use crate::api_params::SendAnimationParams;
Expand Down Expand Up @@ -1174,6 +1175,13 @@ pub trait AsyncTelegramApi {
self.request("setStickerPositionInSet", Some(params)).await
}

async fn replace_sticker_in_set(
&self,
params: &ReplaceStickerInSetParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("replaceStickerInSet", Some(params)).await
}

async fn delete_sticker_from_set(
&self,
params: &DeleteStickerFromSetParams,
Expand Down
8 changes: 8 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use crate::api_params::PinChatMessageParams;
use crate::api_params::PromoteChatMemberParams;
use crate::api_params::ReopenForumTopicParams;
use crate::api_params::ReopenGeneralForumTopicParams;
use crate::api_params::ReplaceStickerInSetParams;
use crate::api_params::RestrictChatMemberParams;
use crate::api_params::RevokeChatInviteLinkParams;
use crate::api_params::SendAnimationParams;
Expand Down Expand Up @@ -1126,6 +1127,13 @@ pub trait TelegramApi {
self.request("deleteStickerFromSet", Some(params))
}

fn replace_sticker_in_set(
&self,
params: &ReplaceStickerInSetParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("replaceStickerInSet", Some(params))
}

fn set_sticker_emoji_list(
&self,
params: &SetStickerEmojiListParams,
Expand Down
89 changes: 84 additions & 5 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ pub struct User {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub supports_inline_queries: Option<bool>,

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
Expand Down Expand Up @@ -505,6 +509,10 @@ pub struct Chat {
#[builder(setter(into, strip_option), default)]
pub active_usernames: Option<Vec<String>>,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_intro: Option<BusinessIntro>,
Expand All @@ -517,6 +525,10 @@ pub struct Chat {
#[builder(setter(into, strip_option), default)]
pub business_opening_hours: Option<BusinessOpeningHours>,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub available_reactions: Option<Vec<ReactionType>>,
Expand Down Expand Up @@ -703,6 +715,10 @@ pub struct Message {
#[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 is_from_offline: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub media_group_id: Option<String>,
Expand Down Expand Up @@ -1530,18 +1546,51 @@ pub struct GeneralForumTopicHidden {}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GeneralForumTopicUnhidden {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SharedUser {
pub user_id: u64,

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

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

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

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

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

pub user_ids: Vec<u64>,
pub users: Vec<SharedUser>,
}

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

pub chat_id: u64,

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

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1665,6 +1714,18 @@ pub struct KeyboardButtonRequestUsers {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub max_quantity: Option<u32>,

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

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1696,6 +1757,18 @@ pub struct KeyboardButtonRequestChat {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub bot_is_member: Option<bool>,

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

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

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

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1987,6 +2060,15 @@ pub struct ChatPermissions {
pub can_manage_topics: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct Birthdate {
pub day: u8,

pub month: u8,

pub year: u16,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct BusinessIntro {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -2183,6 +2265,7 @@ pub struct Sticker {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct InputSticker {
pub sticker: FileUpload,
pub format: StickerFormat,
pub emoji_list: Vec<String>,

#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -2211,10 +2294,6 @@ pub struct StickerSet {
#[serde(rename = "sticker_type")]
pub sticker_type: StickerType,

pub is_animated: bool,

pub is_video: bool,

#[doc(hidden)]
#[deprecated(since = "0.19.2", note = "Please use `sticker_type` instead")]
pub contains_masks: bool,
Expand Down