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,