rutebot/requests/get_updates.rs
1use serde::Serialize;
2
3use crate::{requests::Request, responses::Update};
4
5/// Use this struct to receive incoming updates using long polling. An Array of `Update` objects is returned.
6#[derive(Serialize, Debug, Clone, Default)]
7pub struct GetUpdates<'a> {
8 /// Identifier of the first update to be returned. Must be greater by one than the highest
9 /// among the identifiers of previously received updates.
10 /// By default, updates starting with the earliest unconfirmed update are returned.
11 /// An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
12 /// The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue.
13 /// All previous updates will forgotten.
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub offset: Option<i64>,
16
17 /// Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub limit: Option<u32>,
20
21 /// Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling.
22 /// Should be positive, short polling should be used for testing purposes only.
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub timeout: Option<u32>,
25 /// List the types of updates you want your bot to receive.
26 /// For example, specify ```&[UpdateKind::Message, UpdateKind::EditedChannelPost, UpdateKind::CallbackQuery]```
27 /// to only receive updates of these types.
28 /// See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default).
29 /// If not specified, the previous setting will be used.
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub allowed_updates: Option<&'a [UpdateKind]>,
32}
33
34/// Enumeration of possible update types from telegram bot api
35#[derive(Serialize, Debug, Clone, Copy)]
36#[serde(rename_all = "snake_case")]
37pub enum UpdateKind {
38 Message,
39 EditedMessage,
40 ChannelPost,
41 EditedChannelPost,
42 InlineQuery,
43 ChosenInlineResult,
44 CallbackQuery,
45 ShippingQuery,
46 PreCheckoutQuery,
47}
48
49impl<'a> Request for GetUpdates<'a> {
50 type ResponseType = Vec<Update>;
51
52 fn method(&self) -> &'static str {
53 "getUpdates"
54 }
55}
56
57impl<'a> GetUpdates<'a> {
58 pub fn new() -> Self {
59 Self {
60 offset: None,
61 limit: None,
62 timeout: None,
63 allowed_updates: None,
64 }
65 }
66
67 pub fn new_with_timeout(timeout: u32) -> Self {
68 Self {
69 offset: None,
70 limit: None,
71 timeout: Some(timeout),
72 allowed_updates: None,
73 }
74 }
75}