Implement Update

This commit is contained in:
Waffle 2019-09-12 21:21:18 +03:00
parent 80f588ce1b
commit d591e499c8
7 changed files with 48 additions and 14 deletions

View file

@ -1,8 +1,10 @@
use crate::core::types::{User, Message};
/// This object represents an incoming callback query from a callback button in an inline keyboard. /// This object represents an incoming callback query from a callback button in an inline keyboard.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] #[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct CallbackQuery { pub struct CallbackQuery {
/// Unique identifier for this query /// Unique identifier for this query
pub id: CallbackQueryId, pub id: String,
/// Sender /// Sender
pub from: User, pub from: User,
/// Message with the callback button that originated the query. /// Message with the callback button that originated the query.

View file

@ -1,7 +1,7 @@
use crate::core::types::{ChatPermissions, ChatPhoto, Message}; use crate::core::types::{ChatPermissions, ChatPhoto, Message};
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] #[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
pub struct Chat { pub struct Chat {
pub id: i64, pub id: i64,
#[serde(flatten)] #[serde(flatten)]
@ -10,7 +10,7 @@ pub struct Chat {
} }
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] #[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum ChatKind { pub enum ChatKind {
NonPrivate { NonPrivate {

View file

@ -1,6 +1,6 @@
use crate::core::types::user::User; use crate::core::types::{User, Location};
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone, PartialEq)]
/// Represents a result of an inline query that was chosen by the user and /// Represents a result of an inline query that was chosen by the user and
/// sent to their chat partner. /// sent to their chat partner.
/// https://core.telegram.org/bots/api#inputtextmessagecontent /// https://core.telegram.org/bots/api#inputtextmessagecontent

View file

@ -1,8 +1,6 @@
use serde::{Deserialization, Serialization}; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[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

View file

@ -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(Debug, Deserialize, PartialEq, Clone, 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(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum MessageKind { pub enum MessageKind {
IncomingMessage { IncomingMessage {
@ -82,7 +82,7 @@ pub enum Sender {
Signature(String), Signature(String),
} }
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] #[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum ForwardKind { pub enum ForwardKind {
ChannelForward { ChannelForward {
@ -114,7 +114,7 @@ pub enum ForwardedFrom {
SenderName(String), SenderName(String),
} }
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] #[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum MediaKind { pub enum MediaKind {
Animation { Animation {

View file

@ -36,6 +36,10 @@ pub use self::{
reply_keyboard_remove::ReplyKeyboardRemove, reply_keyboard_remove::ReplyKeyboardRemove,
reply_keyboard_markup::ReplyKeyboardMarkup, reply_keyboard_markup::ReplyKeyboardMarkup,
keyboard_button::KeyboardButton, keyboard_button::KeyboardButton,
update::{Update, UpdateKind},
chosen_inline_result::ChosenInlineResult,
location::Location,
callback_query::CallbackQuery,
}; };
mod answer_pre_checkout_query; mod answer_pre_checkout_query;
@ -73,3 +77,7 @@ mod sticker;
mod successful_payment; mod successful_payment;
mod user; mod user;
mod video; mod video;
mod update;
mod chosen_inline_result;
mod location;
mod callback_query;

26
src/core/types/update.rs Normal file
View file

@ -0,0 +1,26 @@
use crate::core::types::{
Message, ChosenInlineResult, CallbackQuery,
};
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct Update {
#[serde(rename = "update_id")]
pub id: i32,
#[serde(flatten)]
pub kind: UpdateKind,
}
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum UpdateKind {
Message(Message),
EditedMessage(Message),
ChannelPost(Message),
EditedChannelPost(Message),
InlineQuery(()), // TODO
ChosenInlineResult(ChosenInlineResult),
CallbackQuery(CallbackQuery),
}
// TODO: tests for deserialization