tg_flows/types/
response_parameters.rs

1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5/// Contains information about why a request was unsuccessful.
6///
7/// [The official docs](https://core.telegram.org/bots/api#responseparameters).
8#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum ResponseParameters {
11    /// The group has been migrated to a supergroup with the specified
12    /// identifier. This number may be greater than 32 bits and some
13    /// programming languages may have difficulty/silent defects in
14    /// interpreting it. But it is smaller than 52 bits, so a signed 64 bit
15    /// integer or double-precision float type are safe for storing this
16    /// identifier.
17    MigrateToChatId(i64),
18
19    /// In case of exceeding flood control, the number of seconds left to wait
20    /// before the request can be repeated.
21    RetryAfter(#[serde(with = "crate::types::duration_secs")] Duration),
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn migrate_to_chat_id_deserialization() {
30        let expected = ResponseParameters::MigrateToChatId(123_456);
31        let actual: ResponseParameters =
32            serde_json::from_str(r#"{"migrate_to_chat_id":123456}"#).unwrap();
33
34        assert_eq!(expected, actual);
35    }
36
37    #[test]
38    fn retry_after_deserialization() {
39        let expected = ResponseParameters::RetryAfter(Duration::from_secs(123_456));
40        let actual: ResponseParameters = serde_json::from_str(r#"{"retry_after":123456}"#).unwrap();
41
42        assert_eq!(expected, actual);
43    }
44}