mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
add docs
This commit is contained in:
parent
a17f3129a3
commit
17f80589e9
8 changed files with 175 additions and 48 deletions
|
@ -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<Location>,
|
||||
/// 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<String>,
|
||||
/// The query that was used to obtain the result
|
||||
pub query: String,
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
/// Optional. Contact's user identifier in Telegram
|
||||
user_id: Option<i64>,
|
||||
/// Optional. Additional data about the contact in the form of a
|
||||
/// [vCard](https://en.wikipedia.org/wiki/VCard)
|
||||
vcard: Option<String>,
|
||||
}
|
|
@ -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<PhotoSize>,
|
||||
/// 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<String>,
|
||||
/// Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
|
||||
pub text_entities: Option<Vec<MessageEntity>>,
|
||||
/// Optional. Animation that will be displayed in the game message in chats.
|
||||
/// Upload via BotFather
|
||||
pub animation: Option<Animation>,
|
||||
}
|
|
@ -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,
|
||||
}
|
|
@ -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<ParseMode>,
|
||||
|
||||
/// Disables link previews for links in the sent message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
disable_web_page_preview: Option<bool>,
|
||||
},
|
||||
/// 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<u32>
|
||||
},
|
||||
/// 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<String>,
|
||||
|
||||
/// 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<String>,
|
||||
},
|
||||
/// 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<String>,
|
||||
|
||||
/// 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<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[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<ParseMode>,
|
||||
#[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,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub live_period: Option<u32> // should be between 60 and 86400
|
||||
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
|
||||
};
|
||||
|
||||
#[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<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub foursquare_type: Option<String>,
|
||||
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 InputContactMessageContent {
|
||||
pub phone_number: String,
|
||||
pub first_name: String,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub last_name: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vcard: Option<String>,
|
||||
let actual_json = serde_json::to_string(&contact_content).unwrap();
|
||||
assert_eq!(expected_json, actual_json);
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
}
|
|
@ -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<PhotoSize>,
|
||||
/// Optional. File size
|
||||
file_size: Option<u32>,
|
||||
}
|
|
@ -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<String>,
|
||||
/// Optional. File size
|
||||
file_size: Option<u64>
|
||||
}
|
Loading…
Reference in a new issue