line_bot_messaging_api/api/
message.rs

1use crate::message::{
2    LineApiMessageBroadcastRequest, LineApiMessageMulticastRequest, LineApiMessagePushRequest,
3    LineApiMessageReplyRequest,
4};
5use crate::{LineApiResponse, LineClient};
6use serde_derive::{Deserialize, Serialize};
7use serde_json::{json, Value};
8
9impl LineClient {
10    // エンドポイント一覧
11    // POST /v2/bot/message/reply
12    /// https://developers.line.biz/ja/reference/messaging-api/#send-reply-message
13    pub async fn message_send_reply(
14        &self,
15        request: &LineApiMessageReplyRequest,
16    ) -> LineApiResponse<LineApiMessageReplyResponse> {
17        self.http_post("https://api.line.me/v2/bot/message/reply", &request)
18            .await
19    }
20
21    // POST /v2/bot/message/push
22    /// https://developers.line.biz/ja/reference/messaging-api/#send-push-message
23    pub async fn message_send_push(
24        &self,
25        request: &LineApiMessagePushRequest,
26    ) -> LineApiResponse<LineApiMessagePushResponse> {
27        self.http_post("https://api.line.me/v2/bot/message/push", &request)
28            .await
29    }
30    /// https://developers.line.biz/ja/reference/messaging-api/#send-multicast-message
31    // POST /v2/bot/message/multicast
32    pub async fn message_send_multicast(
33        &self,
34        request: &LineApiMessageMulticastRequest,
35    ) -> LineApiResponse<LineApiMessageSendMulticastResponse> {
36        self.http_post("https://api.line.me/v2/bot/message/multicast", &request)
37            .await
38    }
39    // POST /v2/bot/message/narrowcast
40    // GET  /v2/bot/message/progress/narrowcast
41    // POST /v2/bot/message/broadcast
42    pub async fn message_send_broadcast(
43        &self,
44        request: &LineApiMessageBroadcastRequest,
45    ) -> LineApiResponse<LineApiMessageSendBroadcastResponse> {
46        self.http_post("https://api.line.me/v2/bot/message/broadcast", &request)
47            .await
48    }
49    /// https://developers.line.biz/ja/reference/messaging-api/#get-quota
50    // GET  /v2/bot/message/quota
51    pub async fn message_get_quota(&self) -> LineApiResponse<LineApiMessageGetQuotaResponse> {
52        self.http_get("https://api.line.me/v2/bot/message/quota", &json!({}))
53            .await
54    }
55    /// https://developers.line.biz/ja/reference/messaging-api/#get-consumption
56    // GET  /v2/bot/message/quota/consumption
57    pub async fn message_get_quota_consumption(
58        &self,
59    ) -> LineApiResponse<LineApiMessageGetQuotaConsumptionResponse> {
60        self.http_get(
61            "https://api.line.me/v2/bot/message/quota/consumption ",
62            &json!({}),
63        )
64        .await
65    }
66    // GET  /v2/bot/message/delivery/reply
67    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-reply-messages
68    pub async fn message_get_number_of_reply_messages(
69        &self,
70        date: &str,
71    ) -> LineApiResponse<LineApiMessageGetNumberOfReplyMessageResponse> {
72        self.http_get(
73            format!(
74                "https://api.line.me/v2/bot/message/delivery/reply?date={}",
75                date
76            )
77            .as_str(),
78            &json!({}),
79        )
80        .await
81    }
82
83    ///
84    // GET  /v2/bot/message/delivery/push
85    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-push-messages
86
87    pub async fn message_get_number_of_push_messages(
88        &self,
89        date: &str,
90    ) -> LineApiResponse<LineApiMessageGetNumberOfPushMessageResponse> {
91        self.http_get(
92            format!(
93                "https://api.line.me/v2/bot/message/delivery/push?date={}",
94                date
95            )
96            .as_str(),
97            &json!({}),
98        )
99        .await
100    }
101
102    // GET  /v2/bot/message/delivery/multicast
103    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-push-messages
104    pub async fn message_get_number_of_multicast_messages(
105        &self,
106        date: &str,
107    ) -> LineApiResponse<LineApiMessageGetNumberOfMulticastMessageResponse> {
108        self.http_get(
109            format!(
110                "https://api.line.me/v2/bot/message/delivery/multicast?date={}",
111                date
112            )
113            .as_str(),
114            &json!({}),
115        )
116        .await
117    }
118    // GET  /v2/bot/message/delivery/broadcast
119    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-broadcast-messages
120    pub async fn message_get_number_of_broadcast_messages(
121        &self,
122        date: &str,
123    ) -> LineApiResponse<LineApiMessageGetNumberOfBroadcastMessageResponse> {
124        self.http_get(
125            format!(
126                "https://api.line.me/v2/bot/message/delivery/broadcast?date={}",
127                date
128            )
129            .as_str(),
130            &json!({}),
131        )
132        .await
133    }
134    // POST /v2/bot/message/validate/reply
135    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-reply-message
136    pub async fn message_validate_reply(
137        &self,
138        data: &Vec<Value>,
139    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfReplyMessage> {
140        self.http_post(
141            "https://api.line.me/v2/bot/message/validate/reply",
142            &json!({
143                "messages":data
144            }),
145        )
146        .await
147    }
148
149    // POST /v2/bot/message/validate/push
150    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-push-message
151    pub async fn message_validate_push(
152        &self,
153        data: &Vec<Value>,
154    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfPushMessage> {
155        self.http_post(
156            "https://api.line.me/v2/bot/message/validate/push",
157            &json!({
158                "messages":data
159            }),
160        )
161        .await
162    }
163
164    // POST /v2/bot/message/validate/multicast
165    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-multicast-message
166    pub async fn message_validate_multicast(
167        &self,
168        data: &Vec<Value>,
169    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfMulticastMessage> {
170        self.http_post(
171            "https://api.line.me/v2/bot/message/validate/multicast",
172            &json!({
173                "messages":data
174            }),
175        )
176        .await
177    }
178
179    // POST /v2/bot/message/validate/narrowcast
180    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-narrowcast-message
181    pub async fn message_validate_narrowcast(
182        &self,
183        data: &Vec<Value>,
184    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfNarrowcastMessage> {
185        self.http_post(
186            "https://api.line.me/v2/bot/message/validate/narrowcast",
187            &json!({
188                "messages":data
189            }),
190        )
191        .await
192    }
193
194    // POST /v2/bot/message/validate/broadcast
195    /// https://developers.line.biz/ja/reference/messaging-api/#validate-message-objects-of-broadcast-message
196
197    pub async fn message_validate_broadcast(
198        &self,
199        data: &Vec<Value>,
200    ) -> LineApiResponse<LineApiMessageValidateMessageObjectsOfBroadcastMessage> {
201        self.http_post(
202            "https://api.line.me/v2/bot/message/validate/broadcast",
203            &json!({
204                "messages":data
205            }),
206        )
207        .await
208    }
209
210    // GET  /v2/bot/message/aggregation/info
211    /// https://developers.line.biz/ja/reference/messaging-api/#get-number-of-units-used-this-month
212
213    pub async fn message_aggregation_info(
214        &self,
215    ) -> LineApiResponse<LineApiMessageAggregationInfoResponse> {
216        self.http_get(
217            "https://api.line.me/v2/bot/message/aggregation/info",
218            &json!({}),
219        )
220        .await
221    }
222    // GET  /v2/bot/message/aggregation/list
223    /// https://developers.line.biz/ja/reference/messaging-api/#get-name-list-of-units-used-this-month
224    pub async fn message_aggregation_list(
225        &self,
226    ) -> LineApiResponse<LineApiMessageAggregationListResponse> {
227        self.http_get(
228            "https://api.line.me/v2/bot/message/aggregation/list ",
229            &json!({}),
230        )
231        .await
232    }
233}
234
235#[derive(Debug, Default, Deserialize, Serialize, Clone)]
236pub struct LineApiMessageReplyResponse {
237    #[serde(rename = "sentMessages")]
238    pub sent_messages: Vec<LineApiSendMessage>,
239}
240#[derive(Debug, Default, Deserialize, Serialize, Clone)]
241pub struct LineApiMessagePushResponse {
242    #[serde(rename = "sentMessages")]
243    pub sent_messages: Vec<LineApiSendMessage>,
244}
245
246#[derive(Debug, Default, Deserialize, Serialize, Clone)]
247pub struct LineApiSendMessage {
248    pub id: String,
249    #[serde(rename = "quoteToken")]
250    pub quote_token: Option<String>,
251}
252
253#[derive(Debug, Default, Deserialize, Serialize, Clone)]
254pub struct LineApiMessageSendMulticastResponse {}
255
256#[derive(Debug, Default, Deserialize, Serialize, Clone)]
257pub struct LineApiMessageSendBroadcastResponse {}
258
259#[derive(Debug, Default, Deserialize, Serialize, Clone)]
260pub struct LineApiMessageGetQuotaResponse {
261    #[serde(rename = "type")]
262    quota_type: String,
263    value: Option<u32>,
264}
265
266#[derive(Debug, Default, Deserialize, Serialize, Clone)]
267pub struct LineApiMessageGetQuotaConsumptionResponse {
268    #[serde(rename = "totalUsage")]
269    total_usage: u32,
270}
271
272#[derive(Debug, Default, Deserialize, Serialize, Clone)]
273pub struct LineApiMessageGetNumberOfReplyMessageResponse {
274    status: String,
275    success: Option<u32>,
276}
277#[derive(Debug, Default, Deserialize, Serialize, Clone)]
278pub struct LineApiMessageGetNumberOfPushMessageResponse {
279    status: String,
280    success: Option<u32>,
281}
282
283#[derive(Debug, Default, Deserialize, Serialize, Clone)]
284pub struct LineApiMessageGetNumberOfMulticastMessageResponse {
285    status: String,
286    success: Option<u32>,
287}
288
289#[derive(Debug, Default, Deserialize, Serialize, Clone)]
290pub struct LineApiMessageGetNumberOfBroadcastMessageResponse {
291    status: String,
292    success: Option<u32>,
293}
294
295#[derive(Debug, Default, Deserialize, Serialize, Clone)]
296pub struct LineApiMessageValidateMessageObjectsOfPushMessage {}
297#[derive(Debug, Default, Deserialize, Serialize, Clone)]
298pub struct LineApiMessageValidateMessageObjectsOfReplyMessage {}
299
300#[derive(Debug, Default, Deserialize, Serialize, Clone)]
301pub struct LineApiMessageValidateMessageObjectsOfMulticastMessage {}
302
303#[derive(Debug, Default, Deserialize, Serialize, Clone)]
304pub struct LineApiMessageValidateMessageObjectsOfNarrowcastMessage {}
305
306#[derive(Debug, Default, Deserialize, Serialize, Clone)]
307pub struct LineApiMessageValidateMessageObjectsOfBroadcastMessage {}
308
309#[derive(Debug, Default, Deserialize, Serialize, Clone)]
310pub struct LineApiMessageAggregationInfoResponse {
311    #[serde(rename = "numOfCustomAggregationUnits")]
312    num_of_custom_aggregation_units: u32,
313}
314
315#[derive(Debug, Default, Deserialize, Serialize, Clone)]
316pub struct LineApiMessageAggregationListResponse {
317    #[serde(rename = "customAggregationUnits")]
318    custom_aggregation_units: Vec<String>,
319    next: Option<String>,
320}