From 68b7aba836b4d935e2e6896d42224857ed3211a1 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 20:53:46 +0530 Subject: [PATCH] Add method `getBusinessConnection` --- crates/teloxide-core/schema.ron | 14 +++++++++ crates/teloxide-core/src/adaptors/cache_me.rs | 1 + crates/teloxide-core/src/adaptors/erased.rs | 13 +++++++++ .../teloxide-core/src/adaptors/parse_mode.rs | 1 + .../src/adaptors/throttle/requester_impl.rs | 1 + crates/teloxide-core/src/adaptors/trace.rs | 1 + crates/teloxide-core/src/bot/api.rs | 12 ++++++++ crates/teloxide-core/src/local_macros.rs | 22 +++++++++++++- crates/teloxide-core/src/payloads.rs | 2 ++ .../src/payloads/get_business_connection.rs | 16 ++++++++++ crates/teloxide-core/src/payloads/setters.rs | 29 ++++++++++--------- .../teloxide-core/src/requests/requester.rs | 8 +++++ .../src/dispatching/handler_description.rs | 26 ++++++++++++++--- 13 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 crates/teloxide-core/src/payloads/get_business_connection.rs diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 56ed24ea..b75345b8 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -3052,6 +3052,20 @@ Schema( ), ], ), + Method( + names: ("getBusinessConnection", "GetBusinessConnection", "get_business_connection"), + return_ty: RawTy("BusinessConnection"), + doc: Doc(md: "Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success."), + tg_doc: "https://core.telegram.org/bots/api#getbusinessconnection", + tg_category: "Available methods", + params: [ + Param( + name: "business_connection_id", + ty: String, + descr: Doc(md: "Unique identifier of the business connection"), + ), + ], + ), Method( names: ("getMyCommands", "GetMyCommands", "get_my_commands"), return_ty: ArrayOf(RawTy("BotCommand")), diff --git a/crates/teloxide-core/src/adaptors/cache_me.rs b/crates/teloxide-core/src/adaptors/cache_me.rs index 457822a6..251d7473 100644 --- a/crates/teloxide-core/src/adaptors/cache_me.rs +++ b/crates/teloxide-core/src/adaptors/cache_me.rs @@ -163,6 +163,7 @@ where answer_callback_query, get_user_chat_boosts, set_my_commands, + get_business_connection, get_my_commands, set_my_name, get_my_name, diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index fc055f13..c51281b5 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -262,6 +262,7 @@ where answer_callback_query, get_user_chat_boosts, set_my_commands, + get_business_connection, get_my_commands, set_my_name, get_my_name, @@ -751,6 +752,11 @@ trait ErasableRequester<'a> { commands: Vec, ) -> ErasedRequest<'a, SetMyCommands, Self::Err>; + fn get_business_connection( + &self, + business_connection_id: String, + ) -> ErasedRequest<'a, GetBusinessConnection, Self::Err>; + fn get_my_commands(&self) -> ErasedRequest<'a, GetMyCommands, Self::Err>; fn set_my_name(&self) -> ErasedRequest<'a, SetMyName, Self::Err>; @@ -1603,6 +1609,13 @@ where Requester::set_my_commands(self, commands).erase() } + fn get_business_connection( + &self, + business_connection_id: String, + ) -> ErasedRequest<'a, GetBusinessConnection, Self::Err> { + Requester::get_business_connection(self, business_connection_id).erase() + } + fn get_my_commands(&self) -> ErasedRequest<'a, GetMyCommands, Self::Err> { Requester::get_my_commands(self).erase() } diff --git a/crates/teloxide-core/src/adaptors/parse_mode.rs b/crates/teloxide-core/src/adaptors/parse_mode.rs index d6896693..4bc3f6f4 100644 --- a/crates/teloxide-core/src/adaptors/parse_mode.rs +++ b/crates/teloxide-core/src/adaptors/parse_mode.rs @@ -244,6 +244,7 @@ where answer_callback_query, get_user_chat_boosts, set_my_commands, + get_business_connection, get_my_commands, set_my_name, get_my_name, diff --git a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs index d9695664..e12e0de8 100644 --- a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs +++ b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs @@ -146,6 +146,7 @@ where answer_callback_query, get_user_chat_boosts, set_my_commands, + get_business_connection, get_my_commands, set_my_name, get_my_name, diff --git a/crates/teloxide-core/src/adaptors/trace.rs b/crates/teloxide-core/src/adaptors/trace.rs index 2ff661d2..e675453d 100644 --- a/crates/teloxide-core/src/adaptors/trace.rs +++ b/crates/teloxide-core/src/adaptors/trace.rs @@ -192,6 +192,7 @@ where answer_callback_query, get_user_chat_boosts, set_my_commands, + get_business_connection, get_my_commands, set_my_name, get_my_name, diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 0b57b14b..79c79cbb 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -881,6 +881,18 @@ impl Requester for Bot { Self::SetMyCommands::new(self.clone(), payloads::SetMyCommands::new(commands)) } + type GetBusinessConnection = JsonRequest; + + fn get_business_connection(&self, business_connection_id: B) -> Self::GetBusinessConnection + where + B: Into, + { + Self::GetBusinessConnection::new( + self.clone(), + payloads::GetBusinessConnection::new(business_connection_id), + ) + } + type GetMyCommands = JsonRequest; fn get_my_commands(&self) -> Self::GetMyCommands { diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 10d158d3..43e97e36 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -1069,6 +1069,14 @@ macro_rules! requester_forward { $body!(set_my_commands this (commands: C)) } }; + (@method get_business_connection $body:ident $ty:ident) => { + type GetBusinessConnection = $ty![GetBusinessConnection]; + + fn get_business_connection(&self, business_connection_id: BCI) -> Self::GetBusinessConnection where BCI: Into { + let this = self; + $body!(get_business_connection this (business_connection_id: BCI)) + } + }; (@method get_my_commands $body:ident $ty:ident) => { type GetMyCommands = $ty![GetMyCommands]; @@ -1524,7 +1532,7 @@ fn codegen_requester_forward() { convert_params.sort_unstable(); - let prefixes: IndexMap<_, _> = convert_params + let mut prefixes: IndexMap<_, _> = convert_params .iter() .copied() // Workaround to output the last type as the first letter @@ -1533,6 +1541,18 @@ fn codegen_requester_forward() { .map(|(l, r)| (l, min_prefix(l, r))) .collect(); + // FIXME: This hard-coded value has been set to avoid conflicting generic + // parameter 'B' with impl Requester... in all the adaptors and other places + // + // One fix could be to take full abbrevation for all the parameters instead of + // just the first character. Other fix is to change the generic parameter name + // in all the impl blocks to something like 'Z' because that is very less likely + // to conflict in future. + if prefixes.contains_key("business_connection_id") { + prefixes["business_connection_id"] = "BCI"; + } + let prefixes = prefixes; + let args = m .params .iter() diff --git a/crates/teloxide-core/src/payloads.rs b/crates/teloxide-core/src/payloads.rs index f298563d..34e52286 100644 --- a/crates/teloxide-core/src/payloads.rs +++ b/crates/teloxide-core/src/payloads.rs @@ -59,6 +59,7 @@ mod edit_message_text_inline; mod export_chat_invite_link; mod forward_message; mod forward_messages; +mod get_business_connection; mod get_chat; mod get_chat_administrators; mod get_chat_member; @@ -193,6 +194,7 @@ pub use edit_message_text_inline::{EditMessageTextInline, EditMessageTextInlineS pub use export_chat_invite_link::{ExportChatInviteLink, ExportChatInviteLinkSetters}; pub use forward_message::{ForwardMessage, ForwardMessageSetters}; pub use forward_messages::{ForwardMessages, ForwardMessagesSetters}; +pub use get_business_connection::{GetBusinessConnection, GetBusinessConnectionSetters}; pub use get_chat::{GetChat, GetChatSetters}; pub use get_chat_administrators::{GetChatAdministrators, GetChatAdministratorsSetters}; pub use get_chat_member::{GetChatMember, GetChatMemberSetters}; diff --git a/crates/teloxide-core/src/payloads/get_business_connection.rs b/crates/teloxide-core/src/payloads/get_business_connection.rs new file mode 100644 index 00000000..8bab06d6 --- /dev/null +++ b/crates/teloxide-core/src/payloads/get_business_connection.rs @@ -0,0 +1,16 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::BusinessConnection; + +impl_payload! { + /// Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub GetBusinessConnection (GetBusinessConnectionSetters) => BusinessConnection { + required { + /// Unique identifier of the business connection + pub business_connection_id: String [into], + } + } +} diff --git a/crates/teloxide-core/src/payloads/setters.rs b/crates/teloxide-core/src/payloads/setters.rs index 7ed3a581..e7d3640c 100644 --- a/crates/teloxide-core/src/payloads/setters.rs +++ b/crates/teloxide-core/src/payloads/setters.rs @@ -19,20 +19,21 @@ pub use crate::payloads::{ EditMessageReplyMarkupInlineSetters as _, EditMessageReplyMarkupSetters as _, EditMessageTextInlineSetters as _, EditMessageTextSetters as _, ExportChatInviteLinkSetters as _, ForwardMessageSetters as _, ForwardMessagesSetters as _, - GetChatAdministratorsSetters as _, GetChatMemberCountSetters as _, GetChatMemberSetters as _, - GetChatMembersCountSetters as _, GetChatMenuButtonSetters as _, GetChatSetters as _, - GetCustomEmojiStickersSetters as _, GetFileSetters as _, GetForumTopicIconStickersSetters as _, - GetGameHighScoresSetters as _, GetMeSetters as _, GetMyCommandsSetters as _, - GetMyDefaultAdministratorRightsSetters as _, GetMyDescriptionSetters as _, - GetMyNameSetters as _, GetMyShortDescriptionSetters as _, GetStickerSetSetters as _, - GetUpdatesSetters as _, GetUserChatBoostsSetters as _, GetUserProfilePhotosSetters as _, - GetWebhookInfoSetters as _, HideGeneralForumTopicSetters as _, KickChatMemberSetters as _, - LeaveChatSetters as _, LogOutSetters as _, PinChatMessageSetters as _, - PromoteChatMemberSetters as _, ReopenForumTopicSetters as _, - ReopenGeneralForumTopicSetters as _, ReplaceStickerInSetSetters as _, - RestrictChatMemberSetters as _, RevokeChatInviteLinkSetters as _, SendAnimationSetters as _, - SendAudioSetters as _, SendChatActionSetters as _, SendContactSetters as _, - SendDiceSetters as _, SendDocumentSetters as _, SendGameSetters as _, SendInvoiceSetters as _, + GetBusinessConnectionSetters as _, GetChatAdministratorsSetters as _, + GetChatMemberCountSetters as _, GetChatMemberSetters as _, GetChatMembersCountSetters as _, + GetChatMenuButtonSetters as _, GetChatSetters as _, GetCustomEmojiStickersSetters as _, + GetFileSetters as _, GetForumTopicIconStickersSetters as _, GetGameHighScoresSetters as _, + GetMeSetters as _, GetMyCommandsSetters as _, GetMyDefaultAdministratorRightsSetters as _, + GetMyDescriptionSetters as _, GetMyNameSetters as _, GetMyShortDescriptionSetters as _, + GetStickerSetSetters as _, GetUpdatesSetters as _, GetUserChatBoostsSetters as _, + GetUserProfilePhotosSetters as _, GetWebhookInfoSetters as _, + HideGeneralForumTopicSetters as _, KickChatMemberSetters as _, LeaveChatSetters as _, + LogOutSetters as _, PinChatMessageSetters as _, PromoteChatMemberSetters as _, + ReopenForumTopicSetters as _, ReopenGeneralForumTopicSetters as _, + ReplaceStickerInSetSetters as _, RestrictChatMemberSetters as _, + RevokeChatInviteLinkSetters as _, SendAnimationSetters as _, SendAudioSetters as _, + SendChatActionSetters as _, SendContactSetters as _, SendDiceSetters as _, + SendDocumentSetters as _, SendGameSetters as _, SendInvoiceSetters as _, SendLocationSetters as _, SendMediaGroupSetters as _, SendMessageSetters as _, SendPhotoSetters as _, SendPollSetters as _, SendStickerSetters as _, SendVenueSetters as _, SendVideoNoteSetters as _, SendVideoSetters as _, SendVoiceSetters as _, diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 6246f50b..3fdfc7d2 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -831,6 +831,13 @@ pub trait Requester { where C: IntoIterator; + type GetBusinessConnection: Request; + + /// For Telegram documentation see [`GetBusinessConnection`]. + fn get_business_connection(&self, business_connection_id: B) -> Self::GetBusinessConnection + where + B: Into; + type GetMyCommands: Request; /// For Telegram documentation see [`GetMyCommands`]. @@ -1386,6 +1393,7 @@ macro_rules! forward_all { answer_callback_query, get_user_chat_boosts, set_my_commands, + get_business_connection, get_my_commands, set_my_name, get_my_name, diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index 784bb2e4..f798eee3 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -168,10 +168,28 @@ mod tests { for update in allowed_updates_reference { match update { // CAUTION: Don't forget to add new `UpdateKind` to `allowed_updates_reference`! - Message | EditedMessage | ChannelPost | EditedChannelPost | MessageReaction - | MessageReactionCount | InlineQuery | ChosenInlineResult | CallbackQuery - | ShippingQuery | PreCheckoutQuery | Poll | PollAnswer | MyChatMember - | ChatMember | ChatJoinRequest | ChatBoost | RemovedChatBoost => { + Message + | EditedMessage + | ChannelPost + | EditedChannelPost + | MessageReaction + | MessageReactionCount + | InlineQuery + | ChosenInlineResult + | CallbackQuery + | ShippingQuery + | PreCheckoutQuery + | Poll + | PollAnswer + | MyChatMember + | ChatMember + | ChatJoinRequest + | ChatBoost + | RemovedChatBoost + | BusinessMessage + | BusinessConnection + | EditedBusinessMessage + | DeletedBusinessMessages => { assert!(full_set.contains(&Kind(update))) } }