added new type poll_answer

This commit is contained in:
p0lunin 2020-02-04 23:06:36 +02:00
parent 357e2640f4
commit 95b190e573
3 changed files with 23 additions and 1 deletions

View file

@ -64,6 +64,7 @@ pub use passport_element_error::*;
pub use passport_file::*;
pub use photo_size::*;
pub use poll_type::*;
pub use poll_answer::*;
pub use poll::*;
pub use pre_checkout_query::*;
pub use reply_keyboard_markup::*;
@ -125,6 +126,7 @@ mod order_info;
mod parse_mode;
mod photo_size;
mod poll;
mod poll_answer;
mod poll_type;
mod pre_checkout_query;
mod reply_keyboard_markup;

14
src/types/poll_answer.rs Normal file
View file

@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};
use crate::types::User;
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct PollAnswer {
/// Unique poll identifier
pub poll_id: String,
/// The user, who changed the answer to the poll
pub user: User,
/// 0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote.
pub option_ids: Vec<i32>,
}

View file

@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};
use crate::types::{CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll, PreCheckoutQuery, ShippingQuery, User, Sender, Chat};
use crate::types::{CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll, PreCheckoutQuery, ShippingQuery, User, Sender, Chat, PollAnswer};
/// This [object] represents an incoming update.
///
@ -68,6 +68,9 @@ pub enum UpdateKind {
/// New poll state. Bots receive only updates about stopped polls and
/// polls, which are sent by the bot.
Poll(Poll),
/// A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.
PollAnswer(PollAnswer)
}
impl Update {
@ -100,6 +103,9 @@ impl Update {
UpdateKind::PreCheckoutQuery(query) => {
Some(&query.from)
}
UpdateKind::PollAnswer(answer) => {
Some(&answer.user)
}
_ => None
}
}