1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use serde::Serialize;

use crate::{
    net,
    requests::{Request, ResponseResult},
    types::WebhookInfo,
    Bot,
};
use std::sync::Arc;

/// Use this method to get current webhook status.
///
/// If the bot is using [`Bot::get_updates`], will return an object with the url
/// field empty.
///
/// [The official docs](https://core.telegram.org/bots/api#getwebhookinfo).
///
/// [`Bot::get_updates`]: crate::Bot::get_updates
#[derive(Debug, Clone, Serialize)]
pub struct GetWebhookInfo {
    #[serde(skip_serializing)]
    bot: Arc<Bot>,
}

#[async_trait::async_trait]
impl Request for GetWebhookInfo {
    type Output = WebhookInfo;

    #[allow(clippy::trivially_copy_pass_by_ref)]
    async fn send(&self) -> ResponseResult<WebhookInfo> {
        net::request_json(
            self.bot.client(),
            self.bot.token(),
            "getWebhookInfo",
            &self,
        )
        .await
    }
}

impl GetWebhookInfo {
    pub(crate) fn new(bot: Arc<Bot>) -> Self {
        Self { bot }
    }
}