From 653c8040376e649dfdd7cda770b325eb8c82c228 Mon Sep 17 00:00:00 2001 From: Waffle Date: Tue, 4 May 2021 15:55:03 +0300 Subject: [PATCH] Update types to TBA 5.2 --- Cargo.toml | 1 + src/types.rs | 4 + src/types/chat_action.rs | 4 +- src/types/chat_type.rs | 13 ++ src/types/inline_query.rs | 11 +- src/types/input_message_content.rs | 260 ++++++++++++++++++++++++++++- src/types/message.rs | 9 +- src/types/voice_chat_scheduled.rs | 10 ++ 8 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 src/types/chat_type.rs create mode 100644 src/types/voice_chat_scheduled.rs diff --git a/Cargo.toml b/Cargo.toml index a27b496a..10dbe708 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ tokio-util = "0.6.0" pin-project = "1.0.3" bytes = "1.0.0" reqwest = { version = "0.11.0", features = ["json", "stream", "multipart"], default-features = false } +url = { version = "2", features = ["serde"] } log = "0.4" serde = { version = "1.0.114", features = ["derive"] } diff --git a/src/types.rs b/src/types.rs index 2161d872..8cc6a35c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -15,6 +15,7 @@ pub use chat_member::*; pub use chat_member_updated::*; pub use chat_permissions::*; pub use chat_photo::*; +pub use chat_type::*; pub use chosen_inline_result::*; pub use contact::*; pub use dice::*; @@ -99,6 +100,7 @@ pub use video_note::*; pub use voice::*; pub use voice_chat_ended::*; pub use voice_chat_participants_invited::*; +pub use voice_chat_scheduled::*; pub use voice_chat_started::*; pub use webhook_info::*; @@ -117,6 +119,7 @@ mod chat_member; mod chat_member_updated; mod chat_permissions; mod chat_photo; +mod chat_type; mod chosen_inline_result; mod contact; mod dice; @@ -174,6 +177,7 @@ mod video_note; mod voice; mod voice_chat_ended; mod voice_chat_participants_invited; +mod voice_chat_scheduled; mod voice_chat_started; mod webhook_info; diff --git a/src/types/chat_action.rs b/src/types/chat_action.rs index a73887ea..87a07449 100644 --- a/src/types/chat_action.rs +++ b/src/types/chat_action.rs @@ -7,8 +7,8 @@ pub enum ChatAction { UploadPhoto, RecordVideo, UploadVideo, - RecordAudio, - UploadAudio, + RecordVoice, + UploadVoice, UploadDocument, FindLocation, RecordVideoNote, diff --git a/src/types/chat_type.rs b/src/types/chat_type.rs new file mode 100644 index 00000000..23350c59 --- /dev/null +++ b/src/types/chat_type.rs @@ -0,0 +1,13 @@ +use serde::{Deserialize, Serialize}; + +/// Type of the chat, from which the inline query was sent. +#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum ChatType { + /// Private chat with the inline query sender. + Sender, + Private, + Group, + Supergroup, + Channel, +} diff --git a/src/types/inline_query.rs b/src/types/inline_query.rs index 0eba0270..8089cd54 100644 --- a/src/types/inline_query.rs +++ b/src/types/inline_query.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{Location, User}; +use crate::types::{ChatType, Location, User}; /// This object represents an incoming inline query. /// @@ -25,8 +25,16 @@ pub struct InlineQuery { /// Offset of the results to be returned, can be controlled by the bot. pub offset: String, + + /// Type of the chat, from which the inline query was sent. + /// + /// The chat type should be always known for requests sent from official + /// clients and most third-party clients, unless the request was sent + /// from a secret chat. + pub chat_type: Option, } +// TODO(waffle): remove impl InlineQuery { pub fn new(id: S1, from: User, query: S2, offset: S3) -> Self where @@ -40,6 +48,7 @@ impl InlineQuery { location: None, query: query.into(), offset: offset.into(), + chat_type: None, } } diff --git a/src/types/input_message_content.rs b/src/types/input_message_content.rs index c243af72..5f853c19 100644 --- a/src/types/input_message_content.rs +++ b/src/types/input_message_content.rs @@ -1,6 +1,7 @@ +use reqwest::Url; use serde::{Deserialize, Serialize}; -use crate::types::{MessageEntity, ParseMode}; +use crate::types::{Currency, LabeledPrice, MessageEntity, ParseMode}; /// This object represents the content of a message to be sent as a result of an /// inline query. @@ -13,6 +14,7 @@ pub enum InputMessageContent { Location(InputMessageContentLocation), Venue(InputMessageContentVenue), Contact(InputMessageContentContact), + Invoice(InputMessageContentInvoice), } /// Represents the content of a text message to be sent as the result of an /// inline query. @@ -297,6 +299,262 @@ impl InputMessageContentContact { } } +/// Represents the [content] of an invoice message to be sent as the result of +/// an inline query. +/// +/// [content]: InputMessageContent +#[serde_with_macros::skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct InputMessageContentInvoice { + /// Product name, 1-32 characters + pub title: String, + + /// Product description, 1-255 characters + pub description: String, + + /// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to + /// the user, use for your internal processes. + pub payload: String, + + /// Payment provider token, obtained via [@Botfather] + /// + /// [@Botfather]: https://t.me/Botfather + pub provider_token: String, + + /// Three-letter ISO 4217 currency code, see [more on currencies] + /// + /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies + pub currency: Currency, + + /// Price breakdown, list of components (e.g. product price, tax, discount, + /// delivery cost, delivery tax, bonus, etc.) + pub prices: Vec, + + /// ----The maximum accepted amount for tips in the smallest units of the + /// currency (integer, not float/double). For example, for a maximum tip of + /// US$ 1.45 pass max_tip_amount = 145. See the exp parameter in + /// currencies.json, it shows the number of digits past the decimal point + /// for each currency (2 for the majority of currencies). Defaults to 0 + pub max_tip_amount: Option, + + /// List of suggested amounts of tip in the smallest units of the currency + /// (integer, not float/double). At most 4 suggested tip amounts can be + /// specified. The suggested tip amounts must be positive, passed in a + /// strictly increased order and must not exceed max_tip_amount. + pub suggested_tip_amounts: Option>, + + /// ----A JSON-serialized object for data about the invoice, which will be + /// shared with the payment provider. A detailed description of the required + /// fields should be provided by the payment provider. + pub provider_data: Option, + + /// URL of the product photo for the invoice. Can be a photo of the goods or + /// a marketing image for a service. People like it better when they see + /// what they are paying for. + pub photo_url: Option, + + /// Photo size + pub photo_size: Option, + + /// Photo width + pub photo_width: Option, + + /// Photo height + pub photo_height: Option, + + /// Pass `true`, if you require the user's full name to complete the order + pub need_name: Option, + + /// Pass `true`, if you require the user's phone number to complete the + /// order + pub need_phone_number: Option, + + /// Pass `true`, if you require the user's email address to complete the + /// order + pub need_email: Option, + + /// Pass `true`, if you require the user's shipping address to complete the + /// order + pub need_shipping_address: Option, + + /// Pass True, if user's phone number should be sent to provider + pub send_phone_number_to_provider: Option, + + /// Pass True, if user's email address should be sent to provider + pub send_email_to_provider: Option, + + /// Pass True, if the final price depends on the shipping method + pub is_flexible: Option, +} + +impl InputMessageContentInvoice { + pub fn new( + title: T, + description: D, + payload: PA, + provider_token: PT, + currency: Currency, + prices: PR, + ) -> Self + where + T: Into, + D: Into, + PA: Into, + PT: Into, + PR: IntoIterator, + { + let title = title.into(); + let description = description.into(); + let payload = payload.into(); + let provider_token = provider_token.into(); + let prices = prices.into_iter().collect(); + + Self { + title, + description, + payload, + provider_token, + currency, + prices, + max_tip_amount: None, + suggested_tip_amounts: None, + provider_data: None, + photo_url: None, + photo_size: None, + photo_width: None, + photo_height: None, + need_name: None, + need_phone_number: None, + need_email: None, + need_shipping_address: None, + send_phone_number_to_provider: None, + send_email_to_provider: None, + is_flexible: None, + } + } + + pub fn title(mut self, val: T) -> Self + where + T: Into, + { + self.title = val.into(); + self + } + + pub fn description(mut self, val: T) -> Self + where + T: Into, + { + self.description = val.into(); + self + } + + pub fn payload(mut self, val: T) -> Self + where + T: Into, + { + self.payload = val.into(); + self + } + + pub fn provider_token(mut self, val: T) -> Self + where + T: Into, + { + self.provider_token = val.into(); + self + } + + pub fn currency(mut self, val: Currency) -> Self { + self.currency = val.into(); + self + } + + pub fn prices(mut self, val: T) -> Self + where + T: IntoIterator, + { + self.prices = val.into_iter().collect(); + self + } + + pub fn max_tip_amount(mut self, val: u32) -> Self { + self.max_tip_amount = Some(val); + self + } + + pub fn suggested_tip_amounts(mut self, val: T) -> Self + where + T: IntoIterator, + { + self.suggested_tip_amounts = Some(val.into_iter().collect()); + self + } + + pub fn provider_data(mut self, val: T) -> Self + where + T: Into, + { + self.provider_data = Some(val.into()); + self + } + + pub fn photo_url(mut self, val: Url) -> Self { + self.photo_url = Some(val); + self + } + + pub fn photo_size(mut self, val: u32) -> Self { + self.photo_size = Some(val); + self + } + + pub fn photo_width(mut self, val: u32) -> Self { + self.photo_width = Some(val); + self + } + + pub fn photo_height(mut self, val: u32) -> Self { + self.photo_height = Some(val); + self + } + + pub fn need_name(mut self, val: bool) -> Self { + self.need_name = Some(val); + self + } + + pub fn need_phone_number(mut self, val: bool) -> Self { + self.need_phone_number = Some(val); + self + } + + pub fn need_email(mut self, val: bool) -> Self { + self.need_email = Some(val); + self + } + + pub fn need_shipping_address(mut self, val: bool) -> Self { + self.need_shipping_address = Some(val); + self + } + + pub fn send_phone_number_to_provider(mut self, val: bool) -> Self { + self.send_phone_number_to_provider = Some(val); + self + } + + pub fn send_email_to_provider(mut self, val: bool) -> Self { + self.send_email_to_provider = Some(val); + self + } + + pub fn is_flexible(mut self, val: bool) -> Self { + self.is_flexible = Some(val); + self + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/types/message.rs b/src/types/message.rs index 0159c705..e5241004 100644 --- a/src/types/message.rs +++ b/src/types/message.rs @@ -8,7 +8,7 @@ use crate::types::{ Invoice, Location, MessageAutoDeleteTimerChanged, MessageEntity, PassportData, PhotoSize, Poll, ProximityAlertTriggered, PublicChatChannel, PublicChatSupergroup, Sticker, SuccessfulPayment, True, User, Venue, Video, VideoNote, Voice, VoiceChatEnded, VoiceChatParticipantsInvited, - VoiceChatStarted, + VoiceChatScheduled, VoiceChatStarted, }; /// This object represents a message. @@ -54,6 +54,7 @@ pub enum MessageKind { PassportData(MessagePassportData), Dice(MessageDice), ProximityAlertTriggered(MessageProximityAlertTriggered), + VoiceChatScheduled(MessageVoiceChatScheduled), VoiceChatStarted(MessageVoiceChatStarted), VoiceChatEnded(MessageVoiceChatEnded), VoiceChatParticipantsInvited(MessageVoiceChatParticipantsInvited), @@ -456,6 +457,12 @@ pub struct MessageProximityAlertTriggered { pub proximity_alert_triggered: ProximityAlertTriggered, } +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct MessageVoiceChatScheduled { + /// Service message: voice chat scheduled + pub voice_chat_scheduled: VoiceChatScheduled, +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct MessageVoiceChatStarted { /// Service message: voice chat started. diff --git a/src/types/voice_chat_scheduled.rs b/src/types/voice_chat_scheduled.rs new file mode 100644 index 00000000..c33a5ad8 --- /dev/null +++ b/src/types/voice_chat_scheduled.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; + +/// This object represents a service message about a voice chat scheduled in the +/// chat. +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +pub struct VoiceChatScheduled { + /// Point in time (Unix timestamp) when the voice chat is supposed to be + /// started by a chat administrator. + pub start_date: u64, +}