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.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct CallbackQuery {
/// Unique identifier for this query
pub id: CallbackQueryId,
pub id: String,
/// Sender
pub from: User,
/// Message with the callback button that originated the query.

View file

@ -1,7 +1,7 @@
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 id: i64,
#[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)]
pub enum ChatKind {
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
/// sent to their chat partner.
/// https://core.telegram.org/bots/api#inputtextmessagecontent

View file

@ -1,8 +1,6 @@
use serde::{Deserialization, Serialization};
#[derive(Debug, Serialization, Deserialization, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
/// This object represents a point on the map.
struct Location {
pub struct Location {
/// Longitude as defined by sender
pub longitude: f64,
/// Latitude as defined by sender

View file

@ -4,7 +4,7 @@ use crate::core::types::{
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
};
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
pub struct Message {
#[serde(rename = "message_id")]
pub id: i64,
@ -14,7 +14,7 @@ pub struct Message {
pub message_kind: MessageKind,
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)]
pub enum MessageKind {
IncomingMessage {
@ -82,7 +82,7 @@ pub enum Sender {
Signature(String),
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)]
pub enum ForwardKind {
ChannelForward {
@ -114,7 +114,7 @@ pub enum ForwardedFrom {
SenderName(String),
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Clone, Serialize)]
#[serde(untagged)]
pub enum MediaKind {
Animation {

View file

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