From d975e7e51e363292e782558d945ca837a45f5370 Mon Sep 17 00:00:00 2001 From: Desiders Date: Thu, 15 Aug 2024 00:48:17 +0300 Subject: [PATCH 1/2] Add `has_main_web_app` to `User` and delete unused builder methods --- telers/src/types/user.rs | 189 +-------------------------------------- 1 file changed, 2 insertions(+), 187 deletions(-) diff --git a/telers/src/types/user.rs b/telers/src/types/user.rs index 9543bff..9d9dbd3 100644 --- a/telers/src/types/user.rs +++ b/telers/src/types/user.rs @@ -39,6 +39,8 @@ pub struct User { pub supports_inline_queries: Option, /// `true`, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in [`GetMe`](crate::methods::GetMe). pub can_connect_to_business: Option, + /// `true, if the bot has a main Web App. Returned only in [`GetMe`](crate::methods::GetMe). + pub has_main_web_app: Option, } impl User { @@ -50,190 +52,3 @@ impl User { } } } - -impl User { - #[must_use] - pub fn new(id: i64, is_bot: bool, first_name: impl Into) -> Self { - Self { - id, - is_bot, - first_name: first_name.into(), - last_name: None, - username: None, - language_code: None, - is_premium: None, - added_to_attachment_menu: None, - can_join_groups: None, - can_read_all_group_messages: None, - supports_inline_queries: None, - can_connect_to_business: None, - } - } - - #[must_use] - pub fn id(self, val: i64) -> Self { - Self { id: val, ..self } - } - - #[must_use] - pub fn is_bot(self, val: bool) -> Self { - Self { - is_bot: val, - ..self - } - } - - #[must_use] - pub fn first_name(self, val: impl Into) -> Self { - Self { - first_name: val.into(), - ..self - } - } - - #[must_use] - pub fn last_name(self, val: impl Into) -> Self { - Self { - last_name: Some(val.into()), - ..self - } - } - - #[must_use] - pub fn username(self, val: impl Into) -> Self { - Self { - username: Some(val.into()), - ..self - } - } - - #[must_use] - pub fn language_code(self, val: impl Into) -> Self { - Self { - language_code: Some(val.into()), - ..self - } - } - - #[must_use] - pub fn is_premium(self, val: bool) -> Self { - Self { - is_premium: Some(val), - ..self - } - } - - #[must_use] - pub fn added_to_attachment_menu(self, val: bool) -> Self { - Self { - added_to_attachment_menu: Some(val), - ..self - } - } - - #[must_use] - pub fn can_join_groups(self, val: bool) -> Self { - Self { - can_join_groups: Some(val), - ..self - } - } - - #[must_use] - pub fn can_read_all_group_messages(self, val: bool) -> Self { - Self { - can_read_all_group_messages: Some(val), - ..self - } - } - - #[must_use] - pub fn supports_inline_queries(self, val: bool) -> Self { - Self { - supports_inline_queries: Some(val), - ..self - } - } - - #[must_use] - pub fn can_connect_to_business(self, val: bool) -> Self { - Self { - can_connect_to_business: Some(val), - ..self - } - } -} - -impl User { - #[must_use] - pub fn last_name_option(self, val: Option>) -> Self { - Self { - last_name: val.map(Into::into), - ..self - } - } - - #[must_use] - pub fn username_option(self, val: Option>) -> Self { - Self { - username: val.map(Into::into), - ..self - } - } - - #[must_use] - pub fn language_code_option(self, val: Option>) -> Self { - Self { - language_code: val.map(Into::into), - ..self - } - } - - #[must_use] - pub fn is_premium_option(self, val: Option) -> Self { - Self { - is_premium: val, - ..self - } - } - - #[must_use] - pub fn added_to_attachment_menu_option(self, val: Option) -> Self { - Self { - added_to_attachment_menu: val, - ..self - } - } - - #[must_use] - pub fn can_join_groups_option(self, val: Option) -> Self { - Self { - can_join_groups: val, - ..self - } - } - - #[must_use] - pub fn can_read_all_group_messages_option(self, val: Option) -> Self { - Self { - can_read_all_group_messages: val, - ..self - } - } - - #[must_use] - pub fn supports_inline_queries_option(self, val: Option) -> Self { - Self { - supports_inline_queries: val, - ..self - } - } - - #[must_use] - pub fn can_connect_to_business_option(self, val: Option) -> Self { - Self { - can_connect_to_business: val, - ..self - } - } -} From df9bc8053ffe6a43c598121b39878f2bc0d2db28 Mon Sep 17 00:00:00 2001 From: Desiders Date: Thu, 15 Aug 2024 00:53:02 +0300 Subject: [PATCH 2/2] Add `business_connection_id` to `PinChatMessage` and `UnpinChatMessage` methods --- telers/src/methods/pin_chat_message.rs | 19 +++++++++++++++++++ telers/src/methods/unpin_chat_message.rs | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/telers/src/methods/pin_chat_message.rs b/telers/src/methods/pin_chat_message.rs index 3f7f4a9..e102fc5 100644 --- a/telers/src/methods/pin_chat_message.rs +++ b/telers/src/methods/pin_chat_message.rs @@ -13,6 +13,8 @@ use serde_with::skip_serializing_none; #[skip_serializing_none] #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)] pub struct PinChatMessage { + /// Unique identifier of the business connection on behalf of which the message will be pinned + pub business_connection_id: Option, /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: ChatIdKind, /// Identifier of a message to pin @@ -25,12 +27,21 @@ impl PinChatMessage { #[must_use] pub fn new(chat_id: impl Into, message_id: i64) -> Self { Self { + business_connection_id: None, chat_id: chat_id.into(), message_id, disable_notification: None, } } + #[must_use] + pub fn business_connection_id(self, val: impl Into) -> Self { + Self { + business_connection_id: Some(val.into()), + ..self + } + } + #[must_use] pub fn chat_id(self, val: impl Into) -> Self { Self { @@ -57,6 +68,14 @@ impl PinChatMessage { } impl PinChatMessage { + #[must_use] + pub fn business_connection_id_option(self, val: Option>) -> Self { + Self { + business_connection_id: val.map(Into::into), + ..self + } + } + #[must_use] pub fn disable_notification_option(self, val: Option) -> Self { Self { diff --git a/telers/src/methods/unpin_chat_message.rs b/telers/src/methods/unpin_chat_message.rs index 5b85718..d72ddc2 100644 --- a/telers/src/methods/unpin_chat_message.rs +++ b/telers/src/methods/unpin_chat_message.rs @@ -3,14 +3,18 @@ use super::base::{Request, TelegramMethod}; use crate::{client::Bot, types::ChatIdKind}; use serde::Serialize; +use serde_with::skip_serializing_none; /// Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the `can_pin_messages` administrator right in a supergroup or `can_edit_messages` administrator right in a channel. /// # Documentation /// /// # Returns /// Returns `true` on success +#[skip_serializing_none] #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)] pub struct UnpinChatMessage { + /// Unique identifier of the business connection on behalf of which the message will be unpinned + pub business_connection_id: Option, /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: ChatIdKind, /// Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. @@ -21,11 +25,20 @@ impl UnpinChatMessage { #[must_use] pub fn new(chat_id: impl Into, message_id: i64) -> Self { Self { + business_connection_id: None, chat_id: chat_id.into(), message_id, } } + #[must_use] + pub fn business_connection_id(self, val: impl Into) -> Self { + Self { + business_connection_id: Some(val.into()), + ..self + } + } + #[must_use] pub fn chat_id(self, val: impl Into) -> Self { Self { @@ -43,6 +56,16 @@ impl UnpinChatMessage { } } +impl UnpinChatMessage { + #[must_use] + pub fn business_connection_id_option(self, val: Option>) -> Self { + Self { + business_connection_id: val.map(Into::into), + ..self + } + } +} + impl TelegramMethod for UnpinChatMessage { type Method = Self; type Return = bool;