use crate::message::{
LineApiMessageBroadcastRequest, LineApiMessageMulticastRequest, LineApiMessagePushRequest,
LineApiMessageReplyRequest,
};
use crate::{LineApiResponse, LineClient};
use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};
impl LineClient {
pub async fn message_send_reply(
&self,
request: &LineApiMessageReplyRequest,
) -> LineApiResponse<LineApiMessageReplyResponse> {
self.http_post("https://api.line.me/v2/bot/message/reply", &request)
.await
}
pub async fn message_send_push(
&self,
request: &LineApiMessagePushRequest,
) -> LineApiResponse<LineApiMessagePushResponse> {
self.http_post("https://api.line.me/v2/bot/message/push", &request)
.await
}
pub async fn message_send_multicast(
&self,
request: &LineApiMessageMulticastRequest,
) -> LineApiResponse<LineApiMessageSendMulticastResponse> {
self.http_post("https://api.line.me/v2/bot/message/multicast", &request)
.await
}
pub async fn message_send_broadcast(
&self,
request: &LineApiMessageBroadcastRequest,
) -> LineApiResponse<LineApiMessageSendBroadcastResponse> {
self.http_post("https://api.line.me/v2/bot/message/broadcast", &request)
.await
}
pub async fn message_get_quota(&self) -> LineApiResponse<LineApiMessageGetQuotaResponse> {
self.http_get("https://api.line.me/v2/bot/message/quota", &json!({}))
.await
}
pub async fn message_get_quota_consumption(
&self,
) -> LineApiResponse<LineApiMessageGetQuotaConsumptionResponse> {
self.http_get(
"https://api.line.me/v2/bot/message/quota/consumption ",
&json!({}),
)
.await
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
pub async fn message_aggregation_info(
&self,
) -> LineApiResponse<LineApiMessageAggregationInfoResponse> {
self.http_get(
"https://api.line.me/v2/bot/message/aggregation/info",
&json!({}),
)
.await
}
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>,
}