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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
use serde::{Deserialize, Serialize};
use crate::chat::{Chat, Location, Venue};
use crate::file::{Animation, Audio, Document, LivePhoto, PhotoSize, Video};
use crate::message::MessageEntity;
use crate::sticker::Sticker;
use crate::user::User;
/// Media attached to a poll description, quiz explanation, or poll option.
///
/// At most one of the optional fields will be `Some`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PollMedia {
/// Animation media.
#[serde(skip_serializing_if = "Option::is_none")]
pub animation: Option<Animation>,
/// Audio file; currently not receivable in poll options.
#[serde(skip_serializing_if = "Option::is_none")]
pub audio: Option<Audio>,
/// General file; currently not receivable in poll options.
#[serde(skip_serializing_if = "Option::is_none")]
pub document: Option<Document>,
/// Live photo media.
#[serde(skip_serializing_if = "Option::is_none")]
pub live_photo: Option<LivePhoto>,
/// Location media.
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<Location>,
/// Photo media (available sizes).
#[serde(skip_serializing_if = "Option::is_none")]
pub photo: Option<Vec<PhotoSize>>,
/// Sticker media; only for poll options.
#[serde(skip_serializing_if = "Option::is_none")]
pub sticker: Option<Sticker>,
/// Venue media.
#[serde(skip_serializing_if = "Option::is_none")]
pub venue: Option<Venue>,
/// Video media.
#[serde(skip_serializing_if = "Option::is_none")]
pub video: Option<Video>,
/// HTTP link attached to the poll option.
#[serde(skip_serializing_if = "Option::is_none")]
pub link: Option<crate::chat::Link>,
}
/// Media content for a poll description or quiz explanation to be sent.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InputPollMedia {
/// An animation.
Animation(crate::file::InputMediaAnimation),
/// An audio file.
Audio(crate::file::InputMediaAudio),
/// A document.
Document(crate::file::InputMediaDocument),
/// A live photo.
LivePhoto(crate::file::InputMediaLivePhoto),
/// A location.
Location(crate::file::InputMediaLocation),
/// A photo.
Photo(crate::file::InputMediaPhoto),
/// A venue.
Venue(crate::file::InputMediaVenue),
/// A video.
Video(crate::file::InputMediaVideo),
}
/// Media content for a poll option to be sent.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InputPollOptionMedia {
/// An animation.
Animation(crate::file::InputMediaAnimation),
/// A live photo.
LivePhoto(crate::file::InputMediaLivePhoto),
/// An HTTP link.
Link(crate::chat::InputMediaLink),
/// A location.
Location(crate::file::InputMediaLocation),
/// A photo.
Photo(crate::file::InputMediaPhoto),
/// A sticker.
Sticker(crate::file::InputMediaSticker),
/// A venue.
Venue(crate::file::InputMediaVenue),
/// A video.
Video(crate::file::InputMediaVideo),
}
/// 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>>,
/// Media added to the poll description; present only inside `Message` objects.
#[serde(skip_serializing_if = "Option::is_none")]
pub media: Option<PollMedia>,
/// Media added to the quiz explanation.
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation_media: Option<PollMedia>,
/// `true` if voting is limited to users who have been members of the chat for more than 24 hours.
#[serde(skip_serializing_if = "Option::is_none")]
pub members_only: Option<bool>,
/// Two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which users can vote.
/// If absent, users from any country can participate.
#[serde(skip_serializing_if = "Option::is_none")]
pub country_codes: Option<Vec<String>>,
}
/// 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>,
/// Media added to this poll option.
#[serde(skip_serializing_if = "Option::is_none")]
pub media: Option<PollMedia>,
}
/// 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>>,
/// Media added to this poll option.
#[serde(skip_serializing_if = "Option::is_none")]
pub media: Option<InputPollOptionMedia>,
}
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,
media: 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>>,
}