mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +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;
|
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 {
|
pub struct ChosenInlineResult {
|
||||||
|
/// The unique identifier for the result that was chosen
|
||||||
pub result_id: String,
|
pub result_id: String,
|
||||||
|
/// The user that chose the result
|
||||||
pub from: User,
|
pub from: User,
|
||||||
|
/// Optional. Sender location, only for bots that require user location
|
||||||
pub location: Option<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>,
|
pub inline_message_id: Option<String>,
|
||||||
|
/// The query that was used to obtain the result
|
||||||
pub query: String,
|
pub query: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
use serde::Deserialization;
|
use serde::Deserialization;
|
||||||
|
|
||||||
#[derive(Debug, Deserialization)]
|
#[derive(Debug, Deserialization)]
|
||||||
|
/// This object represents a phone contact.
|
||||||
struct Contact {
|
struct Contact {
|
||||||
|
/// Contact's phone number
|
||||||
phone_number: String,
|
phone_number: String,
|
||||||
|
/// Contact's first name
|
||||||
first_name: String,
|
first_name: String,
|
||||||
|
/// Optional. Contact's last name
|
||||||
last_name: Option<String>,
|
last_name: Option<String>,
|
||||||
|
/// Optional. Contact's user identifier in Telegram
|
||||||
user_id: Option<i64>,
|
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>,
|
vcard: Option<String>,
|
||||||
}
|
}
|
|
@ -3,11 +3,22 @@ use serde::Deserialize;
|
||||||
use crate::core::types::MessageEntity;
|
use crate::core::types::MessageEntity;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[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 {
|
pub struct Game {
|
||||||
|
/// Title of the game
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
/// Description of the game
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
/// Photo that will be displayed in the game message in chats.
|
||||||
pub photo: Vec<PhotoSize>,
|
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>,
|
pub text: Option<String>,
|
||||||
|
/// Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
|
||||||
pub text_entities: Option<Vec<MessageEntity>>,
|
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>,
|
pub animation: Option<Animation>,
|
||||||
}
|
}
|
|
@ -3,8 +3,12 @@ use serde::Deserialize;
|
||||||
use crate::core::types::user::User;
|
use crate::core::types::user::User;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// This object represents one row of the high scores table for a game.
|
||||||
pub struct GameHighScore {
|
pub struct GameHighScore {
|
||||||
pub position: i32,
|
/// Position in high score table for the game
|
||||||
|
pub position: u32,
|
||||||
|
/// User
|
||||||
pub user: User,
|
pub user: User,
|
||||||
pub score: i32,
|
/// Score
|
||||||
|
pub score: u32,
|
||||||
}
|
}
|
|
@ -1,56 +1,136 @@
|
||||||
use serde::Serialize;
|
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 {
|
pub enum InputMessageContent {
|
||||||
Text(InputTextMessageContent),
|
/// Represents the content of a text message to be sent as the result of an inline query.
|
||||||
Location(InputLocationMessageContent),
|
Text {
|
||||||
Venue(InputVenueMessageContent),
|
/// Text of the message to be sent, 1-4096 characters
|
||||||
Contact(InputContactMessageContent),
|
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)]
|
#[cfg(test)]
|
||||||
pub struct InputTextMessageContent {
|
mod tests {
|
||||||
pub message_text: String,
|
use super::*;
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[test]
|
||||||
pub parse_mode: Option<ParseMode>,
|
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")]
|
let actual_json = serde_json::to_string(&text_content).unwrap();
|
||||||
pub disable_web_page_preview: bool,
|
assert_eq!(expected_json, actual_json);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
#[derive(Debug, Serialize)]
|
fn location_serialize() {
|
||||||
pub struct InputLocationMessageContent {
|
let expected_json = r#"{"latitude":59.08,"longitude":38.4326}"#;
|
||||||
pub latitude: f64,
|
let location_content = InputMessageContent::Location {
|
||||||
pub longitude: f64,
|
latitude: 59.08,
|
||||||
|
longitude: 38.4326,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
live_period: None
|
||||||
pub live_period: Option<u32> // should be between 60 and 86400
|
};
|
||||||
}
|
|
||||||
|
let actual_json = serde_json::to_string(&location_content).unwrap();
|
||||||
#[derive(Debug, Serialize)]
|
assert_eq!(expected_json, actual_json);
|
||||||
pub struct InputVenueMessageContent {
|
}
|
||||||
pub latitude: f64,
|
#[test]
|
||||||
pub longitude: f64,
|
fn venue_serialize() {
|
||||||
pub title: String,
|
let expected_json = r#"{"latitude":59.08,"longitude":38.4326,"title":"some title",
|
||||||
pub address: String,
|
"address":"some address"}"#;
|
||||||
|
let venue_content = InputMessageContent::Venue {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
latitude: 59.08,
|
||||||
pub foursquare_id: Option<String>,
|
longitude: 38.4326,
|
||||||
|
title: String::from("some title"),
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
address: String::from("some address"),
|
||||||
pub foursquare_type: Option<String>,
|
foursquare_id: None,
|
||||||
}
|
foursquare_type: None
|
||||||
|
};
|
||||||
#[derive(Debug, Serialize)]
|
|
||||||
pub struct InputContactMessageContent {
|
let actual_json = serde_json::to_string(&venue_content).unwrap();
|
||||||
pub phone_number: String,
|
assert_eq!(expected_json, actual_json);
|
||||||
pub first_name: String,
|
}
|
||||||
|
#[test]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
fn contact_serialize() {
|
||||||
pub last_name: Option<String>,
|
let expected_json = r#"{"phone_number":"+3800000000","first_name":"jhon"}"#;
|
||||||
|
let contact_content = InputMessageContent::Contact {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
phone_number: String::from("+3800000000"),
|
||||||
pub vcard: Option<String>,
|
first_name: String::from("jhon"),
|
||||||
|
last_name: None,
|
||||||
|
vcard: None
|
||||||
|
};
|
||||||
|
|
||||||
|
let actual_json = serde_json::to_string(&contact_content).unwrap();
|
||||||
|
assert_eq!(expected_json, actual_json);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
use serde::{Serialization, Deserialization};
|
use serde::{Serialization, Deserialization};
|
||||||
|
|
||||||
#[derive(Debug, Serialization, Deserialization)]
|
#[derive(Debug, Serialization, Deserialization)]
|
||||||
|
/// This object represents a point on the map.
|
||||||
struct Location {
|
struct Location {
|
||||||
|
/// Longitude as defined by sender
|
||||||
longitude: f64,
|
longitude: f64,
|
||||||
|
/// Latitude as defined by sender
|
||||||
latitude: f64,
|
latitude: f64,
|
||||||
}
|
}
|
|
@ -1,10 +1,17 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, 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 {
|
struct VideoNote {
|
||||||
|
/// Identifier for this file
|
||||||
file_id: String,
|
file_id: String,
|
||||||
|
/// Video width and height (diameter of the video message) as defined by sender
|
||||||
length: u32,
|
length: u32,
|
||||||
|
/// Duration of the video in seconds as defined by sender
|
||||||
duration: u32,
|
duration: u32,
|
||||||
|
/// Optional. Video thumbnail
|
||||||
thumb: Option<PhotoSize>,
|
thumb: Option<PhotoSize>,
|
||||||
|
/// Optional. File size
|
||||||
file_size: Option<u32>,
|
file_size: Option<u32>,
|
||||||
}
|
}
|
|
@ -1,9 +1,14 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// This object represents a voice note.
|
||||||
struct Voice {
|
struct Voice {
|
||||||
|
/// Identifier for this file
|
||||||
file_id: String,
|
file_id: String,
|
||||||
|
/// Duration of the audio in seconds as defined by sender
|
||||||
duration: u32,
|
duration: u32,
|
||||||
|
/// Optional. MIME type of the file as defined by sender
|
||||||
mime_type: Option<String>,
|
mime_type: Option<String>,
|
||||||
|
/// Optional. File size
|
||||||
file_size: Option<u64>
|
file_size: Option<u64>
|
||||||
}
|
}
|
Loading…
Reference in a new issue