1extern crate json;
17extern crate rustc_serialize;
18
19use crate::*;
20use json::JsonValue;
21use std::fmt;
22
23#[derive(Debug, Clone, Copy)]
24pub enum MessageEntityType {
25 Mention,
26 Hashtag,
27 Cashtag,
28 BotCommand,
29 Url,
30 Email,
31 PhoneNumber,
32 Bold,
33 Italic,
34 Underline,
35 Strikethrough,
36 Code,
37 Pre,
38 TextLink,
39 TextMention,
40 Spoiler,
41}
42
43impl MessageEntityType {
44 fn from_string(s: String) -> MessageEntityType {
45 let s = s.as_str();
46 match s {
47 "mention" => MessageEntityType::Mention,
48 "hashtag" => MessageEntityType::Hashtag,
49 "cashtag" => MessageEntityType::Cashtag,
50 "bot_command" => MessageEntityType::BotCommand,
51 "url" => MessageEntityType::Url,
52 "email" => MessageEntityType::Email,
53 "phone_number" => MessageEntityType::PhoneNumber,
54 "bold" => MessageEntityType::Bold,
55 "italic" => MessageEntityType::Italic,
56 "underline" => MessageEntityType::Underline,
57 "strikethrough" => MessageEntityType::Strikethrough,
58 "code" => MessageEntityType::Code,
59 "pre" => MessageEntityType::Pre,
60 "text_link" => MessageEntityType::TextLink,
61 "text_mention" => MessageEntityType::TextMention,
62 "spoiler" => MessageEntityType::Spoiler,
63 _ => panic!("can't find MessageEntityType: \"{}\"", s),
64 }
65 }
66}
67
68impl fmt::Display for MessageEntityType {
69 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70 match self {
71 MessageEntityType::Mention => write!(f, "mention"),
72 MessageEntityType::Hashtag => write!(f, "hashtag"),
73 MessageEntityType::Cashtag => write!(f, "cashtag"),
74 MessageEntityType::BotCommand => write!(f, "bot_command"),
75 MessageEntityType::Url => write!(f, "url"),
76 MessageEntityType::Email => write!(f, "email"),
77 MessageEntityType::PhoneNumber => write!(f, "phone_number"),
78 MessageEntityType::Bold => write!(f, "bold"),
79 MessageEntityType::Italic => write!(f, "italic"),
80 MessageEntityType::Underline => write!(f, "underline"),
81 MessageEntityType::Strikethrough => write!(f, "strikethrough"),
82 MessageEntityType::Code => write!(f, "code"),
83 MessageEntityType::Pre => write!(f, "pre"),
84 MessageEntityType::TextLink => write!(f, "text_link"),
85 MessageEntityType::TextMention => write!(f, "text_mention"),
86 MessageEntityType::Spoiler => write!(f, "spoiler"),
87 }
88 }
89}
90
91vec_to_json_array! {
92 vec_me_to_json_array(MessageEntity)
93 vec_i32_to_json_array(i32)
94 vec_string_to_json_array(String)
95 vec_po_to_json_array(PollOption)
96 vec_update_to_json_array(Update)
97 vec_user_to_json_array(User)
98 vec_photo_size_to_json_array(PhotoSize)
99 vec_sticker_to_json_array(Sticker)
100 vec_keyboard_button_to_json_array(KeyboardButton)
101 vec_inline_keyboard_button_to_json_array(InlineKeyboardButton)
102 vec_input_media_to_json_array(InputMedia)
103 vec_message_to_json_array(Message)
104 vec_chat_member_to_json_array(ChatMember)
105 vec_bot_command_to_json_array(BotCommand)
106}
107
108vec_vec_to_json_array! {
109 vec_vec_photo_size_to_json_array(PhotoSize, vec_photo_size_to_json_array)
110 vec_vec_keyboard_button_to_json_array(KeyboardButton, vec_keyboard_button_to_json_array)
111 vec_vec_inline_keyboard_button_to_json_array(InlineKeyboardButton, vec_inline_keyboard_button_to_json_array)
112}
113
114pub(crate) trait Custom {
115 fn from_json(s: JsonValue) -> Self;
116 fn create_json(j: JsonValue, v: Self, name: &'static str) -> JsonValue;
117 fn to_json(v: Self) -> JsonValue;
118 fn push(j: Vec<String>, v: Self, name: &'static str) -> Vec<String>;
119 fn default() -> Self;
120 fn url_encode(v: Self) -> String;
121}
122
123expand_custom_direct_i! {
124 impl Custom for i64 (as_i64, unwrap, 0)
125 impl Custom for i32 (as_i32, unwrap, 0)
126 impl Custom for f64 (as_f64, unwrap, 0.0)
127}
128
129expand_custom_vec! {
130 impl Custom for Vec<i32> (as_vec_i32, unwrap, [].to_vec(), vec_i32_to_json_array)
131 impl Custom for Vec<Update> (as_vec_update, unwrap, [].to_vec(), vec_update_to_json_array)
132 impl Custom for Vec<PollOption> (as_vec_poll_option, unwrap, [].to_vec(), vec_po_to_json_array)
133 impl Custom for Vec<User> (as_vec_user, unwrap, [].to_vec(), vec_user_to_json_array)
134 impl Custom for Vec<Sticker> (as_vec_sticker, unwrap, [].to_vec(), vec_sticker_to_json_array)
135 impl Custom for Vec<String> (as_vec_string, unwrap, [].to_vec(), vec_string_to_json_array)
136 impl Custom for Vec<MessageEntity> (as_vec_message_entity, unwrap, [].to_vec(), vec_me_to_json_array)
137 impl Custom for Vec<InputMedia> (as_vec_input_media, unwrap, [].to_vec(), vec_input_media_to_json_array)
138 impl Custom for Vec<Message> (as_vec_message, unwrap, [].to_vec(), vec_message_to_json_array)
139 impl Custom for Vec<ChatMember> (as_vec_chat_member, unwrap, [].to_vec(), vec_chat_member_to_json_array)
140 impl Custom for Vec<BotCommand> (as_vec_bot_command, unwrap, [].to_vec(), vec_bot_command_to_json_array)
141}
142
143expand_custom_vec_vec! {
144 impl Custom for Vec<Vec<PhotoSize>> (as_vec_vec_photo_size, unwrap, [].to_vec(), vec_vec_photo_size_to_json_array)
145 impl Custom for Vec<Vec<KeyboardButton>> (as_vec_vec_keyboard_button, unwrap, [].to_vec(), vec_vec_keyboard_button_to_json_array)
146 impl Custom for Vec<Vec<InlineKeyboardButton>> (as_vec_vec_inline_keyboard_button, unwrap, [].to_vec(), vec_vec_inline_keyboard_button_to_json_array)
147}
148
149expand_custom_direct_bool! {
150 impl Custom for bool (as_bool, unwrap, false)
151}
152
153expand_custom! {
154 impl Custom for String (to_string, clone, "".to_string())
155 impl Custom for MessageEntityType (as_message_entity_type, unwrap, MessageEntityType::Mention)
156}
157
158expand_custom_direct_object! {
159 impl Custom for Update (as_update, unwrap, Update::empty())
160 impl Custom for User (as_user, unwrap, User::empty())
161 impl Custom for Message (as_message, unwrap, Message::empty())
162 impl Custom for ChatInviteLink (as_chat_invite_link, unwrap, ChatInviteLink::empty())
163 impl Custom for ChatMember (as_chat_member, unwrap, ChatMember::empty())
164 impl Custom for Chat (as_chat, unwrap, Chat::empty())
165 impl Custom for Sticker (as_sticker, unwrap, Sticker::empty())
166 impl Custom for KeyboardButton (as_keyboard_button, unwrap, KeyboardButton::empty())
167 impl Custom for ReplyKeyboardMarkup (as_reply_keyboard_markup, unwrap, ReplyKeyboardMarkup::empty())
168 impl Custom for ReplyKeyboardRemove (as_reply_keyboard_remove, unwrap, ReplyKeyboardRemove::empty())
169 impl Custom for ForceReply (as_force_reply, unwrap, ForceReply::empty())
170 impl Custom for Location (as_location, unwrap, Location::empty())
171 impl Custom for PollOption (as_poll_option, unwrap, PollOption::empty())
172 impl Custom for MessageEntity (as_message_entity, unwrap, MessageEntity::empty())
173 impl Custom for PhotoSize (as_photo_size, unwrap, PhotoSize::empty())
174 impl Custom for InlineKeyboardMarkup (as_inline_keyboard_markup, unwrap, InlineKeyboardMarkup::empty())
175 impl Custom for InlineKeyboardButton (as_inline_keyboard_button, unwrap, InlineKeyboardButton::empty())
176 impl Custom for InputMedia (as_input_media, unwrap, InputMedia::empty())
177 impl Custom for UserProfilePhotos (as_user_profile_photos, unwrap, UserProfilePhotos::empty())
178 impl Custom for ChatPermissions (as_chat_permissions, unwrap, ChatPermissions::empty())
179 impl Custom for BotCommand (as_bot_command, unwrap, BotCommand::empty())
180 impl Custom for Poll (as_poll, unwrap, Poll::empty())
181 impl Custom for StickerSet (as_sticker_set, unwrap, StickerSet::empty())
182 impl Custom for MaskPosition (as_mask_position, unwrap, MaskPosition::empty())
183}
184
185expand_custom_option! {
186 impl Custom for Option<bool> (as_bool, unwrap, None)
187 impl Custom for Option<i32> (as_i32, unwrap, None)
188 impl Custom for Option<i64> (as_i64, unwrap, None)
189 impl Custom for Option<f64> (as_f64, unwrap, None)
190 impl Custom for Option<String> (to_string, clone, None)
191 impl Custom for Option<User> (as_user, unwrap, None)
192 impl Custom for Option<Message> (as_message, unwrap, None)
193 impl Custom for Option<InlineKeyboardMarkup> (as_inline_keyboard_markup, unwrap, None)
194 impl Custom for Option<VoiceChatStarted> (as_voice_chat_started, unwrap, None)
195 impl Custom for Option<VoiceChatEnded> (as_voice_chat_ended, unwrap, None)
196 impl Custom for Option<VoiceChatScheduled> (as_voice_chat_scheduled, unwrap, None)
197 impl Custom for Option<VoiceChatParticipantsInvited> (as_voice_chat_participants_invited, unwrap, None)
198 impl Custom for Option<ProximityAlertTriggered> (as_proximity_alert_triggered, unwrap, None)
199 impl Custom for Option<MessageAutoDeleteTimerChanged> (as_message_auto_delete_timer_changed, unwrap, None)
200 impl Custom for Option<PhotoSize> (as_photo_size, unwrap, None)
201 impl Custom for Option<Contact> (as_contact, unwrap, None)
202 impl Custom for Option<Dice> (as_dice, unwrap, None)
203 impl Custom for Option<Poll> (as_poll, unwrap, None)
204 impl Custom for Option<Venue> (as_venue, unwrap, None)
205 impl Custom for Option<ChatPermissions> (as_chat_permissions, unwrap, None)
206 impl Custom for Option<Location> (as_location, unwrap, None)
207 impl Custom for Option<Chat> (as_chat, unwrap, None)
208 impl Custom for Option<ChatPhoto> (as_chat_photo, unwrap, None)
209 impl Custom for Option<Animation> (as_animation, unwrap, None)
210 impl Custom for Option<Audio> (as_audio, unwrap, None)
211 impl Custom for Option<ChatInviteLink> (as_chat_invite_link, unwrap, None)
212 impl Custom for Option<ChatMember> (as_chat_member, unwrap, None)
213 impl Custom for Option<Document> (as_document, unwrap, None)
214 impl Custom for Option<LoginUrl> (as_login_url, unwrap, None)
215 impl Custom for Option<Sticker> (as_sticker, unwrap, None)
216 impl Custom for Option<Video> (as_video, unwrap, None)
217 impl Custom for Option<VideoNote> (as_video_note, unwrap, None)
218 impl Custom for Option<Voice> (as_voice, unwrap, None)
219 impl Custom for Option<MaskPosition> (as_mask_position, unwrap, None)
220 impl Custom for Option<KeyboardButtonPollType> (as_keyboard_button_poll_type, unwrap, None)
221 impl Custom for Option<ChatLocation> (as_chat_location, unwrap, None)
222 impl Custom for Option<CallbackQuery> (as_callback_query, unwrap, None)
223 impl Custom for Option<PollAnswer> (as_poll_answer, unwrap, None)
224 impl Custom for Option<ChatMemberUpdated> (as_chat_member_updated, unwrap, None)
225}
226
227expand_custom_box! {
228 impl Custom for Box<Chat> (as_box_chat, unwrap, Box::new(Chat::empty()))
229}
230
231expand_custom_option_box! {
232 impl Custom for Option<Box<Chat>> (as_box_chat, unwrap, None)
233 impl Custom for Option<Box<Message>> (as_box_message, unwrap, None)
234}
235
236expand_custom_option_vec! {
237 impl Custom for Option<Vec<MessageEntity>> (as_vec_message_entity, unwrap, None, vec_me_to_json_array)
238 impl Custom for Option<Vec<PhotoSize>> (as_vec_photo_size, unwrap, None, vec_photo_size_to_json_array)
239 impl Custom for Option<Vec<User>> (as_vec_user, unwrap, None, vec_user_to_json_array)
240}
241
242trait JsonExt {
243 fn as_update(&self) -> Option<Update>;
244 fn as_user(&self) -> Option<User>;
245 fn as_chat(&self) -> Option<Chat>;
246 fn as_message(&self) -> Option<Message>;
247 fn as_sticker(&self) -> Option<Sticker>;
248 fn as_keyboard_button_poll_type(&self) -> Option<KeyboardButtonPollType>;
249 fn as_keyboard_button(&self) -> Option<KeyboardButton>;
250 fn as_reply_keyboard_markup(&self) -> Option<ReplyKeyboardMarkup>;
251 fn as_reply_keyboard_remove(&self) -> Option<ReplyKeyboardRemove>;
252 fn as_force_reply(&self) -> Option<ForceReply>;
253 fn as_location(&self) -> Option<Location>;
254 fn as_poll_option(&self) -> Option<PollOption>;
255 fn as_message_entity(&self) -> Option<MessageEntity>;
256 fn as_photo_size(&self) -> Option<PhotoSize>;
257 fn as_mask_position(&self) -> Option<MaskPosition>;
258 fn as_inline_keyboard_markup(&self) -> Option<InlineKeyboardMarkup>;
259 fn as_inline_keyboard_button(&self) -> Option<InlineKeyboardButton>;
260 fn as_voice_chat_started(&self) -> Option<VoiceChatStarted>;
261 fn as_voice_chat_ended(&self) -> Option<VoiceChatEnded>;
262 fn as_voice_chat_scheduled(&self) -> Option<VoiceChatScheduled>;
263 fn as_voice_chat_participants_invited(&self) -> Option<VoiceChatParticipantsInvited>;
264 fn as_proximity_alert_triggered(&self) -> Option<ProximityAlertTriggered>;
265 fn as_message_auto_delete_timer_changed(&self) -> Option<MessageAutoDeleteTimerChanged>;
266 fn as_contact(&self) -> Option<Contact>;
267 fn as_dice(&self) -> Option<Dice>;
268 fn as_poll(&self) -> Option<Poll>;
269 fn as_venue(&self) -> Option<Venue>;
270 fn as_chat_permissions(&self) -> Option<ChatPermissions>;
271 fn as_chat_photo(&self) -> Option<ChatPhoto>;
272 fn as_chat_member(&self) -> Option<ChatMember>;
273 fn as_chat_location(&self) -> Option<ChatLocation>;
274 fn as_animation(&self) -> Option<Animation>;
275 fn as_audio(&self) -> Option<Audio>;
276 fn as_chat_invite_link(&self) -> Option<ChatInviteLink>;
277 fn as_document(&self) -> Option<Document>;
278 fn as_video(&self) -> Option<Video>;
279 fn as_video_note(&self) -> Option<VideoNote>;
280 fn as_voice(&self) -> Option<Voice>;
281 fn as_login_url(&self) -> Option<LoginUrl>;
282 fn as_callback_query(&self) -> Option<CallbackQuery>;
283 fn as_poll_answer(&self) -> Option<PollAnswer>;
284 fn as_chat_member_updated(&self) -> Option<ChatMemberUpdated>;
285 fn as_input_media(&self) -> Option<InputMedia>;
286 fn as_user_profile_photos(&self) -> Option<UserProfilePhotos>;
287 fn as_bot_command(&self) -> Option<BotCommand>;
288 fn as_sticker_set(&self) -> Option<StickerSet>;
289 fn as_vec_poll_option(&self) -> Option<Vec<PollOption>>;
290 fn as_vec_string(&self) -> Option<Vec<String>>;
291 fn as_vec_update(&self) -> Option<Vec<Update>>;
292 fn as_vec_user(&self) -> Option<Vec<User>>;
293 fn as_vec_photo_size(&self) -> Option<Vec<PhotoSize>>;
294 fn as_vec_sticker(&self) -> Option<Vec<Sticker>>;
295 fn as_vec_keyboard_button(&self) -> Option<Vec<KeyboardButton>>;
296 fn as_vec_inline_keyboard_button(&self) -> Option<Vec<InlineKeyboardButton>>;
297 fn as_vec_input_media(&self) -> Option<Vec<InputMedia>>;
298 fn as_vec_message(&self) -> Option<Vec<Message>>;
299 fn as_vec_chat_member(&self) -> Option<Vec<ChatMember>>;
300 fn as_vec_bot_command(&self) -> Option<Vec<BotCommand>>;
301 fn as_vec_vec_photo_size(&self) -> Option<Vec<Vec<PhotoSize>>>;
302 fn as_vec_vec_keyboard_button(&self) -> Option<Vec<Vec<KeyboardButton>>>;
303 fn as_vec_vec_inline_keyboard_button(&self) -> Option<Vec<Vec<InlineKeyboardButton>>>;
304 fn as_vec_i32(&self) -> Option<Vec<i32>>;
305 fn as_message_entity_type(&self) -> Option<MessageEntityType>;
306 fn as_vec_message_entity(&self) -> Option<Vec<MessageEntity>>;
307 fn as_box_chat(&self) -> Option<Box<Chat>>;
308 fn as_box_message(&self) -> Option<Box<Message>>;
309}
310
311impl JsonExt for JsonValue {
312 as_custom! {
313 fn as_update(&self) -> Option<Update>
314 fn as_user(&self) -> Option<User>
315 fn as_chat(&self) -> Option<Chat>
316 fn as_message(&self) -> Option<Message>
317 fn as_sticker(&self) -> Option<Sticker>
318 fn as_keyboard_button_poll_type(&self) -> Option<KeyboardButtonPollType>
319 fn as_keyboard_button(&self) -> Option<KeyboardButton>
320 fn as_reply_keyboard_markup(&self) -> Option<ReplyKeyboardMarkup>
321 fn as_reply_keyboard_remove(&self) -> Option<ReplyKeyboardRemove>
322 fn as_force_reply(&self) -> Option<ForceReply>
323 fn as_inline_keyboard_button(&self) -> Option<InlineKeyboardButton>
324 fn as_location(&self) -> Option<Location>
325 fn as_poll_option(&self) -> Option<PollOption>
326 fn as_photo_size(&self) -> Option<PhotoSize>
327 fn as_mask_position(&self) -> Option<MaskPosition>
328 fn as_message_entity(&self) -> Option<MessageEntity>
329 fn as_contact(&self) -> Option<Contact>
330 fn as_dice(&self) -> Option<Dice>
331 fn as_poll(&self) -> Option<Poll>
332 fn as_venue(&self) -> Option<Venue>
333 fn as_chat_permissions(&self) -> Option<ChatPermissions>
334 fn as_chat_photo(&self) -> Option<ChatPhoto>
335 fn as_chat_member(&self) -> Option<ChatMember>
336 fn as_chat_location(&self) -> Option<ChatLocation>
337 fn as_animation(&self) -> Option<Animation>
338 fn as_audio(&self) -> Option<Audio>
339 fn as_inline_keyboard_markup(&self) -> Option<InlineKeyboardMarkup>
340 fn as_voice_chat_started(&self) -> Option<VoiceChatStarted>
341 fn as_voice_chat_ended(&self) -> Option<VoiceChatEnded>
342 fn as_voice_chat_scheduled(&self) -> Option<VoiceChatScheduled>
343 fn as_voice_chat_participants_invited(&self) -> Option<VoiceChatParticipantsInvited>
344 fn as_proximity_alert_triggered(&self) -> Option<ProximityAlertTriggered>
345 fn as_message_auto_delete_timer_changed(&self) -> Option<MessageAutoDeleteTimerChanged>
346 fn as_chat_invite_link(&self) -> Option<ChatInviteLink>
347 fn as_document(&self) -> Option<Document>
348 fn as_video(&self) -> Option<Video>
349 fn as_video_note(&self) -> Option<VideoNote>
350 fn as_voice(&self) -> Option<Voice>
351 fn as_login_url(&self) -> Option<LoginUrl>
352 fn as_callback_query(&self) -> Option<CallbackQuery>
353 fn as_poll_answer(&self) -> Option<PollAnswer>
354 fn as_chat_member_updated(&self) -> Option<ChatMemberUpdated>
355 fn as_input_media(&self) -> Option<InputMedia>
356 fn as_user_profile_photos(&self) -> Option<UserProfilePhotos>
357 fn as_bot_command(&self) -> Option<BotCommand>
358 fn as_sticker_set(&self) -> Option<StickerSet>
359 }
360 as_vec_custom! {
361 fn as_vec_poll_option(&self) -> Option<Vec<PollOption>>
362 fn as_vec_update(&self) -> Option<Vec<Update>>
363 fn as_vec_user(&self) -> Option<Vec<User>>
364 fn as_vec_i32(&self) -> Option<Vec<i32>>
365 fn as_vec_string(&self) -> Option<Vec<String>>
366 fn as_vec_photo_size(&self) -> Option<Vec<PhotoSize>>
367 fn as_vec_sticker(&self) -> Option<Vec<Sticker>>
368 fn as_vec_keyboard_button(&self) -> Option<Vec<KeyboardButton>>
369 fn as_vec_inline_keyboard_button(&self) -> Option<Vec<InlineKeyboardButton>>
370 fn as_vec_message_entity(&self) -> Option<Vec<MessageEntity>>
371 fn as_vec_input_media(&self) -> Option<Vec<InputMedia>>
372 fn as_vec_message(&self) -> Option<Vec<Message>>
373 fn as_vec_chat_member(&self) -> Option<Vec<ChatMember>>
374 fn as_vec_bot_command(&self) -> Option<Vec<BotCommand>>
375 }
376 as_vec_vec_custom! {
377 fn as_vec_vec_photo_size(&self, as_vec_photo_size) -> Option<Vec<Vec<PhotoSize>>>
378 fn as_vec_vec_keyboard_button(&self, as_vec_keyboard_button) -> Option<Vec<Vec<KeyboardButton>>>
379 fn as_vec_vec_inline_keyboard_button(&self, as_vec_inline_keyboard_button) -> Option<Vec<Vec<InlineKeyboardButton>>>
380 }
381 as_box_custom! {
382 fn as_box_chat(&self) -> Option<Box<Chat>>
383 fn as_box_message(&self) -> Option<Box<Message>>
384 }
385 fn as_message_entity_type(&self) -> Option<MessageEntityType> {
386 if self.is_empty() {
387 None
388 } else {
389 Some(MessageEntityType::from_string(format!("{}", self)))
390 }
391 }
392}
393expand_from! {
394 impl From<Update> for JsonValue
395 impl From<User> for JsonValue
396 impl From<Location> for JsonValue
397 impl From<MessageEntity> for JsonValue
398 impl From<PhotoSize> for JsonValue
399 impl From<PollOption> for JsonValue
400 impl From<InlineKeyboardButton> for JsonValue
401 impl From<KeyboardButtonPollType> for JsonValue
402 impl From<KeyboardButton> for JsonValue
403 impl From<ForceReply> for JsonValue
404 impl From<ReplyKeyboardMarkup> for JsonValue
405 impl From<ReplyKeyboardRemove> for JsonValue
406 impl From<Audio> for JsonValue
407 impl From<Animation> for JsonValue
408 impl From<ChatPhoto> for JsonValue
409 impl From<ChatPermissions> for JsonValue
410 impl From<Venue> for JsonValue
411 impl From<Poll> for JsonValue
412 impl From<Dice> for JsonValue
413 impl From<Contact> for JsonValue
414 impl From<VoiceChatScheduled> for JsonValue
415 impl From<VoiceChatStarted> for JsonValue
416 impl From<VoiceChatEnded> for JsonValue
417 impl From<VoiceChatParticipantsInvited> for JsonValue
418 impl From<ProximityAlertTriggered> for JsonValue
419 impl From<MessageAutoDeleteTimerChanged> for JsonValue
420 impl From<InlineKeyboardMarkup> for JsonValue
421 impl From<Message> for JsonValue
422 impl From<Chat> for JsonValue
423 impl From<Video> for JsonValue
424 impl From<Voice> for JsonValue
425 impl From<VideoNote> for JsonValue
426 impl From<Document> for JsonValue
427 impl From<ChatMember> for JsonValue
428 impl From<ChatInviteLink> for JsonValue
429 impl From<LoginUrl> for JsonValue
430 impl From<ChatLocation> for JsonValue
431 impl From<CallbackQuery> for JsonValue
432 impl From<PollAnswer> for JsonValue
433 impl From<ChatMemberUpdated> for JsonValue
434 impl From<InputMedia> for JsonValue
435 impl From<Sticker> for JsonValue
436 impl From<MaskPosition> for JsonValue
437 impl From<UserProfilePhotos> for JsonValue
438 impl From<BotCommand> for JsonValue
439 impl From<StickerSet> for JsonValue
440}
441
442add_functionality! {
443pub struct Update {
444 pub update_id: i64,
445 pub message: Option<Message>,
446 pub edited_message: Option<Message>,
447 pub channel_post: Option<Message>,
448 pub edited_channel_post: Option<Message>,
449 pub callback_query: Option<CallbackQuery>,
450 pub poll: Option<Poll>,
451 pub poll_answer: Option<PollAnswer>,
452 pub my_chat_member: Option<ChatMemberUpdated>,
453 pub chat_member: Option<ChatMemberUpdated>
454}
455
456pub struct User {
457 pub id: i64,
458 pub is_bot: bool,
459 pub first_name: String,
460 pub last_name: Option<String>,
461 pub username: Option<String>,
462 pub language_code: Option<String>,
463 pub can_join_groups: Option<bool>,
464 pub can_read_all_group_messages: Option<bool>,
465 pub supports_inline_queries: Option<bool>
466}
467
468pub struct Chat {
469 pub id: i64,
470 pub typ: String,
471 pub title: Option<String>,
472 pub username: Option<String>,
473 pub first_name: Option<String>,
474 pub last_name: Option<String>,
475 pub photo: Option<ChatPhoto>,
476 pub bio: Option<String>,
477 pub description: Option<String>,
478 pub invite_link: Option<String>,
479 pub pinned_message: Option<Message>,
480 pub permissions: Option<ChatPermissions>,
481 pub slow_mode_delay: Option<i32>,
482 pub message_auto_delete_time: Option<i32>,
483 pub sticker_set_name: Option<String>,
484 pub can_set_sticker_set: Option<bool>,
485 pub linked_chat_id: Option<i64>,
486 pub location: Option<ChatLocation>
487}
488
489pub struct Message {
490 pub message_id: i32,
491 pub from: Option<User>,
492 pub sender_chat: Option<Box<Chat>>,
493 pub date: i32,
494 pub chat: Box<Chat>,
495 pub forward_from: Option<User>,
496 pub forward_from_chat: Option<Box<Chat>>,
497 pub forward_from_message_id: Option<i32>,
498 pub forward_signature: Option<String>,
499 pub forward_sender_name: Option<String>,
500 pub forward_date: Option<i32>,
501 pub reply_to_message: Option<Box<Message>>,
502 pub via_bot: Option<User>,
503 pub edit_date: Option<i32>,
504 pub media_group_id: Option<String>,
505 pub author_signature: Option<String>,
506 pub text: Option<String>,
507 pub entities: Option<Vec<MessageEntity>>,
508 pub animation: Option<Animation>,
509 pub audio: Option<Audio>,
510 pub document: Option<Document>,
511 pub photo: Option<Vec<PhotoSize>>,
512 pub sticker: Option<Sticker>,
513 pub video: Option<Video>,
514 pub video_note: Option<VideoNote>,
515 pub voice: Option<Voice>,
516 pub caption: Option<String>,
517 pub caption_entities: Option<Vec<MessageEntity>>,
518 pub contact: Option<Contact>,
519 pub dice: Option<Dice>,
520 pub poll: Option<Poll>,
521 pub venue: Option<Venue>,
522 pub location: Option<Location>,
523 pub new_chat_members: Option<Vec<User>>,
524 pub left_chat_member: Option<User>,
525 pub new_chat_title: Option<String>,
526 pub new_chat_photo: Option<Vec<PhotoSize>>,
527 pub delete_chat_photo: Option<bool>,
528 pub group_chat_created: Option<bool>,
529 pub supergroup_chat_created: Option<bool>,
530 pub channel_chat_created: Option<bool>,
531 pub message_auto_delete_timer_changed: Option<MessageAutoDeleteTimerChanged>,
532 pub migrate_to_chat_id: Option<i64>,
533 pub migrate_from_chat_id: Option<i64>,
534 pub pinned_message: Option<Box<Message>>,
535 pub connected_website: Option<String>,
536 pub proximity_alert_triggered: Option<ProximityAlertTriggered>,
537 pub voice_chat_scheduled: Option<VoiceChatScheduled>,
538 pub voice_chat_started: Option<VoiceChatStarted>,
539 pub voice_chat_ended: Option<VoiceChatEnded>,
540 pub voice_chat_participants_invited: Option<VoiceChatParticipantsInvited>,
541 pub reply_markup: Option<InlineKeyboardMarkup>
542}
543
544pub struct MessageId {
545 pub message_id: i32
546}
547
548pub struct MessageEntity {
549 pub typ: MessageEntityType,
550 pub offset: i32,
551 pub length: i32,
552 pub url: Option<String>,
553 pub user: Option<User>,
554 pub language: Option<String>
555}
556
557pub struct PhotoSize {
558 pub file_id: String,
559 pub file_unique_id: String,
560 pub width: i32,
561 pub height: i32,
562 pub file_size: Option<i32>
563}
564
565pub struct Animation {
566 pub file_id: String,
567 pub file_unique_id: String,
568 pub width: i32,
569 pub height: i32,
570 pub duration: i32,
571 pub thumb: Option<PhotoSize>,
572 pub file_name: Option<String>,
573 pub mime_type: Option<String>,
574 pub file_size: Option<i32>
575}
576
577pub struct Audio {
578 pub file_id: String,
579 pub file_unique_id: String,
580 pub duration: i32,
581 pub performer: Option<String>,
582 pub title: Option<String>,
583 pub file_name: Option<String>,
584 pub mime_type: Option<String>,
585 pub file_size: Option<i32>,
586 pub thumb: Option<PhotoSize>
587}
588
589pub struct Document {
590 pub file_id: String,
591 pub file_unique_id: String,
592 pub thumb: Option<PhotoSize>,
593 pub file_name: Option<String>,
594 pub mime_type: Option<String>,
595 pub file_size: Option<i32>
596}
597
598pub struct Video {
599 pub file_id: String,
600 pub file_unique_id: String,
601 pub width: i32,
602 pub height: i32,
603 pub duration: i32,
604 pub thumb: Option<PhotoSize>,
605 pub file_name: Option<String>,
606 pub mime_type: Option<String>,
607 pub file_size: Option<i32>
608}
609
610pub struct VideoNote {
611 pub file_id: String,
612 pub file_unique_id: String,
613 pub length: i32,
614 pub duration: i32,
615 pub thumb: Option<PhotoSize>,
616 pub file_size: Option<i32>
617}
618
619pub struct Voice {
620 pub file_id: String,
621 pub file_unique_id: String,
622 pub duration: i32,
623 pub mime_type: Option<String>,
624 pub file_size: Option<i32>
625}
626
627pub struct Contact {
628 pub phone_number: String,
629 pub first_name: String,
630 pub last_name: Option<String>,
631 pub user_id: Option<i64>,
632 pub vcard: Option<String>
633}
634
635pub struct Dice {
636 pub emoji: String,
637 pub value: i32
638}
639
640pub struct PollOption {
641 pub text: String,
642 pub voter_count: i32
643}
644
645pub struct PollAnswer {
646 pub poll_id: String,
647 pub user: User,
648 pub option_ids: Vec<i32>
649}
650
651pub struct Poll {
652 pub id: String,
653 pub question: String,
654 pub options: Vec<PollOption>,
655 pub total_voter_count: i32,
656 pub is_closed: bool,
657 pub is_anonymous: bool,
658 pub typ: String,
659 pub allows_multiple_answers: bool,
660 pub correct_option_id: Option<i32>,
661 pub explanation: Option<String>,
662 pub explanation_entities: Option<Vec<MessageEntity>>,
663 pub open_period: Option<i32>,
664 pub close_date: Option<i32>
665}
666
667pub struct Location {
668 pub longitude: f64,
669 pub latitude: f64,
670 pub horizontal_accuracy: Option<f64>,
671 pub live_period: Option<i32>,
672 pub heading: Option<i32>,
673 pub proximity_alert_radius: Option<i32>
674}
675
676pub struct Venue {
677 pub location: Location,
678 pub title: String,
679 pub address: String,
680 pub foursquare_id: Option<String>,
681 pub foursquare_type: Option<String>,
682 pub google_place_id: Option<String>,
683 pub google_place_type: Option<String>
684}
685
686pub struct ProximityAlertTriggered {
687 pub traveler: User,
688 pub watcher: User,
689 pub distance: i32
690}
691
692pub struct MessageAutoDeleteTimerChanged {
693 pub message_auto_delete_time: i32
694}
695
696pub struct VoiceChatScheduled {
697 pub start_date: i32
698}
699
700pub struct VoiceChatEnded {
701 pub duration: i32
702}
703
704pub struct VoiceChatParticipantsInvited {
705 pub users: Vec<User>
706}
707
708pub struct UserProfilePhotos {
709 pub total_count: i32,
710 pub photos: Vec<Vec<PhotoSize>>
711}
712
713pub struct File {
714 pub file_id: String,
715 pub file_unique_id: String,
716 pub file_size: Option<String>,
717 pub file_path: Option<String>
718}
719
720pub struct ReplyKeyboardMarkup {
721 pub keyboard: Vec<Vec<KeyboardButton>>,
722 pub resize_keyboard: Option<bool>,
723 pub one_time_keyboard: Option<bool>,
724 pub selective: Option<bool>
725}
726
727pub struct KeyboardButton {
728 pub text: String,
729 pub request_contact: Option<bool>,
730 pub request_location: Option<bool>,
731 pub request_poll: Option<KeyboardButtonPollType>
732}
733
734pub struct KeyboardButtonPollType {
735 pub typ: String
736}
737
738pub struct ReplyKeyboardRemove {
739 pub remove_keyboard: bool, pub selective: Option<bool>
741}
742
743pub struct InlineKeyboardMarkup {
744 pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>
745}
746
747pub struct InlineKeyboardButton {
748 pub text: String,
749 pub url: Option<String>,
750 pub login_url: Option<LoginUrl>,
751 pub callback_data: Option<String>,
752 pub switch_inline_query: Option<String>,
753 pub switch_inline_query_current_chat: Option<String>,
754 pub pay: Option<bool>
755}
756
757pub struct LoginUrl {
758 pub url: String,
759 pub forward_text: Option<String>,
760 pub bot_username: Option<String>,
761 pub request_write_access: Option<bool>
762}
763
764pub struct CallbackQuery {
765 pub id: String,
766 pub from: User,
767 pub message: Option<Message>,
768 pub inline_message_id: Option<String>,
769 pub chat_instance: Option<String>,
770 pub data: Option<String>,
771 pub game_short_name: Option<String>
772}
773
774pub struct ForceReply {
775 pub force_reply: bool, pub selective: Option<bool>
777}
778
779pub struct ChatPhoto {
780 pub small_file_id: String,
781 pub small_file_unique_id: String,
782 pub big_file_id: String,
783 pub big_file_unique_id: String
784}
785
786pub struct ChatInviteLink {
787 pub invite_link: String,
788 pub creator: User,
789 pub is_primary: bool,
790 pub is_revoked: bool,
791 pub expire_date: Option<i32>,
792 pub member_limit: Option<i32>
793}
794
795pub struct ChatMember {
796 pub user: User,
797 pub status: String,
798 pub custom_title: Option<String>,
799 pub is_anonymous: Option<bool>,
800 pub can_be_edited: Option<bool>,
801 pub can_manage_chat: Option<bool>,
802 pub can_post_messages: Option<bool>,
803 pub can_edit_messages: Option<bool>,
804 pub can_delete_messages: Option<bool>,
805 pub can_manage_voice_chats: Option<bool>,
806 pub can_restrict_members: Option<bool>,
807 pub can_promote_members: Option<bool>,
808 pub can_change_info: Option<bool>,
809 pub can_invite_users: Option<bool>,
810 pub can_pin_messages: Option<bool>,
811 pub is_member: Option<bool>,
812 pub can_send_messages: Option<bool>,
813 pub can_send_media_messages: Option<bool>,
814 pub can_send_polls: Option<bool>,
815 pub can_send_other_messages: Option<bool>,
816 pub can_add_web_page_previews: Option<bool>,
817 pub until_date: Option<bool>
818}
819
820pub struct ChatMemberUpdated {
821 pub chat: Chat,
822 pub from: User,
823 pub date: i32,
824 pub old_chat_member: ChatMember,
825 pub new_chat_member: ChatMember,
826 pub invite_link: Option<ChatInviteLink>
827}
828
829pub struct ChatPermissions {
830 pub can_send_messages: Option<bool>,
831 pub can_send_media_messages: Option<bool>,
832 pub can_send_polls: Option<bool>,
833 pub can_send_other_messages: Option<bool>,
834 pub can_add_web_page_previews: Option<bool>,
835 pub can_change_info: Option<bool>,
836 pub can_invite_users: Option<bool>,
837 pub can_pin_messages: Option<bool>
838}
839
840pub struct ChatLocation {
841 pub location: Location,
842 pub address: String
843}
844
845pub struct BotCommand {
846 pub command: String,
847 pub description: String
848}
849
850pub struct ResponseParameters {
851 pub migrate_to_chat_id: Option<i32>,
852 pub retry_after: Option<i32>
853}
854
855pub struct InputMedia {
856 pub typ: String,
857 pub media: String,
858 pub caption: Option<String>,
859 pub parse_mode: Option<String>,
860 pub caption_entities: Option<Vec<MessageEntity>>,
861 pub width: Option<i32>,
862 pub height: Option<i32>,
863 pub duration: Option<i32>,
864 pub supports_streaming: Option<bool>,
865 pub performer: Option<String>,
866 pub title: Option<String>,
867 pub disable_content_type_detection: Option<bool>
868}
869
870pub struct Sticker {
871 pub file_id: String,
872 pub file_unique_id: String,
873 pub width: i32,
874 pub height: i32,
875 pub is_animated: bool,
876 pub thumb: Option<PhotoSize>,
877 pub emoji: Option<String>,
878 pub set_name: Option<String>,
879 pub mask_position: Option<MaskPosition>,
880 pub file_size: Option<i32>
881}
882
883pub struct StickerSet {
884 pub name: String,
885 pub title: String,
886 pub is_animated: bool,
887 pub contains_masks: bool,
888 pub stickers: Vec<Sticker>,
889 pub thumb: Option<PhotoSize>
890}
891
892pub struct MaskPosition {
893 pub point: String,
894 pub x_shift: f64,
895 pub y_shift: f64,
896 pub scale: f64
897}}
898
899add_functionality_empty! {
900 pub struct VoiceChatStarted {
901}}
902
903#[cfg(test)]
904mod tests {
905 use super::*;
906
907 #[test]
908 fn test_empty_user() {
909 let actual = format!("{}", User::empty().to_json());
910 let reference = "{\"id\":0,\"is_bot\":false,\"first_name\":\"\"}".to_string();
911 assert_eq!(actual, reference);
912 }
913
914 #[test]
915 fn test_minimal_user() {
916 let json_user = json::parse("{\"id\":1234,\"is_bot\":true,\"first_name\":\"iamgroot\"}");
917 let user;
918 match json_user {
919 Ok(json_data) => user = User::from_json(json_data),
920 Err(_) => user = User::empty(),
921 }
922 let actual = format!("{}", user.to_json());
923 let reference = "{\"id\":1234,\"is_bot\":true,\"first_name\":\"iamgroot\"}".to_string();
924 assert_eq!(actual, reference);
925 }
926
927 #[test]
928 fn test_full_user() {
929 let reference = "{\"id\":1234,\"is_bot\":true,\"first_name\":\"iAm\",\
930 \"last_name\":\"groot\",\"language_code\":\"US\",\"can_join_groups\":true,\
931 \"can_read_all_group_messages\":false,\"supports_inline_queries\":true}"
932 .to_string();
933 let json_user = json::parse(reference.as_str());
934 let user;
935 match json_user {
936 Ok(json_data) => user = User::from_json(json_data),
937 Err(_) => user = User::empty(),
938 }
939 let actual = format!("{}", user.to_json());
940 assert_eq!(actual, reference);
941 }
942
943 #[test]
944 #[should_panic(expected = "called `Option::unwrap()` on a `None` value")]
945 fn test_invalid_user() {
946 let json_user = json::parse("{\"id\":1234,\"first_name\":\"iamgroot\"}");
947 let _user;
948 match json_user {
949 Ok(json_data) => _user = User::from_json(json_data),
950 Err(_) => _user = User::empty(),
951 }
952 }
953
954 #[test]
955 fn test_clone_user() {
956 let mut user = User::empty();
957 let orig_user = user.clone();
958 user.first_name = "ichangedmyname".to_string();
959 let actual1 = format!("{}", user.to_json());
960 let reference1 =
961 "{\"id\":0,\"is_bot\":false,\"first_name\":\"ichangedmyname\"}".to_string();
962 assert_eq!(actual1, reference1);
963 let actual2 = format!("{}", orig_user.to_json());
964 let reference2 = "{\"id\":0,\"is_bot\":false,\"first_name\":\"\"}".to_string();
965 assert_eq!(actual2, reference2);
966 }
967
968 #[test]
969 fn test_display_user() {
970 let user = User::empty();
971 let reference = "id: 0; is_bot: false; first_name: ".to_string();
972 let actual = format!("{}", user);
973 assert_eq!(actual, reference);
974 }
975
976 #[test]
977 fn test_large_user_id() {
978 let mut user = User::empty();
979 user.id = 288230376151711744;
980 let reference = "id: 288230376151711744; is_bot: false; first_name: ".to_string();
981 let actual = format!("{}", user);
982 assert_eq!(actual, reference);
983 }
984
985 #[test]
986 fn test_empty_me() {
987 let actual = format!("{}", MessageEntity::empty().to_json());
988 let reference = "{\"type\":\"mention\",\"offset\":0,\"length\":0}".to_string();
989 assert_eq!(actual, reference);
990 }
991
992 #[test]
993 fn test_minimal_me() {
994 let json_me = json::parse("{\"type\":\"cashtag\",\"offset\":42,\"length\":69}");
995 let me;
996 match json_me {
997 Ok(json_data) => me = MessageEntity::from_json(json_data),
998 Err(_) => me = MessageEntity::empty(),
999 }
1000 let actual = format!("{}", me.to_json());
1001 let reference = "{\"type\":\"cashtag\",\"offset\":42,\"length\":69}".to_string();
1002 assert_eq!(actual, reference);
1003 }
1004
1005 #[test]
1006 fn test_full_me() {
1007 let reference = "{\"type\":\"cashtag\",\"offset\":42,\"length\":69,\
1008 \"url\":\"https://example.org\",\"user\":{\"id\":0,\"is_bot\":false,\"first_name\":\"user\"},\
1009 \"language\":\"python\"}".to_string();
1010 let json_me = json::parse(reference.as_str());
1011 let me;
1012 match json_me {
1013 Ok(json_data) => me = MessageEntity::from_json(json_data),
1014 Err(_) => me = MessageEntity::empty(),
1015 }
1016 let actual = format!("{}", me.to_json());
1017 assert_eq!(actual, reference);
1018 }
1019
1020 #[test]
1021 #[should_panic(expected = "called `Option::unwrap()` on a `None` value")]
1022 fn test_invalid_me() {
1023 let json_me = json::parse("{\"type\":\"cashtag\",\"length\":69}");
1024 let _me;
1025 match json_me {
1026 Ok(json_data) => _me = MessageEntity::from_json(json_data),
1027 Err(_) => _me = MessageEntity::empty(),
1028 }
1029 }
1030
1031 #[test]
1032 fn test_clone_me() {
1033 let mut me = MessageEntity::empty();
1034 let orig_me = me.clone();
1035 me.offset = 42;
1036 let actual1 = format!("{}", me.to_json());
1037 let reference1 = "{\"type\":\"mention\",\"offset\":42,\"length\":0}".to_string();
1038 assert_eq!(actual1, reference1);
1039 let actual2 = format!("{}", orig_me.to_json());
1040 let reference2 = "{\"type\":\"mention\",\"offset\":0,\"length\":0}".to_string();
1041 assert_eq!(actual2, reference2);
1042 }
1043
1044 #[test]
1045 fn test_display_me() {
1046 let me = MessageEntity::empty();
1047 let reference = "type: mention; offset: 0; length: 0".to_string();
1048 let actual = format!("{}", me);
1049 assert_eq!(actual, reference);
1050 }
1051
1052 #[test]
1053 fn test_input_media_photo() {
1054 let reference = r#"{"type":"photo","media":"test1234","caption_entities":[{"type":"mention","offset":0,"length":0},{"type":"mention","offset":1,"length":0}]}"#;
1055 expand_basic_test! {
1056 fn run_test(InputMedia, reference)
1057 }
1058 }
1059
1060 #[test]
1061 fn test_chat_photo() {
1062 let reference = r#"{"small_file_id":"1","small_file_unique_id":"1234","big_file_id":"2","big_file_unique_id":"2345"}"#;
1063 expand_basic_test! {
1064 fn run_test(ChatPhoto, reference)
1065 }
1066 }
1067
1068 #[test]
1069 fn test_chat_invite_link() {
1070 let reference = r#"{"invite_link":"hello","creator":{"id":1234,"is_bot":true,"first_name":"groot"},"is_primary":true,"is_revoked":false}"#;
1071 expand_basic_test! {
1072 fn run_test(ChatInviteLink, reference)
1073 }
1074 }
1075
1076 #[test]
1077 fn test_chat_member() {
1078 let reference =
1079 r#"{"user":{"id":1234,"is_bot":true,"first_name":"groot"},"status":"creator"}"#;
1080 expand_basic_test! {
1081 fn run_test(ChatMember, reference)
1082 }
1083 }
1084
1085 #[test]
1086 fn test_chat_permissions() {
1087 let reference = r#"{"can_send_messages":true}"#;
1088 expand_basic_test! {
1089 fn run_test(ChatPermissions, reference)
1090 }
1091 }
1092
1093 #[test]
1094 fn test_bot_command() {
1095 let reference = r#"{"command":"do_it","description":"Lets do it"}"#;
1096 expand_basic_test! {
1097 fn run_test(BotCommand, reference)
1098 }
1099 }
1100
1101 #[test]
1102 fn test_response_parameters() {
1103 let reference = r#"{"migrate_to_chat_id":1,"retry_after":120}"#;
1104 expand_basic_test! {
1105 fn run_test(ResponseParameters, reference)
1106 }
1107 }
1108
1109 #[test]
1110 fn test_photo_size() {
1111 let reference =
1112 r#"{"file_id":"1","file_unique_id":"1234","width":800,"height":600,"file_size":1024}"#;
1113 expand_basic_test! {
1114 fn run_test(PhotoSize, reference)
1115 }
1116 }
1117
1118 #[test]
1119 fn test_animation() {
1120 let reference = r#"{"file_id":"1","file_unique_id":"12345","width":600,"height":800,"duration":10,"thumb":{"file_id":"1","file_unique_id":"1234","width":800,"height":600}}"#;
1121 expand_basic_test! {
1122 fn run_test(Animation, reference)
1123 }
1124 }
1125
1126 #[test]
1127 fn test_audio() {
1128 let reference = r#"{"file_id":"1","file_unique_id":"12345","duration":60}"#;
1129 expand_basic_test! {
1130 fn run_test(Audio, reference)
1131 }
1132 }
1133
1134 #[test]
1135 fn test_document() {
1136 let reference = r#"{"file_id":"1","file_unique_id":"12345"}"#;
1137 expand_basic_test! {
1138 fn run_test(Document, reference)
1139 }
1140 }
1141
1142 #[test]
1143 fn test_video() {
1144 let reference =
1145 r#"{"file_id":"1","file_unique_id":"12345","width":800,"height":600,"duration":24}"#;
1146 expand_basic_test! {
1147 fn run_test(Video, reference)
1148 }
1149 }
1150
1151 #[test]
1152 fn test_video_note() {
1153 let reference = r#"{"file_id":"1","file_unique_id":"12345","length":120,"duration":10}"#;
1154 expand_basic_test! {
1155 fn run_test(VideoNote, reference)
1156 }
1157 }
1158
1159 #[test]
1160 fn test_voice() {
1161 let reference = r#"{"file_id":"1","file_unique_id":"12345","duration":5}"#;
1162 expand_basic_test! {
1163 fn run_test(Voice, reference)
1164 }
1165 }
1166
1167 #[test]
1168 fn test_contact() {
1169 let reference = r#"{"phone_number":"01234","first_name":"me","user_id":1234567890}"#;
1170 expand_basic_test! {
1171 fn run_test(Contact, reference)
1172 }
1173 }
1174
1175 #[test]
1176 fn test_dice() {
1177 let reference = r#"{"emoji":"dice","value":4}"#;
1178 expand_basic_test! {
1179 fn run_test(Dice, reference)
1180 }
1181 }
1182
1183 #[test]
1184 fn test_poll_option() {
1185 let reference = r#"{"text":"nein","voter_count":3}"#;
1186 expand_basic_test! {
1187 fn run_test(PollOption, reference)
1188 }
1189 }
1190
1191 #[test]
1192 fn test_poll_answer() {
1193 let reference = r#"{"poll_id":"01234","user":{"id":123654,"is_bot":true,"first_name":"me"},"option_ids":[1,2,3,4,5]}"#;
1194 expand_basic_test! {
1195 fn run_test(PollAnswer, reference)
1196 }
1197 }
1198
1199 #[test]
1200 fn test_poll() {
1201 let reference = r#"{"id":"1234","question":"right?","options":[{"text":"nein","voter_count":3},{"text":"ja","voter_count":4}],"total_voter_count":7,"is_closed":true,"is_anonymous":false,"type":"regular","allows_multiple_answers":false,"explanation_entities":[{"type":"mention","offset":10,"length":20},{"type":"cashtag","offset":1,"length":2}]}"#;
1202 expand_basic_test! {
1203 fn run_test(Poll, reference)
1204 }
1205 }
1206
1207 #[test]
1208 fn test_location() {
1209 let reference = r#"{"longitude":49.5,"latitude":9.4,"horizontal_accuracy":0.2}"#;
1210 expand_basic_test! {
1211 fn run_test(Location, reference)
1212 }
1213 }
1214
1215 #[test]
1216 fn test_venue() {
1217 let reference =
1218 r#"{"location":{"longitude":49.5,"latitude":9.4},"title":"home","address":"at home"}"#;
1219 expand_basic_test! {
1220 fn run_test(Venue, reference)
1221 }
1222 }
1223
1224 #[test]
1225 fn test_proximity_alert_triggered() {
1226 let reference = r#"{"traveler":{"id":123654,"is_bot":true,"first_name":"travel"},"watcher":{"id":123654,"is_bot":true,"first_name":"watch"},"distance":100}"#;
1227 expand_basic_test! {
1228 fn run_test(ProximityAlertTriggered, reference)
1229 }
1230 }
1231
1232 #[test]
1233 fn test_message_id() {
1234 let reference = r#"{"message_id":12334}"#;
1235 expand_basic_test! {
1236 fn run_test(MessageId, reference)
1237 }
1238 }
1239
1240 #[test]
1241 fn test_message_auto_delete_timer_changed() {
1242 let reference = r#"{"message_auto_delete_time":100}"#;
1243 expand_basic_test! {
1244 fn run_test(MessageAutoDeleteTimerChanged, reference)
1245 }
1246 }
1247
1248 #[test]
1249 fn test_voice_chat_scheduled() {
1250 let reference = r#"{"start_date":100}"#;
1251 expand_basic_test! {
1252 fn run_test(VoiceChatScheduled, reference)
1253 }
1254 }
1255
1256 #[test]
1257 fn test_voice_started() {
1258 let reference = r#"{}"#;
1259 expand_basic_test! {
1260 fn run_test(VoiceChatStarted, reference)
1261 }
1262 }
1263
1264 #[test]
1265 fn test_voice_chat_ended() {
1266 let reference = r#"{"duration":100}"#;
1267 expand_basic_test! {
1268 fn run_test(VoiceChatEnded, reference)
1269 }
1270 }
1271
1272 #[test]
1273 fn test_voice_chat_participants_invited() {
1274 let reference = r#"{"users":[{"id":123654,"is_bot":true,"first_name":"user1"},{"id":12365,"is_bot":true,"first_name":"user2"}]}"#;
1275 expand_basic_test! {
1276 fn run_test(VoiceChatParticipantsInvited, reference)
1277 }
1278 }
1279
1280 #[test]
1281 fn test_user_profile_photos() {
1282 let reference = r#"{"total_count":2,"photos":[[{"file_id":"1","file_unique_id":"1234","width":800,"height":600},{"file_id":"2","file_unique_id":"1234","width":600,"height":800}],[{"file_id":"3","file_unique_id":"1234","width":800,"height":600},{"file_id":"4","file_unique_id":"1234","width":600,"height":800}]]}"#;
1283 expand_basic_test! {
1284 fn run_test(UserProfilePhotos, reference)
1285 }
1286 }
1287
1288 #[test]
1289 fn test_file() {
1290 let reference = r#"{"file_id":"1","file_unique_id":"1234"}"#;
1291 expand_basic_test! {
1292 fn run_test(File, reference)
1293 }
1294 }
1295
1296 #[test]
1297 fn test_reply_keyboard_markup() {
1298 let reference = r#"{"keyboard":[[{"text":"quiz1"},{"text":"quiz2"}],[{"text":"quiz3"},{"text":"quiz4"}]]}"#;
1299 expand_basic_test! {
1300 fn run_test(ReplyKeyboardMarkup, reference)
1301 }
1302 }
1303
1304 #[test]
1305 fn test_keyboard_button() {
1306 let reference = r#"{"text":"quiz","request_poll":{"type":"quiz"}}"#;
1307 expand_basic_test! {
1308 fn run_test(KeyboardButton, reference)
1309 }
1310 }
1311
1312 #[test]
1313 fn test_keyboard_button_poll_type() {
1314 let reference = r#"{"type":"quiz"}"#;
1315 expand_basic_test! {
1316 fn run_test(KeyboardButtonPollType, reference)
1317 }
1318 }
1319
1320 #[test]
1321 fn test_reply_keyboard_remove() {
1322 let reference = r#"{"remove_keyboard":true}"#;
1323 expand_basic_test! {
1324 fn run_test(ReplyKeyboardRemove, reference)
1325 }
1326 }
1327
1328 #[test]
1329 fn test_login_url() {
1330 let reference = r#"{"url":"https://its.me"}"#;
1331 expand_basic_test! {
1332 fn run_test(LoginUrl, reference)
1333 }
1334 }
1335
1336 #[test]
1337 fn test_force_reply() {
1338 let reference = r#"{"force_reply":true}"#;
1339 expand_basic_test! {
1340 fn run_test(ForceReply, reference)
1341 }
1342 }
1343
1344 #[test]
1345 fn test_chat_location() {
1346 let reference = r#"{"location":{"longitude":49.5,"latitude":9.4},"address":"home"}"#;
1347 expand_basic_test! {
1348 fn run_test(ChatLocation, reference)
1349 }
1350 }
1351
1352 #[test]
1353 fn test_input_media() {
1354 let reference = r#"{"type":"video","media":"dummy"}"#;
1355 expand_basic_test! {
1356 fn run_test(InputMedia, reference)
1357 }
1358 }
1359
1360 #[test]
1361 fn test_sticker() {
1362 let reference = r#"{"file_id":"1","file_unique_id":"1234","width":64,"height":64,"is_animated":true,"thumb":{"file_id":"1","file_unique_id":"1234","width":800,"height":600},"mask_position":{"point":"chin","x_shift":1.1,"y_shift":2.5,"scale":2.1}}"#;
1363 expand_basic_test! {
1364 fn run_test(Sticker, reference)
1365 }
1366 }
1367
1368 #[test]
1369 fn test_sticker_set() {
1370 let reference = r#"{"name":"stickerset","title":"stickers","is_animated":true,"contains_masks":false,"stickers":[{"file_id":"1","file_unique_id":"1234","width":64,"height":64,"is_animated":true},{"file_id":"2","file_unique_id":"2345","width":32,"height":32,"is_animated":false}]}"#;
1371 expand_basic_test! {
1372 fn run_test(StickerSet, reference)
1373 }
1374 }
1375
1376 #[test]
1377 fn test_mask_position() {
1378 let reference = r#"{"point":"chin","x_shift":1.3,"y_shift":2.5,"scale":2.1}"#;
1379 expand_basic_test! {
1380 fn run_test(MaskPosition, reference)
1381 }
1382 }
1383
1384 #[test]
1385 fn test_chat_member_updated() {
1386 let reference = r#"{"chat":{"id":1234,"type":"private"},"from":{"id":1234,"is_bot":true,"first_name":"itsme"},"date":12,"old_chat_member":{"user":{"id":1234,"is_bot":true,"first_name":"groot"},"status":"creator"},"new_chat_member":{"user":{"id":1234,"is_bot":true,"first_name":"root"},"status":"creator"}}"#;
1387 expand_basic_test! {
1388 fn run_test(ChatMemberUpdated, reference)
1389 }
1390 }
1391
1392 #[test]
1393 fn test_callback_query() {
1394 let reference = r#"{"id":"1234","from":{"id":1234,"is_bot":true,"first_name":"itsme"},"message":{"message_id":10,"date":5,"chat":{"id":12,"type":"private"}}}"#;
1395 expand_basic_test! {
1396 fn run_test(CallbackQuery, reference)
1397 }
1398 }
1399
1400 #[test]
1401 fn test_inline_keyboard_button() {
1402 let reference = r#"{"text":"hello","login_url":{"url":"https://example.com"}}"#;
1403 expand_basic_test! {
1404 fn run_test(InlineKeyboardButton, reference)
1405 }
1406 }
1407
1408 #[test]
1409 fn test_inline_keyboard_markup() {
1410 let reference = r#"{"inline_keyboard":[[{"text":"hello1"},{"text":"hello2"}],[{"text":"hello3"},{"text":"hello4"}]]}"#;
1411 expand_basic_test! {
1412 fn run_test(InlineKeyboardMarkup, reference)
1413 }
1414 }
1415
1416 #[test]
1417 fn test_chat() {
1418 let reference = r#"{"id":1,"type":"private","photo":{"small_file_id":"1","small_file_unique_id":"1234","big_file_id":"2","big_file_unique_id":"2345"},"pinned_message":{"message_id":10,"date":5,"chat":{"id":12,"type":"private"}},"permissions":{"can_send_messages":true},"location":{"location":{"longitude":49.1,"latitude":10.2},"address":"here"}}"#;
1419 expand_basic_test! {
1420 fn run_test(Chat, reference)
1421 }
1422 }
1423
1424 #[test]
1425 fn test_message() {
1426 let reference = r#"{"message_id":32,"from":{"id":1234,"is_bot":true,"first_name":"itsme"},"sender_chat":{"id":12345,"type":"group"},"date":5,"chat":{"id":12,"type":"private"},"reply_to_message":{"message_id":10,"date":5,"chat":{"id":12,"type":"private"}}}"#;
1427 expand_basic_test! {
1428 fn run_test(Message, reference)
1429 }
1430 }
1431
1432 #[test]
1433 fn test_update() {
1434 let reference = r#"{"update_id":10,"message":{"message_id":10,"date":5,"chat":{"id":12,"type":"private"}},"poll_answer":{"poll_id":"test","user":{"id":13,"is_bot":false,"first_name":"user"},"option_ids":[0,1,2]}}"#;
1435 expand_basic_test! {
1436 fn run_test(Update, reference)
1437 }
1438 }
1439}