telegram_bot_raw/requests/
get_updates.rs

1use crate::requests::*;
2use crate::types::*;
3
4/// Use this method to receive incoming updates using long polling.
5#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
6#[must_use = "requests do nothing unless sent"]
7pub struct GetUpdates {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    offset: Option<Integer>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    limit: Option<Integer>, // TODO(knsd): Values between 1—100 are accepted
12    #[serde(skip_serializing_if = "Option::is_none")]
13    timeout: Option<Integer>, // TODO(knsd): Should be positive
14    allowed_updates: Vec<AllowedUpdate>, // TODO(knsd) BitSet? HashSet? BTreeSet?
15}
16
17impl Request for GetUpdates {
18    type Type = JsonRequestType<Self>;
19    type Response = JsonIdResponse<Vec<Update>>;
20
21    fn serialize(&self) -> Result<HttpRequest, Error> {
22        Self::Type::serialize(RequestUrl::method("getUpdates"), self)
23    }
24}
25
26impl GetUpdates {
27    pub fn new() -> Self {
28        GetUpdates {
29            offset: None,
30            limit: None,
31            timeout: None,
32            allowed_updates: Vec::new(),
33        }
34    }
35
36    pub fn offset(&mut self, offset: Integer) -> &mut Self {
37        self.offset = Some(offset);
38        self
39    }
40
41    pub fn limit(&mut self, limit: Integer) -> &mut Self {
42        self.limit = Some(limit);
43        self
44    }
45
46    pub fn timeout(&mut self, timeout: Integer) -> &mut Self {
47        self.timeout = Some(timeout);
48        self
49    }
50
51    pub fn allowed_updates(&mut self, updates: &[AllowedUpdate]) -> &mut Self {
52        self.allowed_updates = updates.to_vec();
53        self
54    }
55}
56
57#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
58pub enum AllowedUpdate {
59    #[serde(rename = "message")]
60    Message,
61    #[serde(rename = "edited_message")]
62    EditedMessage,
63    #[serde(rename = "channel_post")]
64    ChannelPost,
65    #[serde(rename = "edited_channel_post")]
66    EditedChannelPost,
67    #[serde(rename = "inline_query")]
68    InlineQuery,
69    #[serde(rename = "chosen_inline_query")]
70    ChosenInlineResult,
71    #[serde(rename = "callback_query")]
72    CallbackQuery,
73    #[serde(rename = "shipping_query")]
74    ShippingQuery,
75    #[serde(rename = "pre_checkout_query")]
76    PreCheckoutQuery,
77}