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
46
47
48
49
50
51
52
53
use crate::{LineApiResponse, LineClient};
use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};

impl LineClient {
    /// https://developers.line.biz/ja/reference/messaging-api/#set-webhook-endpoint-url
    pub async fn webhook_endpoint_put(&self, endpoint: &str) -> LineApiResponse<Value> {
        self.http_put(
            "https://api.line.me/v2/bot/channel/webhook/endpoint",
            &json!({
                "endpoint": endpoint
            }),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-webhook-endpoint-information
    pub async fn webhook_endpoint_get(&self) -> LineApiResponse<LineApiWebhookEndpointGetResponse> {
        self.http_get(
            "https://api.line.me/v2/bot/channel/webhook/endpoint",
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-webhook-endpoint-information
    pub async fn webhook_test(
        &self,
        request: &LineApiWebhookTestRequest,
    ) -> LineApiResponse<LineApiWebhookTestResponse> {
        self.http_post("https://api.line.me/v2/bot/channel/webhook/test", request)
            .await
    }
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiWebhookEndpointGetResponse {
    pub endpoint: String,
    pub active: bool,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiWebhookTestRequest {
    pub endpoint: Option<String>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiWebhookTestResponse {
    pub success: bool,
    pub timestamp: String,
    #[serde(rename = "statusCode")]
    pub status_code: u32,
    pub reason: String,
    pub detail: String,
}