mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
commit
e640065552
39 changed files with 185 additions and 105 deletions
|
@ -1,8 +1,7 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct AnswerPreCheckoutQuery {
|
||||
pub pre_checkout_query_id: String,
|
||||
pub ok: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::ShippingOption;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct AnswerShippingQuery {
|
||||
pub shipping_query_id: String,
|
||||
pub ok: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub shipping_options: Option<Vec<ShippingOption>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
|
18
src/core/types/audio.rs
Normal file
18
src/core/types/audio.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Audio {
|
||||
pub file_id: String,
|
||||
pub duration: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub performer: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mime_type: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_size: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thumb: Option<PhotoSize>
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// This object represents an incoming callback query from a callback button in an inline keyboard.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct CallbackQuery {
|
||||
|
|
|
@ -1,20 +1,72 @@
|
|||
use serde::Deserialize;
|
||||
use crate::core::types::{ChatPermissions, ChatPhoto, Message, Integer};
|
||||
|
||||
use crate::core::types::{ChatPermissions, ChatPhoto, Message};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
pub struct Chat {
|
||||
pub id: i64,
|
||||
pub chat_type: String,
|
||||
pub title: Option<String>,
|
||||
pub username: Option<String>,
|
||||
pub first_name: Option<String>,
|
||||
pub last_name: Option<String>,
|
||||
pub id: Integer,
|
||||
#[serde(flatten)]
|
||||
pub type_: ChatType,
|
||||
pub photo: Option<ChatPhoto>,
|
||||
pub description: Option<String>,
|
||||
pub invite_link: Option<String>,
|
||||
pub pinned_message: Option<Box<Message>>,
|
||||
pub permissions: Option<ChatPermissions>,
|
||||
pub sticker_set_name: Option<String>,
|
||||
pub can_set_sticker_set: Option<bool>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(untagged)]
|
||||
pub enum ChatType {
|
||||
NotPrivate {
|
||||
title: Option<String>,
|
||||
#[serde(flatten)]
|
||||
type_: NotPrivateChatType,
|
||||
description: Option<String>,
|
||||
invite_link: Option<String>,
|
||||
pinned_message: Option<Box<Message>>
|
||||
},
|
||||
Private {
|
||||
username: Option<String>,
|
||||
first_name: Option<String>,
|
||||
last_name: Option<String>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(tag = "type")]
|
||||
pub enum NotPrivateChatType {
|
||||
Channel {
|
||||
username: Option<String>
|
||||
},
|
||||
Group {
|
||||
permissions: Option<ChatPermissions>
|
||||
},
|
||||
Supergroup {
|
||||
username: Option<String>,
|
||||
sticker_set_name: Option<String>,
|
||||
can_set_sticker_set: Option<bool>,
|
||||
permissions: Option<ChatPermissions>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_chat_de() {
|
||||
use serde_json::from_str;
|
||||
|
||||
assert_eq!(
|
||||
Chat {
|
||||
id: 0,
|
||||
type_: ChatType::NotPrivate {
|
||||
title: None,
|
||||
type_: NotPrivateChatType::Channel {
|
||||
username: Some("channelname".into())
|
||||
},
|
||||
description: None,
|
||||
invite_link: None,
|
||||
pinned_message: None
|
||||
},
|
||||
photo: None,
|
||||
},
|
||||
from_str(r#"{"id":0,"type":"channel","username":"channelname"}"#).unwrap()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use serde::Deserialize;
|
||||
use crate::core::types::{
|
||||
User, ChatMemberStatus, Integer
|
||||
};
|
||||
|
||||
/// This object contains information about one member of the chat.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct ChatPermissions {
|
||||
pub can_send_messages: Option<bool>,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct ChatPhoto {
|
||||
pub small_file_id: String,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::user::User;
|
||||
|
||||
#[derive(Debug, Deserealize)]
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
use crate::core::types::{PhotoSize, UnsignedInteger};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
pub struct Document {
|
||||
pub file_id: String,
|
||||
pub thumb: Option<PhotoSize>,
|
||||
pub file_name: Option<String>,
|
||||
pub mime_type: Option<String>,
|
||||
pub file_size: Option<i64>,
|
||||
pub file_size: Option<UnsignedInteger>,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// Upon receiving a message with this object, Telegram clients will
|
||||
/// display a reply interface to the user (act as if the user has
|
||||
/// selected the bot‘s message and tapped ’Reply'). This can be
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// This object represents one button of an inline keyboard.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct InlineKeyboardButton {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// This object represents an inline keyboard that appears right next to the message it belongs to.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct InlineKeyboardMarkup {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub enum InputFile {
|
||||
File(std::path::PathBuf),
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
use crate::core::types::{InputFile, ParseMode};
|
||||
|
||||
// TODO: should variants use new-type?
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct Invoice {
|
||||
pub title: String,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// This object represents one button of the reply keyboard.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct KeyboardButton {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct LabeledPrice {
|
||||
pub label: String,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct LoginUrl {
|
||||
url: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
forward_text: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
bot_username: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
request_write_access: Option<bool>,
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct MaskPosition {
|
||||
pub point: String,
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
// use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{
|
||||
Animation, Audio, Chat, Contact, Document, Game, InlineKeyboardMarkup, Invoice, Location,
|
||||
MessageEntity, PassportData, PhotoSize, Poll, Sticker, SuccessfulPayment, User, Venue, Video,
|
||||
VideoNote, Voice,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
pub struct Message {
|
||||
pub message_id: i64,
|
||||
pub from: Option<Box<User>>,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::core::types::User;
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
pub struct MessageEntity {
|
||||
#[serde(flatten)]
|
||||
pub kind: MessageEntityKind,
|
||||
|
@ -8,7 +9,8 @@ pub struct MessageEntity {
|
|||
pub length: usize,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(tag = "type")]
|
||||
pub enum MessageEntityKind {
|
||||
|
|
|
@ -1,22 +1,46 @@
|
|||
use self::not_implemented_types::*;
|
||||
|
||||
|
||||
pub type Integer = i32;
|
||||
pub type UnsignedInteger = u32;
|
||||
|
||||
|
||||
pub use self::{
|
||||
answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery,
|
||||
chat::Chat, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, document::Document,
|
||||
invoice::Invoice, label_price::LabeledPrice, message::Message, message_entity::MessageEntity,
|
||||
order_info::OrderInfo, pre_checkout_query::PreCheckoutQuery, send_invoice::SendInvoice,
|
||||
shipping_address::ShippingAddress, shipping_option::ShippingOption,
|
||||
shipping_query::ShippingQuery, sticker::Sticker, successful_payment::SuccessfulPayment,
|
||||
answer_pre_checkout_query::AnswerPreCheckoutQuery,
|
||||
answer_shipping_query::AnswerShippingQuery,
|
||||
audio::Audio,
|
||||
chat::Chat,
|
||||
chat_permissions::ChatPermissions,
|
||||
chat_photo::ChatPhoto,
|
||||
chat_member::ChatMember,
|
||||
document::Document,
|
||||
invoice::Invoice,
|
||||
label_price::LabeledPrice,
|
||||
message::Message,
|
||||
message_entity::MessageEntity,
|
||||
order_info::OrderInfo,
|
||||
photo_size::PhotoSize,
|
||||
pre_checkout_query::PreCheckoutQuery,
|
||||
send_invoice::SendInvoice,
|
||||
shipping_address::ShippingAddress,
|
||||
shipping_option::ShippingOption,
|
||||
shipping_query::ShippingQuery,
|
||||
sticker::Sticker,
|
||||
successful_payment::SuccessfulPayment,
|
||||
user::User,
|
||||
input_file::InputFile,
|
||||
input_media::InputMedia,
|
||||
parse_mode::ParseMode,
|
||||
video::Video
|
||||
};
|
||||
|
||||
mod answer_pre_checkout_query;
|
||||
mod answer_shipping_query;
|
||||
mod audio;
|
||||
mod chat;
|
||||
mod chat_permissions;
|
||||
mod chat_photo;
|
||||
mod chat_member;
|
||||
mod document;
|
||||
mod invoice;
|
||||
mod label_price;
|
||||
|
@ -24,6 +48,7 @@ mod message;
|
|||
mod message_entity;
|
||||
mod not_implemented_types;
|
||||
mod order_info;
|
||||
mod photo_size;
|
||||
mod pre_checkout_query;
|
||||
mod send_invoice;
|
||||
mod shipping_address;
|
||||
|
@ -35,3 +60,4 @@ mod user;
|
|||
mod input_file;
|
||||
mod input_media;
|
||||
mod parse_mode;
|
||||
mod video;
|
||||
|
|
|
@ -1,41 +1,35 @@
|
|||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct PhotoSize;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Location;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct InlineKeyboardMarkup;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct PassportData;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Poll;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Animation;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Audio;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Game;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Contact;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Video;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct VideoNote;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Venue;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Voice;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct MaskPosition;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct ChatMemberStatus;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::ShippingAddress;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
10
src/core/types/photo_size.rs
Normal file
10
src/core/types/photo_size.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use crate::core::types::{Integer, UnsignedInteger};
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct PhotoSize {
|
||||
pub file_id: String,
|
||||
pub width: Integer,
|
||||
pub heigth: Integer,
|
||||
pub file_size: Option<UnsignedInteger>
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{OrderInfo, User};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// This object represents a custom keyboard with reply options.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct ReplyKeyboardMarkup {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
/// Upon receiving a message with this object, Telegram clients will remove
|
||||
/// the current custom keyboard and display the default letter-keyboard.
|
||||
/// By default, custom keyboards are displayed until a new keyboard is sent
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct ResponseParameters {
|
||||
migrate_to_chat_id: Option<i64>,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct ShippingAddress {
|
||||
pub country_code: String,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::LabeledPrice;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{ShippingAddress, User};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{MaskPosition, PhotoSize};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::Sticker;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::OrderInfo;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct User {
|
||||
pub id: i64,
|
||||
|
|
13
src/core/types/venue.rs
Normal file
13
src/core/types/venue.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use crate::core::types::Location;
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Venue {
|
||||
pub location: Location,
|
||||
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>
|
||||
}
|
13
src/core/types/video.rs
Normal file
13
src/core/types/video.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use crate::core::types::{PhotoSize, UnsignedInteger};
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Video {
|
||||
pub file_id: String,
|
||||
pub width: UnsignedInteger,
|
||||
pub height: UnsignedInteger,
|
||||
pub duration: UnsignedInteger,
|
||||
pub thumb: Option<PhotoSize>,
|
||||
pub mime_type: Option<String>,
|
||||
pub file_size: Option<UnsignedInteger>
|
||||
}
|
Loading…
Reference in a new issue