mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
commit
68913d7d48
4 changed files with 25 additions and 2 deletions
|
@ -37,6 +37,7 @@ tokio-util = "0.6.0"
|
|||
pin-project = "1.0.3"
|
||||
bytes = "1.0.0"
|
||||
reqwest = { version = "0.11.0", features = ["json", "stream", "multipart"] }
|
||||
log = "0.4"
|
||||
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
serde_json = "1.0.55"
|
||||
|
|
|
@ -188,10 +188,10 @@ mod passport_data;
|
|||
mod passport_element_error;
|
||||
mod passport_file;
|
||||
|
||||
pub use non_telegram_types::{country_code::*, currency::*, non_strict_vec::*};
|
||||
pub use non_telegram_types::{country_code::*, currency::*, semiparsed_vec::*};
|
||||
mod non_telegram_types {
|
||||
pub(super) mod country_code;
|
||||
pub(super) mod currency;
|
||||
pub(crate) mod mime;
|
||||
pub(super) mod non_strict_vec;
|
||||
pub(super) mod semiparsed_vec;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use crate::types::{
|
|||
CallbackQuery, Chat, ChosenInlineResult, InlineQuery, Message, Poll, PollAnswer,
|
||||
PreCheckoutQuery, ShippingQuery, User,
|
||||
};
|
||||
use serde_json::Value;
|
||||
|
||||
/// This [object] represents an incoming update.
|
||||
///
|
||||
|
@ -28,6 +29,27 @@ pub struct Update {
|
|||
pub kind: UpdateKind,
|
||||
}
|
||||
|
||||
impl Update {
|
||||
/// Tries to parse `value` into `Update`, logging an error on failure.
|
||||
///
|
||||
/// It is used to implement update listeners.
|
||||
pub fn try_parse(value: &Value) -> Result<Self, serde_json::Error> {
|
||||
match serde_json::from_value(value.clone()) {
|
||||
Ok(update) => Ok(update),
|
||||
Err(error) => {
|
||||
log::error!(
|
||||
"Cannot parse an update.\nError: {:?}\nValue: {}\n\
|
||||
This is a bug in teloxide-core, please open an issue here: \
|
||||
https://github.com/teloxide/teloxide-core/issues.",
|
||||
error,
|
||||
value
|
||||
);
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum UpdateKind {
|
||||
|
|
Loading…
Add table
Reference in a new issue