diff --git a/src/core/types/chosen_inline_result.rs b/src/core/types/chosen_inline_result.rs index 489acfaa..875f5948 100644 --- a/src/core/types/chosen_inline_result.rs +++ b/src/core/types/chosen_inline_result.rs @@ -2,11 +2,21 @@ use serde::Deserialize; use crate::core::types::user::User; -#[derive(Debug, Deserealize)] +#[derive(Debug, Deserialize)] +/// Represents a result of an inline query that was chosen by the user and +/// sent to their chat partner. +/// https://core.telegram.org/bots/api#inputtextmessagecontent pub struct ChosenInlineResult { + /// The unique identifier for the result that was chosen pub result_id: String, + /// The user that chose the result pub from: User, + /// Optional. Sender location, only for bots that require user location pub location: Option, + /// Optional. Identifier of the sent inline message. Available only if there is an inline + /// keyboard attached to the message. Will be also received in callback queries and can + /// be used to edit the message. pub inline_message_id: Option, + /// The query that was used to obtain the result pub query: String, } diff --git a/src/core/types/contact.rs b/src/core/types/contact.rs index c2756245..9aa2e513 100644 --- a/src/core/types/contact.rs +++ b/src/core/types/contact.rs @@ -1,10 +1,17 @@ use serde::Deserialization; #[derive(Debug, Deserialization)] +/// This object represents a phone contact. struct Contact { + /// Contact's phone number phone_number: String, + /// Contact's first name first_name: String, + /// Optional. Contact's last name last_name: Option, + /// Optional. Contact's user identifier in Telegram user_id: Option, + /// Optional. Additional data about the contact in the form of a + /// [vCard](https://en.wikipedia.org/wiki/VCard) vcard: Option, } \ No newline at end of file diff --git a/src/core/types/game.rs b/src/core/types/game.rs index 26890b06..3fb5654b 100644 --- a/src/core/types/game.rs +++ b/src/core/types/game.rs @@ -3,11 +3,22 @@ use serde::Deserialize; use crate::core::types::MessageEntity; #[derive(Debug, Deserialize)] +/// This object represents a game. Use BotFather to create and edit games, their short names +/// will act as unique identifiers. pub struct Game { + /// Title of the game pub title: String, + /// Description of the game pub description: String, + /// Photo that will be displayed in the game message in chats. pub photo: Vec, + /// Optional. Brief description of the game or high scores included in the game message. + /// Can be automatically edited to include current high scores for the game when + /// the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. pub text: Option, + /// Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. pub text_entities: Option>, + /// Optional. Animation that will be displayed in the game message in chats. + /// Upload via BotFather pub animation: Option, } \ No newline at end of file diff --git a/src/core/types/game_high_score.rs b/src/core/types/game_high_score.rs index 97e5329b..8cf53a84 100644 --- a/src/core/types/game_high_score.rs +++ b/src/core/types/game_high_score.rs @@ -3,8 +3,12 @@ use serde::Deserialize; use crate::core::types::user::User; #[derive(Debug, Deserialize)] +/// This object represents one row of the high scores table for a game. pub struct GameHighScore { - pub position: i32, + /// Position in high score table for the game + pub position: u32, + /// User pub user: User, - pub score: i32, + /// Score + pub score: u32, } \ No newline at end of file diff --git a/src/core/types/input_message_content.rs b/src/core/types/input_message_content.rs index cf4c6873..0cbf50f8 100644 --- a/src/core/types/input_message_content.rs +++ b/src/core/types/input_message_content.rs @@ -1,56 +1,136 @@ use serde::Serialize; -use crate::core::parse_mode::ParseMode; +use crate::core::types::ParseMode; +#[derive(Debug, Serialize)] +#[serde(untagged)] +/// This object represents the content of a message to be sent as +/// a result of an inline query. +/// [More](https://core.telegram.org/bots/api#inputmessagecontent) pub enum InputMessageContent { - Text(InputTextMessageContent), - Location(InputLocationMessageContent), - Venue(InputVenueMessageContent), - Contact(InputContactMessageContent), + /// Represents the content of a text message to be sent as the result of an inline query. + Text { + /// Text of the message to be sent, 1-4096 characters + message_text: String, + + /// Send [Markdown] or [HTML], + /// if you want Telegram apps to show [bold, italic, fixed-width text or inline URLs] + /// in the media caption. + /// + /// [Markdown]: crate::core::types::ParseMode::Markdown + /// [Html]: crate::core::types::ParseMode::Html + /// [bold, italic, fixed-width text or inline URLs]: crate::core::types::ParseMode + #[serde(skip_serializing_if = "Option::is_none")] + parse_mode: Option, + + /// Disables link previews for links in the sent message + #[serde(skip_serializing_if = "Option::is_none")] + disable_web_page_preview: Option, + }, + /// Represents the content of a location message to be sent as the result of an inline query. + Location { + /// Latitude of the location in degrees + latitude: f64, + /// Longitude of the location in degrees + longitude: f64, + + /// Period in seconds for which the location can be updated, should be between 60 and 86400. + #[serde(skip_serializing_if = "Option::is_none")] + live_period: Option + }, + /// Represents the content of a venue message to be sent as the result of an inline query. + Venue { + /// Latitude of the venue in degrees + latitude: f64, + /// Longitude of the venue in degrees + longitude: f64, + /// Name of the venue + title: String, + /// Address of the venue + address: String, + + /// Foursquare identifier of the venue, if known + #[serde(skip_serializing_if = "Option::is_none")] + foursquare_id: Option, + + /// Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, + /// “arts_entertainment/aquarium” or “food/icecream”.) + #[serde(skip_serializing_if = "Option::is_none")] + foursquare_type: Option, + }, + /// Represents the content of a contact message to be sent as the result of an inline query. + Contact { + /// Contact's phone number + phone_number: String, + /// Contact's first name + first_name: String, + + /// Contact's last name + #[serde(skip_serializing_if = "Option::is_none")] + last_name: Option, + + /// Additional data about the contact in the form of a + /// [vCard](https://en.wikipedia.org/wiki/VCard), 0-2048 bytes + #[serde(skip_serializing_if = "Option::is_none")] + vcard: Option, + }, } -#[derive(Debug, Serialize)] -pub struct InputTextMessageContent { - pub message_text: String, +#[cfg(test)] +mod tests { + use super::*; - #[serde(skip_serializing_if = "Option::is_none")] - pub parse_mode: Option, + #[test] + fn text_serialize() { + let expected_json = r#"{"message_text":"text"}"#; + let text_content = InputMessageContent::Text { + message_text: String::from("text"), + parse_mode: None, + disable_web_page_preview: None + }; - #[serde(skip_serializing_if = "Not::not")] - pub disable_web_page_preview: bool, -} + let actual_json = serde_json::to_string(&text_content).unwrap(); + assert_eq!(expected_json, actual_json); + } + #[test] + fn location_serialize() { + let expected_json = r#"{"latitude":59.08,"longitude":38.4326}"#; + let location_content = InputMessageContent::Location { + latitude: 59.08, + longitude: 38.4326, + live_period: None + }; -#[derive(Debug, Serialize)] -pub struct InputLocationMessageContent { - pub latitude: f64, - pub longitude: f64, + let actual_json = serde_json::to_string(&location_content).unwrap(); + assert_eq!(expected_json, actual_json); + } + #[test] + fn venue_serialize() { + let expected_json = r#"{"latitude":59.08,"longitude":38.4326,"title":"some title", + "address":"some address"}"#; + let venue_content = InputMessageContent::Venue { + latitude: 59.08, + longitude: 38.4326, + title: String::from("some title"), + address: String::from("some address"), + foursquare_id: None, + foursquare_type: None + }; - #[serde(skip_serializing_if = "Option::is_none")] - pub live_period: Option // should be between 60 and 86400 -} + let actual_json = serde_json::to_string(&venue_content).unwrap(); + assert_eq!(expected_json, actual_json); + } + #[test] + fn contact_serialize() { + let expected_json = r#"{"phone_number":"+3800000000","first_name":"jhon"}"#; + let contact_content = InputMessageContent::Contact { + phone_number: String::from("+3800000000"), + first_name: String::from("jhon"), + last_name: None, + vcard: None + }; -#[derive(Debug, Serialize)] -pub struct InputVenueMessageContent { - pub latitude: f64, - pub longitude: f64, - pub title: String, - pub address: String, - - #[serde(skip_serializing_if = "Option::is_none")] - pub foursquare_id: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - pub foursquare_type: Option, -} - -#[derive(Debug, Serialize)] -pub struct InputContactMessageContent { - pub phone_number: String, - pub first_name: String, - - #[serde(skip_serializing_if = "Option::is_none")] - pub last_name: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - pub vcard: Option, -} + let actual_json = serde_json::to_string(&contact_content).unwrap(); + assert_eq!(expected_json, actual_json); + } +} \ No newline at end of file diff --git a/src/core/types/location.rs b/src/core/types/location.rs index 34dcda51..74660660 100644 --- a/src/core/types/location.rs +++ b/src/core/types/location.rs @@ -1,7 +1,10 @@ use serde::{Serialization, Deserialization}; #[derive(Debug, Serialization, Deserialization)] +/// This object represents a point on the map. struct Location { + /// Longitude as defined by sender longitude: f64, + /// Latitude as defined by sender latitude: f64, } \ No newline at end of file diff --git a/src/core/types/video_note.rs b/src/core/types/video_note.rs index 6e0d9cf1..63f2885c 100644 --- a/src/core/types/video_note.rs +++ b/src/core/types/video_note.rs @@ -1,10 +1,17 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] +/// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope) +/// (available in Telegram apps as of v.4.0). struct VideoNote { + /// Identifier for this file file_id: String, + /// Video width and height (diameter of the video message) as defined by sender length: u32, + /// Duration of the video in seconds as defined by sender duration: u32, + /// Optional. Video thumbnail thumb: Option, + /// Optional. File size file_size: Option, } \ No newline at end of file diff --git a/src/core/types/voice.rs b/src/core/types/voice.rs index 9e1890fb..0b19ada3 100644 --- a/src/core/types/voice.rs +++ b/src/core/types/voice.rs @@ -1,9 +1,14 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] +/// This object represents a voice note. struct Voice { + /// Identifier for this file file_id: String, + /// Duration of the audio in seconds as defined by sender duration: u32, + /// Optional. MIME type of the file as defined by sender mime_type: Option, + /// Optional. File size file_size: Option } \ No newline at end of file