1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use serde::{Deserialize, Serialize};
use crate::chat::Chat;
use crate::message::MessageEntity;
use crate::user::User;
/// A native Telegram poll or quiz.
///
/// Polls are either `regular` (users vote freely) or `quiz` (one or more correct
/// answers). Returned inside [`Message`](crate::message::Message) when a poll is
/// sent or forwarded.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Poll {
/// Unique poll identifier.
pub id: String,
/// Poll question (1–300 characters).
pub question: String,
/// Special entities in the question.
#[serde(skip_serializing_if = "Option::is_none")]
pub question_entities: Option<Vec<MessageEntity>>,
/// List of answer options.
pub options: Vec<PollOption>,
/// Total number of users who voted.
pub total_voter_count: u32,
/// `true` if the poll is closed.
pub is_closed: bool,
/// `true` if the poll is anonymous.
pub is_anonymous: bool,
/// Poll type.
#[serde(rename = "type")]
pub kind: PollType,
/// `true` if the poll allows multiple answers.
pub allows_multiple_answers: bool,
/// `true` if voters can change their chosen answer options.
pub allows_revoting: bool,
/// Zero-based indices of the correct answers (quiz polls only).
///
/// Bot API 9.6 changed this from a single `u8` to an array to support
/// quizzes with multiple correct answers.
#[serde(skip_serializing_if = "Option::is_none")]
pub correct_option_ids: Option<Vec<u8>>,
/// Explanation shown after a quiz is answered.
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation: Option<String>,
/// Special entities in the explanation.
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation_entities: Option<Vec<MessageEntity>>,
/// Duration in seconds the poll stays active after creation.
#[serde(skip_serializing_if = "Option::is_none")]
pub open_period: Option<u32>,
/// Unix timestamp when the poll closes automatically.
#[serde(skip_serializing_if = "Option::is_none")]
pub close_date: Option<i64>,
/// Description of the poll; present only inside `Message` objects.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Special entities in the description.
#[serde(skip_serializing_if = "Option::is_none")]
pub description_entities: Option<Vec<MessageEntity>>,
}
/// One option in a [`Poll`].
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PollOption {
/// Persistent identifier of this option, stable across poll edits.
pub persistent_id: String,
/// Option text (1–100 characters).
pub text: String,
/// Special entities in the option text.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_entities: Option<Vec<MessageEntity>>,
/// Number of users who voted for this option.
pub voter_count: u32,
/// The user who added this option, if applicable.
#[serde(skip_serializing_if = "Option::is_none")]
pub added_by_user: Option<User>,
/// The chat that added this option, if applicable.
#[serde(skip_serializing_if = "Option::is_none")]
pub added_by_chat: Option<Chat>,
/// Unix timestamp when this option was added; absent if it existed at poll creation.
#[serde(skip_serializing_if = "Option::is_none")]
pub addition_date: Option<i64>,
}
/// An option to include when creating a poll with `sendPoll`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InputPollOption {
/// Option text (1–100 characters).
pub text: String,
/// Parse mode for the option text.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_parse_mode: Option<crate::message::ParseMode>,
/// Special entities in the option text; alternative to `text_parse_mode`.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_entities: Option<Vec<MessageEntity>>,
}
impl InputPollOption {
/// Creates a new `InputPollOption` with the given text.
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
text_parse_mode: None,
text_entities: None,
}
}
}
/// The type of a poll.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PollType {
/// A regular poll where users can vote freely.
Regular,
/// A quiz with one or more correct answers.
Quiz,
}
/// An answer submitted by a user in a non-anonymous poll.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PollAnswer {
/// Unique poll identifier.
pub poll_id: String,
/// The chat that changed the answer (for anonymous polls in groups).
#[serde(skip_serializing_if = "Option::is_none")]
pub voter_chat: Option<Chat>,
/// The user who changed the answer (for non-anonymous polls).
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<User>,
/// Zero-based indices of the chosen options; empty if the vote was retracted.
pub option_ids: Vec<u8>,
/// Persistent identifiers of the chosen options; empty if the vote was retracted.
pub option_persistent_ids: Vec<String>,
}
/// Service message: a new option was added to a poll.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PollOptionAdded {
/// Message containing the poll to which the option was added.
///
/// Uses `serde_json::Value` because the API returns a `MaybeInaccessibleMessage`
/// union type here. Will not contain `reply_to_message`.
#[serde(skip_serializing_if = "Option::is_none")]
pub poll_message: Option<serde_json::Value>,
/// Persistent identifier of the added option.
pub option_persistent_id: String,
/// Text of the added option.
pub option_text: String,
/// Special entities in the option text.
#[serde(skip_serializing_if = "Option::is_none")]
pub option_text_entities: Option<Vec<MessageEntity>>,
}
/// Service message: an option was deleted from a poll.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PollOptionDeleted {
/// Message containing the poll from which the option was deleted.
///
/// Uses `serde_json::Value` because the API returns a `MaybeInaccessibleMessage`
/// union type here. Will not contain `reply_to_message`.
#[serde(skip_serializing_if = "Option::is_none")]
pub poll_message: Option<serde_json::Value>,
/// Persistent identifier of the deleted option.
pub option_persistent_id: String,
/// Text of the deleted option.
pub option_text: String,
/// Special entities in the option text.
#[serde(skip_serializing_if = "Option::is_none")]
pub option_text_entities: Option<Vec<MessageEntity>>,
}