mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-23 07:09:34 +01:00
commit
df4259bf60
9 changed files with 227 additions and 260 deletions
13
src/core/types/animation.rs
Normal file
13
src/core/types/animation.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
use crate::core::types::PhotoSize;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
|
pub struct Animation {
|
||||||
|
pub file_id: String,
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
pub duration: u32,
|
||||||
|
pub thumb: PhotoSize,
|
||||||
|
pub file_name: Option<String>,
|
||||||
|
pub mime_type: Option<String>,
|
||||||
|
pub file_size: Option<u32>
|
||||||
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
use serde::Deserialization;
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
|
|
||||||
#[derive(Debug, Deserialization, Clone)]
|
|
||||||
/// This object represents a phone contact.
|
/// This object represents a phone contact.
|
||||||
struct Contact {
|
pub struct Contact {
|
||||||
/// Contact's phone number
|
/// Contact's phone number
|
||||||
pub phone_number: String,
|
pub phone_number: String,
|
||||||
/// Contact's first name
|
/// Contact's first name
|
||||||
|
|
6
src/core/types/file.rs
Normal file
6
src/core/types/file.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
||||||
|
pub struct File {
|
||||||
|
pub file_id: String,
|
||||||
|
pub file_size: u32,
|
||||||
|
pub file_path: String
|
||||||
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
use serde::{Deserialization, Serialization};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialization, Deserialization, Clone)]
|
#[derive(Debug, Serialization, Deserialization, Clone)]
|
||||||
/// This object represents a point on the map.
|
/// This object represents a point on the map.
|
||||||
struct Location {
|
pub struct Location {
|
||||||
/// Longitude as defined by sender
|
/// Longitude as defined by sender
|
||||||
pub longitude: f64,
|
pub longitude: f64,
|
||||||
/// Latitude as defined by sender
|
/// Latitude as defined by sender
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::core::types::{
|
||||||
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
|
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
#[serde(rename = "message_id")]
|
#[serde(rename = "message_id")]
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
|
@ -14,7 +14,7 @@ pub struct Message {
|
||||||
pub message_kind: MessageKind,
|
pub message_kind: MessageKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum MessageKind {
|
pub enum MessageKind {
|
||||||
IncomingMessage {
|
IncomingMessage {
|
||||||
|
@ -72,7 +72,7 @@ pub enum MessageKind {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
pub enum Sender {
|
pub enum Sender {
|
||||||
/// If message is sent from Chat
|
/// If message is sent from Chat
|
||||||
#[serde(rename = "from")]
|
#[serde(rename = "from")]
|
||||||
|
@ -82,7 +82,7 @@ pub enum Sender {
|
||||||
Signature(String),
|
Signature(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum ForwardKind {
|
pub enum ForwardKind {
|
||||||
ChannelForward {
|
ChannelForward {
|
||||||
|
@ -106,7 +106,7 @@ pub enum ForwardKind {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
pub enum ForwardedFrom {
|
pub enum ForwardedFrom {
|
||||||
#[serde(rename = "forward_from")]
|
#[serde(rename = "forward_from")]
|
||||||
User(User),
|
User(User),
|
||||||
|
@ -114,7 +114,7 @@ pub enum ForwardedFrom {
|
||||||
SenderName(String),
|
SenderName(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum MediaKind {
|
pub enum MediaKind {
|
||||||
Animation {
|
Animation {
|
||||||
|
@ -193,64 +193,7 @@ mod tests {
|
||||||
use serde_json::from_str;
|
use serde_json::from_str;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sent_message_de() {
|
fn de_media_forwarded() {
|
||||||
let expected = Message {
|
|
||||||
id: 6534,
|
|
||||||
date: 1567898953,
|
|
||||||
chat: Chat {
|
|
||||||
id: 218485655,
|
|
||||||
photo: None,
|
|
||||||
kind: ChatKind::Private {
|
|
||||||
type_: (),
|
|
||||||
first_name: Some("W".to_string()),
|
|
||||||
last_name: None,
|
|
||||||
username: Some("WaffleLapkin".to_string()),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
message_kind: MessageKind::IncomingMessage {
|
|
||||||
from: Sender::User(User {
|
|
||||||
id: 457569668,
|
|
||||||
is_bot: true,
|
|
||||||
first_name: "BT".to_string(),
|
|
||||||
last_name: None,
|
|
||||||
username: Some("BloodyTestBot".to_string()),
|
|
||||||
language_code: None,
|
|
||||||
}),
|
|
||||||
forward_kind: ForwardKind::Origin {
|
|
||||||
reply_to_message: None,
|
|
||||||
},
|
|
||||||
edit_date: None,
|
|
||||||
media_kind: MediaKind::Text {
|
|
||||||
text: "text".to_string(),
|
|
||||||
entities: vec![],
|
|
||||||
},
|
|
||||||
reply_markup: None,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// actual message from telegram
|
|
||||||
let json = r#"{
|
|
||||||
"message_id": 6534,
|
|
||||||
"from": {
|
|
||||||
"id": 457569668,
|
|
||||||
"is_bot": true,
|
|
||||||
"first_name": "BT",
|
|
||||||
"username": "BloodyTestBot"
|
|
||||||
},
|
|
||||||
"chat": {
|
|
||||||
"id": 218485655,
|
|
||||||
"first_name": "W",
|
|
||||||
"username": "WaffleLapkin",
|
|
||||||
"type": "private"
|
|
||||||
},
|
|
||||||
"date": 1567898953,
|
|
||||||
"text": "text"
|
|
||||||
}"#;
|
|
||||||
let actual = from_str::<Message>(json).unwrap();
|
|
||||||
assert_eq!(expected, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn media_message_de() {
|
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"message_id": 198283,
|
"message_id": 198283,
|
||||||
"from": {
|
"from": {
|
||||||
|
@ -284,59 +227,12 @@ mod tests {
|
||||||
"file_size": 1381334
|
"file_size": 1381334
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
let actual = from_str::<Message>(json).unwrap();
|
let message = from_str::<Message>(json);
|
||||||
let expected = Message {
|
assert!(message.is_ok());
|
||||||
id: 198283,
|
|
||||||
date: 1567927221,
|
|
||||||
chat: Chat {
|
|
||||||
id: 250918540,
|
|
||||||
photo: None,
|
|
||||||
kind: ChatKind::Private {
|
|
||||||
first_name: Some("Андрей".to_string()),
|
|
||||||
last_name: Some("Власов".to_string()),
|
|
||||||
username: Some("aka_dude".to_string()),
|
|
||||||
type_: ()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
message_kind: MessageKind::IncomingMessage {
|
|
||||||
from: Sender::User(User {
|
|
||||||
id: 250918540,
|
|
||||||
is_bot: false,
|
|
||||||
first_name: "Андрей".to_string(),
|
|
||||||
last_name: Some("Власов".to_string()),
|
|
||||||
username: Some("aka_dude".to_string()),
|
|
||||||
language_code: Some("en".to_string())
|
|
||||||
}),
|
|
||||||
forward_kind: ForwardKind::Origin { reply_to_message: None },
|
|
||||||
edit_date: None,
|
|
||||||
media_kind: MediaKind::Video {
|
|
||||||
video: Video {
|
|
||||||
duration: 13,
|
|
||||||
width: 512,
|
|
||||||
height: 640,
|
|
||||||
mime_type: Some("video/mp4".to_string()),
|
|
||||||
thumb: Some(PhotoSize {
|
|
||||||
file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(),
|
|
||||||
file_size: Some(10339),
|
|
||||||
width: 256,
|
|
||||||
height: 320
|
|
||||||
}),
|
|
||||||
file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(),
|
|
||||||
file_size: Some(1381334)
|
|
||||||
},
|
|
||||||
caption: None,
|
|
||||||
caption_entities: vec![],
|
|
||||||
media_group_id: None
|
|
||||||
},
|
|
||||||
reply_markup: None
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
||||||
assert_eq!(actual, expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn media_group_message_de() {
|
fn de_media_group_forwarded() {
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"message_id": 198283,
|
"message_id": 198283,
|
||||||
"from": {
|
"from": {
|
||||||
|
@ -371,54 +267,118 @@ mod tests {
|
||||||
"file_size": 1381334
|
"file_size": 1381334
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
let actual = from_str::<Message>(json).unwrap();
|
let message = from_str::<Message>(json);
|
||||||
let expected = Message {
|
assert!(message.is_ok());
|
||||||
id: 198283,
|
|
||||||
date: 1567927221,
|
|
||||||
chat: Chat {
|
|
||||||
id: 250918540,
|
|
||||||
photo: None,
|
|
||||||
kind: ChatKind::Private {
|
|
||||||
first_name: Some("Андрей".to_string()),
|
|
||||||
last_name: Some("Власов".to_string()),
|
|
||||||
username: Some("aka_dude".to_string()),
|
|
||||||
type_: ()
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
message_kind: MessageKind::IncomingMessage {
|
|
||||||
from: Sender::User(User {
|
|
||||||
id: 250918540,
|
|
||||||
is_bot: false,
|
|
||||||
first_name: "Андрей".to_string(),
|
|
||||||
last_name: Some("Власов".to_string()),
|
|
||||||
username: Some("aka_dude".to_string()),
|
|
||||||
language_code: Some("en".to_string())
|
|
||||||
}),
|
|
||||||
forward_kind: ForwardKind::Origin { reply_to_message: None },
|
|
||||||
edit_date: None,
|
|
||||||
media_kind: MediaKind::Video {
|
|
||||||
video: Video {
|
|
||||||
duration: 13,
|
|
||||||
width: 512,
|
|
||||||
height: 640,
|
|
||||||
mime_type: Some("video/mp4".to_string()),
|
|
||||||
thumb: Some(PhotoSize {
|
|
||||||
file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(),
|
|
||||||
file_size: Some(10339),
|
|
||||||
width: 256,
|
|
||||||
height: 320
|
|
||||||
}),
|
|
||||||
file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(),
|
|
||||||
file_size: Some(1381334)
|
|
||||||
},
|
|
||||||
caption: None,
|
|
||||||
caption_entities: vec![],
|
|
||||||
media_group_id: Some("12543417770506682".to_string())
|
|
||||||
},
|
|
||||||
reply_markup: None
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
#[test]
|
||||||
assert_eq!(actual, expected);
|
fn de_text() {
|
||||||
|
let json = r#"{
|
||||||
|
"message_id": 199785,
|
||||||
|
"from": {
|
||||||
|
"id": 250918540,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 250918540,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1568289890,
|
||||||
|
"text": "Лол кек 😂"
|
||||||
|
}"#;
|
||||||
|
let message = from_str::<Message>(json);
|
||||||
|
assert!(message.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_sticker() {
|
||||||
|
let json = r#"{
|
||||||
|
"message_id": 199787,
|
||||||
|
"from": {
|
||||||
|
"id": 250918540,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 250918540,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1568290188,
|
||||||
|
"sticker": {
|
||||||
|
"width": 512,
|
||||||
|
"height": 512,
|
||||||
|
"emoji": "😡",
|
||||||
|
"set_name": "AdvenTimeAnim",
|
||||||
|
"is_animated": true,
|
||||||
|
"thumb": {
|
||||||
|
"file_id": "AAQCAAMjAAOw0PgMaabKAcaXKCBLubkPAAQBAAdtAAPGKwACFgQ",
|
||||||
|
"file_size": 4118,
|
||||||
|
"width": 128,
|
||||||
|
"height": 128
|
||||||
|
},
|
||||||
|
"file_id": "CAADAgADIwADsND4DGmmygHGlyggFgQ",
|
||||||
|
"file_size": 16639
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
let message = from_str::<Message>(json);
|
||||||
|
assert!(message.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_image() {
|
||||||
|
let json = r#"{
|
||||||
|
"message_id": 199791,
|
||||||
|
"from": {
|
||||||
|
"id": 250918540,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 250918540,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1568290622,
|
||||||
|
"photo": [
|
||||||
|
{
|
||||||
|
"file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA20AAybcBAABFgQ",
|
||||||
|
"file_size": 18188,
|
||||||
|
"width": 320,
|
||||||
|
"height": 239
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA3gAAyfcBAABFgQ",
|
||||||
|
"file_size": 62123,
|
||||||
|
"width": 800,
|
||||||
|
"height": 598
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA3kAAyTcBAABFgQ",
|
||||||
|
"file_size": 75245,
|
||||||
|
"width": 962,
|
||||||
|
"height": 719
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}"#;
|
||||||
|
let message = from_str::<Message>(json);
|
||||||
|
assert!(message.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ pub use self::{
|
||||||
order_info::OrderInfo,
|
order_info::OrderInfo,
|
||||||
parse_mode::ParseMode,
|
parse_mode::ParseMode,
|
||||||
photo_size::PhotoSize,
|
photo_size::PhotoSize,
|
||||||
|
poll::{Poll, PollOption},
|
||||||
pre_checkout_query::PreCheckoutQuery,
|
pre_checkout_query::PreCheckoutQuery,
|
||||||
response_parameters::ResponseParameters,
|
response_parameters::ResponseParameters,
|
||||||
send_invoice::SendInvoice,
|
send_invoice::SendInvoice,
|
||||||
|
@ -60,6 +61,7 @@ mod not_implemented_types;
|
||||||
mod order_info;
|
mod order_info;
|
||||||
mod parse_mode;
|
mod parse_mode;
|
||||||
mod photo_size;
|
mod photo_size;
|
||||||
|
mod poll;
|
||||||
mod pre_checkout_query;
|
mod pre_checkout_query;
|
||||||
mod response_parameters;
|
mod response_parameters;
|
||||||
mod reply_markup;
|
mod reply_markup;
|
||||||
|
|
|
@ -1,35 +1,5 @@
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Location;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct InlineKeyboardMarkup;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
||||||
pub struct PassportData;
|
pub struct PassportData;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Poll;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Animation;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Game;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Contact;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct VideoNote;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Venue;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct Voice;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
|
||||||
pub struct MaskPosition;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
||||||
pub struct ChatMemberStatus;
|
pub struct ChatMemberStatus;
|
||||||
|
|
13
src/core/types/poll.rs
Normal file
13
src/core/types/poll.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
|
pub struct Poll {
|
||||||
|
pub id: String,
|
||||||
|
pub question: String,
|
||||||
|
pub options: Vec<PollOption>,
|
||||||
|
pub is_closed: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
|
pub struct PollOption {
|
||||||
|
pub text: String,
|
||||||
|
pub voter_count: i32
|
||||||
|
}
|
7
src/core/types/user_profile_photos.rs
Normal file
7
src/core/types/user_profile_photos.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
use crate::core::types::PhotoSize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
|
pub struct UserProfilePhotos {
|
||||||
|
pub total_count: u32,
|
||||||
|
pub photos: Vec<Vec<PhotoSize>>
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue