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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
use crate::message::{
    LineApiMessageBroadcastRequest, LineApiMessageMulticastRequest, LineApiMessagePushRequest,
    LineApiMessageReplyRequest,
};
use crate::{LineApiResponse, LineClient};
use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};

impl LineClient {
    // エンドポイント一覧
    // POST /v2/bot/message/reply
    /// https://developers.line.biz/ja/reference/messaging-api/#send-reply-message
    pub async fn message_send_reply(
        &self,
        request: &LineApiMessageReplyRequest,
    ) -> LineApiResponse<LineApiMessageReplyResponse> {
        self.http_post("https://api.line.me/v2/bot/message/reply", &request)
            .await
    }

    // POST /v2/bot/message/push
    /// https://developers.line.biz/ja/reference/messaging-api/#send-push-message
    pub async fn message_send_push(
        &self,
        request: &LineApiMessagePushRequest,
    ) -> LineApiResponse<LineApiMessagePushResponse> {
        self.http_post("https://api.line.me/v2/bot/message/push", &request)
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#send-multicast-message
    // POST /v2/bot/message/multicast
    pub async fn message_send_multicast(
        &self,
        request: &LineApiMessageMulticastRequest,
    ) -> LineApiResponse<LineApiMessageSendMulticastResponse> {
        self.http_post("https://api.line.me/v2/bot/message/multicast", &request)
            .await
    }
    // POST /v2/bot/message/narrowcast
    // GET  /v2/bot/message/progress/narrowcast
    // POST /v2/bot/message/broadcast
    pub async fn message_send_broadcast(
        &self,
        request: &LineApiMessageBroadcastRequest,
    ) -> LineApiResponse<LineApiMessageSendBroadcastResponse> {
        self.http_post("https://api.line.me/v2/bot/message/broadcast", &request)
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-quota
    // GET  /v2/bot/message/quota
    pub async fn message_get_quota(&self) -> LineApiResponse<LineApiMessageGetQuotaResponse> {
        self.http_get("https://api.line.me/v2/bot/message/quota", &json!({}))
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-consumption
    // GET  /v2/bot/message/quota/consumption
    pub async fn message_get_quota_consumption(
        &self,
    ) -> LineApiResponse<LineApiMessageGetQuotaConsumptionResponse> {
        self.http_get(
            "https://api.line.me/v2/bot/message/quota/consumption ",
            &json!({}),
        )
        .await
    }
    // GET  /v2/bot/message/delivery/reply
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-reply-messages
    pub async fn message_get_number_of_reply_messages(
        &self,
        date: &str,
    ) -> LineApiResponse<LineApiMessageGetNumberOfReplyMessageResponse> {
        self.http_get(
            format!(
                "https://api.line.me/v2/bot/message/delivery/reply?date={}",
                date
            )
            .as_str(),
            &json!({}),
        )
        .await
    }

    ///
    // GET  /v2/bot/message/delivery/push
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-push-messages

    pub async fn message_get_number_of_push_messages(
        &self,
        date: &str,
    ) -> LineApiResponse<LineApiMessageGetNumberOfPushMessageResponse> {
        self.http_get(
            format!(
                "https://api.line.me/v2/bot/message/delivery/push?date={}",
                date
            )
            .as_str(),
            &json!({}),
        )
        .await
    }

    // GET  /v2/bot/message/delivery/multicast
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-push-messages
    pub async fn message_get_number_of_multicast_messages(
        &self,
        date: &str,
    ) -> LineApiResponse<LineApiMessageGetNumberOfMulticastMessageResponse> {
        self.http_get(
            format!(
                "https://api.line.me/v2/bot/message/delivery/multicast?date={}",
                date
            )
            .as_str(),
            &json!({}),
        )
        .await
    }
    // GET  /v2/bot/message/delivery/broadcast
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-broadcast-messages
    pub async fn message_get_number_of_broadcast_messages(
        &self,
        date: &str,
    ) -> LineApiResponse<LineApiMessageGetNumberOfBroadcastMessageResponse> {
        self.http_get(
            format!(
                "https://api.line.me/v2/bot/message/delivery/broadcast?date={}",
                date
            )
            .as_str(),
            &json!({}),
        )
        .await
    }
    // POST /v2/bot/message/validate/reply
    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-reply-message
    pub async fn message_validate_reply(
        &self,
        data: &Vec<Value>,
    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfReplyMessage> {
        self.http_post(
            "https://api.line.me/v2/bot/message/validate/reply",
            &json!({
                "messages":data
            }),
        )
        .await
    }

    // POST /v2/bot/message/validate/push
    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-push-message
    pub async fn message_validate_push(
        &self,
        data: &Vec<Value>,
    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfPushMessage> {
        self.http_post(
            "https://api.line.me/v2/bot/message/validate/push",
            &json!({
                "messages":data
            }),
        )
        .await
    }

    // POST /v2/bot/message/validate/multicast
    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-multicast-message
    pub async fn message_validate_multicast(
        &self,
        data: &Vec<Value>,
    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfMulticastMessage> {
        self.http_post(
            "https://api.line.me/v2/bot/message/validate/multicast",
            &json!({
                "messages":data
            }),
        )
        .await
    }

    // POST /v2/bot/message/validate/narrowcast
    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-narrowcast-message
    pub async fn message_validate_narrowcast(
        &self,
        data: &Vec<Value>,
    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfNarrowcastMessage> {
        self.http_post(
            "https://api.line.me/v2/bot/message/validate/narrowcast",
            &json!({
                "messages":data
            }),
        )
        .await
    }

    // POST /v2/bot/message/validate/broadcast
    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-broadcast-message

    pub async fn message_validate_broadcast(
        &self,
        data: &Vec<Value>,
    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfBroadcastMessage> {
        self.http_post(
            "https://api.line.me/v2/bot/message/validate/broadcast",
            &json!({
                "messages":data
            }),
        )
        .await
    }

    // GET  /v2/bot/message/aggregation/info
    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-units-used-this-month

    pub async fn message_aggregation_info(
        &self,
    ) -> LineApiResponse<LineApiMessageAggregationInfoResponse> {
        self.http_get(
            "https://api.line.me/v2/bot/message/aggregation/info",
            &json!({}),
        )
        .await
    }
    // GET  /v2/bot/message/aggregation/list
    /// https://developers.line.biz/ja/reference/messaging-api/#get-name-list-of-units-used-this-month
    pub async fn message_aggregation_list(
        &self,
    ) -> LineApiResponse<LineApiMessageAggregationListResponse> {
        self.http_get(
            "https://api.line.me/v2/bot/message/aggregation/list ",
            &json!({}),
        )
        .await
    }
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageReplyResponse {
    #[serde(rename = "sentMessages")]
    pub sent_messages: Vec<LineApiSendMessage>,
}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessagePushResponse {
    #[serde(rename = "sentMessages")]
    pub sent_messages: Vec<LineApiSendMessage>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiSendMessage {
    pub id: String,
    #[serde(rename = "quoteToken")]
    pub quote_token: Option<String>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageSendMulticastResponse {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageSendBroadcastResponse {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageGetQuotaResponse {
    #[serde(rename = "type")]
    quota_type: String,
    value: Option<u32>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageGetQuotaConsumptionResponse {
    #[serde(rename = "totalUsage")]
    total_usage: u32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageGetNumberOfReplyMessageResponse {
    status: String,
    success: Option<u32>,
}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageGetNumberOfPushMessageResponse {
    status: String,
    success: Option<u32>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageGetNumberOfMulticastMessageResponse {
    status: String,
    success: Option<u32>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageGetNumberOfBroadcastMessageResponse {
    status: String,
    success: Option<u32>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageValidateMessageObjectsOfPushMessage {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageValidateMessageObjectsOfReplyMessage {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageValidateMessageObjectsOfMulticastMessage {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageValidateMessageObjectsOfNarrowcastMessage {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageValidateMessageObjectsOfBroadcastMessage {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageAggregationInfoResponse {
    #[serde(rename = "numOfCustomAggregationUnits")]
    num_of_custom_aggregation_units: u32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiMessageAggregationListResponse {
    #[serde(rename = "customAggregationUnits")]
    custom_aggregation_units: Vec<String>,
    next: Option<String>,
}