Skip to content

Commit

Permalink
Bot API 7.2 (#155)
Browse files Browse the repository at this point in the history
* Bot API 7.2 - Integration with Business Accounts

* Bot API 7.2 - Working on Behalf of Business Accounts (#156)

* Bot API 7.2 - Working on Behalf of Business Accounts

* Bot API 7.2 - Information about Business Accounts (#157)

* 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 ae43586 commit 90e37d3
Show file tree
Hide file tree
Showing 5 changed files with 297 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
91 changes: 89 additions & 2 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ pub struct DeleteWebhookParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendMessageParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -435,6 +439,10 @@ pub struct CopyMessagesParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendPhotoParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -480,6 +488,10 @@ pub struct SendPhotoParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendAudioParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -537,6 +549,10 @@ pub struct SendAudioParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendDocumentParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -586,6 +602,10 @@ pub struct SendDocumentParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendVideoParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -651,6 +671,10 @@ pub struct SendVideoParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendAnimationParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -712,6 +736,10 @@ pub struct SendAnimationParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendVoiceParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -757,6 +785,10 @@ pub struct SendVoiceParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendVideoNoteParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -798,6 +830,10 @@ pub struct SendVideoNoteParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendMediaGroupParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand All @@ -822,6 +858,10 @@ pub struct SendMediaGroupParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct SendLocationParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -922,6 +962,10 @@ pub struct StopMessageLiveLocationParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct SendVenueParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -974,6 +1018,10 @@ pub struct SendVenueParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendContactParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -1014,6 +1062,10 @@ pub struct SendContactParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendPollParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -1085,6 +1137,10 @@ pub struct SendPollParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendDiceParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -1115,6 +1171,10 @@ pub struct SendDiceParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendChatActionParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -1630,6 +1690,12 @@ pub struct GetUserChatBoostsParams {
pub user_id: u64,
}

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetMyCommandsParams {
pub commands: Vec<BotCommand>,
Expand Down Expand Up @@ -1855,6 +1921,10 @@ pub struct DeleteMessagesParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendStickerParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -1913,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 @@ -1954,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 @@ -2001,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 Expand Up @@ -2272,6 +2355,10 @@ pub struct SetPassportDataErrorsParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendGameParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

pub chat_id: i64,

#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
17 changes: 17 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::api_params::ExportChatInviteLinkParams;
use crate::api_params::FileUpload;
use crate::api_params::ForwardMessageParams;
use crate::api_params::ForwardMessagesParams;
use crate::api_params::GetBusinessConnectionParams;
use crate::api_params::GetChatAdministratorsParams;
use crate::api_params::GetChatMemberCountParams;
use crate::api_params::GetChatMemberParams;
Expand All @@ -64,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 @@ -119,6 +121,7 @@ use crate::objects::BotCommand;
use crate::objects::BotDescription;
use crate::objects::BotName;
use crate::objects::BotShortDescription;
use crate::objects::BusinessConnection;
use crate::objects::Chat;
use crate::objects::ChatAdministratorRights;
use crate::objects::ChatInviteLink;
Expand Down Expand Up @@ -824,6 +827,13 @@ pub trait AsyncTelegramApi {
self.request("getUserChatBoosts", Some(params)).await
}

async fn get_business_connection(
&self,
params: &GetBusinessConnectionParams,
) -> Result<MethodResponse<BusinessConnection>, Self::Error> {
self.request("getBusinessConnection", Some(params)).await
}

async fn get_my_commands(
&self,
params: &GetMyCommandsParams,
Expand Down Expand Up @@ -1165,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
17 changes: 17 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::api_params::ExportChatInviteLinkParams;
use crate::api_params::FileUpload;
use crate::api_params::ForwardMessageParams;
use crate::api_params::ForwardMessagesParams;
use crate::api_params::GetBusinessConnectionParams;
use crate::api_params::GetChatAdministratorsParams;
use crate::api_params::GetChatMemberCountParams;
use crate::api_params::GetChatMemberParams;
Expand All @@ -63,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 @@ -118,6 +120,7 @@ use crate::objects::BotCommand;
use crate::objects::BotDescription;
use crate::objects::BotName;
use crate::objects::BotShortDescription;
use crate::objects::BusinessConnection;
use crate::objects::Chat;
use crate::objects::ChatAdministratorRights;
use crate::objects::ChatInviteLink;
Expand Down Expand Up @@ -779,6 +782,13 @@ pub trait TelegramApi {
self.request("getUserChatBoosts", Some(params))
}

fn get_business_connection(
&self,
params: &GetBusinessConnectionParams,
) -> Result<MethodResponse<BusinessConnection>, Self::Error> {
self.request("getBusinessConnection", Some(params))
}

fn get_my_commands(
&self,
params: &GetMyCommandsParams,
Expand Down Expand Up @@ -1117,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
Loading

0 comments on commit 90e37d3

Please sign in to comment.