Skip to content

Commit a24ab28

Browse files
committed
Supports an API to get number of messages sent this month
Also support API to get number of sent broadcast messages
1 parent 811e5f4 commit a24ab28

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingClient.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.linecorp.bot.model.response.BotApiResponse;
3030
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
3131
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
32+
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
3233
import com.linecorp.bot.model.richmenu.RichMenu;
3334
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
3435
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
@@ -80,6 +81,15 @@ public interface LineMessagingClient {
8081
*/
8182
CompletableFuture<MessageContentResponse> getMessageContent(String messageId);
8283

84+
/**
85+
* Gets the number of messages sent in the current month. The number of messages retrieved by this
86+
* operation includes the number of messages sent from LINE Official Account Manager. The number of
87+
* messages retrieved by this operation is approximate. To get the correct number of sent messages,
88+
* use LINE Official Account Manager or execute API operations for getting the number of sent messages.
89+
* Note: LINE@ accounts cannot call this API endpoint.
90+
*/
91+
CompletableFuture<QuotaConsumptionResponse> getMessageQuotaConsumption();
92+
8393
/**
8494
* Gets the number of messages sent with the /bot/message/reply endpoint. Note that the number of messages
8595
* retrieved by this operation does not include the number of messages sent from LINE@ Manager.
@@ -107,6 +117,19 @@ public interface LineMessagingClient {
107117
*/
108118
CompletableFuture<NumberOfMessagesResponse> getNumberOfSentMulticastMessages(String date);
109119

120+
/**
121+
* Gets the number of messages sent with the {@code "/bot/message/broadcast"} endpoint. The number of
122+
* messages retrieved by this operation does not include the number of messages sent from LINE Official
123+
* Account Manager.
124+
* Note: LINE@ accounts cannot call this API endpoint. Please migrate it to a LINE official account.
125+
* For more information, see <a href="https://developers.line.biz/en/docs/messaging-api/migrating-line-at/">
126+
* Migration of LINE@ accounts</a>.
127+
*
128+
* @param date Date the messages were sent. The format should be {@code yyyyMMdd} (for Example:
129+
* {@literal "20191231"}) and the timezone should be UTC+9.
130+
*/
131+
CompletableFuture<NumberOfMessagesResponse> getNumberOfSentBroadcastMessages(String date);
132+
110133
/**
111134
* Get user profile information.
112135
*

line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingClientImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.linecorp.bot.model.response.BotApiResponse;
3232
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
3333
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
34+
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
3435
import com.linecorp.bot.model.richmenu.RichMenu;
3536
import com.linecorp.bot.model.richmenu.RichMenuBlukLinkRequest;
3637
import com.linecorp.bot.model.richmenu.RichMenuBlukUnlinkRequest;
@@ -82,6 +83,11 @@ public CompletableFuture<MessageContentResponse> getMessageContent(final String
8283
return toMessageContentResponseFuture(retrofitImpl.getMessageContent(messageId));
8384
}
8485

86+
@Override
87+
public CompletableFuture<QuotaConsumptionResponse> getMessageQuotaConsumption() {
88+
return toFuture(retrofitImpl.getMessageQuotaConsumption());
89+
}
90+
8591
@Override
8692
public CompletableFuture<NumberOfMessagesResponse> getNumberOfSentReplyMessages(String date) {
8793
return toFuture(retrofitImpl.getNumberOfSentReplyMessages(date));
@@ -97,6 +103,11 @@ public CompletableFuture<NumberOfMessagesResponse> getNumberOfSentMulticastMessa
97103
return toFuture(retrofitImpl.getNumberOfSentMulticastMessages(date));
98104
}
99105

106+
@Override
107+
public CompletableFuture<NumberOfMessagesResponse> getNumberOfSentBroadcastMessages(String date) {
108+
return toFuture(retrofitImpl.getNumberOfSentBroadcastMessages(date));
109+
}
110+
100111
@Override
101112
public CompletableFuture<UserProfileResponse> getProfile(final String userId) {
102113
return toFuture(retrofitImpl.getProfile(userId));

line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.linecorp.bot.model.response.BotApiResponse;
2727
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
2828
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
29+
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
2930
import com.linecorp.bot.model.richmenu.RichMenu;
3031
import com.linecorp.bot.model.richmenu.RichMenuBlukLinkRequest;
3132
import com.linecorp.bot.model.richmenu.RichMenuBlukUnlinkRequest;
@@ -82,6 +83,16 @@ interface LineMessagingService {
8283
@GET("v2/bot/message/{messageId}/content")
8384
Call<ResponseBody> getMessageContent(@Path("messageId") String messageId);
8485

86+
/**
87+
* Gets the number of messages sent in the current month. The number of messages retrieved by this
88+
* operation includes the number of messages sent from LINE Official Account Manager. The number of
89+
* messages retrieved by this operation is approximate. To get the correct number of sent messages,
90+
* use LINE Official Account Manager or execute API operations for getting the number of sent messages.
91+
* Note: LINE@ accounts cannot call this API endpoint.
92+
*/
93+
@GET("v2/bot/message/quota/consumption")
94+
Call<QuotaConsumptionResponse> getMessageQuotaConsumption();
95+
8596
/**
8697
* Gets the number of messages sent with the /bot/message/reply endpoint. Note that the number of messages
8798
* retrieved by this operation does not include the number of messages sent from LINE@ Manager.
@@ -112,6 +123,20 @@ interface LineMessagingService {
112123
@GET("v2/bot/message/delivery/multicast")
113124
Call<NumberOfMessagesResponse> getNumberOfSentMulticastMessages(@Query("date") String date);
114125

126+
/**
127+
* Gets the number of messages sent with the {@code "/bot/message/broadcast"} endpoint. The number of
128+
* messages retrieved by this operation does not include the number of messages sent from LINE Official
129+
* Account Manager.
130+
* Note: LINE@ accounts cannot call this API endpoint. Please migrate it to a LINE official account.
131+
* For more information, see <a href="https://developers.line.biz/en/docs/messaging-api/migrating-line-at/">
132+
* Migration of LINE@ accounts</a>.
133+
*
134+
* @param date Date the messages were sent. The format should be {@code yyyyMMdd} (for Example:
135+
* {@literal "20191231"}) and the timezone should be UTC+9.
136+
*/
137+
@GET("v2/bot/message/delivery/broadcast")
138+
Call<NumberOfMessagesResponse> getNumberOfSentBroadcastMessages(String date);
139+
115140
/**
116141
* Method for Retrofit.
117142
*

line-bot-api-client/src/test/java/com/linecorp/bot/client/LineMessagingClientImplTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
4848
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
4949
import com.linecorp.bot.model.response.NumberOfMessagesResponse.Status;
50+
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
5051
import com.linecorp.bot.model.richmenu.RichMenu;
5152
import com.linecorp.bot.model.richmenu.RichMenuBlukLinkRequest;
5253
import com.linecorp.bot.model.richmenu.RichMenuBlukUnlinkRequest;
@@ -137,6 +138,16 @@ public void getMessageContentTest() throws Exception {
137138
assertThat(contentResponse.getMimeType()).isEqualTo("image/jpeg");
138139
}
139140

141+
@Test
142+
public void getMessageQuotaConsumption() {
143+
whenCall(retrofitMock.getMessageQuotaConsumption(),
144+
new QuotaConsumptionResponse(1024));
145+
146+
QuotaConsumptionResponse response = target.getMessageQuotaConsumption().join();
147+
verify(retrofitMock, only()).getMessageQuotaConsumption();
148+
assertThat(response.getTotalUsage()).isEqualTo(1024);
149+
}
150+
140151
@Test
141152
public void getNumberOfSentReplyMessages() {
142153
whenCall(retrofitMock.getNumberOfSentReplyMessages(any()),
@@ -170,6 +181,17 @@ public void getNumberOfSentMulticastMessages() {
170181
assertThat(response.getSuccess()).isEqualTo(1024);
171182
}
172183

184+
@Test
185+
public void getNumberOfSentBroadcastMessages() {
186+
whenCall(retrofitMock.getNumberOfSentBroadcastMessages(any()),
187+
new NumberOfMessagesResponse(Status.Ready, 1024));
188+
189+
NumberOfMessagesResponse response = target.getNumberOfSentBroadcastMessages("20181231").join();
190+
verify(retrofitMock, only()).getNumberOfSentBroadcastMessages("20181231");
191+
assertThat(response.getStatus()).isEqualTo(Status.Ready);
192+
assertThat(response.getSuccess()).isEqualTo(1024);
193+
}
194+
173195
@Test
174196
public void getProfileTest() throws Exception {
175197
final UserProfileResponse mockUserProfileResponse =
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2019 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.bot.model.response;
18+
19+
import com.fasterxml.jackson.annotation.JsonCreator;
20+
21+
import lombok.AllArgsConstructor;
22+
import lombok.Value;
23+
24+
@Value
25+
@AllArgsConstructor(onConstructor = @__(@JsonCreator))
26+
public class QuotaConsumptionResponse {
27+
long totalUsage;
28+
}

0 commit comments

Comments
 (0)