tg_flows/types/
webhook_info.rs

1use std::net::IpAddr;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use crate::types::AllowedUpdate;
7
8/// Contains information about the current status of a webhook.
9///
10/// [The official docs](https://core.telegram.org/bots/api#webhookinfo).
11#[serde_with_macros::skip_serializing_none]
12#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
13pub struct WebhookInfo {
14    /// Webhook URL, `None` if webhook is not set up.
15    #[serde(with = "crate::types::option_url_from_string")]
16    pub url: Option<url::Url>,
17
18    /// `true`, if a custom certificate was provided for webhook certificate
19    /// checks.
20    pub has_custom_certificate: bool,
21
22    /// Number of updates awaiting delivery.
23    pub pending_update_count: u32,
24
25    /// Currently used webhook IP address.
26    pub ip_address: Option<IpAddr>,
27
28    /// Time of the most recent error that happened when trying to
29    /// deliver an update via webhook.
30    #[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
31    pub last_error_date: Option<DateTime<Utc>>,
32
33    /// Error message in human-readable format for the most recent error that
34    /// happened when trying to deliver an update via webhook.
35    pub last_error_message: Option<String>,
36
37    /// Time of the most recent error that happened when trying to synchronize
38    /// available updates with Telegram data-centers.
39    #[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
40    pub last_synchronization_error_date: Option<DateTime<Utc>>,
41
42    /// Maximum allowed number of simultaneous HTTPS connections to the webhook
43    /// for update delivery.
44    pub max_connections: Option<u32>,
45
46    /// A list of update types the bot is subscribed to. Defaults to all update
47    /// types.
48    pub allowed_updates: Option<Vec<AllowedUpdate>>,
49}
50
51// Regression test for <https://github.com/teloxide/teloxide-core/pull/166>
52#[test]
53fn empty_url() {
54    let json = r#"{"url":"","has_custom_certificate":false,"pending_update_count":0,"allowed_updates":["message"]}"#;
55    let actual: WebhookInfo = serde_json::from_str(json).unwrap();
56    let expected = WebhookInfo {
57        url: None,
58        has_custom_certificate: false,
59        pending_update_count: 0,
60        ip_address: None,
61        last_error_date: None,
62        last_error_message: None,
63        last_synchronization_error_date: None,
64        max_connections: None,
65        allowed_updates: Some(vec![AllowedUpdate::Message]),
66    };
67
68    assert_eq!(actual, expected);
69}