From 83147809598f3c1b6131b0edd9b759606dff5a1d Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 01:12:04 +0530 Subject: [PATCH 01/46] Add `is_from_offline` field to `MessageCommon` struct --- crates/teloxide-core/src/types/message.rs | 5 +++++ crates/teloxide-core/src/types/update.rs | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 9a749ea9..7f1a8554 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -154,6 +154,11 @@ pub struct MessageCommon { /// `true`, if the message can't be forwarded. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub has_protected_content: bool, + + /// `true`, if the message was sent by an implicit action, for example, as + /// an away or a greeting business message, or as a scheduled message + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub is_from_offline: bool, } #[serde_with::skip_serializing_none] diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index d806f1cf..2a36763a 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -567,6 +567,7 @@ mod test { author_signature: None, is_automatic_forward: false, has_protected_content: false, + is_from_offline: false, }), }), }; @@ -589,7 +590,7 @@ mod test { "from": { "first_name": "Wert", "id": 6962620676, - "is_bot": false, + "is_bot": false, "username": "WertCrypto" }, "message_id": 134545, @@ -631,7 +632,7 @@ mod test { "from": { "first_name": "the Cable Guy", "id": 5964236329, - "is_bot": false, + "is_bot": false, "language_code":"en", "username": "spacewhaleblues" }, @@ -648,7 +649,7 @@ mod test { "from": { "first_name": "Wert", "id": 6962620676, - "is_bot": false, + "is_bot": false, "username": "WertCrypto" }, "message_id": 134545, From 5a533ebc34f1f87e6f374d8602c38875fc32d68e Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 01:16:08 +0530 Subject: [PATCH 02/46] Add `can_connect_to_business` field to `Me` struct --- crates/teloxide-core/src/types/me.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/teloxide-core/src/types/me.rs b/crates/teloxide-core/src/types/me.rs index d5e58a9d..d0cb8287 100644 --- a/crates/teloxide-core/src/types/me.rs +++ b/crates/teloxide-core/src/types/me.rs @@ -23,6 +23,10 @@ pub struct Me { /// `true`, if the bot supports inline queries. pub supports_inline_queries: bool, + + /// `true`, if the bot can be connected to a Telegram Business account to + /// receive its messages. + pub can_connect_to_business: bool, } impl Me { @@ -73,6 +77,7 @@ mod tests { can_join_groups: false, can_read_all_group_messages: false, supports_inline_queries: false, + can_connect_to_business: false, }; assert_eq!(me.username(), "SomethingSomethingBot"); From b534a09633993a7ab390d6d9ba0e46d56c649580 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 01:33:13 +0530 Subject: [PATCH 03/46] Add `personal_chat` field to `ChatPrivate` struct --- crates/teloxide-core/src/types/chat.rs | 13 +++++++++++++ crates/teloxide-core/src/types/message.rs | 3 ++- crates/teloxide-core/src/types/update.rs | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index b4adaa5a..53a4a2f7 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -133,6 +133,12 @@ pub struct ChatPrivate { /// /// [`GetChat`]: crate::payloads::GetChat pub has_restricted_voice_and_video_messages: Option, + + /// For private chats, the personal channel of the user. Returned only in + /// [`GetChat`]. + /// + /// [`GetChat`]: crate::payloads::GetChat + pub personal_chat: Option>, } #[serde_with::skip_serializing_none] @@ -584,6 +590,7 @@ mod serde_helper { bio: Option, has_private_forwards: Option, has_restricted_voice_and_video_messages: Option, + personal_chat: Option>, } impl From for super::ChatPrivate { @@ -596,6 +603,7 @@ mod serde_helper { bio, has_private_forwards, has_restricted_voice_and_video_messages, + personal_chat, }: ChatPrivate, ) -> Self { Self { @@ -605,6 +613,7 @@ mod serde_helper { bio, has_private_forwards, has_restricted_voice_and_video_messages, + personal_chat, } } } @@ -618,6 +627,7 @@ mod serde_helper { bio, has_private_forwards, has_restricted_voice_and_video_messages, + personal_chat, }: super::ChatPrivate, ) -> Self { Self { @@ -628,6 +638,7 @@ mod serde_helper { bio, has_private_forwards, has_restricted_voice_and_video_messages, + personal_chat, } } } @@ -690,6 +701,7 @@ mod tests { bio: None, has_private_forwards: None, has_restricted_voice_and_video_messages: None, + personal_chat: None, }), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), @@ -728,6 +740,7 @@ mod tests { bio: None, has_private_forwards: None, has_restricted_voice_and_video_messages: None, + personal_chat: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 7f1a8554..0b625ed5 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1890,7 +1890,8 @@ mod tests { username: Some("aka_dude".to_string()), bio: None, has_private_forwards: None, - has_restricted_voice_and_video_messages: None + has_restricted_voice_and_video_messages: None, + personal_chat: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 2a36763a..54b285ac 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -535,6 +535,7 @@ mod test { bio: None, has_private_forwards: None, has_restricted_voice_and_video_messages: None, + personal_chat: None, }), photo: None, available_reactions: None, From 226514103043ad4f25599c07d0e3578b88d4614b Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 02:05:00 +0530 Subject: [PATCH 04/46] Add `replaceStickerInSet` TBA method --- crates/teloxide-core/schema.ron | 180 +++++++++++------- crates/teloxide-core/src/adaptors/cache_me.rs | 1 + crates/teloxide-core/src/adaptors/erased.rs | 1 + .../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 | 24 +++ crates/teloxide-core/src/local_macros.rs | 9 + crates/teloxide-core/src/payloads.rs | 2 + .../src/payloads/replace_sticker_in_set.rs | 27 +++ crates/teloxide-core/src/payloads/setters.rs | 8 +- .../teloxide-core/src/requests/requester.rs | 15 ++ 12 files changed, 194 insertions(+), 76 deletions(-) create mode 100644 crates/teloxide-core/src/payloads/replace_sticker_in_set.rs diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 4a0c41e8..446c1d11 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -1,14 +1,14 @@ //! This file is written in [RON] (Rusty Object Notation). -//! -//! This "schema" is a formalized version of the +//! +//! This "schema" is a formalized version of the //! [telegram bot api documentation][tbadoc] which is not machine readable. //! (note: this schema currently covers only API methods and **not** types). -//! +//! //! Also, note that this file is **hand written** and may contain typos, //! deviations from original doc, and other kinds of typical human errors. //! If you found an error please open an issue (or make a PR) on [github]. -//! -//! This schema is targeting code generation for API wrappers in a statically +//! +//! This schema is targeting code generation for API wrappers in a statically //! typed language, though you may use it whatever you want. //! //! This scheme also has some intentional differences from original doc: @@ -20,26 +20,26 @@ //! + `AllowedUpdate` inner type of `allowed_updates` in `getUpdates` and //! `setWebhook` (so type is `ArrayOf(AllowedUpdate)`) //! + `ReplyMarkup` - type of `reply_markup` parameter, in the original -//! documentation written as `InlineKeyboardMarkup or ReplyKeyboardMarkup or +//! documentation written as `InlineKeyboardMarkup or ReplyKeyboardMarkup or //! ReplyKeyboardRemove or ForceReply` //! + `ParseMode` type of `parse_mode` params //! + `PollType` type of poll, either β€œquiz” or β€œregular” //! + `DiceEmoji` emoji that can be used in `sendDice` one of β€œπŸŽ²β€, β€œπŸŽ―β€, or β€œπŸ€β€ //! + `TargetMessage` either `inline_message_id: String` or `chat_id: ChatId` and `message_id: i64` //! * Integers represented with more strict (when possible) types, e.g.: -//! `u8` (unsigned, 8-bit integer), `u32` (unsigned, 32-bit), +//! `u8` (unsigned, 8-bit integer), `u32` (unsigned, 32-bit), //! `i64` (signed, 64-bit), etc //! * Instead of optional parameters `Option(Ty)` is used //! * Instead of `InputFile or String` just `InputFile` is used (assuming that //! `InputFile` is a sum-type or something and it can contain `String`s) //! * `f64` ~= `Float number` -//! +//! //! [tbadoc]: https://core.telegram.org/bots/api //! [RON]: https://github.com/ron-rs/ron //! [github]: https://github.com/WaffleLapkin/tg-methods-schema Schema( - api_version: ApiVersion(ver: "7.1", date: "February 16, 2024"), + api_version: ApiVersion(ver: "7.2", date: "March 31, 2024"), methods: [ Method( names: ("getUpdates", "GetUpdates", "get_updates"), @@ -49,7 +49,7 @@ Schema( md_links: { "wiki": "https://en.wikipedia.org/wiki/Push_technology#Long_polling", "Update": "https://core.telegram.org/bots/api#update", - }, + }, ), tg_doc: "https://core.telegram.org/bots/api#getupdates", tg_category: "Getting updates", @@ -155,7 +155,7 @@ Schema( md_links: {"amazing guide to Webhooks": "https://core.telegram.org/bots/webhooks"} ) ] - ), + ), Method( names: ("deleteWebhook", "DeleteWebhook", "delete_webhook"), return_ty: True, @@ -205,7 +205,7 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#logout", tg_category: "Available methods", params: [], - ), + ), Method( names: ("close", "Close", "close"), return_ty: True, @@ -259,7 +259,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -315,7 +315,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -328,7 +328,7 @@ Schema( ), Param( name: "message_id", - ty: RawTy("MessageId"), + ty: RawTy("MessageId"), descr: Doc(md: "Message identifier in the chat specified in _from\\_chat\\_id_") ), ], @@ -365,7 +365,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -405,7 +405,7 @@ Schema( ), Param( name: "message_id", - ty: RawTy("MessageId"), + ty: RawTy("MessageId"), descr: Doc(md: "Message identifier in the chat specified in _from\\_chat\\_id_") ), Param( @@ -428,7 +428,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -487,12 +487,12 @@ Schema( ), Param( name: "message_ids", - ty: ArrayOf(RawTy("MessageId")), + ty: ArrayOf(RawTy("MessageId")), descr: Doc(md: "Identifiers of 1-100 messages in the chat _from\\_chat\\_id_ to copy. The identifiers must be specified in a strictly increasing order.") ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -555,7 +555,7 @@ Schema( name: "caption_entities", ty: Option(ArrayOf(RawTy("MessageEntity"))), descr: Doc(md: "List of special entities that appear in the photo caption, which can be specified instead of _parse\\_mode_"), - ), + ), Param( name: "has_spoiler", ty: Option(bool), @@ -563,7 +563,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -666,7 +666,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"}, @@ -756,7 +756,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"}, @@ -869,7 +869,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"}, @@ -895,7 +895,7 @@ Schema( "custom reply keyboard": "https://core.telegram.org/bots#keyboards", } ), - + ), ], ), @@ -975,7 +975,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"}, @@ -1061,7 +1061,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"}, @@ -1080,7 +1080,7 @@ Schema( md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", - } + } ), ), ], @@ -1136,7 +1136,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"}, @@ -1160,9 +1160,9 @@ Schema( md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", - } + } ), - + ), ], ), @@ -1193,7 +1193,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -1256,17 +1256,17 @@ Schema( ), Param( name: "heading", - ty: Option(u16), + ty: Option(u16), descr: Doc(md: "For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.") ), Param( name: "proximity_alert_radius", - ty: Option(u32), + ty: Option(u32), descr: Doc(md: "For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.") ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -1312,7 +1312,7 @@ Schema( ), Param( name: "message_id", - ty: RawTy("MessageId"), + ty: RawTy("MessageId"), descr: Doc(md: "Identifier of the message to edit") ), Param( @@ -1332,12 +1332,12 @@ Schema( ), Param( name: "heading", - ty: Option(u16), + ty: Option(u16), descr: Doc(md: "For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.") ), Param( name: "proximity_alert_radius", - ty: Option(u32), + ty: Option(u32), descr: Doc(md: "For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.") ), Param( @@ -1386,12 +1386,12 @@ Schema( ), Param( name: "heading", - ty: Option(u16), + ty: Option(u16), descr: Doc(md: "For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.") ), Param( name: "proximity_alert_radius", - ty: Option(u32), + ty: Option(u32), descr: Doc(md: "For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.") ), Param( @@ -1428,7 +1428,7 @@ Schema( ), Param( name: "message_id", - ty: RawTy("MessageId"), + ty: RawTy("MessageId"), descr: Doc(md: "Identifier of the message to edit") ), Param( @@ -1439,7 +1439,7 @@ Schema( md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", - } + } ), ), ], @@ -1539,7 +1539,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -1563,7 +1563,7 @@ Schema( md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", - } + } ), ), ], @@ -1613,7 +1613,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -1727,7 +1727,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -1751,7 +1751,7 @@ Schema( md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", - } + } ), ), ], @@ -1783,7 +1783,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -1826,7 +1826,7 @@ Schema( name: "chat_id", ty: RawTy("Recipient"), descr: Doc(md: "Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)") - ), + ), Param( name: "action", ty: RawTy("ChatAction"), @@ -2189,7 +2189,7 @@ Schema( descr: Doc(md: "Unique identifier of the target sender chat") ), ], - ), + ), Method( names: ("unbanChatSenderChat", "UnbanChatSenderChat", "unban_chat_sender_chat"), return_ty: True, @@ -2246,7 +2246,7 @@ Schema( descr: Doc(md: "Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)") ), ], - ), + ), Method( names: ("createChatInviteLink", "CreateChatInviteLink", "create_chat_invite_link"), return_ty: RawTy("ChatInviteLink"), @@ -2286,7 +2286,7 @@ Schema( descr: Doc(md: "True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified") ), ], - ), + ), Method( names: ("editChatInviteLink", "EditChatInviteLink", "edit_chat_invite_link"), return_ty: String, @@ -2328,7 +2328,7 @@ Schema( descr: Doc(md: "True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified") ), ], - ), + ), Method( names: ("revokeChatInviteLink", "RevokeChatInviteLink", "revoke_chat_invite_link"), return_ty: String, @@ -2479,7 +2479,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc(md: "Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels.") ), ], @@ -2976,7 +2976,7 @@ Schema( descr: Doc(md: "A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands") ), ], - ), + ), Method( names: ("getMyCommands", "GetMyCommands", "get_my_commands"), return_ty: ArrayOf(RawTy("BotCommand")), @@ -3238,7 +3238,7 @@ Schema( names: ("answerWebAppQuery", "AnswerWebAppQuery", "answer_web_app_query"), return_ty: RawTy("SentWebAppMessage"), doc: Doc( - md: "Use this method to set the result of an interaction with a [Web App] and send a corresponding message on behalf of the user to the chat from which the query originated.", + md: "Use this method to set the result of an interaction with a [Web App] and send a corresponding message on behalf of the user to the chat from which the query originated.", md_links: {"Web App": "https://core.telegram.org/bots/webapps"} ), tg_doc: "https://core.telegram.org/bots/api#answerwebappquery", @@ -3305,7 +3305,7 @@ Schema( ty: Option(RawTy("InlineKeyboardMarkup")), descr: Doc( md: "A JSON-serialized object for an [inline keyboard].", - md_links: {"inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating"}, + md_links: {"inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating"}, ), ), ], @@ -3399,7 +3399,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("InlineKeyboardMarkup")), descr: Doc( - md: "A JSON-serialized object for an [inline keyboard].", + md: "A JSON-serialized object for an [inline keyboard].", md_links: {"inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating",} ), ), @@ -3442,7 +3442,7 @@ Schema( ty: Option(RawTy("InlineKeyboardMarkup")), descr: Doc( md: "A JSON-serialized object for an [inline keyboard].", - md_links: {"inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating"} + md_links: {"inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating"} ), ), ], @@ -3602,7 +3602,7 @@ Schema( name: "message_id", ty: RawTy("MessageId"), descr: Doc(md: "Identifier of the message to delete") - ), + ), ], ), Method( @@ -3624,14 +3624,14 @@ Schema( md: "Identifiers of 1-100 messages to delete. See [deleteMessage] for limitations on which messages can be deleted", md_links: {"deleteMessage": "https://core.telegram.org/bots/api#delete_message"} ) - ), + ), ], ), Method( names: ("sendSticker", "SendSticker", "send_sticker"), return_ty: RawTy("Message"), doc: Doc( - md: "Use this method to send static .WEBP or [animated] .TGS stickers. On success, the sent Message is returned.", + md: "Use this method to send static .WEBP or [animated] .TGS stickers. On success, the sent Message is returned.", md_links: {"animated": "https://telegram.org/blog/animated-stickers"} ), tg_doc: "https://core.telegram.org/bots/api#sendsticker", @@ -3662,7 +3662,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -3859,6 +3859,42 @@ Schema( ), ], ), + Method( + names: ("replaceStickerInSet", "ReplaceStickerInSet", "replace_sticker_in_set"), + return_ty: True, + doc: Doc( + md: "Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling [DeleteStickerFromSet], then [AddStickerToSet], then [SetStickerPositionInSet]. Returns _True_ on success.", + md_links: { + "DeleteStickerFromSet": "https://docs.rs/teloxide/latest/teloxide/payloads/struct.DeleteStickerFromSet.html", + "AddStickerToSet": "https://docs.rs/teloxide/latest/teloxide/payloads/struct.AddStickerToSet.html", + "SetStickerPositionInSet": "https://docs.rs/teloxide/latest/teloxide/payloads/struct.SetStickerPositionInSet.html", + } + ), + tg_doc: "https://core.telegram.org/bots/api#replacestickerinset", + tg_category: "Stickers", + params: [ + Param( + name: "user_id", + ty: RawTy("UserId"), + descr: Doc(md: "User identifier of the sticker set owner"), + ), + Param( + name: "name", + ty: String, + descr: Doc(md: "Sticker set name"), + ), + Param( + name: "old_sticker", + ty: String, + descr: Doc(md: "File identifier of the replaced sticker"), + ), + Param( + name: "sticker", + ty: RawTy("InputSticker"), + descr: Doc(md: "A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged."), + ), + ], + ), Method( names: ("setStickerSetThumbnail", "SetStickerSetThumbnail", "set_sticker_set_thumbnail"), return_ty: True, @@ -4035,7 +4071,7 @@ Schema( ty: String, descr: Doc( md: "Payments provider token, obtained via [Botfather]", - md_links: {"Botfather":"https://t.me/botfather"} + md_links: {"Botfather":"https://t.me/botfather"} ), ), Param( @@ -4128,7 +4164,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -4181,7 +4217,7 @@ Schema( ty: String, descr: Doc( md: "Payments provider token, obtained via [Botfather]", - md_links: {"Botfather":"https://t.me/botfather"} + md_links: {"Botfather":"https://t.me/botfather"} ), ), Param( @@ -4352,7 +4388,7 @@ Schema( return_ty: RawTy("Message"), doc: Doc( md: "Use this method to send a game. On success, the sent [Message] is returned.", - md_links: {"Message": "https://core.telegram.org/bots/api#message"} + md_links: {"Message": "https://core.telegram.org/bots/api#message"} ), tg_doc: "https://core.telegram.org/bots/api#sendgame", tg_category: "Games", @@ -4374,7 +4410,7 @@ Schema( ), Param( name: "disable_notification", - ty: Option(bool), + ty: Option(bool), descr: Doc( md: "Sends the message [silently]. Users will receive a notification with no sound.", md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} @@ -4405,7 +4441,7 @@ Schema( return_ty: RawTy("Message"), doc: Doc( md: "Use this method to set the score of the specified user in a game. On success, returns the edited [Message]. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.", - md_links: {"Message": "https://core.telegram.org/bots/api#message"} + md_links: {"Message": "https://core.telegram.org/bots/api#message"} ), tg_doc: "https://core.telegram.org/bots/api#setgamescore", tg_category: "Games", @@ -4437,7 +4473,7 @@ Schema( ), Param( name: "message_id", - ty: RawTy("MessageId"), + ty: RawTy("MessageId"), descr: Doc(md: "Identifier of the message to edit") ), ], @@ -4508,7 +4544,7 @@ Schema( "Updating messages": "https://core.telegram.org/bots/api#updating-messages", "Stickers": "https://core.telegram.org/bots/api#stickers", "Payments": "https://core.telegram.org/bots/api#payments", - "Telegram Passport": "https://core.telegram.org/bots/api#telegram-passport", + "Telegram Passport": "https://core.telegram.org/bots/api#telegram-passport", "Games": "https://core.telegram.org/bots/api#games", } ) diff --git a/crates/teloxide-core/src/adaptors/cache_me.rs b/crates/teloxide-core/src/adaptors/cache_me.rs index aafe2aca..457822a6 100644 --- a/crates/teloxide-core/src/adaptors/cache_me.rs +++ b/crates/teloxide-core/src/adaptors/cache_me.rs @@ -196,6 +196,7 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, + replace_sticker_in_set, set_sticker_set_thumbnail, set_custom_emoji_sticker_set_thumbnail, set_sticker_set_title, diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index 7d4eae0f..fc055f13 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -295,6 +295,7 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, + replace_sticker_in_set, set_sticker_set_thumbnail, set_custom_emoji_sticker_set_thumbnail, set_sticker_set_title, diff --git a/crates/teloxide-core/src/adaptors/parse_mode.rs b/crates/teloxide-core/src/adaptors/parse_mode.rs index 2906302e..d6896693 100644 --- a/crates/teloxide-core/src/adaptors/parse_mode.rs +++ b/crates/teloxide-core/src/adaptors/parse_mode.rs @@ -269,6 +269,7 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, + replace_sticker_in_set, set_sticker_set_thumbnail, set_custom_emoji_sticker_set_thumbnail, set_sticker_set_title, diff --git a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs index 9c6fbd28..d9695664 100644 --- a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs +++ b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs @@ -178,6 +178,7 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, + replace_sticker_in_set, set_sticker_set_thumbnail, set_custom_emoji_sticker_set_thumbnail, set_sticker_set_title, diff --git a/crates/teloxide-core/src/adaptors/trace.rs b/crates/teloxide-core/src/adaptors/trace.rs index 4a865dc3..2ff661d2 100644 --- a/crates/teloxide-core/src/adaptors/trace.rs +++ b/crates/teloxide-core/src/adaptors/trace.rs @@ -225,6 +225,7 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, + replace_sticker_in_set, set_sticker_set_thumbnail, set_custom_emoji_sticker_set_thumbnail, set_sticker_set_title, diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 2088bbcb..a1c1bbf9 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -1244,6 +1244,30 @@ impl Requester for Bot { Self::DeleteStickerFromSet::new(self.clone(), payloads::DeleteStickerFromSet::new(sticker)) } + type ReplaceStickerInSet = JsonRequest; + + fn replace_sticker_in_set( + &self, + user_id: UserId, + name: N, + old_sticker: O, + sticker: InputSticker, + ) -> Self::ReplaceStickerInSet + where + N: Into, + O: Into, + { + Self::ReplaceStickerInSet::new( + self.clone(), + payloads::ReplaceStickerInSet { + user_id, + name: name.into(), + old_sticker: old_sticker.into(), + sticker, + }, + ) + } + type SetStickerSetThumbnail = MultipartRequest; fn set_sticker_set_thumbnail(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumbnail diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 3fd2bbc7..7bc088cc 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -1339,6 +1339,15 @@ macro_rules! requester_forward { $body!(delete_sticker_from_set this (sticker: S)) } }; + (@method replace_sticker_in_set $body:ident $ty:ident) => { + type ReplaceStickerInSet = $ty![ReplaceStickerInSet]; + + fn replace_sticker_in_set(&self, user_id: UserId, name: N, old_sticker: O, sticker: InputSticker) -> Self::ReplaceStickerInSet where N: Into, + O: Into { + let this = self; + $body!(replace_sticker_in_set this (user_id: UserId, name: N, old_sticker: O, sticker: InputSticker)) + } + }; (@method set_sticker_set_thumbnail $body:ident $ty:ident) => { type SetStickerSetThumbnail = $ty![SetStickerSetThumbnail]; diff --git a/crates/teloxide-core/src/payloads.rs b/crates/teloxide-core/src/payloads.rs index 47fbac31..f298563d 100644 --- a/crates/teloxide-core/src/payloads.rs +++ b/crates/teloxide-core/src/payloads.rs @@ -88,6 +88,7 @@ mod pin_chat_message; mod promote_chat_member; mod reopen_forum_topic; mod reopen_general_forum_topic; +mod replace_sticker_in_set; mod restrict_chat_member; mod revoke_chat_invite_link; mod send_animation; @@ -225,6 +226,7 @@ pub use pin_chat_message::{PinChatMessage, PinChatMessageSetters}; pub use promote_chat_member::{PromoteChatMember, PromoteChatMemberSetters}; pub use reopen_forum_topic::{ReopenForumTopic, ReopenForumTopicSetters}; pub use reopen_general_forum_topic::{ReopenGeneralForumTopic, ReopenGeneralForumTopicSetters}; +pub use replace_sticker_in_set::{ReplaceStickerInSet, ReplaceStickerInSetSetters}; pub use restrict_chat_member::{RestrictChatMember, RestrictChatMemberSetters}; pub use revoke_chat_invite_link::{RevokeChatInviteLink, RevokeChatInviteLinkSetters}; pub use send_animation::{SendAnimation, SendAnimationSetters}; diff --git a/crates/teloxide-core/src/payloads/replace_sticker_in_set.rs b/crates/teloxide-core/src/payloads/replace_sticker_in_set.rs new file mode 100644 index 00000000..8e64e9b5 --- /dev/null +++ b/crates/teloxide-core/src/payloads/replace_sticker_in_set.rs @@ -0,0 +1,27 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::{InputSticker, True, UserId}; + +impl_payload! { + @[multipart = sticker] + /// Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling [DeleteStickerFromSet], then [AddStickerToSet], then [SetStickerPositionInSet]. Returns _True_ on success. + /// + /// [DeleteStickerFromSet]: https://docs.rs/teloxide/latest/teloxide/payloads/struct.DeleteStickerFromSet.html + /// [AddStickerToSet]: https://docs.rs/teloxide/latest/teloxide/payloads/struct.AddStickerToSet.html + /// [SetStickerPositionInSet]: https://docs.rs/teloxide/latest/teloxide/payloads/struct.SetStickerPositionInSet.html + #[derive(Debug, Clone, Serialize)] + pub ReplaceStickerInSet (ReplaceStickerInSetSetters) => True { + required { + /// User identifier of the sticker set owner + pub user_id: UserId, + /// Sticker set name + pub name: String [into], + /// File identifier of the replaced sticker + pub old_sticker: String [into], + /// A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged. + pub sticker: InputSticker, + } + } +} diff --git a/crates/teloxide-core/src/payloads/setters.rs b/crates/teloxide-core/src/payloads/setters.rs index 06a24b76..7ed3a581 100644 --- a/crates/teloxide-core/src/payloads/setters.rs +++ b/crates/teloxide-core/src/payloads/setters.rs @@ -29,10 +29,10 @@ pub use crate::payloads::{ GetWebhookInfoSetters as _, HideGeneralForumTopicSetters as _, KickChatMemberSetters as _, LeaveChatSetters as _, LogOutSetters as _, PinChatMessageSetters as _, PromoteChatMemberSetters as _, ReopenForumTopicSetters as _, - ReopenGeneralForumTopicSetters as _, RestrictChatMemberSetters as _, - RevokeChatInviteLinkSetters as _, SendAnimationSetters as _, SendAudioSetters as _, - SendChatActionSetters as _, SendContactSetters as _, SendDiceSetters as _, - SendDocumentSetters as _, SendGameSetters as _, SendInvoiceSetters 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 977e2c19..731e370f 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -1108,6 +1108,20 @@ pub trait Requester { where S: Into; + type ReplaceStickerInSet: Request; + + /// For Telegram documentation see [`ReplaceStickerInSet`]. + fn replace_sticker_in_set( + &self, + user_id: UserId, + name: N, + old_sticker: O, + sticker: InputSticker, + ) -> Self::ReplaceStickerInSet + where + N: Into, + O: Into; + type SetStickerSetThumbnail: Request; /// For Telegram documentation see [`SetStickerSetThumbnail`]. @@ -1405,6 +1419,7 @@ macro_rules! forward_all { add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, + replace_sticker_in_set, set_sticker_set_thumbnail, set_custom_emoji_sticker_set_thumbnail, set_sticker_set_title, From cb8ff44b09481b3e0b6cc2e6bce6003f03bfdcc8 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 19:34:09 +0530 Subject: [PATCH 05/46] Add `Birthdate` struct and corresponding field in `ChatPrivate` --- crates/teloxide-core/src/types.rs | 2 ++ crates/teloxide-core/src/types/birthdate.rs | 17 +++++++++++++++++ crates/teloxide-core/src/types/chat.rs | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 crates/teloxide-core/src/types/birthdate.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 0177bd91..2eb997e4 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -3,6 +3,7 @@ pub use allowed_update::*; pub use animation::*; pub use audio::*; +pub use birthdate::*; pub use bot_command::*; pub use bot_command_scope::*; pub use bot_description::*; @@ -156,6 +157,7 @@ pub use write_access_allowed::*; mod allowed_update; mod animation; mod audio; +mod birthdate; mod bot_command; mod bot_command_scope; mod bot_description; diff --git a/crates/teloxide-core/src/types/birthdate.rs b/crates/teloxide-core/src/types/birthdate.rs new file mode 100644 index 00000000..8454b820 --- /dev/null +++ b/crates/teloxide-core/src/types/birthdate.rs @@ -0,0 +1,17 @@ +use serde::{Deserialize, Serialize}; + +/// Describes the birthdate of a user. +/// +/// [The official docs](https://core.telegram.org/bots/api#birthdate) +#[serde_with::skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct Birthdate { + /// Day of the user's birth; 1-31 + pub day: u8, + + /// Month of the user's birth; 1-12 + pub month: u8, + + /// Optional. Year of the user's birth + pub year: Option, +} diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index 53a4a2f7..a3fbed62 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -5,6 +5,8 @@ use crate::types::{ True, User, }; +use super::Birthdate; + /// This object represents a chat. /// /// [The official docs](https://core.telegram.org/bots/api#chat). @@ -139,6 +141,12 @@ pub struct ChatPrivate { /// /// [`GetChat`]: crate::payloads::GetChat pub personal_chat: Option>, + + /// For private chats, the date of birth of the user. Returned only in + /// [`GetChat`]. + /// + /// [`GetChat`]: crate::payloads::GetChat + pub birthdate: Option, } #[serde_with::skip_serializing_none] From df416079f04741428542cb9fcdebed1603268078 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 19:39:47 +0530 Subject: [PATCH 06/46] Add `request_*` fields to `KeyboardButtonRequestUsers` struct Added fields: `request_name`, `request_username` and `request_photo` --- .../types/keyboard_button_request_users.rs | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/src/types/keyboard_button_request_users.rs b/crates/teloxide-core/src/types/keyboard_button_request_users.rs index 6f126622..7b873c3b 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_users.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_users.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::types::RequestId; -/// This object defines the criteria used to request a suitable users. The -/// identifiers of the selected users will be shared with the bot when the +/// This object defines the criteria used to request a suitable users. +/// Information about the selected users will be shared with the bot when the /// corresponding button is pressed. More about requesting users Β» /// /// [More about requesting users Β»]: https://core.telegram.org/bots/features#chat-and-user-selection @@ -30,12 +30,32 @@ pub struct KeyboardButtonRequestUsers { /// The maximum number of users to be selected; 1-10. Defaults to 1. #[serde(default = "one", skip_serializing_if = "is_one")] pub max_quantity: u8, + + /// Pass `true` to request the users' first and last names + #[serde(default, skip_serializing_if = "Option::is_none")] + pub request_name: Option, + + /// Pass `true` to request the users' username + #[serde(default, skip_serializing_if = "Option::is_none")] + pub request_username: Option, + + /// Pass `true` to request the users' photos + #[serde(default, skip_serializing_if = "Option::is_none")] + pub request_photo: Option, } impl KeyboardButtonRequestUsers { /// Creates a new [`KeyboardButtonRequestUsers`]. pub fn new(request_id: RequestId) -> Self { - Self { request_id, user_is_bot: None, user_is_premium: None, max_quantity: 1 } + Self { + request_id, + user_is_bot: None, + user_is_premium: None, + max_quantity: 1, + request_name: None, + request_username: None, + request_photo: None, + } } /// Setter for `user_is_bot` field @@ -57,6 +77,24 @@ impl KeyboardButtonRequestUsers { self.max_quantity = value; self } + + /// Setter for `request_name` field + pub fn request_name(mut self, value: bool) -> Self { + self.request_name = Some(value); + self + } + + /// Setter for `request_username` field + pub fn request_username(mut self, value: bool) -> Self { + self.request_username = Some(value); + self + } + + /// Setter for `request_photo` field + pub fn request_photo(mut self, value: bool) -> Self { + self.request_photo = Some(value); + self + } } fn one() -> u8 { From 550d306f6542cd74981f5eb63fe35cef0af02b12 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 19:43:51 +0530 Subject: [PATCH 07/46] Fix broken tests due to addition of `birthdate` --- crates/teloxide-core/src/types/chat.rs | 8 ++++++++ crates/teloxide-core/src/types/message.rs | 1 + crates/teloxide-core/src/types/update.rs | 1 + 3 files changed, 10 insertions(+) diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index a3fbed62..41fae489 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -577,6 +577,7 @@ impl Chat { } mod serde_helper { + use super::Birthdate; use crate::types::True; use serde::{Deserialize, Serialize}; @@ -599,6 +600,7 @@ mod serde_helper { has_private_forwards: Option, has_restricted_voice_and_video_messages: Option, personal_chat: Option>, + birthdate: Option, } impl From for super::ChatPrivate { @@ -612,6 +614,7 @@ mod serde_helper { has_private_forwards, has_restricted_voice_and_video_messages, personal_chat, + birthdate, }: ChatPrivate, ) -> Self { Self { @@ -622,6 +625,7 @@ mod serde_helper { has_private_forwards, has_restricted_voice_and_video_messages, personal_chat, + birthdate, } } } @@ -636,6 +640,7 @@ mod serde_helper { has_private_forwards, has_restricted_voice_and_video_messages, personal_chat, + birthdate, }: super::ChatPrivate, ) -> Self { Self { @@ -647,6 +652,7 @@ mod serde_helper { has_private_forwards, has_restricted_voice_and_video_messages, personal_chat, + birthdate, } } } @@ -710,6 +716,7 @@ mod tests { has_private_forwards: None, has_restricted_voice_and_video_messages: None, personal_chat: None, + birthdate: None, }), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), @@ -749,6 +756,7 @@ mod tests { has_private_forwards: None, has_restricted_voice_and_video_messages: None, personal_chat: None, + birthdate: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 0b625ed5..17fbe150 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1892,6 +1892,7 @@ mod tests { has_private_forwards: None, has_restricted_voice_and_video_messages: None, personal_chat: None, + birthdate: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 54b285ac..1c792bfc 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -536,6 +536,7 @@ mod test { has_private_forwards: None, has_restricted_voice_and_video_messages: None, personal_chat: None, + birthdate: None, }), photo: None, available_reactions: None, From e1f1b4e8740a7258ccfad76d8a01478e588aba1d Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 19:52:18 +0530 Subject: [PATCH 08/46] Add `request_*` fields to `KeyboardButtonRequestChat` Added fields are `request_title`, `request_username` and `request_photo` --- .../src/types/keyboard_button_request_chat.rs | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/src/types/keyboard_button_request_chat.rs b/crates/teloxide-core/src/types/keyboard_button_request_chat.rs index 2765aa69..96a0512e 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_chat.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_chat.rs @@ -2,9 +2,10 @@ use serde::{Deserialize, Serialize}; use crate::types::{ChatAdministratorRights, RequestId}; -/// This object defines the criteria used to request a suitable chat. The -/// identifier of the selected chat will be shared with the bot when the -/// corresponding button is pressed. [More about requesting chats Β»] +/// This object defines the criteria used to request a suitable chat. +/// Information about the selected chat will be shared with the bot when the +/// corresponding button is pressed. The bot will be granted requested rights in +/// the chat if appropriate. [More about requesting chats Β»] /// /// [More about requesting chats Β»]: https://core.telegram.org/bots/features#chat-and-user-selection #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] @@ -53,6 +54,18 @@ pub struct KeyboardButtonRequestChat { /// additional restrictions are applied. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub bot_is_member: bool, + + /// Pass `true` to request the chat's title. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub request_title: bool, + + /// Pass `true` to request the chat's username. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub request_username: bool, + + /// Pass `true` to request the chat's photos. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub request_photo: bool, } impl KeyboardButtonRequestChat { @@ -67,6 +80,9 @@ impl KeyboardButtonRequestChat { user_administrator_rights: None, bot_administrator_rights: None, bot_is_member: false, + request_title: false, + request_username: false, + request_photo: false, } } @@ -111,4 +127,25 @@ impl KeyboardButtonRequestChat { self.bot_is_member = value; self } + + /// Setter for `request_title` field. + #[must_use] + pub fn request_title(mut self, value: bool) -> Self { + self.request_title = value; + self + } + + /// Setter for `request_username` field. + #[must_use] + pub fn request_username(mut self, value: bool) -> Self { + self.request_username = value; + self + } + + /// Setter for `request_photo` field. + #[must_use] + pub fn request_photo(mut self, value: bool) -> Self { + self.request_photo = value; + self + } } From a48d071456dfe2b94301223ada531307bf84d4be Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 19:53:53 +0530 Subject: [PATCH 09/46] Make setters of `KeyboardButtonRequestUsers` must use --- .../src/types/keyboard_button_request_users.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/teloxide-core/src/types/keyboard_button_request_users.rs b/crates/teloxide-core/src/types/keyboard_button_request_users.rs index 7b873c3b..ea14101a 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_users.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_users.rs @@ -59,18 +59,21 @@ impl KeyboardButtonRequestUsers { } /// Setter for `user_is_bot` field + #[must_use] pub fn user_is_bot(mut self, value: bool) -> Self { self.user_is_bot = Some(value); self } /// Setter for `user_is_premium` field + #[must_use] pub fn user_is_premium(mut self, value: bool) -> Self { self.user_is_premium = Some(value); self } /// Setter for `max_quantity` field, the value must be in the range 1..=10 + #[must_use] pub fn max_quantity(mut self, value: u8) -> Self { assert!((1..=10).contains(&value)); @@ -79,18 +82,21 @@ impl KeyboardButtonRequestUsers { } /// Setter for `request_name` field + #[must_use] pub fn request_name(mut self, value: bool) -> Self { self.request_name = Some(value); self } /// Setter for `request_username` field + #[must_use] pub fn request_username(mut self, value: bool) -> Self { self.request_username = Some(value); self } /// Setter for `request_photo` field + #[must_use] pub fn request_photo(mut self, value: bool) -> Self { self.request_photo = Some(value); self From cc8df7a32ef966e7ee8722d76e20787e5056a4c1 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 20:11:32 +0530 Subject: [PATCH 10/46] Add `SharedUser` struct and add to `UsersShared` --- crates/teloxide-core/src/types.rs | 2 ++ .../src/types/keyboard_button_request_chat.rs | 2 +- crates/teloxide-core/src/types/shared_user.rs | 29 +++++++++++++++++++ .../teloxide-core/src/types/users_shared.rs | 4 +-- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 crates/teloxide-core/src/types/shared_user.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 2eb997e4..f8219d75 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -122,6 +122,7 @@ pub use reply_parameters::*; pub use request_id::*; pub use response_parameters::*; pub use sent_web_app_message::*; +pub use shared_user::*; pub use shipping_address::*; pub use shipping_option::*; pub use shipping_query::*; @@ -248,6 +249,7 @@ mod reply_parameters; mod request_id; mod response_parameters; mod sent_web_app_message; +mod shared_user; mod shipping_address; mod shipping_option; mod shipping_query; diff --git a/crates/teloxide-core/src/types/keyboard_button_request_chat.rs b/crates/teloxide-core/src/types/keyboard_button_request_chat.rs index 96a0512e..b1df9448 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_chat.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_chat.rs @@ -63,7 +63,7 @@ pub struct KeyboardButtonRequestChat { #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub request_username: bool, - /// Pass `true` to request the chat's photos. + /// Pass `true` to request the chat's photo. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub request_photo: bool, } diff --git a/crates/teloxide-core/src/types/shared_user.rs b/crates/teloxide-core/src/types/shared_user.rs new file mode 100644 index 00000000..ad4028bf --- /dev/null +++ b/crates/teloxide-core/src/types/shared_user.rs @@ -0,0 +1,29 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::{PhotoSize, UserId}; + +/// This object contains information about a user that was shared with the bot +/// using a [`KeyboardButtonRequestUsers`] button. +/// +/// [`KeyboardButtonRequestUsers`]: crate::types::KeyboardButtonRequestUsers +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +pub struct SharedUser { + /// Identifier of the shared user + pub user_id: UserId, + + /// First name of the user, if it was requested by the bot + #[serde(default)] + pub first_name: Option, + + /// Last name of the user, if it was requested by the bot + #[serde(default)] + pub last_name: Option, + + /// Username of the user, if it was requested by the bot + #[serde(default)] + pub username: Option, + + /// Available sizes of the chat photo, if it was requested + #[serde(default)] + pub photo: Option>, +} diff --git a/crates/teloxide-core/src/types/users_shared.rs b/crates/teloxide-core/src/types/users_shared.rs index d522fa54..c78c3625 100644 --- a/crates/teloxide-core/src/types/users_shared.rs +++ b/crates/teloxide-core/src/types/users_shared.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{RequestId, UserId}; +use crate::types::{RequestId, SharedUser}; /// This object contains information about the users whose identifiers were /// shared with the bot using a [KeyboardButtonRequestUsers] button. @@ -11,5 +11,5 @@ pub struct UsersShared { /// Identifier of the request pub request_id: RequestId, /// Identifiers of the shared users - pub user_ids: Vec, + pub users: Vec, } From d92ba9c12a27bc7f1f8b8f62a67fbcfafe4db455 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 20:16:59 +0530 Subject: [PATCH 11/46] Add `title`, `username` and `photo` to `ChatShared` --- crates/teloxide-core/src/types/chat_shared.rs | 17 +++++++++++++++-- crates/teloxide-core/src/types/message.rs | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/src/types/chat_shared.rs b/crates/teloxide-core/src/types/chat_shared.rs index f23c94bb..3eeace53 100644 --- a/crates/teloxide-core/src/types/chat_shared.rs +++ b/crates/teloxide-core/src/types/chat_shared.rs @@ -1,8 +1,8 @@ use serde::{Deserialize, Serialize}; -use crate::types::{ChatId, RequestId}; +use crate::types::{ChatId, PhotoSize, RequestId}; -/// Information about the chat whose identifier was shared with the bot using a +/// Information about a chat that was shared with the bot using a /// [`KeyboardButtonRequestChat`] button. /// /// [`KeyboardButtonRequestChat`]: crate::types::KeyboardButtonRequestChat @@ -10,6 +10,19 @@ use crate::types::{ChatId, RequestId}; pub struct ChatShared { /// Identifier of the request. pub request_id: RequestId, + /// Identifier of the shared chat. pub chat_id: ChatId, + + /// Title of the chat, if it was requested. + #[serde(default)] + pub title: Option, + + /// Username of the chat, if it was requested. + #[serde(default)] + pub username: Option, + + /// Available sizes of the chat photo, if it was requested. + #[serde(default)] + pub photo: Option>, } diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 17fbe150..7789142e 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1905,7 +1905,10 @@ mod tests { kind: MessageKind::ChatShared(MessageChatShared { chat_shared: ChatShared { request_id: RequestId(348349), - chat_id: ChatId(384939) + chat_id: ChatId(384939), + title: None, + username: None, + photo: None, } }), via_bot: None From 924affbdde55fb9a3396b9bf2482b06b70620037 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 20:43:10 +0530 Subject: [PATCH 12/46] Remove `flags` field from `StickerSet` struct --- crates/teloxide-core/src/types/sticker_set.rs | 67 +------------------ 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/crates/teloxide-core/src/types/sticker_set.rs b/crates/teloxide-core/src/types/sticker_set.rs index 12c92bb1..32b9f379 100644 --- a/crates/teloxide-core/src/types/sticker_set.rs +++ b/crates/teloxide-core/src/types/sticker_set.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use serde::{Deserialize, Serialize}; -use crate::types::{PhotoSize, Sticker, StickerFormat, StickerFormatFlags, StickerType}; +use crate::types::{PhotoSize, Sticker, StickerType}; /// This object represents a sticker set. /// @@ -20,11 +20,6 @@ pub struct StickerSet { #[serde(flatten)] pub kind: StickerType, - // FIXME: remove it in 7.2 https://core.telegram.org/bots/api#march-31-2024 - /// Sticker format flags shared by all stickers in this set. - #[serde(flatten)] - pub flags: StickerFormatFlags, - /// List of all set stickers. pub stickers: Vec, @@ -50,66 +45,6 @@ impl Deref for StickerSet { } } -impl StickerSet { - // FIXME: remove deprecation, when it will be a way to determine the format of - // the sticker set - /// Returns the format of the stickers in this set - /// - /// Note: this method currently is useless, so the format is always - /// StickerFormat::Static - #[must_use] - #[deprecated(note = "TBA7.2 brought the breaking change: flags 'is_video' and 'is_animated' \ - were removed, so currently there is no way to determine the format of \ - the sticker set in the currently supported version (TBA6.6)")] - pub fn format(&self) -> StickerFormat { - self.flags.format() - } - - /// Returns `true` is this is a "normal" raster sticker. - /// - /// Alias to [`self.format().is_static()`]. - /// - /// [`self.format().is_static()`]: StickerFormat::is_static - #[must_use] - #[deprecated(note = "TBA7.2 brought the breaking change: flags 'is_video' and 'is_animated' \ - were removed, so currently there is no way to determine the format of \ - the sticker set in the currently supported version (TBA6.6)")] - pub fn is_static(&self) -> bool { - #[allow(deprecated)] - self.format().is_static() - } - - /// Returns `true` is this is an [animated] sticker. - /// - /// Alias to [`self.format().is_animated()`]. - /// - /// [`self.format().is_animated()`]: StickerFormat::is_animated - /// [animated]: https://telegram.org/blog/animated-stickers - #[must_use] - #[deprecated(note = "TBA7.2 brought the breaking change: flags 'is_video' and 'is_animated' \ - were removed, so currently there is no way to determine the format of \ - the sticker set in the currently supported version (TBA6.6)")] - pub fn is_animated(&self) -> bool { - #[allow(deprecated)] - self.format().is_animated() - } - - /// Returns `true` is this is a [video] sticker. - /// - /// Alias to [`self.format().is_video()`]. - /// - /// [`self.format().is_video()`]: StickerFormat::is_video - /// [video]: https://telegram.org/blog/video-stickers-better-reactions - #[must_use] - #[deprecated(note = "TBA7.2 brought the breaking change: flags 'is_video' and 'is_animated' \ - were removed, so currently there is no way to determine the format of \ - the sticker set in the currently supported version (TBA6.6)")] - pub fn is_video(&self) -> bool { - #[allow(deprecated)] - self.format().is_video() - } -} - #[cfg(test)] mod tests { use crate::types::StickerSet; From 590d46477f9c434446d1f75b3b18847121729e79 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 20:50:47 +0530 Subject: [PATCH 13/46] Add `format` field to `InputSticker` struct --- crates/teloxide-core/src/serde_multipart/mod.rs | 3 ++- crates/teloxide-core/src/types/input_sticker.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/teloxide-core/src/serde_multipart/mod.rs b/crates/teloxide-core/src/serde_multipart/mod.rs index a83af2b3..d48380e8 100644 --- a/crates/teloxide-core/src/serde_multipart/mod.rs +++ b/crates/teloxide-core/src/serde_multipart/mod.rs @@ -90,7 +90,7 @@ mod tests { types::{ ChatId, InputFile, InputMedia, InputMediaAnimation, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo, InputSticker, MessageEntity, - MessageEntityKind, ParseMode, UserId, + MessageEntityKind, ParseMode, StickerFormat, UserId, }, }; @@ -157,6 +157,7 @@ mod tests { emoji_list: vec!["βœˆοΈβš™οΈ".to_owned()], keywords: vec![], mask_position: None, + format: StickerFormat::Static, }, )) .unwrap() diff --git a/crates/teloxide-core/src/types/input_sticker.rs b/crates/teloxide-core/src/types/input_sticker.rs index 18fffe7d..fa2677f8 100644 --- a/crates/teloxide-core/src/types/input_sticker.rs +++ b/crates/teloxide-core/src/types/input_sticker.rs @@ -2,6 +2,8 @@ use serde::Serialize; use crate::types::{InputFile, MaskPosition}; +use super::StickerFormat; + /// This object describes a sticker to be added to a sticker set. #[serde_with::skip_serializing_none] #[derive(Clone, Debug, Serialize)] @@ -16,6 +18,10 @@ pub struct InputSticker { /// More information on Sending Files pub sticker: InputFile, + /// Format of the added sticker, must be one of "static" for a .WEBP or .PNG + /// image, "animated" for a .TGS animation, "video" for a WEBM video + pub format: StickerFormat, + /// List of 1-20 emoji associated with the sticker pub emoji_list: Vec, From 2655607320c65db248cd0469a7510d20c29ef633 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 20:55:08 +0530 Subject: [PATCH 14/46] Remove `sticker_format` parameter from `CreateNewStickerSet` --- crates/teloxide-core/schema.ron | 5 ----- crates/teloxide-core/src/bot/api.rs | 5 ++--- crates/teloxide-core/src/local_macros.rs | 4 ++-- crates/teloxide-core/src/payloads/create_new_sticker_set.rs | 4 +--- crates/teloxide-core/src/requests/requester.rs | 1 - 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 446c1d11..8f0e0996 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -3783,11 +3783,6 @@ Schema( ty: ArrayOf(RawTy("InputSticker")), descr: Doc(md: "A JSON-serialized list of 1-50 initial stickers to be added to the sticker set") ), - Param( - name: "sticker_format", - ty: RawTy("StickerFormat"), - descr: Doc(md: "Format of the sticker, must be one of β€œstatic”, β€œanimated”, β€œvideo”") - ), Param( name: "sticker_type", ty: Option(RawTy("StickerType")), diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index a1c1bbf9..26ce46f0 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -6,7 +6,7 @@ use crate::{ requests::{JsonRequest, MultipartRequest}, types::{ BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, MessageId, Recipient, StickerFormat, ThreadId, UserId, + InputSticker, LabeledPrice, MessageId, Recipient, ThreadId, UserId, }, Bot, }; @@ -1189,7 +1189,6 @@ impl Requester for Bot { name: N, title: T, stickers: S, - sticker_format: StickerFormat, ) -> Self::CreateNewStickerSet where N: Into, @@ -1198,7 +1197,7 @@ impl Requester for Bot { { Self::CreateNewStickerSet::new( self.clone(), - payloads::CreateNewStickerSet::new(user_id, name, title, stickers, sticker_format), + payloads::CreateNewStickerSet::new(user_id, name, title, stickers), ) } diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 7bc088cc..e8f4e794 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -1308,11 +1308,11 @@ macro_rules! requester_forward { (@method create_new_sticker_set $body:ident $ty:ident) => { type CreateNewStickerSet = $ty![CreateNewStickerSet]; - fn create_new_sticker_set(&self, user_id: UserId, name: N, title: T, stickers: S, sticker_format: StickerFormat) -> Self::CreateNewStickerSet where N: Into, + fn create_new_sticker_set(&self, user_id: UserId, name: N, title: T, stickers: S) -> Self::CreateNewStickerSet where N: Into, T: Into, S: IntoIterator { let this = self; - $body!(create_new_sticker_set this (user_id: UserId, name: N, title: T, stickers: S, sticker_format: StickerFormat)) + $body!(create_new_sticker_set this (user_id: UserId, name: N, title: T, stickers: S)) } }; (@method add_sticker_to_set $body:ident $ty:ident) => { diff --git a/crates/teloxide-core/src/payloads/create_new_sticker_set.rs b/crates/teloxide-core/src/payloads/create_new_sticker_set.rs index 9ca7be3d..d3a41491 100644 --- a/crates/teloxide-core/src/payloads/create_new_sticker_set.rs +++ b/crates/teloxide-core/src/payloads/create_new_sticker_set.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{InputSticker, StickerFormat, StickerType, True, UserId}; +use crate::types::{InputSticker, StickerType, True, UserId}; impl_payload! { /// Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. Returns True on success. @@ -17,8 +17,6 @@ impl_payload! { pub title: String [into], /// A JSON-serialized list of 1-50 initial stickers to be added to the sticker set pub stickers: Vec [collect], - /// Format of the sticker, must be one of β€œstatic”, β€œanimated”, β€œvideo” - pub sticker_format: StickerFormat, } optional { /// Type of stickers in the set, pass β€œregular”, β€œmask”, or β€œcustom_emoji”. By default, a regular sticker set is created. diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 731e370f..204d6d9c 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -1071,7 +1071,6 @@ pub trait Requester { name: N, title: T, stickers: S, - sticker_format: StickerFormat, ) -> Self::CreateNewStickerSet where N: Into, From cf1b73b8b21149da382600230aa68fceac881d2a Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 20 Aug 2024 20:58:32 +0530 Subject: [PATCH 15/46] Add `format` parameter to `SetStickerSetThumbnail` --- crates/teloxide-core/schema.ron | 5 +++++ crates/teloxide-core/src/bot/api.rs | 13 +++++++++---- crates/teloxide-core/src/local_macros.rs | 4 ++-- .../src/payloads/set_sticker_set_thumbnail.rs | 4 +++- crates/teloxide-core/src/requests/requester.rs | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 8f0e0996..91837a2e 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -3915,6 +3915,11 @@ Schema( md_links: {"More info on Sending Files Β»": "https://core.telegram.org/bots/api#sending-files"}, ), ), + Param( + name: "format", + ty: RawTy("StickerFormat"), + descr: Doc(md: "Format of the thumbnail, must be one of \"static\" for a .WEBP or .PNG image, \"animated\" for a .TGS animation, or \"video\" for a WEBM video") + ) ], ), Method( diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 26ce46f0..0b57b14b 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -6,7 +6,7 @@ use crate::{ requests::{JsonRequest, MultipartRequest}, types::{ BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, MessageId, Recipient, ThreadId, UserId, + InputSticker, LabeledPrice, MessageId, Recipient, StickerFormat, ThreadId, UserId, }, Bot, }; @@ -1173,7 +1173,7 @@ impl Requester for Bot { &self, user_id: UserId, sticker: InputFile, - sticker_format: crate::types::StickerFormat, + sticker_format: StickerFormat, ) -> Self::UploadStickerFile { Self::UploadStickerFile::new( self.clone(), @@ -1269,13 +1269,18 @@ impl Requester for Bot { type SetStickerSetThumbnail = MultipartRequest; - fn set_sticker_set_thumbnail(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumbnail + fn set_sticker_set_thumbnail( + &self, + name: N, + user_id: UserId, + format: StickerFormat, + ) -> Self::SetStickerSetThumbnail where N: Into, { Self::SetStickerSetThumbnail::new( self.clone(), - payloads::SetStickerSetThumbnail::new(name, user_id), + payloads::SetStickerSetThumbnail::new(name, user_id, format), ) } diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index e8f4e794..10d158d3 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -1351,9 +1351,9 @@ macro_rules! requester_forward { (@method set_sticker_set_thumbnail $body:ident $ty:ident) => { type SetStickerSetThumbnail = $ty![SetStickerSetThumbnail]; - fn set_sticker_set_thumbnail(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumbnail where N: Into { + fn set_sticker_set_thumbnail(&self, name: N, user_id: UserId, format: StickerFormat) -> Self::SetStickerSetThumbnail where N: Into { let this = self; - $body!(set_sticker_set_thumbnail this (name: N, user_id: UserId)) + $body!(set_sticker_set_thumbnail this (name: N, user_id: UserId, format: StickerFormat)) } }; (@method set_custom_emoji_sticker_set_thumbnail $body:ident $ty:ident) => { diff --git a/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs b/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs index 4c0d6835..0c1d0690 100644 --- a/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs +++ b/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{InputFile, True, UserId}; +use crate::types::{InputFile, StickerFormat, True, UserId}; impl_payload! { @[multipart = thumbnail] @@ -14,6 +14,8 @@ impl_payload! { pub name: String [into], /// User identifier of sticker file owner pub user_id: UserId, + /// Format of the thumbnail, must be one of "static" for a .WEBP or .PNG image, "animated" for a .TGS animation, or "video" for a WEBM video + pub format: StickerFormat, } optional { /// A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 204d6d9c..6246f50b 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -1128,6 +1128,7 @@ pub trait Requester { &self, name: N, user_id: UserId, + format: StickerFormat, ) -> Self::SetStickerSetThumbnail where N: Into; From 78f909e621bbae5782b42e7732d1b38b786b788d Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 00:15:43 +0530 Subject: [PATCH 16/46] Update documentation of `sendSticker` method --- crates/teloxide-core/schema.ron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 91837a2e..34f41d41 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -3631,7 +3631,7 @@ Schema( names: ("sendSticker", "SendSticker", "send_sticker"), return_ty: RawTy("Message"), doc: Doc( - md: "Use this method to send static .WEBP or [animated] .TGS stickers. On success, the sent Message is returned.", + md: "Use this method to send static .WEBP, .TGS or .WEBM stickers. On success, the sent Message is returned.", md_links: {"animated": "https://telegram.org/blog/animated-stickers"} ), tg_doc: "https://core.telegram.org/bots/api#sendsticker", From 941d1eb82a1b5c9d27f0f8b1b83cd280bfe329eb Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 00:29:11 +0530 Subject: [PATCH 17/46] Add `business_connection_id` to add `Send*` methods except `SendInvoice` --- crates/teloxide-core/schema.ron | 85 +++++++++++++++++++ .../src/payloads/send_animation.rs | 2 + .../teloxide-core/src/payloads/send_audio.rs | 2 + .../src/payloads/send_chat_action.rs | 2 + .../src/payloads/send_contact.rs | 2 + .../teloxide-core/src/payloads/send_dice.rs | 2 + .../src/payloads/send_document.rs | 2 + .../teloxide-core/src/payloads/send_game.rs | 2 + .../src/payloads/send_location.rs | 2 + .../src/payloads/send_media_group.rs | 2 + .../src/payloads/send_message.rs | 2 + .../teloxide-core/src/payloads/send_photo.rs | 2 + .../teloxide-core/src/payloads/send_poll.rs | 2 + .../src/payloads/send_sticker.rs | 4 +- .../teloxide-core/src/payloads/send_venue.rs | 2 + .../teloxide-core/src/payloads/send_video.rs | 2 + .../src/payloads/send_video_note.rs | 2 + .../teloxide-core/src/payloads/send_voice.rs | 2 + 18 files changed, 120 insertions(+), 1 deletion(-) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 34f41d41..56ed24ea 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -224,6 +224,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendmessage", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -520,6 +525,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendphoto", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -605,6 +615,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendaudio", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -705,6 +720,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#senddocument", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -798,6 +818,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendvideo", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -909,6 +934,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendanimation", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1018,6 +1048,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendvoice", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1098,6 +1133,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendvideonote", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1176,6 +1216,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendmediagroup", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1221,6 +1266,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendlocation", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1484,6 +1534,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendvenue", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1578,6 +1633,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendcontact", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1652,6 +1712,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendpoll", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1766,6 +1831,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#senddice", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -1822,6 +1892,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendchataction", tg_category: "Available methods", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the action will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -3637,6 +3712,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendsticker", tg_category: "Stickers", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("Recipient"), @@ -4393,6 +4473,11 @@ Schema( tg_doc: "https://core.telegram.org/bots/api#sendgame", tg_category: "Games", params: [ + Param( + name: "business_connection_id", + ty: Option(String), + descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), + ), Param( name: "chat_id", ty: RawTy("ChatId"), diff --git a/crates/teloxide-core/src/payloads/send_animation.rs b/crates/teloxide-core/src/payloads/send_animation.rs index ba2348ee..9670d5f0 100644 --- a/crates/teloxide-core/src/payloads/send_animation.rs +++ b/crates/teloxide-core/src/payloads/send_animation.rs @@ -22,6 +22,8 @@ impl_payload! { pub animation: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Duration of the animation in seconds diff --git a/crates/teloxide-core/src/payloads/send_audio.rs b/crates/teloxide-core/src/payloads/send_audio.rs index 2c579ec8..e87ae0db 100644 --- a/crates/teloxide-core/src/payloads/send_audio.rs +++ b/crates/teloxide-core/src/payloads/send_audio.rs @@ -25,6 +25,8 @@ impl_payload! { pub audio: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Audio caption, 0-1024 characters after entities parsing diff --git a/crates/teloxide-core/src/payloads/send_chat_action.rs b/crates/teloxide-core/src/payloads/send_chat_action.rs index 46726fba..e5f39806 100644 --- a/crates/teloxide-core/src/payloads/send_chat_action.rs +++ b/crates/teloxide-core/src/payloads/send_chat_action.rs @@ -30,6 +30,8 @@ impl_payload! { pub action: ChatAction, } optional { + /// Unique identifier of the business connection on behalf of which the action will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread; supergroups only pub message_thread_id: ThreadId, } diff --git a/crates/teloxide-core/src/payloads/send_contact.rs b/crates/teloxide-core/src/payloads/send_contact.rs index b350b1b5..96c1ef2a 100644 --- a/crates/teloxide-core/src/payloads/send_contact.rs +++ b/crates/teloxide-core/src/payloads/send_contact.rs @@ -19,6 +19,8 @@ impl_payload! { pub first_name: String [into], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Contact's last name diff --git a/crates/teloxide-core/src/payloads/send_dice.rs b/crates/teloxide-core/src/payloads/send_dice.rs index 2444c39b..ccb08e26 100644 --- a/crates/teloxide-core/src/payloads/send_dice.rs +++ b/crates/teloxide-core/src/payloads/send_dice.rs @@ -15,6 +15,8 @@ impl_payload! { pub chat_id: Recipient [into], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Emoji on which the dice throw animation is based. Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, β€œπŸŽ³β€, or β€œπŸŽ°β€. Dice can have values 1-6 for β€œπŸŽ²β€, β€œπŸŽ―β€ and β€œπŸŽ³β€, values 1-5 for β€œπŸ€β€ and β€œβš½β€, and values 1-64 for β€œπŸŽ°β€. Defaults to β€œπŸŽ²β€ diff --git a/crates/teloxide-core/src/payloads/send_document.rs b/crates/teloxide-core/src/payloads/send_document.rs index 7f570058..b0925663 100644 --- a/crates/teloxide-core/src/payloads/send_document.rs +++ b/crates/teloxide-core/src/payloads/send_document.rs @@ -22,6 +22,8 @@ impl_payload! { pub document: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass β€œattach://” if the thumbnail was uploaded using multipart/form-data under . [More info on Sending Files Β»] diff --git a/crates/teloxide-core/src/payloads/send_game.rs b/crates/teloxide-core/src/payloads/send_game.rs index 0b355e1f..46888759 100644 --- a/crates/teloxide-core/src/payloads/send_game.rs +++ b/crates/teloxide-core/src/payloads/send_game.rs @@ -17,6 +17,8 @@ impl_payload! { pub game_short_name: String [into], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. diff --git a/crates/teloxide-core/src/payloads/send_location.rs b/crates/teloxide-core/src/payloads/send_location.rs index f1e0f736..e0b38b51 100644 --- a/crates/teloxide-core/src/payloads/send_location.rs +++ b/crates/teloxide-core/src/payloads/send_location.rs @@ -19,6 +19,8 @@ impl_payload! { pub longitude: f64, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// The radius of uncertainty for the location, measured in meters; 0-1500 diff --git a/crates/teloxide-core/src/payloads/send_media_group.rs b/crates/teloxide-core/src/payloads/send_media_group.rs index 0098ead4..428a4951 100644 --- a/crates/teloxide-core/src/payloads/send_media_group.rs +++ b/crates/teloxide-core/src/payloads/send_media_group.rs @@ -26,6 +26,8 @@ impl_payload! { pub media: Vec [collect], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. diff --git a/crates/teloxide-core/src/payloads/send_message.rs b/crates/teloxide-core/src/payloads/send_message.rs index d7006c4f..dbdc07cb 100644 --- a/crates/teloxide-core/src/payloads/send_message.rs +++ b/crates/teloxide-core/src/payloads/send_message.rs @@ -20,6 +20,8 @@ impl_payload! { pub text: String [into], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Mode for parsing entities in the message text. See [formatting options] for more details. diff --git a/crates/teloxide-core/src/payloads/send_photo.rs b/crates/teloxide-core/src/payloads/send_photo.rs index 452b16e7..2091761e 100644 --- a/crates/teloxide-core/src/payloads/send_photo.rs +++ b/crates/teloxide-core/src/payloads/send_photo.rs @@ -22,6 +22,8 @@ impl_payload! { pub photo: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Photo caption (may also be used when resending photos by _file\_id_), 0-1024 characters after entities parsing diff --git a/crates/teloxide-core/src/payloads/send_poll.rs b/crates/teloxide-core/src/payloads/send_poll.rs index aaa69580..642a1755 100644 --- a/crates/teloxide-core/src/payloads/send_poll.rs +++ b/crates/teloxide-core/src/payloads/send_poll.rs @@ -22,6 +22,8 @@ impl_payload! { pub options: Vec [collect], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// True, if the poll needs to be anonymous, defaults to True diff --git a/crates/teloxide-core/src/payloads/send_sticker.rs b/crates/teloxide-core/src/payloads/send_sticker.rs index 13678400..10492701 100644 --- a/crates/teloxide-core/src/payloads/send_sticker.rs +++ b/crates/teloxide-core/src/payloads/send_sticker.rs @@ -6,7 +6,7 @@ use crate::types::{InputFile, Message, Recipient, ReplyMarkup, ReplyParameters, impl_payload! { @[multipart = sticker] - /// Use this method to send static .WEBP or [animated] .TGS stickers. On success, the sent Message is returned. + /// Use this method to send static .WEBP, .TGS or .WEBM stickers. On success, the sent Message is returned. /// /// [animated]: https://telegram.org/blog/animated-stickers #[derive(Debug, Clone, Serialize)] @@ -20,6 +20,8 @@ impl_payload! { pub sticker: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Emoji associated with the sticker; only for just uploaded stickers diff --git a/crates/teloxide-core/src/payloads/send_venue.rs b/crates/teloxide-core/src/payloads/send_venue.rs index 3ccca409..994d1eb3 100644 --- a/crates/teloxide-core/src/payloads/send_venue.rs +++ b/crates/teloxide-core/src/payloads/send_venue.rs @@ -23,6 +23,8 @@ impl_payload! { pub address: String [into], } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Foursquare identifier of the venue diff --git a/crates/teloxide-core/src/payloads/send_video.rs b/crates/teloxide-core/src/payloads/send_video.rs index be52eb1a..a3edd504 100644 --- a/crates/teloxide-core/src/payloads/send_video.rs +++ b/crates/teloxide-core/src/payloads/send_video.rs @@ -23,6 +23,8 @@ impl_payload! { pub video: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Duration of the video in seconds diff --git a/crates/teloxide-core/src/payloads/send_video_note.rs b/crates/teloxide-core/src/payloads/send_video_note.rs index f4387c94..a038b0ff 100644 --- a/crates/teloxide-core/src/payloads/send_video_note.rs +++ b/crates/teloxide-core/src/payloads/send_video_note.rs @@ -21,6 +21,8 @@ impl_payload! { pub video_note: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Duration of the video in seconds diff --git a/crates/teloxide-core/src/payloads/send_voice.rs b/crates/teloxide-core/src/payloads/send_voice.rs index a7d3b139..76382829 100644 --- a/crates/teloxide-core/src/payloads/send_voice.rs +++ b/crates/teloxide-core/src/payloads/send_voice.rs @@ -24,6 +24,8 @@ impl_payload! { pub voice: InputFile, } optional { + /// Unique identifier of the business connection on behalf of which the message will be sent + pub business_connection_id: String [into], /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Voice message caption, 0-1024 characters after entities parsing From 1a5eca0a7560ec4fbe7a3b361e85775d25367d83 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 00:35:20 +0530 Subject: [PATCH 18/46] Add business conn. related fields to `Message` Added `sender_business_bot` and `business_connection_id` fields --- crates/teloxide-core/src/types/message.rs | 15 +++++++++++++++ crates/teloxide-core/src/types/update.rs | 2 ++ 2 files changed, 17 insertions(+) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 7789142e..71b6cd9e 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -54,6 +54,17 @@ pub struct Message { /// Bot through which the message was sent. pub via_bot: Option, + /// The bot that actually sent the message on behalf of the business + /// account. Available only for outgoing messages sent on behalf of the + /// connected business account. + pub sender_business_bot: Option, + + /// Unique identifier of the business connection from which the message was + /// received. If non-empty, the message belongs to a chat of the + /// corresponding business account that is independent from any potential + /// bot chat which might share the same identifier. + pub business_connection_id: Option, + #[serde(flatten)] pub kind: MessageKind, } @@ -1902,6 +1913,8 @@ mod tests { has_hidden_members: false, chat_full_info: ChatFullInfo::default() }, + sender_business_bot: None, + business_connection_id: None, kind: MessageKind::ChatShared(MessageChatShared { chat_shared: ChatShared { request_id: RequestId(348349), @@ -2573,6 +2586,8 @@ mod tests { chat_full_info: ChatFullInfo::default() }, via_bot: None, + sender_business_bot: None, + business_connection_id: None, kind: MessageKind::Giveaway(MessageGiveaway { giveaway: Giveaway { chats: vec![Chat { diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 1c792bfc..ca33cc8c 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -546,6 +546,8 @@ mod test { has_aggressive_anti_spam_enabled: false, chat_full_info: ChatFullInfo::default(), }, + sender_business_bot: None, + business_connection_id: None, kind: MessageKind::Common(MessageCommon { reply_to_message: None, forward_origin: None, From fa17b48793a6b549ea4c6d8bb9a9e62fba7eeb6e Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:02:32 +0530 Subject: [PATCH 19/46] Add `BusinessIntro` class and corres. field to `ChatPrivate` --- crates/teloxide-core/src/types.rs | 2 ++ .../teloxide-core/src/types/business_intro.rs | 15 ++++++++++++++ crates/teloxide-core/src/types/chat.rs | 20 +++++++++++++++---- crates/teloxide-core/src/types/message.rs | 1 + crates/teloxide-core/src/types/update.rs | 1 + 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 crates/teloxide-core/src/types/business_intro.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index f8219d75..0f8a6315 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -9,6 +9,7 @@ pub use bot_command_scope::*; pub use bot_description::*; pub use bot_name::*; pub use bot_short_description::*; +pub use business_intro::*; pub use callback_game::*; pub use callback_query::*; pub use chat::*; @@ -164,6 +165,7 @@ mod bot_command_scope; mod bot_description; mod bot_name; mod bot_short_description; +mod business_intro; mod callback_game; mod callback_query; mod chat; diff --git a/crates/teloxide-core/src/types/business_intro.rs b/crates/teloxide-core/src/types/business_intro.rs new file mode 100644 index 00000000..fbfd4b66 --- /dev/null +++ b/crates/teloxide-core/src/types/business_intro.rs @@ -0,0 +1,15 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::Sticker; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessIntro { + /// Title text of the business intro + pub title: Option, + + /// Message text of the business intro + pub message: Option, + + /// Sticker of the business intro + pub sticker: Option, +} diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index 41fae489..fed38b57 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -1,8 +1,8 @@ use serde::{Deserialize, Serialize}; use crate::types::{ - ChatFullInfo, ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, ReactionType, Seconds, - True, User, + BusinessIntro, ChatFullInfo, ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, + ReactionType, Seconds, True, User, }; use super::Birthdate; @@ -147,6 +147,12 @@ pub struct ChatPrivate { /// /// [`GetChat`]: crate::payloads::GetChat pub birthdate: Option, + + /// For private chats with business accounts, the intro of the business. + /// Returned only in [`GetChat`]. + /// + /// [`GetChat`]: crate::payloads::GetChat + pub business_intro: Option, } #[serde_with::skip_serializing_none] @@ -577,8 +583,7 @@ impl Chat { } mod serde_helper { - use super::Birthdate; - use crate::types::True; + use crate::types::{Birthdate, BusinessIntro, True}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] @@ -601,6 +606,7 @@ mod serde_helper { has_restricted_voice_and_video_messages: Option, personal_chat: Option>, birthdate: Option, + business_intro: Option, } impl From for super::ChatPrivate { @@ -615,6 +621,7 @@ mod serde_helper { has_restricted_voice_and_video_messages, personal_chat, birthdate, + business_intro, }: ChatPrivate, ) -> Self { Self { @@ -626,6 +633,7 @@ mod serde_helper { has_restricted_voice_and_video_messages, personal_chat, birthdate, + business_intro, } } } @@ -641,6 +649,7 @@ mod serde_helper { has_restricted_voice_and_video_messages, personal_chat, birthdate, + business_intro, }: super::ChatPrivate, ) -> Self { Self { @@ -653,6 +662,7 @@ mod serde_helper { has_restricted_voice_and_video_messages, personal_chat, birthdate, + business_intro, } } } @@ -717,6 +727,7 @@ mod tests { has_restricted_voice_and_video_messages: None, personal_chat: None, birthdate: None, + business_intro: None, }), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), @@ -757,6 +768,7 @@ mod tests { has_restricted_voice_and_video_messages: None, personal_chat: None, birthdate: None, + business_intro: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 71b6cd9e..ba5186ad 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1904,6 +1904,7 @@ mod tests { has_restricted_voice_and_video_messages: None, personal_chat: None, birthdate: None, + business_intro: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index ca33cc8c..3f9251fe 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -537,6 +537,7 @@ mod test { has_restricted_voice_and_video_messages: None, personal_chat: None, birthdate: None, + business_intro: None, }), photo: None, available_reactions: None, From f84e15a0a6d74ae2a428fde1822ec9c5af0651f3 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:07:58 +0530 Subject: [PATCH 20/46] Add `BusinessLocation` class and corresp. field to `ChatPrivate` --- crates/teloxide-core/src/types.rs | 2 ++ .../src/types/business_location.rs | 12 ++++++++++++ crates/teloxide-core/src/types/chat.rs | 19 ++++++++++++++++--- crates/teloxide-core/src/types/message.rs | 1 + crates/teloxide-core/src/types/update.rs | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 crates/teloxide-core/src/types/business_location.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 0f8a6315..c95847d3 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -10,6 +10,7 @@ pub use bot_description::*; pub use bot_name::*; pub use bot_short_description::*; pub use business_intro::*; +pub use business_location::*; pub use callback_game::*; pub use callback_query::*; pub use chat::*; @@ -166,6 +167,7 @@ mod bot_description; mod bot_name; mod bot_short_description; mod business_intro; +mod business_location; mod callback_game; mod callback_query; mod chat; diff --git a/crates/teloxide-core/src/types/business_location.rs b/crates/teloxide-core/src/types/business_location.rs new file mode 100644 index 00000000..7eaee63d --- /dev/null +++ b/crates/teloxide-core/src/types/business_location.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::Location; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessLocation { + /// Address of the business. + pub address: String, + + /// Location of the business. + pub location: Option, +} diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index fed38b57..7a1b0a83 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -1,8 +1,8 @@ use serde::{Deserialize, Serialize}; use crate::types::{ - BusinessIntro, ChatFullInfo, ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, - ReactionType, Seconds, True, User, + BusinessIntro, BusinessLocation, ChatFullInfo, ChatId, ChatLocation, ChatPermissions, + ChatPhoto, Message, ReactionType, Seconds, True, User, }; use super::Birthdate; @@ -153,6 +153,12 @@ pub struct ChatPrivate { /// /// [`GetChat`]: crate::payloads::GetChat pub business_intro: Option, + + /// For private chats with business accounts, the location of the business. + /// Returned only in [`GetChat`]. + /// + /// [`GetChat`]: crate::payloads::GetChat + pub business_location: Option, } #[serde_with::skip_serializing_none] @@ -583,7 +589,7 @@ impl Chat { } mod serde_helper { - use crate::types::{Birthdate, BusinessIntro, True}; + use crate::types::{Birthdate, BusinessIntro, BusinessLocation, True}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] @@ -607,6 +613,7 @@ mod serde_helper { personal_chat: Option>, birthdate: Option, business_intro: Option, + business_location: Option, } impl From for super::ChatPrivate { @@ -622,6 +629,7 @@ mod serde_helper { personal_chat, birthdate, business_intro, + business_location, }: ChatPrivate, ) -> Self { Self { @@ -634,6 +642,7 @@ mod serde_helper { personal_chat, birthdate, business_intro, + business_location, } } } @@ -650,6 +659,7 @@ mod serde_helper { personal_chat, birthdate, business_intro, + business_location, }: super::ChatPrivate, ) -> Self { Self { @@ -663,6 +673,7 @@ mod serde_helper { personal_chat, birthdate, business_intro, + business_location, } } } @@ -728,6 +739,7 @@ mod tests { personal_chat: None, birthdate: None, business_intro: None, + business_location: None, }), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), @@ -769,6 +781,7 @@ mod tests { personal_chat: None, birthdate: None, business_intro: None, + business_location: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index ba5186ad..7a6e14de 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1905,6 +1905,7 @@ mod tests { personal_chat: None, birthdate: None, business_intro: None, + business_location: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 3f9251fe..a8c8ed2b 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -538,6 +538,7 @@ mod test { personal_chat: None, birthdate: None, business_intro: None, + business_location: None, }), photo: None, available_reactions: None, From 47fd589ea249c247cf7f4ddbd5d5f65a1aa77aa5 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:18:18 +0530 Subject: [PATCH 21/46] Add `BusinessOpeningHoursInterval` and `BusinessOpeningHours` structs --- crates/teloxide-core/src/types.rs | 2 ++ .../src/types/business_opening_hours.rs | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 crates/teloxide-core/src/types/business_opening_hours.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index c95847d3..2ad352a8 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -11,6 +11,7 @@ pub use bot_name::*; pub use bot_short_description::*; pub use business_intro::*; pub use business_location::*; +pub use business_opening_hours::*; pub use callback_game::*; pub use callback_query::*; pub use chat::*; @@ -168,6 +169,7 @@ mod bot_name; mod bot_short_description; mod business_intro; mod business_location; +mod business_opening_hours; mod callback_game; mod callback_query; mod chat; diff --git a/crates/teloxide-core/src/types/business_opening_hours.rs b/crates/teloxide-core/src/types/business_opening_hours.rs new file mode 100644 index 00000000..54e1a1e2 --- /dev/null +++ b/crates/teloxide-core/src/types/business_opening_hours.rs @@ -0,0 +1,23 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessOpeningHoursInterval { + /// The minute's sequence number in a week, starting on Monday, marking the + /// start of the time interval during which the business is open; + /// 0 - 7 * 24* 60 + pub opening_minute: u16, + + /// The minute's sequence number in a week, starting on Monday, marking the + /// end of the time interval during which the business is open; + /// 0 - 8 * 24* 60 + pub closing_minute: u16, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessOpeningHours { + /// Unique name of the time zone for which the opening hours are defined. + pub time_zone_name: String, + + /// List of time intervals describing business opening hours. + pub opening_hours: Vec, +} From 6bec7a84ff9ee2d53bb8d14fc867f9e79576c442 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:18:36 +0530 Subject: [PATCH 22/46] Add `business_opening_hours` field to `ChatPrivate` --- crates/teloxide-core/src/types/chat.rs | 21 ++++++++++++++++----- crates/teloxide-core/src/types/message.rs | 1 + crates/teloxide-core/src/types/update.rs | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index 7a1b0a83..1ae99527 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -1,12 +1,10 @@ use serde::{Deserialize, Serialize}; use crate::types::{ - BusinessIntro, BusinessLocation, ChatFullInfo, ChatId, ChatLocation, ChatPermissions, - ChatPhoto, Message, ReactionType, Seconds, True, User, + Birthdate, BusinessIntro, BusinessLocation, BusinessOpeningHours, ChatFullInfo, ChatId, + ChatLocation, ChatPermissions, ChatPhoto, Message, ReactionType, Seconds, True, User, }; -use super::Birthdate; - /// This object represents a chat. /// /// [The official docs](https://core.telegram.org/bots/api#chat). @@ -159,6 +157,12 @@ pub struct ChatPrivate { /// /// [`GetChat`]: crate::payloads::GetChat pub business_location: Option, + + /// For private chats with business accounts, the opening hours of the + /// business. Returned only in [`GetChat`]. + /// + /// [`GetChat`]: crate::payloads::GetChat + pub business_opening_hours: Option, } #[serde_with::skip_serializing_none] @@ -589,7 +593,7 @@ impl Chat { } mod serde_helper { - use crate::types::{Birthdate, BusinessIntro, BusinessLocation, True}; + use crate::types::{Birthdate, BusinessIntro, BusinessLocation, BusinessOpeningHours, True}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] @@ -614,6 +618,7 @@ mod serde_helper { birthdate: Option, business_intro: Option, business_location: Option, + business_opening_hours: Option, } impl From for super::ChatPrivate { @@ -630,6 +635,7 @@ mod serde_helper { birthdate, business_intro, business_location, + business_opening_hours, }: ChatPrivate, ) -> Self { Self { @@ -643,6 +649,7 @@ mod serde_helper { birthdate, business_intro, business_location, + business_opening_hours, } } } @@ -660,6 +667,7 @@ mod serde_helper { birthdate, business_intro, business_location, + business_opening_hours, }: super::ChatPrivate, ) -> Self { Self { @@ -674,6 +682,7 @@ mod serde_helper { birthdate, business_intro, business_location, + business_opening_hours, } } } @@ -740,6 +749,7 @@ mod tests { birthdate: None, business_intro: None, business_location: None, + business_opening_hours: None, }), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), @@ -782,6 +792,7 @@ mod tests { birthdate: None, business_intro: None, business_location: None, + business_opening_hours: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 7a6e14de..3c28604b 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1906,6 +1906,7 @@ mod tests { birthdate: None, business_intro: None, business_location: None, + business_opening_hours: None, }), photo: None, available_reactions: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index a8c8ed2b..7b00a20e 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -539,6 +539,7 @@ mod test { birthdate: None, business_intro: None, business_location: None, + business_opening_hours: None, }), photo: None, available_reactions: None, From e8afdc58fc0226c22be1a692ec4dd6634c514916 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:28:31 +0530 Subject: [PATCH 23/46] Add `BusinessConnection` struct --- crates/teloxide-core/src/types.rs | 2 ++ .../src/types/business_connection.rs | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 crates/teloxide-core/src/types/business_connection.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 2ad352a8..54a24e76 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -9,6 +9,7 @@ pub use bot_command_scope::*; pub use bot_description::*; pub use bot_name::*; pub use bot_short_description::*; +pub use business_connection::*; pub use business_intro::*; pub use business_location::*; pub use business_opening_hours::*; @@ -167,6 +168,7 @@ mod bot_command_scope; mod bot_description; mod bot_name; mod bot_short_description; +mod business_connection; mod business_intro; mod business_location; mod business_opening_hours; diff --git a/crates/teloxide-core/src/types/business_connection.rs b/crates/teloxide-core/src/types/business_connection.rs new file mode 100644 index 00000000..466e3c3c --- /dev/null +++ b/crates/teloxide-core/src/types/business_connection.rs @@ -0,0 +1,28 @@ +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +use crate::types::{User, UserId}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessConnection { + /// Unique identifier of the business connection + pub id: String, + + /// Business account user that created the business connection + pub user: User, + + /// The user id of the private chat with the user who created the business + /// connection + pub user_chat_id: UserId, + + /// Date the connection was established in Unix time + #[serde(with = "crate::types::serde_date_from_unix_timestamp")] + pub date: DateTime, + + /// `true`, if the bot can act on behalf of the business account in chats + /// that were active in the last 24 hours + pub can_reply: bool, + + /// `true`, if the connection is alive + pub is_enabled: bool, +} From 2fe5daccff815d4772d210e1ec2d36e3e211d3ac Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:42:17 +0530 Subject: [PATCH 24/46] Add `BusinessConnection` variant to `UpdateKind` enum --- .../teloxide-core/src/types/allowed_update.rs | 1 + crates/teloxide-core/src/types/update.rs | 52 ++++++++++++------- crates/teloxide/src/dispatching/filter_ext.rs | 1 + .../src/dispatching/handler_description.rs | 1 + 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/crates/teloxide-core/src/types/allowed_update.rs b/crates/teloxide-core/src/types/allowed_update.rs index 12949ec5..1b8d05b7 100644 --- a/crates/teloxide-core/src/types/allowed_update.rs +++ b/crates/teloxide-core/src/types/allowed_update.rs @@ -7,6 +7,7 @@ pub enum AllowedUpdate { EditedMessage, ChannelPost, EditedChannelPost, + BusinessConnection, MessageReaction, MessageReactionCount, InlineQuery, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 7b00a20e..d40c6d61 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -3,9 +3,9 @@ use serde::{de::MapAccess, Deserialize, Serialize, Serializer}; use serde_json::Value; use crate::types::{ - CallbackQuery, Chat, ChatBoostRemoved, ChatBoostUpdated, ChatJoinRequest, ChatMemberUpdated, - ChosenInlineResult, InlineQuery, Message, MessageReactionCountUpdated, MessageReactionUpdated, - Poll, PollAnswer, PreCheckoutQuery, ShippingQuery, User, + BusinessConnection, CallbackQuery, Chat, ChatBoostRemoved, ChatBoostUpdated, ChatJoinRequest, + ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, MessageReactionCountUpdated, + MessageReactionUpdated, Poll, PollAnswer, PreCheckoutQuery, ShippingQuery, User, }; /// This [object] represents an incoming update. @@ -60,6 +60,10 @@ pub enum UpdateKind { /// New version of a channel post that is known to the bot and was edited. EditedChannelPost(Message), + /// The bot was connected to or disconnected from a business account, or a + /// user edited an existing connection with the bot + BusinessConnection(BusinessConnection), + /// A reaction to a message was changed by a user. The bot must be an /// administrator in the chat and must explicitly specify /// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates` @@ -160,6 +164,8 @@ impl Update { m.from.as_ref()? } + BusinessConnection(conn) => &conn.user, + CallbackQuery(query) => &query.from, ChosenInlineResult(chosen) => &chosen.from, MessageReaction(reaction) => return reaction.user(), @@ -262,7 +268,9 @@ impl Update { i6(empty()) } - UpdateKind::MessageReactionCount(_) | UpdateKind::Error(_) => i6(empty()), + UpdateKind::MessageReactionCount(_) + | UpdateKind::BusinessConnection(_) + | UpdateKind::Error(_) => i6(empty()), } } @@ -283,6 +291,7 @@ impl Update { RemovedChatBoost(b) => &b.chat, InlineQuery(_) + | BusinessConnection(_) | ChosenInlineResult(_) | ShippingQuery(_) | PreCheckoutQuery(_) @@ -350,6 +359,10 @@ impl<'de> Deserialize<'de> for UpdateKind { "edited_channel_post" => { map.next_value::().ok().map(UpdateKind::EditedChannelPost) } + "business_connection" => map + .next_value::() + .ok() + .map(UpdateKind::BusinessConnection), "message_reaction" => map .next_value::() .ok() @@ -423,37 +436,40 @@ impl Serialize for UpdateKind { UpdateKind::EditedChannelPost(v) => { s.serialize_newtype_variant(name, 3, "edited_channel_post", v) } + UpdateKind::BusinessConnection(b) => { + s.serialize_newtype_variant(name, 4, "business_connection", b) + } UpdateKind::MessageReaction(v) => { - s.serialize_newtype_variant(name, 4, "message_reaction", v) + s.serialize_newtype_variant(name, 5, "message_reaction", v) } UpdateKind::MessageReactionCount(v) => { - s.serialize_newtype_variant(name, 5, "message_reaction_count", v) + s.serialize_newtype_variant(name, 6, "message_reaction_count", v) } - UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 6, "inline_query", v), + UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 7, "inline_query", v), UpdateKind::ChosenInlineResult(v) => { - s.serialize_newtype_variant(name, 7, "chosen_inline_result", v) + s.serialize_newtype_variant(name, 8, "chosen_inline_result", v) } UpdateKind::CallbackQuery(v) => { - s.serialize_newtype_variant(name, 8, "callback_query", v) + s.serialize_newtype_variant(name, 9, "callback_query", v) } UpdateKind::ShippingQuery(v) => { - s.serialize_newtype_variant(name, 9, "shipping_query", v) + s.serialize_newtype_variant(name, 10, "shipping_query", v) } UpdateKind::PreCheckoutQuery(v) => { - s.serialize_newtype_variant(name, 10, "pre_checkout_query", v) + s.serialize_newtype_variant(name, 11, "pre_checkout_query", v) } - UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 11, "poll", v), - UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 12, "poll_answer", v), + UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 12, "poll", v), + UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 13, "poll_answer", v), UpdateKind::MyChatMember(v) => { - s.serialize_newtype_variant(name, 13, "my_chat_member", v) + s.serialize_newtype_variant(name, 14, "my_chat_member", v) } - UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 14, "chat_member", v), + UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 15, "chat_member", v), UpdateKind::ChatJoinRequest(v) => { - s.serialize_newtype_variant(name, 15, "chat_join_request", v) + s.serialize_newtype_variant(name, 16, "chat_join_request", v) } - UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 16, "chat_boost", v), + UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 17, "chat_boost", v), UpdateKind::RemovedChatBoost(v) => { - s.serialize_newtype_variant(name, 17, "removed_chat_boost", v) + s.serialize_newtype_variant(name, 18, "removed_chat_boost", v) } UpdateKind::Error(v) => v.serialize(s), } diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index e9cb3f4c..c92e88df 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -155,6 +155,7 @@ define_update_ext! { (filter_edited_message, UpdateKind::EditedMessage, EditedMessage), (filter_channel_post, UpdateKind::ChannelPost, ChannelPost), (filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost), + (filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection), (filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction), (filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount), (filter_inline_query, UpdateKind::InlineQuery, InlineQuery), diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index 0398f2df..0a8bb621 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -65,6 +65,7 @@ impl EventKind for Kind { EditedMessage, ChannelPost, EditedChannelPost, + BusinessConnection, MessageReaction, MessageReactionCount, InlineQuery, From 9e57d3acff8c2a09e59247da4479613dd7048423 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:46:53 +0530 Subject: [PATCH 25/46] Add `BusinessMessage` variant to `UpdateKind` enum --- .../teloxide-core/src/types/allowed_update.rs | 1 + crates/teloxide-core/src/types/update.rs | 52 +++++++++++-------- crates/teloxide/src/dispatching/filter_ext.rs | 1 + .../src/dispatching/handler_description.rs | 1 + 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/crates/teloxide-core/src/types/allowed_update.rs b/crates/teloxide-core/src/types/allowed_update.rs index 1b8d05b7..15a184b9 100644 --- a/crates/teloxide-core/src/types/allowed_update.rs +++ b/crates/teloxide-core/src/types/allowed_update.rs @@ -8,6 +8,7 @@ pub enum AllowedUpdate { ChannelPost, EditedChannelPost, BusinessConnection, + BusinessMessage, MessageReaction, MessageReactionCount, InlineQuery, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index d40c6d61..d244bc90 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -64,6 +64,9 @@ pub enum UpdateKind { /// user edited an existing connection with the bot BusinessConnection(BusinessConnection), + /// New non-service message from a connected business account + BusinessMessage(Message), + /// A reaction to a message was changed by a user. The bot must be an /// administrator in the chat and must explicitly specify /// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates` @@ -160,9 +163,8 @@ impl Update { use UpdateKind::*; let from = match &self.kind { - Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) => { - m.from.as_ref()? - } + Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) + | BusinessMessage(m) => m.from.as_ref()?, BusinessConnection(conn) => &conn.user, @@ -227,7 +229,8 @@ impl Update { UpdateKind::Message(message) | UpdateKind::EditedMessage(message) | UpdateKind::ChannelPost(message) - | UpdateKind::EditedChannelPost(message) => i0(message.mentioned_users()), + | UpdateKind::EditedChannelPost(message) + | UpdateKind::BusinessMessage(message) => i0(message.mentioned_users()), UpdateKind::MessageReaction(answer) => { if let Some(user) = answer.user() { @@ -280,7 +283,8 @@ impl Update { use UpdateKind::*; let chat = match &self.kind { - Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) => &m.chat, + Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) + | BusinessMessage(m) => &m.chat, CallbackQuery(q) => q.message.as_ref()?.chat(), ChatMember(m) => &m.chat, MyChatMember(m) => &m.chat, @@ -363,6 +367,9 @@ impl<'de> Deserialize<'de> for UpdateKind { .next_value::() .ok() .map(UpdateKind::BusinessConnection), + "business_message" => { + map.next_value::().ok().map(UpdateKind::BusinessMessage) + } "message_reaction" => map .next_value::() .ok() @@ -436,40 +443,43 @@ impl Serialize for UpdateKind { UpdateKind::EditedChannelPost(v) => { s.serialize_newtype_variant(name, 3, "edited_channel_post", v) } - UpdateKind::BusinessConnection(b) => { - s.serialize_newtype_variant(name, 4, "business_connection", b) + UpdateKind::BusinessConnection(v) => { + s.serialize_newtype_variant(name, 4, "business_connection", v) + } + UpdateKind::BusinessMessage(v) => { + s.serialize_newtype_variant(name, 5, "business_message", v) } UpdateKind::MessageReaction(v) => { - s.serialize_newtype_variant(name, 5, "message_reaction", v) + s.serialize_newtype_variant(name, 6, "message_reaction", v) } UpdateKind::MessageReactionCount(v) => { - s.serialize_newtype_variant(name, 6, "message_reaction_count", v) + s.serialize_newtype_variant(name, 7, "message_reaction_count", v) } - UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 7, "inline_query", v), + UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 8, "inline_query", v), UpdateKind::ChosenInlineResult(v) => { - s.serialize_newtype_variant(name, 8, "chosen_inline_result", v) + s.serialize_newtype_variant(name, 9, "chosen_inline_result", v) } UpdateKind::CallbackQuery(v) => { - s.serialize_newtype_variant(name, 9, "callback_query", v) + s.serialize_newtype_variant(name, 10, "callback_query", v) } UpdateKind::ShippingQuery(v) => { - s.serialize_newtype_variant(name, 10, "shipping_query", v) + s.serialize_newtype_variant(name, 11, "shipping_query", v) } UpdateKind::PreCheckoutQuery(v) => { - s.serialize_newtype_variant(name, 11, "pre_checkout_query", v) + s.serialize_newtype_variant(name, 12, "pre_checkout_query", v) } - UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 12, "poll", v), - UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 13, "poll_answer", v), + UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 13, "poll", v), + UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 14, "poll_answer", v), UpdateKind::MyChatMember(v) => { - s.serialize_newtype_variant(name, 14, "my_chat_member", v) + s.serialize_newtype_variant(name, 15, "my_chat_member", v) } - UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 15, "chat_member", v), + UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 16, "chat_member", v), UpdateKind::ChatJoinRequest(v) => { - s.serialize_newtype_variant(name, 16, "chat_join_request", v) + s.serialize_newtype_variant(name, 17, "chat_join_request", v) } - UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 17, "chat_boost", v), + UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 18, "chat_boost", v), UpdateKind::RemovedChatBoost(v) => { - s.serialize_newtype_variant(name, 18, "removed_chat_boost", v) + s.serialize_newtype_variant(name, 19, "removed_chat_boost", v) } UpdateKind::Error(v) => v.serialize(s), } diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index c92e88df..305750ec 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -156,6 +156,7 @@ define_update_ext! { (filter_channel_post, UpdateKind::ChannelPost, ChannelPost), (filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost), (filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection), + (filter_business_message, UpdateKind::BusinessMessage, BusinessMessage), (filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction), (filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount), (filter_inline_query, UpdateKind::InlineQuery, InlineQuery), diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index 0a8bb621..37e740b5 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -66,6 +66,7 @@ impl EventKind for Kind { ChannelPost, EditedChannelPost, BusinessConnection, + BusinessMessage, MessageReaction, MessageReactionCount, InlineQuery, From 0efb15aa6a00c477a51ded6ef06779a75e819deb Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:52:44 +0530 Subject: [PATCH 26/46] Add `EditedBusinessMessage` variant to `UpdateKind` --- .../teloxide-core/src/types/allowed_update.rs | 1 + crates/teloxide-core/src/types/update.rs | 56 ++++++++++++------- crates/teloxide/src/dispatching/filter_ext.rs | 1 + .../src/dispatching/handler_description.rs | 1 + 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/crates/teloxide-core/src/types/allowed_update.rs b/crates/teloxide-core/src/types/allowed_update.rs index 15a184b9..17142bec 100644 --- a/crates/teloxide-core/src/types/allowed_update.rs +++ b/crates/teloxide-core/src/types/allowed_update.rs @@ -9,6 +9,7 @@ pub enum AllowedUpdate { EditedChannelPost, BusinessConnection, BusinessMessage, + EditedBusinessMessage, MessageReaction, MessageReactionCount, InlineQuery, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index d244bc90..d72db1b7 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -67,6 +67,9 @@ pub enum UpdateKind { /// New non-service message from a connected business account BusinessMessage(Message), + /// New version of a message from a connected business account + EditedBusinessMessage(Message), + /// A reaction to a message was changed by a user. The bot must be an /// administrator in the chat and must explicitly specify /// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates` @@ -163,8 +166,12 @@ impl Update { use UpdateKind::*; let from = match &self.kind { - Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) - | BusinessMessage(m) => m.from.as_ref()?, + Message(m) + | EditedMessage(m) + | ChannelPost(m) + | EditedChannelPost(m) + | BusinessMessage(m) + | EditedBusinessMessage(m) => m.from.as_ref()?, BusinessConnection(conn) => &conn.user, @@ -230,7 +237,8 @@ impl Update { | UpdateKind::EditedMessage(message) | UpdateKind::ChannelPost(message) | UpdateKind::EditedChannelPost(message) - | UpdateKind::BusinessMessage(message) => i0(message.mentioned_users()), + | UpdateKind::BusinessMessage(message) + | UpdateKind::EditedBusinessMessage(message) => i0(message.mentioned_users()), UpdateKind::MessageReaction(answer) => { if let Some(user) = answer.user() { @@ -283,8 +291,12 @@ impl Update { use UpdateKind::*; let chat = match &self.kind { - Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) - | BusinessMessage(m) => &m.chat, + Message(m) + | EditedMessage(m) + | ChannelPost(m) + | EditedChannelPost(m) + | BusinessMessage(m) + | EditedBusinessMessage(m) => &m.chat, CallbackQuery(q) => q.message.as_ref()?.chat(), ChatMember(m) => &m.chat, MyChatMember(m) => &m.chat, @@ -370,6 +382,9 @@ impl<'de> Deserialize<'de> for UpdateKind { "business_message" => { map.next_value::().ok().map(UpdateKind::BusinessMessage) } + "edited_business_message" => { + map.next_value::().ok().map(UpdateKind::EditedBusinessMessage) + } "message_reaction" => map .next_value::() .ok() @@ -449,37 +464,40 @@ impl Serialize for UpdateKind { UpdateKind::BusinessMessage(v) => { s.serialize_newtype_variant(name, 5, "business_message", v) } + UpdateKind::EditedBusinessMessage(v) => { + s.serialize_newtype_variant(name, 6, "edited_business_message", v) + } UpdateKind::MessageReaction(v) => { - s.serialize_newtype_variant(name, 6, "message_reaction", v) + s.serialize_newtype_variant(name, 7, "message_reaction", v) } UpdateKind::MessageReactionCount(v) => { - s.serialize_newtype_variant(name, 7, "message_reaction_count", v) + s.serialize_newtype_variant(name, 8, "message_reaction_count", v) } - UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 8, "inline_query", v), + UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 9, "inline_query", v), UpdateKind::ChosenInlineResult(v) => { - s.serialize_newtype_variant(name, 9, "chosen_inline_result", v) + s.serialize_newtype_variant(name, 10, "chosen_inline_result", v) } UpdateKind::CallbackQuery(v) => { - s.serialize_newtype_variant(name, 10, "callback_query", v) + s.serialize_newtype_variant(name, 11, "callback_query", v) } UpdateKind::ShippingQuery(v) => { - s.serialize_newtype_variant(name, 11, "shipping_query", v) + s.serialize_newtype_variant(name, 12, "shipping_query", v) } UpdateKind::PreCheckoutQuery(v) => { - s.serialize_newtype_variant(name, 12, "pre_checkout_query", v) + s.serialize_newtype_variant(name, 13, "pre_checkout_query", v) } - UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 13, "poll", v), - UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 14, "poll_answer", v), + UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 14, "poll", v), + UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 15, "poll_answer", v), UpdateKind::MyChatMember(v) => { - s.serialize_newtype_variant(name, 15, "my_chat_member", v) + s.serialize_newtype_variant(name, 16, "my_chat_member", v) } - UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 16, "chat_member", v), + UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 17, "chat_member", v), UpdateKind::ChatJoinRequest(v) => { - s.serialize_newtype_variant(name, 17, "chat_join_request", v) + s.serialize_newtype_variant(name, 18, "chat_join_request", v) } - UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 18, "chat_boost", v), + UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 19, "chat_boost", v), UpdateKind::RemovedChatBoost(v) => { - s.serialize_newtype_variant(name, 19, "removed_chat_boost", v) + s.serialize_newtype_variant(name, 20, "removed_chat_boost", v) } UpdateKind::Error(v) => v.serialize(s), } diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index 305750ec..c74c008a 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -157,6 +157,7 @@ define_update_ext! { (filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost), (filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection), (filter_business_message, UpdateKind::BusinessMessage, BusinessMessage), + (filter_edited_business_message, UpdateKind::EditedBusinessMessage, EditedBusinessMessage), (filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction), (filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount), (filter_inline_query, UpdateKind::InlineQuery, InlineQuery), diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index 37e740b5..c3e16369 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -67,6 +67,7 @@ impl EventKind for Kind { EditedChannelPost, BusinessConnection, BusinessMessage, + EditedBusinessMessage, MessageReaction, MessageReactionCount, InlineQuery, From f6c957182fc4837b5f67a132ffe8d5520b31b647 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 10:16:07 +0530 Subject: [PATCH 27/46] Add `BusinessMessagesDeleted` struct --- crates/teloxide-core/src/types.rs | 2 ++ .../src/types/business_messages_deleted.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 crates/teloxide-core/src/types/business_messages_deleted.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 54a24e76..c35096da 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -12,6 +12,7 @@ pub use bot_short_description::*; pub use business_connection::*; pub use business_intro::*; pub use business_location::*; +pub use business_messages_deleted::*; pub use business_opening_hours::*; pub use callback_game::*; pub use callback_query::*; @@ -171,6 +172,7 @@ mod bot_short_description; mod business_connection; mod business_intro; mod business_location; +mod business_messages_deleted; mod business_opening_hours; mod callback_game; mod callback_query; diff --git a/crates/teloxide-core/src/types/business_messages_deleted.rs b/crates/teloxide-core/src/types/business_messages_deleted.rs new file mode 100644 index 00000000..9bb3245b --- /dev/null +++ b/crates/teloxide-core/src/types/business_messages_deleted.rs @@ -0,0 +1,17 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::{Chat, MessageId}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessMessagesDeleted { + /// Unique identifier of the business connection. + pub business_connection_id: String, + + /// Information about a chat in the business account. The bot may not have + /// access to the chat or the corresponding user. + pub chat: Chat, + + /// The list of identifiers of deleted messages in the chat of the business + /// account. + pub message_ids: Vec, +} From b15d85ec0a03cf726e816486fc8aa30158cc88a3 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 10:18:47 +0530 Subject: [PATCH 28/46] Move `BusinessOpeningHoursInterval` to separate file --- crates/teloxide-core/src/types.rs | 2 ++ .../src/types/business_opening_hours.rs | 13 +------------ .../src/types/business_opening_hours_interval.rs | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 crates/teloxide-core/src/types/business_opening_hours_interval.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index c35096da..3d3ef44a 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -14,6 +14,7 @@ pub use business_intro::*; pub use business_location::*; pub use business_messages_deleted::*; pub use business_opening_hours::*; +pub use business_opening_hours_interval::*; pub use callback_game::*; pub use callback_query::*; pub use chat::*; @@ -174,6 +175,7 @@ mod business_intro; mod business_location; mod business_messages_deleted; mod business_opening_hours; +mod business_opening_hours_interval; mod callback_game; mod callback_query; mod chat; diff --git a/crates/teloxide-core/src/types/business_opening_hours.rs b/crates/teloxide-core/src/types/business_opening_hours.rs index 54e1a1e2..f149563a 100644 --- a/crates/teloxide-core/src/types/business_opening_hours.rs +++ b/crates/teloxide-core/src/types/business_opening_hours.rs @@ -1,17 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct BusinessOpeningHoursInterval { - /// The minute's sequence number in a week, starting on Monday, marking the - /// start of the time interval during which the business is open; - /// 0 - 7 * 24* 60 - pub opening_minute: u16, - - /// The minute's sequence number in a week, starting on Monday, marking the - /// end of the time interval during which the business is open; - /// 0 - 8 * 24* 60 - pub closing_minute: u16, -} +use crate::types::BusinessOpeningHoursInterval; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessOpeningHours { diff --git a/crates/teloxide-core/src/types/business_opening_hours_interval.rs b/crates/teloxide-core/src/types/business_opening_hours_interval.rs new file mode 100644 index 00000000..0c7c1a61 --- /dev/null +++ b/crates/teloxide-core/src/types/business_opening_hours_interval.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BusinessOpeningHoursInterval { + /// The minute's sequence number in a week, starting on Monday, marking the + /// start of the time interval during which the business is open; + /// 0 - 7 * 24* 60 + pub opening_minute: u16, + + /// The minute's sequence number in a week, starting on Monday, marking the + /// end of the time interval during which the business is open; + /// 0 - 8 * 24* 60 + pub closing_minute: u16, +} From 7fe9278ce882ea4de65b74fb49aae677a686537d Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 19:42:02 +0530 Subject: [PATCH 29/46] Add `DeletedBusinessMessages` variant to `UpdateKind` --- .../teloxide-core/src/types/allowed_update.rs | 1 + crates/teloxide-core/src/types/update.rs | 51 ++++++++++++------- crates/teloxide/src/dispatching/filter_ext.rs | 1 + .../src/dispatching/handler_description.rs | 1 + 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/crates/teloxide-core/src/types/allowed_update.rs b/crates/teloxide-core/src/types/allowed_update.rs index 17142bec..73f70044 100644 --- a/crates/teloxide-core/src/types/allowed_update.rs +++ b/crates/teloxide-core/src/types/allowed_update.rs @@ -10,6 +10,7 @@ pub enum AllowedUpdate { BusinessConnection, BusinessMessage, EditedBusinessMessage, + DeletedBusinessMessages, MessageReaction, MessageReactionCount, InlineQuery, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index d72db1b7..50f0daa1 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -3,9 +3,10 @@ use serde::{de::MapAccess, Deserialize, Serialize, Serializer}; use serde_json::Value; use crate::types::{ - BusinessConnection, CallbackQuery, Chat, ChatBoostRemoved, ChatBoostUpdated, ChatJoinRequest, - ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, MessageReactionCountUpdated, - MessageReactionUpdated, Poll, PollAnswer, PreCheckoutQuery, ShippingQuery, User, + BusinessConnection, BusinessMessagesDeleted, CallbackQuery, Chat, ChatBoostRemoved, + ChatBoostUpdated, ChatJoinRequest, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, + MessageReactionCountUpdated, MessageReactionUpdated, Poll, PollAnswer, PreCheckoutQuery, + ShippingQuery, User, }; /// This [object] represents an incoming update. @@ -70,6 +71,9 @@ pub enum UpdateKind { /// New version of a message from a connected business account EditedBusinessMessage(Message), + /// Messages were deleted from a connected business account + DeletedBusinessMessages(BusinessMessagesDeleted), + /// A reaction to a message was changed by a user. The bot must be an /// administrator in the chat and must explicitly specify /// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates` @@ -188,7 +192,9 @@ impl Update { ChatBoost(b) => return b.boost.source.user(), RemovedChatBoost(b) => return b.source.user(), - MessageReactionCount(_) | Poll(_) | Error(_) => return None, + MessageReactionCount(_) | DeletedBusinessMessages(_) | Poll(_) | Error(_) => { + return None + } }; Some(from) @@ -281,6 +287,7 @@ impl Update { UpdateKind::MessageReactionCount(_) | UpdateKind::BusinessConnection(_) + | UpdateKind::DeletedBusinessMessages(_) | UpdateKind::Error(_) => i6(empty()), } } @@ -305,6 +312,7 @@ impl Update { MessageReactionCount(r) => &r.chat, ChatBoost(b) => &b.chat, RemovedChatBoost(b) => &b.chat, + DeletedBusinessMessages(m) => &m.chat, InlineQuery(_) | BusinessConnection(_) @@ -385,6 +393,10 @@ impl<'de> Deserialize<'de> for UpdateKind { "edited_business_message" => { map.next_value::().ok().map(UpdateKind::EditedBusinessMessage) } + "deleted_business_messages" => map + .next_value::() + .ok() + .map(UpdateKind::DeletedBusinessMessages), "message_reaction" => map .next_value::() .ok() @@ -467,37 +479,40 @@ impl Serialize for UpdateKind { UpdateKind::EditedBusinessMessage(v) => { s.serialize_newtype_variant(name, 6, "edited_business_message", v) } + UpdateKind::DeletedBusinessMessages(v) => { + s.serialize_newtype_variant(name, 7, "deleted_business_messages", v) + } UpdateKind::MessageReaction(v) => { - s.serialize_newtype_variant(name, 7, "message_reaction", v) + s.serialize_newtype_variant(name, 8, "message_reaction", v) } UpdateKind::MessageReactionCount(v) => { - s.serialize_newtype_variant(name, 8, "message_reaction_count", v) + s.serialize_newtype_variant(name, 9, "message_reaction_count", v) } - UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 9, "inline_query", v), + UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 10, "inline_query", v), UpdateKind::ChosenInlineResult(v) => { - s.serialize_newtype_variant(name, 10, "chosen_inline_result", v) + s.serialize_newtype_variant(name, 11, "chosen_inline_result", v) } UpdateKind::CallbackQuery(v) => { - s.serialize_newtype_variant(name, 11, "callback_query", v) + s.serialize_newtype_variant(name, 12, "callback_query", v) } UpdateKind::ShippingQuery(v) => { - s.serialize_newtype_variant(name, 12, "shipping_query", v) + s.serialize_newtype_variant(name, 13, "shipping_query", v) } UpdateKind::PreCheckoutQuery(v) => { - s.serialize_newtype_variant(name, 13, "pre_checkout_query", v) + s.serialize_newtype_variant(name, 14, "pre_checkout_query", v) } - UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 14, "poll", v), - UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 15, "poll_answer", v), + UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 15, "poll", v), + UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 16, "poll_answer", v), UpdateKind::MyChatMember(v) => { - s.serialize_newtype_variant(name, 16, "my_chat_member", v) + s.serialize_newtype_variant(name, 17, "my_chat_member", v) } - UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 17, "chat_member", v), + UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 18, "chat_member", v), UpdateKind::ChatJoinRequest(v) => { - s.serialize_newtype_variant(name, 18, "chat_join_request", v) + s.serialize_newtype_variant(name, 19, "chat_join_request", v) } - UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 19, "chat_boost", v), + UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 20, "chat_boost", v), UpdateKind::RemovedChatBoost(v) => { - s.serialize_newtype_variant(name, 20, "removed_chat_boost", v) + s.serialize_newtype_variant(name, 21, "removed_chat_boost", v) } UpdateKind::Error(v) => v.serialize(s), } diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index c74c008a..09b16eb6 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -158,6 +158,7 @@ define_update_ext! { (filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection), (filter_business_message, UpdateKind::BusinessMessage, BusinessMessage), (filter_edited_business_message, UpdateKind::EditedBusinessMessage, EditedBusinessMessage), + (filter_deleted_business_messages, UpdateKind::DeletedBusinessMessages, DeletedBusinessMessages), (filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction), (filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount), (filter_inline_query, UpdateKind::InlineQuery, InlineQuery), diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index c3e16369..784bb2e4 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -68,6 +68,7 @@ impl EventKind for Kind { BusinessConnection, BusinessMessage, EditedBusinessMessage, + DeletedBusinessMessages, MessageReaction, MessageReactionCount, InlineQuery, From 68b7aba836b4d935e2e6896d42224857ed3211a1 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 20:53:46 +0530 Subject: [PATCH 30/46] 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))) } } From 504081373722c895b69237245f5711d9c8afe14b Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 20:59:29 +0530 Subject: [PATCH 31/46] Bump TBA version --- README.md | 2 +- crates/teloxide-core/CHANGELOG.md | 16 ++++++++-------- crates/teloxide-core/README.md | 2 +- crates/teloxide-core/src/lib.rs | 2 +- crates/teloxide/src/lib.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 10ed4f93..5ee10261 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - + diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index c2b49259..a5c0726e 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `ChatId::as_user` ([#905][pr905]) - Implement `PartialEq for UserId` and `PartialEq for ChatId` ([#905][pr905]) - `ChatId::{MIN, MAX}` ([#905][pr905]) -- Missing `Message` getters ([#982][pr982]): +- Missing `Message` getters ([#982][pr982]): - `message_auto_delete_timer_changed` - `write_access_allowed` - `forum_topic_created` @@ -61,7 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `video_chat_scheduled` - `video_chat_started` - `video_chat_ended` - - `web_app_data` + - `web_app_data` - `is_delete_chat_photo`, `is_group_chat_created`, `is_super_group_chat_created`, `is_channel_chat_created` functions to `Message` ([#982][pr982]) - Support for TBA 6.5 ([#954][pr954]) - Add `can_send_audios`, `can_send_documents`, `can_send_photos`, `can_send_videos`, `can_send_video_notes`, and `can_send_voice_notes` to `ChatPermissions` and `Restricted` @@ -91,7 +91,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add parameter `emoji` to the `send_sticker` method to specify an emoji for just uploaded stickers - Add support for the creation of custom emoji sticker sets in `create_new_sticker_set` - Add parameter `needs_repainting` to the `create_new_sticker_set` methodto automatically change the color of emoji based on context (e.g., use text color in messages, accent color in statuses, etc.) - - Add field `needs_repainting` to the `Sticker` struct + - Add field `needs_repainting` to the `Sticker` struct - Add support for the creation of sticker sets with multiple initial stickers in `create_new_sticker_set` by replacing the parameters `sticker`, `emojis` and `mask_position` with the parameters `stickers` and `sticker_format`. - Add support for .WEBP files in `create_new_sticker_set` and `add_sticker_to_set` - Add support for .WEBP, .TGS, and .WEBM files in `upload_sticker_file` by replacing the parameter `png_sticker` with the parameters `sticker` and `sticker_format` @@ -145,7 +145,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Giveaway: - Add `Giveaway`, `GiveawayCreated`, `GiveawayWinners` and `GiveawayCompleted` structs - Add `Giveaway`, `GiveawayCreated`, `GiveawayWinners` and `GiveawayCompleted` variants to `MessageKind` enum - - Add `giveaway`, `giveaway_created`, `giveaway_winners` and `giveaway_completed` getters to `Message` + - Add `giveaway`, `giveaway_created`, `giveaway_winners` and `giveaway_completed` getters to `Message` - Other Changes - Add fields `ChafFullInfo::{has_visible_history, accent_color_id, background_custom_emoji_id, profile_accent_color_id, profile_background_custom_emoji_id}` - Add `RequestId` type @@ -197,7 +197,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `InlineQueryResultLocation::live_period` - `Location::live_period` - `MessageAutoDeleteTimerChanged::message_auto_delete_time` - - `Poll::open_period` + - `Poll::open_period` - `Video::duration` - `VideoNote::duration` - `Voice::duration` @@ -260,12 +260,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Struct `KeyboardButtonRequestUser` was renamed to `KeyboardButtonRequestUsers` + added field `max_quantity` to it - Field `KeyboardButton::request_user` was renamed to `request_users` - `MessageUserShared` was renamed to `MessageUsersShared` - - Other Changes + - Other Changes - `Message::pinned_message` and `CallbackQuery::message` now have `MaybeInaccessibleMessage` type - Field `emoji_status_custom_emoji_id` is allowed in non-private chats (moved to the `ChatFullInfo`) - Struct `Forward` was replaced by `MessageOrigin` in `MessageCommon` - `RequestId` replaces `i32` in `ChatShared` and `KeyboardButtonRequestChat` structs - + [pr852]: https://github.com/teloxide/teloxide/pull/853 [pr859]: https://github.com/teloxide/teloxide/pull/859 @@ -308,7 +308,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.9.1 - 2023-02-15 -### Fixed +### Fixed - `Update::user` now handles channel posts, chat member changes and chat join request updates correctly ([#835][pr835]) - In cases when `teloxide` can't deserialize an update, error now includes the full json value ([#826][pr826]) diff --git a/crates/teloxide-core/README.md b/crates/teloxide-core/README.md index d4bd5edc..8e8a1ec3 100644 --- a/crates/teloxide-core/README.md +++ b/crates/teloxide-core/README.md @@ -12,7 +12,7 @@ - + diff --git a/crates/teloxide-core/src/lib.rs b/crates/teloxide-core/src/lib.rs index 84e1a1a2..25f91ec7 100644 --- a/crates/teloxide-core/src/lib.rs +++ b/crates/teloxide-core/src/lib.rs @@ -1,7 +1,7 @@ //! Core part of the [`teloxide`] library. //! //! This library provides tools for making requests to the [Telegram Bot API] -//! (Currently, version `7.1` is supported) with ease. The library is fully +//! (Currently, version `7.2` is supported) with ease. The library is fully //! asynchronous and built using [`tokio`]. //! //!```toml diff --git a/crates/teloxide/src/lib.rs b/crates/teloxide/src/lib.rs index 7a789398..bcb901f1 100644 --- a/crates/teloxide/src/lib.rs +++ b/crates/teloxide/src/lib.rs @@ -1,6 +1,6 @@ //! A full-featured framework that empowers you to easily build [Telegram bots] //! using [Rust]. It handles all the difficult stuff so you can focus only on -//! your business logic. Currently, version `7.1` of [Telegram Bot API] is +//! your business logic. Currently, version `7.2` of [Telegram Bot API] is //! supported. //! //! For a high-level overview, see [our GitHub repository](https://github.com/teloxide/teloxide). From 336ae4f646e7d301f8bf3dd635b3829412c8420c Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 20:59:45 +0530 Subject: [PATCH 32/46] Fix tests for 'full' features --- crates/teloxide-core/src/adaptors/erased.rs | 27 +++++++++++++++---- .../teloxide/src/dispatching/handler_ext.rs | 9 +++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index c51281b5..1785ccf7 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -889,7 +889,6 @@ trait ErasableRequester<'a> { name: String, title: String, stickers: Vec, - sticker_format: StickerFormat, ) -> ErasedRequest<'a, CreateNewStickerSet, Self::Err>; fn add_sticker_to_set( @@ -910,10 +909,19 @@ trait ErasableRequester<'a> { sticker: String, ) -> ErasedRequest<'a, DeleteStickerFromSet, Self::Err>; + fn replace_sticker_in_set( + &self, + user_id: UserId, + name: String, + old_sticker: String, + sticker: InputSticker, + ) -> ErasedRequest<'a, ReplaceStickerInSet, Self::Err>; + fn set_sticker_set_thumbnail( &self, name: String, user_id: UserId, + format: StickerFormat, ) -> ErasedRequest<'a, SetStickerSetThumbnail, Self::Err>; fn set_custom_emoji_sticker_set_thumbnail( @@ -1806,10 +1814,8 @@ where name: String, title: String, stickers: Vec, - sticker_format: StickerFormat, ) -> ErasedRequest<'a, CreateNewStickerSet, Self::Err> { - Requester::create_new_sticker_set(self, user_id, name, title, stickers, sticker_format) - .erase() + Requester::create_new_sticker_set(self, user_id, name, title, stickers).erase() } fn add_sticker_to_set( @@ -1836,12 +1842,23 @@ where Requester::delete_sticker_from_set(self, sticker).erase() } + fn replace_sticker_in_set( + &self, + user_id: UserId, + name: String, + old_sticker: String, + sticker: InputSticker, + ) -> ErasedRequest<'a, ReplaceStickerInSet, Self::Err> { + Requester::replace_sticker_in_set(self, user_id, name, old_sticker, sticker).erase() + } + fn set_sticker_set_thumbnail( &self, name: String, user_id: UserId, + format: StickerFormat, ) -> ErasedRequest<'a, SetStickerSetThumbnail, Self::Err> { - Requester::set_sticker_set_thumbnail(self, name, user_id).erase() + Requester::set_sticker_set_thumbnail(self, name, user_id, format).erase() } fn set_custom_emoji_sticker_set_thumbnail( diff --git a/crates/teloxide/src/dispatching/handler_ext.rs b/crates/teloxide/src/dispatching/handler_ext.rs index ecda2406..ae59c76f 100644 --- a/crates/teloxide/src/dispatching/handler_ext.rs +++ b/crates/teloxide/src/dispatching/handler_ext.rs @@ -189,6 +189,8 @@ mod tests { }), sender_chat: None, is_topic_message: false, + sender_business_bot: None, + business_connection_id: None, date, chat: Chat { id: ChatId(109_998_024), @@ -199,6 +201,11 @@ mod tests { bio: None, has_private_forwards: None, has_restricted_voice_and_video_messages: None, + business_intro: None, + business_location: None, + business_opening_hours: None, + birthdate: None, + personal_chat: None, }), photo: None, available_reactions: None, @@ -231,6 +238,7 @@ mod tests { has_protected_content: false, reply_to_story: None, sender_boost_count: None, + is_from_offline: false, }), }), } @@ -251,6 +259,7 @@ mod tests { can_join_groups: false, can_read_all_group_messages: false, supports_inline_queries: false, + can_connect_to_business: false, } } From 057a37cea0ae2dce044dd5ea4fc4f2387f2fdf56 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 21:27:40 +0530 Subject: [PATCH 33/46] Update CHANGELOG.md to add changes related to #1146 --- crates/teloxide-core/CHANGELOG.md | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index a5c0726e..618d2ba4 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -19,7 +19,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `boost_added` and `reply_to_story` getters to `Message` struct - Add `unrestrict_boost_count` and `custom_emoji_sticker_set_name` getters to `Chat` struct +- Support for TBA 7.2 ([#1146](pr1146)) + - Update documentation of `SendSticker` method + - Add `is_from_offline` field to `MessageCommon` struct + - Add `can_connect_to_business` field to `Me` struct + - Add `personal_chat` field to `ChatPrivate` struct + - Add `ReplaceStickerInSet` and `GetBusinessConnection` methods + - Add `Birthdate` struct and corresponding field `birthdate` in `ChatPrivate` + - Add `request_name`, `request_username` and `request_photo` fields to `KeyboardButtonRequestUsers` struct + - Add `request_title`, `request_username` and `request_photo` fields to `KeyboardButtonRequestChat` struct + - Add `SharedUser` struct and add corresponding field `users` to `UsersShared` struct + - Add `title`, `username` and `photo` fields to `ChatShared` struct + - Add `format` field to `InputSticker` struct + - Add `format` parameter to `SetStickerSetThumbnail` method + - Add `business_connection_id` parameter to `SendMessage`, `SendPhoto`, `SendVideo`, `SendAnimation`, `SendAudio`, `SendDocument`, `SendSticker`, `SendVideoNote`, `SendVoice`, `SendLocation`, `SendVenue`, `SendContact`, `SendPoll`, `SendDice`, `SendGame`, and `SendMediaGroup` methods + - Add `sender_business_bot` and `business_connection_id` fields to `Message` struct + - Add `BusinessIntro` struct and corresponding field `business_intro` to `ChatPrivate` struct + - Add `BusinessLocation` struct and corresponding field `business_location` to `ChatPrivate` struct + - Add `BusinessOpeningHoursInterval` and `BusinessOpeningHours` structs and corresponding field `business_opening_hours` to `ChatPrivate` struct + - Add `BusinessConnection` struct + - Add `BusinessMessagesDeleted` struct + - Add `BusinessConnection`, `BusinessMessage`, `EditedBusinessMessage` and `DeletedBusinessMessages` variants to `UpdateKind` enum + + [pr1131]: https://github.com/teloxide/teloxide/pull/1131 +[pr1146]: https://github.com/teloxide/teloxide/pull/1146 ### Changed @@ -27,6 +51,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr1134]: https://github.com/teloxide/teloxide/pull/1134 +### Removed + +- Support for TBA 7.2 ([#1146](pr1146)) + - Remove `flags` field from `StickerSet` struct + - Remove `sticker_format` parameter from `CreateNewStickerSet` method + +[pr1146]: https://github.com/teloxide/teloxide/pull/1146 + ## 0.10.1 - 2024-08-17 ### Fixed From c9eec050d0fcd0b451ed9ca1cbe6516d6cd973ae Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Thu, 22 Aug 2024 01:18:16 +0530 Subject: [PATCH 34/46] Wrap `Public` variant of `ChatKind` in `Box` --- crates/teloxide-core/CHANGELOG.md | 7 ++++++ crates/teloxide-core/src/types/chat.rs | 27 +++++++++++++++-------- crates/teloxide-core/src/types/message.rs | 24 ++++++++++---------- crates/teloxide-core/src/types/story.rs | 4 ++-- crates/teloxide-core/src/types/update.rs | 16 +++++++------- 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 618d2ba4..a6ff75df 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -59,6 +59,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 +### Breaking Changes + +- Support for TBA 7.2 ([#1146](pr1146)) + - Wrap `Public` variant of `ChatKind` in `Box` + +[pr1146]: https://github.com/teloxide/teloxide/pull/1146 + ## 0.10.1 - 2024-08-17 ### Fixed diff --git a/crates/teloxide-core/src/types/chat.rs b/crates/teloxide-core/src/types/chat.rs index 1ae99527..f9e94d9c 100644 --- a/crates/teloxide-core/src/types/chat.rs +++ b/crates/teloxide-core/src/types/chat.rs @@ -63,7 +63,7 @@ pub struct Chat { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum ChatKind { - Public(ChatPublic), + Public(Box), Private(ChatPrivate), } @@ -286,20 +286,29 @@ impl Chat { #[must_use] pub fn is_group(&self) -> bool { - matches!(self.kind, ChatKind::Public(ChatPublic { kind: PublicChatKind::Group(_), .. })) + if let ChatKind::Public(chat_pub) = &self.kind { + matches!(**chat_pub, ChatPublic { kind: PublicChatKind::Group(_), .. }) + } else { + false + } } #[must_use] pub fn is_supergroup(&self) -> bool { - matches!( - self.kind, - ChatKind::Public(ChatPublic { kind: PublicChatKind::Supergroup(_), .. }) - ) + if let ChatKind::Public(chat_pub) = &self.kind { + matches!(**chat_pub, ChatPublic { kind: PublicChatKind::Supergroup(_), .. }) + } else { + false + } } #[must_use] pub fn is_channel(&self) -> bool { - matches!(self.kind, ChatKind::Public(ChatPublic { kind: PublicChatKind::Channel(_), .. })) + if let ChatKind::Public(chat_pub) = &self.kind { + matches!(**chat_pub, ChatPublic { kind: PublicChatKind::Channel(_), .. }) + } else { + false + } } #[must_use] @@ -698,7 +707,7 @@ mod tests { fn channel_de() { let expected = Chat { id: ChatId(-1), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: None, kind: PublicChatKind::Channel(PublicChatChannel { username: Some("channel_name".into()), @@ -707,7 +716,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: Some(vec![ReactionType::Emoji { emoji: "🌭".to_owned() }]), pinned_message: None, diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 3c28604b..cea0a3d1 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -2134,7 +2134,7 @@ mod tests { let group = Chat { id: ChatId(-1001160242915), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("a".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: None, @@ -2154,7 +2154,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None, - }), + })), message_auto_delete_time: None, photo: None, available_reactions: None, @@ -2439,7 +2439,7 @@ mod tests { &Giveaway { chats: vec![Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2448,7 +2448,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -2548,7 +2548,7 @@ mod tests { from: None, sender_chat: Some(Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { linked_chat_id: None, @@ -2557,7 +2557,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), chat_full_info: ChatFullInfo::default(), available_reactions: None, photo: None, @@ -2570,7 +2570,7 @@ mod tests { date: DateTime::from_timestamp(1721161230, 0).unwrap(), chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2579,7 +2579,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -2595,7 +2595,7 @@ mod tests { giveaway: Giveaway { chats: vec![Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2604,7 +2604,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -2696,7 +2696,7 @@ mod tests { &GiveawayWinners { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -2705,7 +2705,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None - }), + })), photo: None, available_reactions: None, pinned_message: None, diff --git a/crates/teloxide-core/src/types/story.rs b/crates/teloxide-core/src/types/story.rs index 41ac32c5..abe63eac 100644 --- a/crates/teloxide-core/src/types/story.rs +++ b/crates/teloxide-core/src/types/story.rs @@ -44,7 +44,7 @@ mod tests { let story = Story { chat: Chat { id: ChatId(-1001389841361), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("GNOME".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: Some("gnome_ru".to_owned()), @@ -64,7 +64,7 @@ mod tests { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 50f0daa1..6af03fba 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -930,7 +930,7 @@ mod test { kind: UpdateKind::MessageReaction(MessageReactionUpdated { chat: Chat { id: ChatId(-1002184233434), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: None, @@ -950,7 +950,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -1090,7 +1090,7 @@ mod test { kind: UpdateKind::MessageReactionCount(MessageReactionCountUpdated { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -1099,7 +1099,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -1163,7 +1163,7 @@ mod test { kind: UpdateKind::ChatBoost(ChatBoostUpdated { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -1172,7 +1172,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, @@ -1238,7 +1238,7 @@ mod test { kind: UpdateKind::RemovedChatBoost(ChatBoostRemoved { chat: Chat { id: ChatId(-1002236736395), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("Test".to_owned()), kind: PublicChatKind::Channel(PublicChatChannel { username: None, @@ -1247,7 +1247,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, From ccc2c68751396b3bb0500a222096bae295b592f3 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Thu, 22 Aug 2024 23:19:34 +0530 Subject: [PATCH 35/46] Update docs and changelogs --- CHANGELOG.md | 7 +-- crates/teloxide-core/CHANGELOG.md | 7 ++- crates/teloxide-core/schema.ron | 43 ++++++++++--------- .../src/payloads/copy_message.rs | 2 +- .../payloads/edit_message_live_location.rs | 2 +- .../edit_message_live_location_inline.rs | 2 +- .../src/payloads/send_animation.rs | 2 +- .../teloxide-core/src/payloads/send_audio.rs | 2 +- .../src/payloads/send_contact.rs | 2 +- .../teloxide-core/src/payloads/send_dice.rs | 2 +- .../src/payloads/send_document.rs | 2 +- .../teloxide-core/src/payloads/send_game.rs | 2 +- .../src/payloads/send_location.rs | 2 +- .../src/payloads/send_message.rs | 2 +- .../teloxide-core/src/payloads/send_photo.rs | 2 +- .../teloxide-core/src/payloads/send_poll.rs | 2 +- .../src/payloads/send_sticker.rs | 2 +- .../teloxide-core/src/payloads/send_venue.rs | 2 +- .../teloxide-core/src/payloads/send_video.rs | 2 +- .../src/payloads/send_video_note.rs | 2 +- .../teloxide-core/src/payloads/send_voice.rs | 2 +- .../payloads/stop_message_live_location.rs | 2 +- .../stop_message_live_location_inline.rs | 2 +- .../src/payloads/upload_sticker_file.rs | 3 +- crates/teloxide-core/src/types/birthdate.rs | 4 +- .../src/types/business_connection.rs | 1 + .../src/types/business_messages_deleted.rs | 2 + .../src/types/reply_parameters.rs | 7 ++- 28 files changed, 60 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index deae0c9a..23b195d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,15 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `filter_boost_added` and `filter_reply_to_story` filters to `MessageFilterExt` trait - Add `filter_mention_command` filter to `HandlerExt` trait ([issue #494](https://github.com/teloxide/teloxide/issues/494)) +- Add `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to update filters ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) ## 0.13.0 - 2024-08-16 ### Added - Documentation regarding the way captions work for the official clients on `SendMediaGroup` ([PR 992](https://github.com/teloxide/teloxide/pull/992)) -- Add `MessageToCopyNotFound` error to `teloxide::errors::ApiError` ([PR 917](https://github.com/teloxide/teloxide/pull/917)) +- Add `MessageToCopyNotFound` error to `teloxide::errors::ApiError` ([PR 917](https://github.com/teloxide/teloxide/pull/917)) - `Dispatcher::try_dispatch_with_listener` ([PR 913](https://github.com/teloxide/teloxide/pull/913)) -- Missing Message::filter_* functions ([PR 982](https://github.com/teloxide/teloxide/pull/982)): +- Missing Message::filter_* functions ([PR 982](https://github.com/teloxide/teloxide/pull/982)): - `filter_game` - `filter_venue` - `filter_video` @@ -50,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `filter_video_chat_started` - `filter_video_chat_ended` - `filter_video_chat_participants_invited` - - `filter_web_app_data` + - `filter_web_app_data` - Implement `PostgresStorage`, a persistent dialogue storage based on [PostgreSQL](https://www.postgresql.org/)([PR 996](https://github.com/teloxide/teloxide/pull/996)). - Implement `GetChatId` for `teloxide_core::types::{Chat, ChatJoinRequest, ChatMemberUpdated}`. - Use [deadpool-redis](https://crates.io/crates/deadpool-redis) for Redis connection pooling ([PR 1081](https://github.com/teloxide/teloxide/pull/1081)). diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index a6ff75df..3b58ef53 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -28,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `Birthdate` struct and corresponding field `birthdate` in `ChatPrivate` - Add `request_name`, `request_username` and `request_photo` fields to `KeyboardButtonRequestUsers` struct - Add `request_title`, `request_username` and `request_photo` fields to `KeyboardButtonRequestChat` struct - - Add `SharedUser` struct and add corresponding field `users` to `UsersShared` struct + - Add `SharedUser` struct - Add `title`, `username` and `photo` fields to `ChatShared` struct - Add `format` field to `InputSticker` struct - Add `format` parameter to `SetStickerSetThumbnail` method @@ -41,7 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `BusinessMessagesDeleted` struct - Add `BusinessConnection`, `BusinessMessage`, `EditedBusinessMessage` and `DeletedBusinessMessages` variants to `UpdateKind` enum - [pr1131]: https://github.com/teloxide/teloxide/pull/1131 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 @@ -57,13 +56,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove `flags` field from `StickerSet` struct - Remove `sticker_format` parameter from `CreateNewStickerSet` method -[pr1146]: https://github.com/teloxide/teloxide/pull/1146 - ### Breaking Changes - Support for TBA 7.2 ([#1146](pr1146)) - Wrap `Public` variant of `ChatKind` in `Box` + - Replaced `user_ids` with `users` in `UsersShared` struct +[pr1131]: https://github.com/teloxide/teloxide/pull/1131 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 ## 0.10.1 - 2024-08-17 diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index b75345b8..ab9fc046 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -284,7 +284,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -453,7 +453,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -593,7 +593,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -701,7 +701,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -796,7 +796,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -914,7 +914,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1025,7 +1025,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1111,7 +1111,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1196,7 +1196,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1336,7 +1336,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1394,7 +1394,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1448,7 +1448,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1485,7 +1485,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1514,7 +1514,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1614,7 +1614,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1693,7 +1693,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1812,7 +1812,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -1873,7 +1873,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -3776,7 +3776,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user.", + md: "Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account.", md_links: { "inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating", "custom reply keyboard": "https://core.telegram.org/bots#keyboards", @@ -3817,10 +3817,11 @@ Schema( names: ("uploadStickerFile", "UploadStickerFile", "upload_sticker_file"), return_ty: RawTy("FileMeta"), doc: Doc( - md: "Use this method to upload a file with a sticker for later use in the [CreateNewStickerSet] and [AddStickerToSet] methods (the file can be used multiple times). Returns the uploaded [File] on success.", + md: "Use this method to upload a file with a sticker for later use in the [CreateNewStickerSet], [AddStickerToSet] or [ReplaceStickerInSet] methods (the file can be used multiple times). Returns the uploaded [File] on success.", md_links: { "CreateNewStickerSet": "https://docs.rs/teloxide/latest/teloxide/payloads/struct.CreateNewStickerSet.html", "AddStickerToSet": "https://docs.rs/teloxide/latest/teloxide/payloads/struct.AddStickerToSet.html", + "ReplaceStickerInSet": "https://docs.rs/teloxide/latest/teloxide/payloads/struct.ReplaceStickerInSet.html", "File": "https://core.telegram.org/bots/api#file" } ), @@ -4529,7 +4530,7 @@ Schema( name: "reply_markup", ty: Option(RawTy("ReplyMarkup")), descr: Doc( - md: "A JSON-serialized object for an [inline keyboard]. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game.", + md: "A JSON-serialized object for an [inline keyboard]. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game. Not supported for messages sent on behalf of a business account.", md_links: {"inline keyboard": "https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating"}, ), ), diff --git a/crates/teloxide-core/src/payloads/copy_message.rs b/crates/teloxide-core/src/payloads/copy_message.rs index daa67928..bc7a770a 100644 --- a/crates/teloxide-core/src/payloads/copy_message.rs +++ b/crates/teloxide-core/src/payloads/copy_message.rs @@ -40,7 +40,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/edit_message_live_location.rs b/crates/teloxide-core/src/payloads/edit_message_live_location.rs index b8df0e5a..a3168fe9 100644 --- a/crates/teloxide-core/src/payloads/edit_message_live_location.rs +++ b/crates/teloxide-core/src/payloads/edit_message_live_location.rs @@ -30,7 +30,7 @@ impl_payload! { pub heading: u16, /// For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. pub proximity_alert_radius: u32, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/edit_message_live_location_inline.rs b/crates/teloxide-core/src/payloads/edit_message_live_location_inline.rs index e0f6e5e4..936c8994 100644 --- a/crates/teloxide-core/src/payloads/edit_message_live_location_inline.rs +++ b/crates/teloxide-core/src/payloads/edit_message_live_location_inline.rs @@ -27,7 +27,7 @@ impl_payload! { pub heading: u16, /// For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. pub proximity_alert_radius: u32, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_animation.rs b/crates/teloxide-core/src/payloads/send_animation.rs index 9670d5f0..44d6e593 100644 --- a/crates/teloxide-core/src/payloads/send_animation.rs +++ b/crates/teloxide-core/src/payloads/send_animation.rs @@ -54,7 +54,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_audio.rs b/crates/teloxide-core/src/payloads/send_audio.rs index e87ae0db..e382b7bf 100644 --- a/crates/teloxide-core/src/payloads/send_audio.rs +++ b/crates/teloxide-core/src/payloads/send_audio.rs @@ -55,7 +55,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_contact.rs b/crates/teloxide-core/src/payloads/send_contact.rs index 96c1ef2a..610615b8 100644 --- a/crates/teloxide-core/src/payloads/send_contact.rs +++ b/crates/teloxide-core/src/payloads/send_contact.rs @@ -37,7 +37,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_dice.rs b/crates/teloxide-core/src/payloads/send_dice.rs index ccb08e26..eeb05f89 100644 --- a/crates/teloxide-core/src/payloads/send_dice.rs +++ b/crates/teloxide-core/src/payloads/send_dice.rs @@ -29,7 +29,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_document.rs b/crates/teloxide-core/src/payloads/send_document.rs index b0925663..c8c04eee 100644 --- a/crates/teloxide-core/src/payloads/send_document.rs +++ b/crates/teloxide-core/src/payloads/send_document.rs @@ -48,7 +48,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_game.rs b/crates/teloxide-core/src/payloads/send_game.rs index 46888759..0bfe03e8 100644 --- a/crates/teloxide-core/src/payloads/send_game.rs +++ b/crates/teloxide-core/src/payloads/send_game.rs @@ -29,7 +29,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// A JSON-serialized object for an [inline keyboard]. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game. + /// A JSON-serialized object for an [inline keyboard]. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating pub reply_markup: ReplyMarkup [into], diff --git a/crates/teloxide-core/src/payloads/send_location.rs b/crates/teloxide-core/src/payloads/send_location.rs index e0b38b51..89ea1784 100644 --- a/crates/teloxide-core/src/payloads/send_location.rs +++ b/crates/teloxide-core/src/payloads/send_location.rs @@ -41,7 +41,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_message.rs b/crates/teloxide-core/src/payloads/send_message.rs index dbdc07cb..de72861e 100644 --- a/crates/teloxide-core/src/payloads/send_message.rs +++ b/crates/teloxide-core/src/payloads/send_message.rs @@ -40,7 +40,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_photo.rs b/crates/teloxide-core/src/payloads/send_photo.rs index 2091761e..37522c08 100644 --- a/crates/teloxide-core/src/payloads/send_photo.rs +++ b/crates/teloxide-core/src/payloads/send_photo.rs @@ -44,7 +44,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_poll.rs b/crates/teloxide-core/src/payloads/send_poll.rs index 642a1755..f696b36a 100644 --- a/crates/teloxide-core/src/payloads/send_poll.rs +++ b/crates/teloxide-core/src/payloads/send_poll.rs @@ -58,7 +58,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_sticker.rs b/crates/teloxide-core/src/payloads/send_sticker.rs index 10492701..b5562d40 100644 --- a/crates/teloxide-core/src/payloads/send_sticker.rs +++ b/crates/teloxide-core/src/payloads/send_sticker.rs @@ -34,7 +34,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_venue.rs b/crates/teloxide-core/src/payloads/send_venue.rs index 994d1eb3..117ccd9b 100644 --- a/crates/teloxide-core/src/payloads/send_venue.rs +++ b/crates/teloxide-core/src/payloads/send_venue.rs @@ -45,7 +45,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_video.rs b/crates/teloxide-core/src/payloads/send_video.rs index a3edd504..862d43df 100644 --- a/crates/teloxide-core/src/payloads/send_video.rs +++ b/crates/teloxide-core/src/payloads/send_video.rs @@ -57,7 +57,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_video_note.rs b/crates/teloxide-core/src/payloads/send_video_note.rs index a038b0ff..26231fc3 100644 --- a/crates/teloxide-core/src/payloads/send_video_note.rs +++ b/crates/teloxide-core/src/payloads/send_video_note.rs @@ -41,7 +41,7 @@ impl_payload! { pub protect_content: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/send_voice.rs b/crates/teloxide-core/src/payloads/send_voice.rs index 76382829..8db5230a 100644 --- a/crates/teloxide-core/src/payloads/send_voice.rs +++ b/crates/teloxide-core/src/payloads/send_voice.rs @@ -44,7 +44,7 @@ impl_payload! { pub disable_notification: bool, /// Description of the message to reply to pub reply_parameters: ReplyParameters, - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/stop_message_live_location.rs b/crates/teloxide-core/src/payloads/stop_message_live_location.rs index 7e2a312c..28d5c9b7 100644 --- a/crates/teloxide-core/src/payloads/stop_message_live_location.rs +++ b/crates/teloxide-core/src/payloads/stop_message_live_location.rs @@ -21,7 +21,7 @@ impl_payload! { pub message_id: MessageId, } optional { - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/stop_message_live_location_inline.rs b/crates/teloxide-core/src/payloads/stop_message_live_location_inline.rs index fdc7543c..c932f5f6 100644 --- a/crates/teloxide-core/src/payloads/stop_message_live_location_inline.rs +++ b/crates/teloxide-core/src/payloads/stop_message_live_location_inline.rs @@ -17,7 +17,7 @@ impl_payload! { pub inline_message_id: String [into], } optional { - /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove reply keyboard or to force a reply from the user. + /// Additional interface options. A JSON-serialized object for an [inline keyboard], [custom reply keyboard], instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account. /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards diff --git a/crates/teloxide-core/src/payloads/upload_sticker_file.rs b/crates/teloxide-core/src/payloads/upload_sticker_file.rs index ef00a015..d3adc35f 100644 --- a/crates/teloxide-core/src/payloads/upload_sticker_file.rs +++ b/crates/teloxide-core/src/payloads/upload_sticker_file.rs @@ -6,10 +6,11 @@ use crate::types::{FileMeta, InputFile, StickerFormat, UserId}; impl_payload! { @[multipart = sticker] - /// Use this method to upload a file with a sticker for later use in the [CreateNewStickerSet] and [AddStickerToSet] methods (the file can be used multiple times). Returns the uploaded [`File`] on success. + /// Use this method to upload a file with a sticker for later use in the [CreateNewStickerSet], [AddStickerToSet] or [ReplaceStickerInSet] methods (the file can be used multiple times). Returns the uploaded [`File`] on success. /// /// [CreateNewStickerSet]: https://docs.rs/teloxide/latest/teloxide/payloads/struct.CreateNewStickerSet.html /// [AddStickerToSet]: https://docs.rs/teloxide/latest/teloxide/payloads/struct.AddStickerToSet.html + /// [ReplaceStickerInSet]: https://docs.rs/teloxide/latest/teloxide/payloads/struct.ReplaceStickerInSet.html /// [`File`]: crate::types::File #[derive(Debug, Clone, Serialize)] pub UploadStickerFile (UploadStickerFileSetters) => FileMeta { diff --git a/crates/teloxide-core/src/types/birthdate.rs b/crates/teloxide-core/src/types/birthdate.rs index 8454b820..1c7ba65b 100644 --- a/crates/teloxide-core/src/types/birthdate.rs +++ b/crates/teloxide-core/src/types/birthdate.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; /// Describes the birthdate of a user. -/// -/// [The official docs](https://core.telegram.org/bots/api#birthdate) #[serde_with::skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Birthdate { @@ -12,6 +10,6 @@ pub struct Birthdate { /// Month of the user's birth; 1-12 pub month: u8, - /// Optional. Year of the user's birth + /// Year of the user's birth pub year: Option, } diff --git a/crates/teloxide-core/src/types/business_connection.rs b/crates/teloxide-core/src/types/business_connection.rs index 466e3c3c..69ef1f9b 100644 --- a/crates/teloxide-core/src/types/business_connection.rs +++ b/crates/teloxide-core/src/types/business_connection.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::types::{User, UserId}; +/// Describes the connection of the bot with a business account. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessConnection { /// Unique identifier of the business connection diff --git a/crates/teloxide-core/src/types/business_messages_deleted.rs b/crates/teloxide-core/src/types/business_messages_deleted.rs index 9bb3245b..f6d699a0 100644 --- a/crates/teloxide-core/src/types/business_messages_deleted.rs +++ b/crates/teloxide-core/src/types/business_messages_deleted.rs @@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::types::{Chat, MessageId}; +/// This object is received when messages are deleted from a connected business +/// account. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessMessagesDeleted { /// Unique identifier of the business connection. diff --git a/crates/teloxide-core/src/types/reply_parameters.rs b/crates/teloxide-core/src/types/reply_parameters.rs index 794c4896..6baa8ed9 100644 --- a/crates/teloxide-core/src/types/reply_parameters.rs +++ b/crates/teloxide-core/src/types/reply_parameters.rs @@ -13,11 +13,14 @@ pub struct ReplyParameters { pub message_id: MessageId, /// If the message to be replied to is from a different chat, unique /// identifier for the chat or username of the channel (in the format - /// `@channelusername`) + /// `@channelusername`). Not supported for messages sent on behalf of a + /// business account. pub chat_id: Option, /// Pass _true_ if the message should be sent even if the specified message /// to be replied to is not found; can be used only for replies in the - /// same chat and forum topic. + /// same chat and forum topic. Always `false` for replies in another chat or + /// forum topic. Always `true` for messages sent on behalf of a business + /// account. pub allow_sending_without_reply: Option, /// Quoted part of the message to be replied to; 0-1024 characters after /// entities parsing. The quote must be an exact substring of the message to From 2f8e62f401e0d77fd203d9ca25f40d0c1c70b3ad Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Thu, 22 Aug 2024 23:47:20 +0530 Subject: [PATCH 36/46] Use `BusinessConnectionId` instead of `String` for `business_connection_id` fields and parameters --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide-core/schema.ron | 36 ++++++++-------- crates/teloxide-core/src/adaptors/erased.rs | 4 +- crates/teloxide-core/src/bot/api.rs | 13 +++--- crates/teloxide-core/src/local_macros.rs | 4 +- .../src/payloads/get_business_connection.rs | 4 +- .../src/payloads/send_animation.rs | 5 ++- .../teloxide-core/src/payloads/send_audio.rs | 5 ++- .../src/payloads/send_chat_action.rs | 4 +- .../src/payloads/send_contact.rs | 6 ++- .../teloxide-core/src/payloads/send_dice.rs | 6 ++- .../src/payloads/send_document.rs | 5 ++- .../teloxide-core/src/payloads/send_game.rs | 4 +- .../src/payloads/send_location.rs | 6 ++- .../src/payloads/send_media_group.rs | 6 ++- .../src/payloads/send_message.rs | 6 +-- .../teloxide-core/src/payloads/send_photo.rs | 5 ++- .../teloxide-core/src/payloads/send_poll.rs | 5 ++- .../src/payloads/send_sticker.rs | 6 ++- .../teloxide-core/src/payloads/send_venue.rs | 6 ++- .../teloxide-core/src/payloads/send_video.rs | 5 ++- .../src/payloads/send_video_note.rs | 6 ++- .../teloxide-core/src/payloads/send_voice.rs | 5 ++- .../teloxide-core/src/requests/requester.rs | 7 ++-- crates/teloxide-core/src/types.rs | 2 + .../src/types/business_connection_id.rs | 42 +++++++++++++++++++ .../src/types/business_messages_deleted.rs | 4 +- crates/teloxide-core/src/types/message.rs | 10 ++--- 28 files changed, 143 insertions(+), 75 deletions(-) create mode 100644 crates/teloxide-core/src/types/business_connection_id.rs diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 3b58ef53..8f49c123 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `title`, `username` and `photo` fields to `ChatShared` struct - Add `format` field to `InputSticker` struct - Add `format` parameter to `SetStickerSetThumbnail` method + - Add `BusinessConnectionId` struct - Add `business_connection_id` parameter to `SendMessage`, `SendPhoto`, `SendVideo`, `SendAnimation`, `SendAudio`, `SendDocument`, `SendSticker`, `SendVideoNote`, `SendVoice`, `SendLocation`, `SendVenue`, `SendContact`, `SendPoll`, `SendDice`, `SendGame`, and `SendMediaGroup` methods - Add `sender_business_bot` and `business_connection_id` fields to `Message` struct - Add `BusinessIntro` struct and corresponding field `business_intro` to `ChatPrivate` struct diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index ab9fc046..afa35a50 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -226,7 +226,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -527,7 +527,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -617,7 +617,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -722,7 +722,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -820,7 +820,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -936,7 +936,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1050,7 +1050,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1135,7 +1135,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1218,7 +1218,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1268,7 +1268,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1536,7 +1536,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1635,7 +1635,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1714,7 +1714,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1833,7 +1833,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -1894,7 +1894,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the action will be sent"), ), Param( @@ -3061,7 +3061,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: String, + ty: RawTy("BusinessConnectionId"), descr: Doc(md: "Unique identifier of the business connection"), ), ], @@ -3728,7 +3728,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( @@ -4490,7 +4490,7 @@ Schema( params: [ Param( name: "business_connection_id", - ty: Option(String), + ty: Option(RawTy("BusinessConnectionId")), descr: Doc(md: "Unique identifier of the business connection on behalf of which the message will be sent"), ), Param( diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index 1785ccf7..e813300a 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -754,7 +754,7 @@ trait ErasableRequester<'a> { fn get_business_connection( &self, - business_connection_id: String, + business_connection_id: BusinessConnectionId, ) -> ErasedRequest<'a, GetBusinessConnection, Self::Err>; fn get_my_commands(&self) -> ErasedRequest<'a, GetMyCommands, Self::Err>; @@ -1619,7 +1619,7 @@ where fn get_business_connection( &self, - business_connection_id: String, + business_connection_id: BusinessConnectionId, ) -> ErasedRequest<'a, GetBusinessConnection, Self::Err> { Requester::get_business_connection(self, business_connection_id).erase() } diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 79c79cbb..4305505c 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -5,8 +5,9 @@ use crate::{ prelude::Requester, requests::{JsonRequest, MultipartRequest}, types::{ - BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, MessageId, Recipient, StickerFormat, ThreadId, UserId, + BotCommand, BusinessConnectionId, ChatId, ChatPermissions, InlineQueryResult, InputFile, + InputMedia, InputSticker, LabeledPrice, MessageId, Recipient, StickerFormat, ThreadId, + UserId, }, Bot, }; @@ -883,10 +884,10 @@ impl Requester for Bot { type GetBusinessConnection = JsonRequest; - fn get_business_connection(&self, business_connection_id: B) -> Self::GetBusinessConnection - where - B: Into, - { + fn get_business_connection( + &self, + business_connection_id: BusinessConnectionId, + ) -> Self::GetBusinessConnection { Self::GetBusinessConnection::new( self.clone(), payloads::GetBusinessConnection::new(business_connection_id), diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 43e97e36..db71eea2 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -1072,9 +1072,9 @@ macro_rules! requester_forward { (@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 { + fn get_business_connection(&self, business_connection_id: BusinessConnectionId) -> Self::GetBusinessConnection { let this = self; - $body!(get_business_connection this (business_connection_id: BCI)) + $body!(get_business_connection this (business_connection_id: BusinessConnectionId)) } }; (@method get_my_commands $body:ident $ty:ident) => { diff --git a/crates/teloxide-core/src/payloads/get_business_connection.rs b/crates/teloxide-core/src/payloads/get_business_connection.rs index 8bab06d6..1ae65748 100644 --- a/crates/teloxide-core/src/payloads/get_business_connection.rs +++ b/crates/teloxide-core/src/payloads/get_business_connection.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::BusinessConnection; +use crate::types::{BusinessConnection, BusinessConnectionId}; impl_payload! { /// Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success. @@ -10,7 +10,7 @@ impl_payload! { pub GetBusinessConnection (GetBusinessConnectionSetters) => BusinessConnection { required { /// Unique identifier of the business connection - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, } } } diff --git a/crates/teloxide-core/src/payloads/send_animation.rs b/crates/teloxide-core/src/payloads/send_animation.rs index 44d6e593..d1fd7758 100644 --- a/crates/teloxide-core/src/payloads/send_animation.rs +++ b/crates/teloxide-core/src/payloads/send_animation.rs @@ -3,7 +3,8 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -23,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Duration of the animation in seconds diff --git a/crates/teloxide-core/src/payloads/send_audio.rs b/crates/teloxide-core/src/payloads/send_audio.rs index e382b7bf..1b0829eb 100644 --- a/crates/teloxide-core/src/payloads/send_audio.rs +++ b/crates/teloxide-core/src/payloads/send_audio.rs @@ -3,7 +3,8 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -26,7 +27,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Audio caption, 0-1024 characters after entities parsing diff --git a/crates/teloxide-core/src/payloads/send_chat_action.rs b/crates/teloxide-core/src/payloads/send_chat_action.rs index e5f39806..898a84e3 100644 --- a/crates/teloxide-core/src/payloads/send_chat_action.rs +++ b/crates/teloxide-core/src/payloads/send_chat_action.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{ChatAction, Recipient, ThreadId, True}; +use crate::types::{BusinessConnectionId, ChatAction, Recipient, ThreadId, True}; impl_payload! { /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. @@ -31,7 +31,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the action will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread; supergroups only pub message_thread_id: ThreadId, } diff --git a/crates/teloxide-core/src/payloads/send_contact.rs b/crates/teloxide-core/src/payloads/send_contact.rs index 610615b8..7f395d5d 100644 --- a/crates/teloxide-core/src/payloads/send_contact.rs +++ b/crates/teloxide-core/src/payloads/send_contact.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId, +}; impl_payload! { /// Use this method to send phone contacts. On success, the sent [`Message`] is returned. @@ -20,7 +22,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Contact's last name diff --git a/crates/teloxide-core/src/payloads/send_dice.rs b/crates/teloxide-core/src/payloads/send_dice.rs index eeb05f89..069a9507 100644 --- a/crates/teloxide-core/src/payloads/send_dice.rs +++ b/crates/teloxide-core/src/payloads/send_dice.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{DiceEmoji, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, DiceEmoji, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId, +}; impl_payload! { /// Use this method to send an animated emoji that will display a random value. On success, the sent [`Message`] is returned. @@ -16,7 +18,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Emoji on which the dice throw animation is based. Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, β€œπŸŽ³β€, or β€œπŸŽ°β€. Dice can have values 1-6 for β€œπŸŽ²β€, β€œπŸŽ―β€ and β€œπŸŽ³β€, values 1-5 for β€œπŸ€β€ and β€œβš½β€, and values 1-64 for β€œπŸŽ°β€. Defaults to β€œπŸŽ²β€ diff --git a/crates/teloxide-core/src/payloads/send_document.rs b/crates/teloxide-core/src/payloads/send_document.rs index c8c04eee..43e6f7d1 100644 --- a/crates/teloxide-core/src/payloads/send_document.rs +++ b/crates/teloxide-core/src/payloads/send_document.rs @@ -3,7 +3,8 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -23,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass β€œattach://” if the thumbnail was uploaded using multipart/form-data under . [More info on Sending Files Β»] diff --git a/crates/teloxide-core/src/payloads/send_game.rs b/crates/teloxide-core/src/payloads/send_game.rs index 0bfe03e8..413e57ba 100644 --- a/crates/teloxide-core/src/payloads/send_game.rs +++ b/crates/teloxide-core/src/payloads/send_game.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{ChatId, Message, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{BusinessConnectionId, ChatId, Message, ReplyMarkup, ReplyParameters, ThreadId}; impl_payload! { /// Use this method to send a game. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. diff --git a/crates/teloxide-core/src/payloads/send_location.rs b/crates/teloxide-core/src/payloads/send_location.rs index 89ea1784..03094933 100644 --- a/crates/teloxide-core/src/payloads/send_location.rs +++ b/crates/teloxide-core/src/payloads/send_location.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId, +}; impl_payload! { /// Use this method to send point on the map. On success, the sent [`Message`] is returned. @@ -20,7 +22,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// The radius of uncertainty for the location, measured in meters; 0-1500 diff --git a/crates/teloxide-core/src/payloads/send_media_group.rs b/crates/teloxide-core/src/payloads/send_media_group.rs index 428a4951..ab5782a1 100644 --- a/crates/teloxide-core/src/payloads/send_media_group.rs +++ b/crates/teloxide-core/src/payloads/send_media_group.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{InputMedia, Message, Recipient, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, InputMedia, Message, Recipient, ReplyParameters, ThreadId, +}; impl_payload! { /// Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of [`Message`]s that were sent is returned. @@ -27,7 +29,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Sends the message [silently]. Users will receive a notification with no sound. diff --git a/crates/teloxide-core/src/payloads/send_message.rs b/crates/teloxide-core/src/payloads/send_message.rs index de72861e..46d1c616 100644 --- a/crates/teloxide-core/src/payloads/send_message.rs +++ b/crates/teloxide-core/src/payloads/send_message.rs @@ -3,8 +3,8 @@ use serde::Serialize; use crate::types::{ - LinkPreviewOptions, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, - ThreadId, + BusinessConnectionId, LinkPreviewOptions, Message, MessageEntity, ParseMode, Recipient, + ReplyMarkup, ReplyParameters, ThreadId, }; impl_payload! { @@ -21,7 +21,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Mode for parsing entities in the message text. See [formatting options] for more details. diff --git a/crates/teloxide-core/src/payloads/send_photo.rs b/crates/teloxide-core/src/payloads/send_photo.rs index 37522c08..037c3935 100644 --- a/crates/teloxide-core/src/payloads/send_photo.rs +++ b/crates/teloxide-core/src/payloads/send_photo.rs @@ -3,7 +3,8 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -23,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Photo caption (may also be used when resending photos by _file\_id_), 0-1024 characters after entities parsing diff --git a/crates/teloxide-core/src/payloads/send_poll.rs b/crates/teloxide-core/src/payloads/send_poll.rs index f696b36a..4704cc60 100644 --- a/crates/teloxide-core/src/payloads/send_poll.rs +++ b/crates/teloxide-core/src/payloads/send_poll.rs @@ -4,7 +4,8 @@ use chrono::{DateTime, Utc}; use serde::Serialize; use crate::types::{ - Message, MessageEntity, ParseMode, PollType, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, Message, MessageEntity, ParseMode, PollType, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -23,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// True, if the poll needs to be anonymous, defaults to True diff --git a/crates/teloxide-core/src/payloads/send_sticker.rs b/crates/teloxide-core/src/payloads/send_sticker.rs index b5562d40..754615e4 100644 --- a/crates/teloxide-core/src/payloads/send_sticker.rs +++ b/crates/teloxide-core/src/payloads/send_sticker.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{InputFile, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, InputFile, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId, +}; impl_payload! { @[multipart = sticker] @@ -21,7 +23,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Emoji associated with the sticker; only for just uploaded stickers diff --git a/crates/teloxide-core/src/payloads/send_venue.rs b/crates/teloxide-core/src/payloads/send_venue.rs index 117ccd9b..e9629e39 100644 --- a/crates/teloxide-core/src/payloads/send_venue.rs +++ b/crates/teloxide-core/src/payloads/send_venue.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId, +}; impl_payload! { /// Use this method to send information about a venue. On success, the sent [`Message`] is returned. @@ -24,7 +26,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Foursquare identifier of the venue diff --git a/crates/teloxide-core/src/payloads/send_video.rs b/crates/teloxide-core/src/payloads/send_video.rs index 862d43df..c4de05f1 100644 --- a/crates/teloxide-core/src/payloads/send_video.rs +++ b/crates/teloxide-core/src/payloads/send_video.rs @@ -3,7 +3,8 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -24,7 +25,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Duration of the video in seconds diff --git a/crates/teloxide-core/src/payloads/send_video_note.rs b/crates/teloxide-core/src/payloads/send_video_note.rs index 26231fc3..72c1e60b 100644 --- a/crates/teloxide-core/src/payloads/send_video_note.rs +++ b/crates/teloxide-core/src/payloads/send_video_note.rs @@ -2,7 +2,9 @@ use serde::Serialize; -use crate::types::{InputFile, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId}; +use crate::types::{ + BusinessConnectionId, InputFile, Message, Recipient, ReplyMarkup, ReplyParameters, ThreadId, +}; impl_payload! { @[multipart = video_note, thumbnail] @@ -22,7 +24,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Duration of the video in seconds diff --git a/crates/teloxide-core/src/payloads/send_voice.rs b/crates/teloxide-core/src/payloads/send_voice.rs index 8db5230a..40b85c42 100644 --- a/crates/teloxide-core/src/payloads/send_voice.rs +++ b/crates/teloxide-core/src/payloads/send_voice.rs @@ -3,7 +3,8 @@ use serde::Serialize; use crate::types::{ - InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, ReplyParameters, ThreadId, + BusinessConnectionId, InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup, + ReplyParameters, ThreadId, }; impl_payload! { @@ -25,7 +26,7 @@ impl_payload! { } optional { /// Unique identifier of the business connection on behalf of which the message will be sent - pub business_connection_id: String [into], + pub business_connection_id: BusinessConnectionId, /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, /// Voice message caption, 0-1024 characters after entities parsing diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 3fdfc7d2..7e34161a 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -834,9 +834,10 @@ pub trait Requester { type GetBusinessConnection: Request; /// For Telegram documentation see [`GetBusinessConnection`]. - fn get_business_connection(&self, business_connection_id: B) -> Self::GetBusinessConnection - where - B: Into; + fn get_business_connection( + &self, + business_connection_id: BusinessConnectionId, + ) -> Self::GetBusinessConnection; type GetMyCommands: Request; diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 3d3ef44a..c55477c7 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -10,6 +10,7 @@ pub use bot_description::*; pub use bot_name::*; pub use bot_short_description::*; pub use business_connection::*; +pub use business_connection_id::*; pub use business_intro::*; pub use business_location::*; pub use business_messages_deleted::*; @@ -171,6 +172,7 @@ mod bot_description; mod bot_name; mod bot_short_description; mod business_connection; +mod business_connection_id; mod business_intro; mod business_location; mod business_messages_deleted; diff --git a/crates/teloxide-core/src/types/business_connection_id.rs b/crates/teloxide-core/src/types/business_connection_id.rs new file mode 100644 index 00000000..982a3f66 --- /dev/null +++ b/crates/teloxide-core/src/types/business_connection_id.rs @@ -0,0 +1,42 @@ +use serde::{Deserialize, Serialize}; + +/// A unique business connection identifier. +#[derive(Default, Clone, Debug, derive_more::Display, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(from = "BusinessConnectionIdRaw", into = "BusinessConnectionIdRaw")] +pub struct BusinessConnectionId(pub String); + +#[derive(Serialize, Deserialize)] +struct BusinessConnectionIdRaw { + business_connection_id: String, +} + +impl From for BusinessConnectionId { + fn from(BusinessConnectionIdRaw { business_connection_id }: BusinessConnectionIdRaw) -> Self { + BusinessConnectionId(business_connection_id) + } +} + +impl From for BusinessConnectionIdRaw { + fn from(BusinessConnectionId(business_connection_id): BusinessConnectionId) -> Self { + BusinessConnectionIdRaw { business_connection_id } + } +} + +#[cfg(test)] +mod tests { + use crate::types::BusinessConnectionId; + + #[test] + fn business_connection_id_deser() { + let json = r#"{"business_connection_id": "abcd1234"}"#; + let bcid: BusinessConnectionId = serde_json::from_str(json).unwrap(); + assert_eq!(bcid, BusinessConnectionId(String::from("abcd1234"))); + } + + #[test] + fn business_connection_id_ser() { + let bcid: BusinessConnectionId = BusinessConnectionId(String::from("abcd1234")); + let json = serde_json::to_string(&bcid).unwrap(); + assert_eq!(json, r#"{"business_connection_id":"abcd1234"}"#); + } +} diff --git a/crates/teloxide-core/src/types/business_messages_deleted.rs b/crates/teloxide-core/src/types/business_messages_deleted.rs index f6d699a0..3c84daea 100644 --- a/crates/teloxide-core/src/types/business_messages_deleted.rs +++ b/crates/teloxide-core/src/types/business_messages_deleted.rs @@ -1,13 +1,13 @@ use serde::{Deserialize, Serialize}; -use crate::types::{Chat, MessageId}; +use crate::types::{BusinessConnectionId, Chat, MessageId}; /// This object is received when messages are deleted from a connected business /// account. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessMessagesDeleted { /// Unique identifier of the business connection. - pub business_connection_id: String, + pub business_connection_id: BusinessConnectionId, /// Information about a chat in the business account. The bot may not have /// access to the chat or the corresponding user. diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index cea0a3d1..23d67f63 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -5,10 +5,10 @@ use serde::{Deserialize, Serialize}; use url::Url; use crate::types::{ - Animation, Audio, BareChatId, Chat, ChatBoostAdded, ChatId, ChatShared, Contact, Dice, - Document, ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, - ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, - GiveawayCompleted, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, + Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBoostAdded, ChatId, ChatShared, + Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated, + ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, + Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, LinkPreviewOptions, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, TextQuote, ThreadId, True, User, @@ -63,7 +63,7 @@ pub struct Message { /// received. If non-empty, the message belongs to a chat of the /// corresponding business account that is independent from any potential /// bot chat which might share the same identifier. - pub business_connection_id: Option, + pub business_connection_id: Option, #[serde(flatten)] pub kind: MessageKind, From 31caa3ba048527e075702db3b309c449609a3cc2 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 12:59:19 +0530 Subject: [PATCH 37/46] Add more docs for business related structs --- crates/teloxide-core/src/types/business_intro.rs | 1 + crates/teloxide-core/src/types/business_location.rs | 1 + crates/teloxide-core/src/types/business_opening_hours.rs | 1 + .../teloxide-core/src/types/business_opening_hours_interval.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/crates/teloxide-core/src/types/business_intro.rs b/crates/teloxide-core/src/types/business_intro.rs index fbfd4b66..b4ce8694 100644 --- a/crates/teloxide-core/src/types/business_intro.rs +++ b/crates/teloxide-core/src/types/business_intro.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::types::Sticker; +/// An introduction for a Business. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessIntro { /// Title text of the business intro diff --git a/crates/teloxide-core/src/types/business_location.rs b/crates/teloxide-core/src/types/business_location.rs index 7eaee63d..7763a0de 100644 --- a/crates/teloxide-core/src/types/business_location.rs +++ b/crates/teloxide-core/src/types/business_location.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::types::Location; +/// Details about the location of a Business #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessLocation { /// Address of the business. diff --git a/crates/teloxide-core/src/types/business_opening_hours.rs b/crates/teloxide-core/src/types/business_opening_hours.rs index f149563a..0ebddbfe 100644 --- a/crates/teloxide-core/src/types/business_opening_hours.rs +++ b/crates/teloxide-core/src/types/business_opening_hours.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::types::BusinessOpeningHoursInterval; +/// Details about the opening hours of a Business. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessOpeningHours { /// Unique name of the time zone for which the opening hours are defined. diff --git a/crates/teloxide-core/src/types/business_opening_hours_interval.rs b/crates/teloxide-core/src/types/business_opening_hours_interval.rs index 0c7c1a61..3c966928 100644 --- a/crates/teloxide-core/src/types/business_opening_hours_interval.rs +++ b/crates/teloxide-core/src/types/business_opening_hours_interval.rs @@ -1,5 +1,6 @@ use serde::{Deserialize, Serialize}; +/// Time intervals used to describe the opening hours of a Business. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessOpeningHoursInterval { /// The minute's sequence number in a week, starting on Monday, marking the From ca5dddab54fa4930b5a6788c09c3480cc8ac0df0 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 13:10:05 +0530 Subject: [PATCH 38/46] Remove unecessary serde defaults and remove params from bool setters --- crates/teloxide-core/src/types/chat_shared.rs | 3 --- .../src/types/keyboard_button_request_chat.rs | 12 ++++++------ .../src/types/keyboard_button_request_users.rs | 12 ++++++------ crates/teloxide-core/src/types/shared_user.rs | 4 ---- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/crates/teloxide-core/src/types/chat_shared.rs b/crates/teloxide-core/src/types/chat_shared.rs index 3eeace53..4616190a 100644 --- a/crates/teloxide-core/src/types/chat_shared.rs +++ b/crates/teloxide-core/src/types/chat_shared.rs @@ -15,14 +15,11 @@ pub struct ChatShared { pub chat_id: ChatId, /// Title of the chat, if it was requested. - #[serde(default)] pub title: Option, /// Username of the chat, if it was requested. - #[serde(default)] pub username: Option, /// Available sizes of the chat photo, if it was requested. - #[serde(default)] pub photo: Option>, } diff --git a/crates/teloxide-core/src/types/keyboard_button_request_chat.rs b/crates/teloxide-core/src/types/keyboard_button_request_chat.rs index b1df9448..47f9c4a3 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_chat.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_chat.rs @@ -130,22 +130,22 @@ impl KeyboardButtonRequestChat { /// Setter for `request_title` field. #[must_use] - pub fn request_title(mut self, value: bool) -> Self { - self.request_title = value; + pub fn request_title(mut self) -> Self { + self.request_title = true; self } /// Setter for `request_username` field. #[must_use] - pub fn request_username(mut self, value: bool) -> Self { - self.request_username = value; + pub fn request_username(mut self) -> Self { + self.request_username = true; self } /// Setter for `request_photo` field. #[must_use] - pub fn request_photo(mut self, value: bool) -> Self { - self.request_photo = value; + pub fn request_photo(mut self) -> Self { + self.request_photo = true; self } } diff --git a/crates/teloxide-core/src/types/keyboard_button_request_users.rs b/crates/teloxide-core/src/types/keyboard_button_request_users.rs index ea14101a..ffad3e1f 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_users.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_users.rs @@ -83,22 +83,22 @@ impl KeyboardButtonRequestUsers { /// Setter for `request_name` field #[must_use] - pub fn request_name(mut self, value: bool) -> Self { - self.request_name = Some(value); + pub fn request_name(mut self) -> Self { + self.request_name = Some(true); self } /// Setter for `request_username` field #[must_use] - pub fn request_username(mut self, value: bool) -> Self { - self.request_username = Some(value); + pub fn request_username(mut self) -> Self { + self.request_username = Some(true); self } /// Setter for `request_photo` field #[must_use] - pub fn request_photo(mut self, value: bool) -> Self { - self.request_photo = Some(value); + pub fn request_photo(mut self) -> Self { + self.request_photo = Some(true); self } } diff --git a/crates/teloxide-core/src/types/shared_user.rs b/crates/teloxide-core/src/types/shared_user.rs index ad4028bf..bca2dcb9 100644 --- a/crates/teloxide-core/src/types/shared_user.rs +++ b/crates/teloxide-core/src/types/shared_user.rs @@ -12,18 +12,14 @@ pub struct SharedUser { pub user_id: UserId, /// First name of the user, if it was requested by the bot - #[serde(default)] pub first_name: Option, /// Last name of the user, if it was requested by the bot - #[serde(default)] pub last_name: Option, /// Username of the user, if it was requested by the bot - #[serde(default)] pub username: Option, /// Available sizes of the chat photo, if it was requested - #[serde(default)] pub photo: Option>, } From 21b164a4162cfc1d1422e09c17d494ed57c0be46 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 13:14:38 +0530 Subject: [PATCH 39/46] Change some Option fields to bool in `KeyboardButtonRequestUsers` --- .../types/keyboard_button_request_users.rs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/teloxide-core/src/types/keyboard_button_request_users.rs b/crates/teloxide-core/src/types/keyboard_button_request_users.rs index ffad3e1f..8c38b831 100644 --- a/crates/teloxide-core/src/types/keyboard_button_request_users.rs +++ b/crates/teloxide-core/src/types/keyboard_button_request_users.rs @@ -32,16 +32,16 @@ pub struct KeyboardButtonRequestUsers { pub max_quantity: u8, /// Pass `true` to request the users' first and last names - #[serde(default, skip_serializing_if = "Option::is_none")] - pub request_name: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub request_name: bool, /// Pass `true` to request the users' username - #[serde(default, skip_serializing_if = "Option::is_none")] - pub request_username: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub request_username: bool, /// Pass `true` to request the users' photos - #[serde(default, skip_serializing_if = "Option::is_none")] - pub request_photo: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub request_photo: bool, } impl KeyboardButtonRequestUsers { @@ -52,9 +52,9 @@ impl KeyboardButtonRequestUsers { user_is_bot: None, user_is_premium: None, max_quantity: 1, - request_name: None, - request_username: None, - request_photo: None, + request_name: false, + request_username: false, + request_photo: false, } } @@ -84,21 +84,21 @@ impl KeyboardButtonRequestUsers { /// Setter for `request_name` field #[must_use] pub fn request_name(mut self) -> Self { - self.request_name = Some(true); + self.request_name = true; self } /// Setter for `request_username` field #[must_use] pub fn request_username(mut self) -> Self { - self.request_username = Some(true); + self.request_username = true; self } /// Setter for `request_photo` field #[must_use] pub fn request_photo(mut self) -> Self { - self.request_photo = Some(true); + self.request_photo = true; self } } From cef553eeae08e2adabca4c7d90bc7406e3e890d3 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 13:16:46 +0530 Subject: [PATCH 40/46] Add serde default to `can_connect_to_business` in `Me` --- crates/teloxide-core/src/types/me.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/teloxide-core/src/types/me.rs b/crates/teloxide-core/src/types/me.rs index d0cb8287..f404d438 100644 --- a/crates/teloxide-core/src/types/me.rs +++ b/crates/teloxide-core/src/types/me.rs @@ -26,6 +26,7 @@ pub struct Me { /// `true`, if the bot can be connected to a Telegram Business account to /// receive its messages. + #[serde(default)] pub can_connect_to_business: bool, } From 08d7d8f6b4195fae8a43414809ce24cf493b4c61 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 13:25:15 +0530 Subject: [PATCH 41/46] Move `business_connection_id` from `Message` to `MessageCommon` --- crates/teloxide-core/src/types/message.rs | 14 ++++++-------- crates/teloxide-core/src/types/update.rs | 2 +- crates/teloxide/src/dispatching/handler_ext.rs | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 23d67f63..2b2ce6e2 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -59,12 +59,6 @@ pub struct Message { /// connected business account. pub sender_business_bot: Option, - /// Unique identifier of the business connection from which the message was - /// received. If non-empty, the message belongs to a chat of the - /// corresponding business account that is independent from any potential - /// bot chat which might share the same identifier. - pub business_connection_id: Option, - #[serde(flatten)] pub kind: MessageKind, } @@ -170,6 +164,12 @@ pub struct MessageCommon { /// an away or a greeting business message, or as a scheduled message #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub is_from_offline: bool, + + /// Unique identifier of the business connection from which the message was + /// received. If non-empty, the message belongs to a chat of the + /// corresponding business account that is independent from any potential + /// bot chat which might share the same identifier. + pub business_connection_id: Option, } #[serde_with::skip_serializing_none] @@ -1917,7 +1917,6 @@ mod tests { chat_full_info: ChatFullInfo::default() }, sender_business_bot: None, - business_connection_id: None, kind: MessageKind::ChatShared(MessageChatShared { chat_shared: ChatShared { request_id: RequestId(348349), @@ -2590,7 +2589,6 @@ mod tests { }, via_bot: None, sender_business_bot: None, - business_connection_id: None, kind: MessageKind::Giveaway(MessageGiveaway { giveaway: Giveaway { chats: vec![Chat { diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 6af03fba..b6707c2b 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -609,7 +609,6 @@ mod test { chat_full_info: ChatFullInfo::default(), }, sender_business_bot: None, - business_connection_id: None, kind: MessageKind::Common(MessageCommon { reply_to_message: None, forward_origin: None, @@ -634,6 +633,7 @@ mod test { is_automatic_forward: false, has_protected_content: false, is_from_offline: false, + business_connection_id: None, }), }), }; diff --git a/crates/teloxide/src/dispatching/handler_ext.rs b/crates/teloxide/src/dispatching/handler_ext.rs index ae59c76f..d45c29f1 100644 --- a/crates/teloxide/src/dispatching/handler_ext.rs +++ b/crates/teloxide/src/dispatching/handler_ext.rs @@ -190,7 +190,6 @@ mod tests { sender_chat: None, is_topic_message: false, sender_business_bot: None, - business_connection_id: None, date, chat: Chat { id: ChatId(109_998_024), @@ -239,6 +238,7 @@ mod tests { reply_to_story: None, sender_boost_count: None, is_from_offline: false, + business_connection_id: None, }), }), } From 951c8f1438aa63d52580acce44325ddd39183839 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 13:39:05 +0530 Subject: [PATCH 42/46] Derive Default for `BusinessIntro`, `BusinessLocation` and `BusinessOpeningHours` --- crates/teloxide-core/src/types/business_intro.rs | 2 +- crates/teloxide-core/src/types/business_location.rs | 2 +- crates/teloxide-core/src/types/business_opening_hours.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/src/types/business_intro.rs b/crates/teloxide-core/src/types/business_intro.rs index b4ce8694..c4684211 100644 --- a/crates/teloxide-core/src/types/business_intro.rs +++ b/crates/teloxide-core/src/types/business_intro.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::types::Sticker; /// An introduction for a Business. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct BusinessIntro { /// Title text of the business intro pub title: Option, diff --git a/crates/teloxide-core/src/types/business_location.rs b/crates/teloxide-core/src/types/business_location.rs index 7763a0de..514fe581 100644 --- a/crates/teloxide-core/src/types/business_location.rs +++ b/crates/teloxide-core/src/types/business_location.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::types::Location; /// Details about the location of a Business -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct BusinessLocation { /// Address of the business. pub address: String, diff --git a/crates/teloxide-core/src/types/business_opening_hours.rs b/crates/teloxide-core/src/types/business_opening_hours.rs index 0ebddbfe..f6bac2b9 100644 --- a/crates/teloxide-core/src/types/business_opening_hours.rs +++ b/crates/teloxide-core/src/types/business_opening_hours.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::types::BusinessOpeningHoursInterval; /// Details about the opening hours of a Business. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct BusinessOpeningHours { /// Unique name of the time zone for which the opening hours are defined. pub time_zone_name: String, From 17b3807d3fd02da14e6141b6470e07a5f30316ea Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 15:29:52 +0530 Subject: [PATCH 43/46] Use serde(flatten) for `BusinessConnectionId` --- .../src/types/business_connection_id.rs | 22 ++----------------- .../src/types/business_messages_deleted.rs | 1 + crates/teloxide-core/src/types/message.rs | 1 + crates/teloxide-core/src/types/update.rs | 4 ++-- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/crates/teloxide-core/src/types/business_connection_id.rs b/crates/teloxide-core/src/types/business_connection_id.rs index 982a3f66..672caddf 100644 --- a/crates/teloxide-core/src/types/business_connection_id.rs +++ b/crates/teloxide-core/src/types/business_connection_id.rs @@ -2,33 +2,15 @@ use serde::{Deserialize, Serialize}; /// A unique business connection identifier. #[derive(Default, Clone, Debug, derive_more::Display, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(from = "BusinessConnectionIdRaw", into = "BusinessConnectionIdRaw")] pub struct BusinessConnectionId(pub String); -#[derive(Serialize, Deserialize)] -struct BusinessConnectionIdRaw { - business_connection_id: String, -} - -impl From for BusinessConnectionId { - fn from(BusinessConnectionIdRaw { business_connection_id }: BusinessConnectionIdRaw) -> Self { - BusinessConnectionId(business_connection_id) - } -} - -impl From for BusinessConnectionIdRaw { - fn from(BusinessConnectionId(business_connection_id): BusinessConnectionId) -> Self { - BusinessConnectionIdRaw { business_connection_id } - } -} - #[cfg(test)] mod tests { use crate::types::BusinessConnectionId; #[test] fn business_connection_id_deser() { - let json = r#"{"business_connection_id": "abcd1234"}"#; + let json = r#""abcd1234""#; let bcid: BusinessConnectionId = serde_json::from_str(json).unwrap(); assert_eq!(bcid, BusinessConnectionId(String::from("abcd1234"))); } @@ -37,6 +19,6 @@ mod tests { fn business_connection_id_ser() { let bcid: BusinessConnectionId = BusinessConnectionId(String::from("abcd1234")); let json = serde_json::to_string(&bcid).unwrap(); - assert_eq!(json, r#"{"business_connection_id":"abcd1234"}"#); + assert_eq!(json, r#""abcd1234""#); } } diff --git a/crates/teloxide-core/src/types/business_messages_deleted.rs b/crates/teloxide-core/src/types/business_messages_deleted.rs index 3c84daea..ec5a6b4d 100644 --- a/crates/teloxide-core/src/types/business_messages_deleted.rs +++ b/crates/teloxide-core/src/types/business_messages_deleted.rs @@ -7,6 +7,7 @@ use crate::types::{BusinessConnectionId, Chat, MessageId}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessMessagesDeleted { /// Unique identifier of the business connection. + #[serde(flatten)] pub business_connection_id: BusinessConnectionId, /// Information about a chat in the business account. The bot may not have diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 2b2ce6e2..95a6d615 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -169,6 +169,7 @@ pub struct MessageCommon { /// received. If non-empty, the message belongs to a chat of the /// corresponding business account that is independent from any potential /// bot chat which might share the same identifier. + #[serde(flatten)] pub business_connection_id: Option, } diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index b6707c2b..dd06de27 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -1007,7 +1007,7 @@ mod test { "#; let chat = Chat { id: ChatId(-1002199793788), - kind: ChatKind::Public(ChatPublic { + kind: ChatKind::Public(Box::new(ChatPublic { title: Some("тСст".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { username: None, @@ -1027,7 +1027,7 @@ mod test { description: None, invite_link: None, has_protected_content: None, - }), + })), photo: None, available_reactions: None, pinned_message: None, From e10af95add70114f96631fd5ae4218333b43ad2d Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 15:36:55 +0530 Subject: [PATCH 44/46] Mark `BusinessConnectionId` as serde(transparent) --- crates/teloxide-core/src/types/business_connection_id.rs | 1 + crates/teloxide-core/src/types/business_messages_deleted.rs | 1 - crates/teloxide-core/src/types/message.rs | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/teloxide-core/src/types/business_connection_id.rs b/crates/teloxide-core/src/types/business_connection_id.rs index 672caddf..263e2c02 100644 --- a/crates/teloxide-core/src/types/business_connection_id.rs +++ b/crates/teloxide-core/src/types/business_connection_id.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; /// A unique business connection identifier. #[derive(Default, Clone, Debug, derive_more::Display, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(transparent)] pub struct BusinessConnectionId(pub String); #[cfg(test)] diff --git a/crates/teloxide-core/src/types/business_messages_deleted.rs b/crates/teloxide-core/src/types/business_messages_deleted.rs index ec5a6b4d..3c84daea 100644 --- a/crates/teloxide-core/src/types/business_messages_deleted.rs +++ b/crates/teloxide-core/src/types/business_messages_deleted.rs @@ -7,7 +7,6 @@ use crate::types::{BusinessConnectionId, Chat, MessageId}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessMessagesDeleted { /// Unique identifier of the business connection. - #[serde(flatten)] pub business_connection_id: BusinessConnectionId, /// Information about a chat in the business account. The bot may not have diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 95a6d615..2b2ce6e2 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -169,7 +169,6 @@ pub struct MessageCommon { /// received. If non-empty, the message belongs to a chat of the /// corresponding business account that is independent from any potential /// bot chat which might share the same identifier. - #[serde(flatten)] pub business_connection_id: Option, } From f4fc11a011d2cabbd4de907a0de3e1b92d566711 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 16:02:42 +0530 Subject: [PATCH 45/46] Change `id` type in `BusinessConnection` to `BusinessConnectionId` --- crates/teloxide-core/src/types/business_connection.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/teloxide-core/src/types/business_connection.rs b/crates/teloxide-core/src/types/business_connection.rs index 69ef1f9b..5b620d9b 100644 --- a/crates/teloxide-core/src/types/business_connection.rs +++ b/crates/teloxide-core/src/types/business_connection.rs @@ -1,13 +1,13 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use crate::types::{User, UserId}; +use crate::types::{BusinessConnectionId, User, UserId}; /// Describes the connection of the bot with a business account. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct BusinessConnection { /// Unique identifier of the business connection - pub id: String, + pub id: BusinessConnectionId, /// Business account user that created the business connection pub user: User, From 32de39602df6d4de80df8bc824ac3f069fe46047 Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Sat, 24 Aug 2024 16:03:10 +0530 Subject: [PATCH 46/46] Fix unstructured docs --- crates/teloxide-core/CHANGELOG.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 8f49c123..3198fadc 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -42,28 +42,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `BusinessMessagesDeleted` struct - Add `BusinessConnection`, `BusinessMessage`, `EditedBusinessMessage` and `DeletedBusinessMessages` variants to `UpdateKind` enum -[pr1131]: https://github.com/teloxide/teloxide/pull/1131 -[pr1146]: https://github.com/teloxide/teloxide/pull/1146 - ### Changed - `MaybeAnonymousUser` type introduced, which replaced `PollAnswer::voter: Voter` and `MessageReactionUpdated::{user, actor_chat}` in `MessageReactionUpdated`([#1134][pr1134]) -[pr1134]: https://github.com/teloxide/teloxide/pull/1134 - -### Removed - - Support for TBA 7.2 ([#1146](pr1146)) - Remove `flags` field from `StickerSet` struct - Remove `sticker_format` parameter from `CreateNewStickerSet` method - -### Breaking Changes - -- Support for TBA 7.2 ([#1146](pr1146)) - Wrap `Public` variant of `ChatKind` in `Box` - Replaced `user_ids` with `users` in `UsersShared` struct [pr1131]: https://github.com/teloxide/teloxide/pull/1131 +[pr1134]: https://github.com/teloxide/teloxide/pull/1134 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 ## 0.10.1 - 2024-08-17