line_bot_messaging_api/api/
webhook.rs

1use crate::{LineApiResponse, LineClient};
2use serde_derive::{Deserialize, Serialize};
3use serde_json::{json, Value};
4
5impl LineClient {
6    /// https://developers.line.biz/ja/reference/messaging-api/#set-webhook-endpoint-url
7    pub async fn webhook_endpoint_put(&self, endpoint: &str) -> LineApiResponse<Value> {
8        self.http_put(
9            "https://api.line.me/v2/bot/channel/webhook/endpoint",
10            &json!({
11                "endpoint": endpoint
12            }),
13        )
14        .await
15    }
16    /// https://developers.line.biz/ja/reference/messaging-api/#get-webhook-endpoint-information
17    pub async fn webhook_endpoint_get(&self) -> LineApiResponse<LineApiWebhookEndpointGetResponse> {
18        self.http_get(
19            "https://api.line.me/v2/bot/channel/webhook/endpoint",
20            &json!({}),
21        )
22        .await
23    }
24    /// https://developers.line.biz/ja/reference/messaging-api/#get-webhook-endpoint-information
25    pub async fn webhook_test(
26        &self,
27        request: &LineApiWebhookTestRequest,
28    ) -> LineApiResponse<LineApiWebhookTestResponse> {
29        self.http_post("https://api.line.me/v2/bot/channel/webhook/test", request)
30            .await
31    }
32}
33
34#[derive(Debug, Default, Deserialize, Serialize, Clone)]
35pub struct LineApiWebhookEndpointGetResponse {
36    pub endpoint: String,
37    pub active: bool,
38}
39
40#[derive(Debug, Default, Deserialize, Serialize, Clone)]
41pub struct LineApiWebhookTestRequest {
42    pub endpoint: Option<String>,
43}
44
45#[derive(Debug, Default, Deserialize, Serialize, Clone)]
46pub struct LineApiWebhookTestResponse {
47    pub success: bool,
48    pub timestamp: String,
49    #[serde(rename = "statusCode")]
50    pub status_code: u32,
51    pub reason: String,
52    pub detail: String,
53}