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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use crate::{LineApiResponse, LineClient};
use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};

impl LineClient {
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-delivery-messages
    pub async fn insight_message_delivery(
        &self,
        date: &str,
    ) -> LineApiResponse<LineApiInsightMessageDeliveryResponse> {
        self.http_get(
            format!(
                "https://api.line.me/v2/bot/insight/message/delivery?date={}",
                date
            )
            .as_str(),
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-followers
    pub async fn insight_followers(
        &self,
        date: &str,
    ) -> LineApiResponse<LineApiInsightFollowersResponse> {
        self.http_get(
            format!("https://api.line.me/v2/bot/insight/followers?date={}", date).as_str(),
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-demographic
    pub async fn insight_demographic(&self) -> LineApiResponse<LineApiInsightDemographicResponse> {
        self.http_get("https://api.line.me/v2/bot/insight/demographic", &json!({}))
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-demographic
    pub async fn insight_message_event(&self, request_id: &str) -> LineApiResponse<Value> {
        self.http_get(
            format!(
                "https://api.line.me/v2/bot/insight/message/event?requestId={}",
                request_id
            )
            .as_str(),
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-statistics-per-unit
    pub async fn insight_message_event_aggregation(
        &self,
        custom_aggregation_unit: &str,
        from: &str,
        to: &str,
    ) -> LineApiResponse<Value> {
        self.http_get(format!("https://api.line.me/v2/bot/insight/message/event/aggregation?customAggregationUnit={}&from={}&to={}", custom_aggregation_unit, from, to).as_str(), &json!({})).await
    }
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightMessageDeliveryResponse {
    pub status: String,
    pub broadcast: Option<u32>,
    pub targeting: Option<u32>,
    #[serde(rename = "autoResponse")]
    pub auto_response: Option<u32>,
    #[serde(rename = "welcomeResponse")]
    pub welcome_response: Option<u32>,
    #[serde(rename = "chat")]
    pub chat: Option<u32>,
    #[serde(rename = "apiBroadcast")]
    pub api_broadcast: Option<u32>,
    #[serde(rename = "apiPush")]
    pub api_push: Option<u32>,
    #[serde(rename = "apiMulticast")]
    pub api_multicast: Option<u32>,
    #[serde(rename = "apiNarrowcast")]
    pub api_narrowcast: Option<u32>,
    #[serde(rename = "apiReply")]
    pub api_reply: Option<u32>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightFollowersResponse {
    pub status: String,
    pub followers: Option<u32>,
    #[serde(rename = "targetedReaches")]
    pub targeted_reaches: Option<u32>,
    pub blocks: Option<u32>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightDemographicResponse {
    pub available: bool,
    pub genders: Vec<LineApiInsightDemographicGender>,
    pub ages: Vec<LineApiInsightDemographicAge>,
    pub areas: Vec<LineApiInsightDemographicArea>,
    #[serde(rename = "appTypes")]
    pub app_types: Vec<LineApiInsightDemographicAppType>,
    #[serde(rename = "subscriptionPeriods")]
    pub subscription_periods: Vec<LineApiInsightDemographicSubscriptionPeriods>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightDemographicGender {
    gender: String,
    percentage: f32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightDemographicAge {
    age: String,
    percentage: f32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightDemographicArea {
    area: String,
    percentage: f32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightDemographicAppType {
    #[serde(rename = "appType")]
    app_type: String,
    percentage: f32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiInsightDemographicSubscriptionPeriods {
    #[serde(rename = "subscriptionPeriod")]
    subscription_period: String,
    percentage: f32,
}