Skip to content

Commit

Permalink
Bot API 7.2 - Information about Business Accounts (#157)
Browse files Browse the repository at this point in the history
* Bot API 7.2 - Information about Business Accounts

* Bot API 7.2 - Mixed-Format Sticker Packs (#158)

* Bot API 7.2 - Mixed-Format Sticker Packs

* Bot API 7.2 - Request Chat Improvements (#159)

* Bot API 7.2 - Request Chat Improvements

* Bot API 7.2 - Other Changes (#160)
  • Loading branch information
ayrat555 authored Apr 19, 2024
1 parent 710e726 commit 528c882
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 8 deletions.
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
140 changes: 135 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,26 @@ 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>,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[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 @@ -691,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 @@ -1518,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 @@ -1653,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 @@ -1684,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 @@ -1975,6 +2060,54 @@ 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")]
#[builder(setter(into, strip_option), default)]
pub title: Option<String>,

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

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

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct BusinessOpeningHoursInterval {
pub opening_minute: u16,

pub closing_minute: u16,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct BusinessOpeningHours {
pub time_zone_name: String,

pub opening_hours: Vec<BusinessOpeningHoursInterval>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct ChatLocation {
pub location: Location,
Expand Down Expand Up @@ -2132,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 @@ -2160,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

0 comments on commit 528c882

Please sign in to comment.