Skip to content

Commit 9ad7d7f

Browse files
authored
Support RichMenuAlias APIs and RichMenuSwitchAction (#653)
1 parent 7d05534 commit 9ad7d7f

File tree

9 files changed

+404
-0
lines changed

9 files changed

+404
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
5151
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
5252
import com.linecorp.bot.model.richmenu.RichMenuResponse;
53+
import com.linecorp.bot.model.richmenualias.CreateRichMenuAliasRequest;
54+
import com.linecorp.bot.model.richmenualias.RichMenuAliasListResponse;
55+
import com.linecorp.bot.model.richmenualias.RichMenuAliasResponse;
56+
import com.linecorp.bot.model.richmenualias.UpdateRichMenuAliasRequest;
5357
import com.linecorp.bot.model.room.RoomMemberCountResponse;
5458

5559
public interface LineMessagingClient {
@@ -340,6 +344,42 @@ public interface LineMessagingClient {
340344
*/
341345
CompletableFuture<BotApiResponse> cancelDefaultRichMenu();
342346

347+
/**
348+
* Create a rich menu alias.
349+
*
350+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-rich-menu-alias">//developers.line.biz/en/reference/messaging-api/#create-rich-menu-alias</a>
351+
*/
352+
CompletableFuture<BotApiResponse> createRichMenuAlias(CreateRichMenuAliasRequest request);
353+
354+
/**
355+
* Update the rich menu Id which associated with the rich menu alias.
356+
*
357+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#update-rich-menu-alias">//developers.line.biz/en/reference/messaging-api/#update-rich-menu-alias</a>
358+
*/
359+
CompletableFuture<BotApiResponse> updateRichMenuAlias(String richMenuAliasId,
360+
UpdateRichMenuAliasRequest request);
361+
362+
/**
363+
* Get specified rich menu alias.
364+
*
365+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-rich-menu-alias-by-id">//developers.line.biz/en/reference/messaging-api/#get-rich-menu-alias-by-id</a>
366+
*/
367+
CompletableFuture<RichMenuAliasResponse> getRichMenuAlias(String richMenuAliasId);
368+
369+
/**
370+
* Get rich menu alias list.
371+
*
372+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-rich-menu-alias-list">//developers.line.biz/en/reference/messaging-api/#get-rich-menu-alias-list</a>
373+
*/
374+
CompletableFuture<RichMenuAliasListResponse> getRichMenuAliasList();
375+
376+
/**
377+
* Delete specified rich menu alias.
378+
*
379+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#delete-rich-menu-alias">//developers.line.biz/en/reference/messaging-api/#delete-rich-menu-alias</a>
380+
*/
381+
CompletableFuture<BotApiResponse> deleteRichMenuAlias(String richMenuAliasId);
382+
343383
/**
344384
* Issues a link token used for the account link feature.
345385
*

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
5454
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
5555
import com.linecorp.bot.model.richmenu.RichMenuResponse;
56+
import com.linecorp.bot.model.richmenualias.CreateRichMenuAliasRequest;
57+
import com.linecorp.bot.model.richmenualias.RichMenuAliasListResponse;
58+
import com.linecorp.bot.model.richmenualias.RichMenuAliasResponse;
59+
import com.linecorp.bot.model.richmenualias.UpdateRichMenuAliasRequest;
5660
import com.linecorp.bot.model.room.RoomMemberCountResponse;
5761

5862
import lombok.AllArgsConstructor;
@@ -260,6 +264,33 @@ public CompletableFuture<BotApiResponse> cancelDefaultRichMenu() {
260264
return toBotApiFuture(retrofitImpl.cancelDefaultRichMenu());
261265
}
262266

267+
@Override
268+
public CompletableFuture<BotApiResponse> createRichMenuAlias(CreateRichMenuAliasRequest request) {
269+
return toBotApiResponseFuture(retrofitImpl.createRichMenuAlias(request));
270+
}
271+
272+
@Override
273+
public CompletableFuture<BotApiResponse> updateRichMenuAlias(String richMenuAliasId,
274+
UpdateRichMenuAliasRequest request) {
275+
return toBotApiResponseFuture(retrofitImpl.updateRichMenuAlias(richMenuAliasId, request));
276+
}
277+
278+
@Override
279+
public CompletableFuture<RichMenuAliasResponse> getRichMenuAlias(
280+
String richMenuAliasId) {
281+
return toFuture(retrofitImpl.getRichMenuAlias(richMenuAliasId));
282+
}
283+
284+
@Override
285+
public CompletableFuture<RichMenuAliasListResponse> getRichMenuAliasList() {
286+
return toFuture(retrofitImpl.getRichMenuAliasList());
287+
}
288+
289+
@Override
290+
public CompletableFuture<BotApiResponse> deleteRichMenuAlias(String richMenuAliasId) {
291+
return toBotApiResponseFuture(retrofitImpl.deleteRichMenuAlias(richMenuAliasId));
292+
}
293+
263294
@Override
264295
public CompletableFuture<IssueLinkTokenResponse> issueLinkToken(String userId) {
265296
return toFuture(retrofitImpl.issueLinkToken(userId));

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
4949
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
5050
import com.linecorp.bot.model.richmenu.RichMenuResponse;
51+
import com.linecorp.bot.model.richmenualias.CreateRichMenuAliasRequest;
52+
import com.linecorp.bot.model.richmenualias.RichMenuAliasListResponse;
53+
import com.linecorp.bot.model.richmenualias.RichMenuAliasResponse;
54+
import com.linecorp.bot.model.richmenualias.UpdateRichMenuAliasRequest;
5155
import com.linecorp.bot.model.room.RoomMemberCountResponse;
5256

5357
import retrofit2.Call;
@@ -397,4 +401,47 @@ Call<Void> linkRichMenuToUser(
397401

398402
@POST("v2/bot/channel/webhook/test")
399403
Call<TestWebhookEndpointResponse> testWebhookEndpoint(@Body TestWebhookEndpointRequest request);
404+
405+
/**
406+
* Method for Retrofit.
407+
*
408+
* @see LineMessagingClient#createRichMenuAlias(CreateRichMenuAliasRequest)
409+
*/
410+
@POST("v2/bot/richmenu/alias")
411+
Call<BotApiResponseBody> createRichMenuAlias(@Body CreateRichMenuAliasRequest request);
412+
413+
/**
414+
* Method for Retrofit.
415+
*
416+
* @see LineMessagingClient#updateRichMenuAlias(String, UpdateRichMenuAliasRequest)
417+
*/
418+
@POST("v2/bot/richmenu/alias/{richMenuAliasId}")
419+
Call<BotApiResponseBody> updateRichMenuAlias(
420+
@Path("richMenuAliasId") String richMenuAliasId,
421+
@Body UpdateRichMenuAliasRequest request);
422+
423+
/**
424+
* Method for Retrofit.
425+
*
426+
* @see LineMessagingClient#getRichMenuAliasList()
427+
*/
428+
@GET("v2/bot/richmenu/alias/list")
429+
Call<RichMenuAliasListResponse> getRichMenuAliasList();
430+
431+
/**
432+
* Method for Retrofit.
433+
*
434+
* @see LineMessagingClient#getRichMenuAlias(String)
435+
*/
436+
@GET("v2/bot/richmenu/alias/{richMenuAliasId}")
437+
Call<RichMenuAliasResponse> getRichMenuAlias(@Path("richMenuAliasId") String richMenuAliasId);
438+
439+
/**
440+
* Method for Retrofit.
441+
*
442+
* @see LineMessagingClient#deleteRichMenuAlias(String)
443+
*/
444+
@DELETE("v2/bot/richmenu/alias/{richMenuAliasId}")
445+
Call<BotApiResponseBody> deleteRichMenuAlias(@Path("richMenuAliasId") String richMenuAliasId);
446+
400447
}

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
7878
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
7979
import com.linecorp.bot.model.richmenu.RichMenuResponse;
80+
import com.linecorp.bot.model.richmenualias.CreateRichMenuAliasRequest;
81+
import com.linecorp.bot.model.richmenualias.RichMenuAliasListResponse;
82+
import com.linecorp.bot.model.richmenualias.RichMenuAliasResponse;
83+
import com.linecorp.bot.model.richmenualias.UpdateRichMenuAliasRequest;
8084
import com.linecorp.bot.model.room.RoomMemberCountResponse;
8185

8286
import okhttp3.Headers;
@@ -717,6 +721,76 @@ public void testWebhookEndpoint() throws Exception {
717721
assertThat(actual).isEqualTo(response);
718722
}
719723

724+
@Test
725+
public void createRichMenuAliasTest() throws Exception {
726+
final CreateRichMenuAliasRequest request = CreateRichMenuAliasRequest
727+
.builder()
728+
.richMenuAliasId("richmenu-alias-id")
729+
.richMenuId("RICHMENU_ID")
730+
.build();
731+
whenCall(retrofitMock.createRichMenuAlias(request), BOT_API_SUCCESS_RESPONSE_BODY);
732+
final BotApiResponse actual = target.createRichMenuAlias(request).get();
733+
verify(retrofitMock, only()).createRichMenuAlias(request);
734+
assertThat(actual).isEqualTo(BOT_API_SUCCESS_RESPONSE);
735+
}
736+
737+
@Test
738+
public void updateRichMenuAliasTest() throws Exception {
739+
final UpdateRichMenuAliasRequest request = UpdateRichMenuAliasRequest
740+
.builder()
741+
.richMenuId("RICHMENU_ID")
742+
.build();
743+
final String richMenuAliasId = "richmenu-alias-id";
744+
whenCall(retrofitMock.updateRichMenuAlias(richMenuAliasId, request), BOT_API_SUCCESS_RESPONSE_BODY);
745+
final BotApiResponse actual = target.updateRichMenuAlias(richMenuAliasId, request).get();
746+
verify(retrofitMock, only()).updateRichMenuAlias(richMenuAliasId, request);
747+
assertThat(actual).isEqualTo(BOT_API_SUCCESS_RESPONSE);
748+
}
749+
750+
@Test
751+
public void getRichMenuAliasTest() throws Exception {
752+
final String richMenuAliasId = "richmenu-alias-id";
753+
final RichMenuAliasResponse response = RichMenuAliasResponse
754+
.builder()
755+
.richMenuAliasId(richMenuAliasId)
756+
.richMenuId("RICHMENU_ID")
757+
.build();
758+
whenCall(retrofitMock.getRichMenuAlias(richMenuAliasId), response);
759+
final RichMenuAliasResponse actual = target.getRichMenuAlias(richMenuAliasId).get();
760+
verify(retrofitMock, only()).getRichMenuAlias(richMenuAliasId);
761+
assertThat(actual).isEqualTo(response);
762+
}
763+
764+
@Test
765+
public void getRichMenuAliasListTest() throws Exception {
766+
final RichMenuAliasListResponse response = RichMenuAliasListResponse
767+
.builder()
768+
.alias(RichMenuAliasResponse
769+
.builder()
770+
.richMenuAliasId("richmenu-alias-id-1")
771+
.richMenuId("RICHMENU_ID_1")
772+
.build())
773+
.alias(RichMenuAliasResponse
774+
.builder()
775+
.richMenuAliasId("richmenu-alias-id-2")
776+
.richMenuId("RICHMENU_ID_2")
777+
.build())
778+
.build();
779+
whenCall(retrofitMock.getRichMenuAliasList(), response);
780+
final RichMenuAliasListResponse actual = target.getRichMenuAliasList().get();
781+
verify(retrofitMock, only()).getRichMenuAliasList();
782+
assertThat(actual).isEqualTo(response);
783+
}
784+
785+
@Test
786+
public void deleteRichMenuAliasTest() throws Exception {
787+
final String richMenuAliasId = "richmenu-alias-id";
788+
whenCall(retrofitMock.deleteRichMenuAlias(richMenuAliasId), BOT_API_SUCCESS_RESPONSE_BODY);
789+
final BotApiResponse actual = target.deleteRichMenuAlias(richMenuAliasId).get();
790+
verify(retrofitMock, only()).deleteRichMenuAlias(richMenuAliasId);
791+
assertThat(actual).isEqualTo(BOT_API_SUCCESS_RESPONSE);
792+
}
793+
720794
// Utility methods
721795

722796
private static <T> void whenCall(Call<T> call, T value) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2021 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.action;
18+
19+
import com.fasterxml.jackson.annotation.JsonCreator;
20+
import com.fasterxml.jackson.annotation.JsonInclude;
21+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.annotation.JsonTypeName;
24+
25+
import lombok.Value;
26+
27+
/**
28+
* When this action is tapped, switch between rich menus and a postback event including the rich menu alias ID
29+
* selected by the user and the specified string in the data field is returned via webhook.
30+
*
31+
* <p>This action can be configured only with rich menus.
32+
*/
33+
@Value
34+
@JsonTypeName("richmenuswitch")
35+
@JsonInclude(Include.NON_NULL)
36+
public class RichMenuSwitchAction implements Action {
37+
/**
38+
* Label for the action.
39+
*
40+
* <p>Max: 20 characters
41+
*/
42+
String label;
43+
44+
/**
45+
* String returned via webhook in the postback.data property of the postback event.
46+
*
47+
* <p>Max: 300 characters
48+
*/
49+
String data;
50+
51+
/**
52+
* RichMenuAliasId to switch rich menu to.
53+
*/
54+
String richMenuAliasId;
55+
56+
/**
57+
* Create new instance.
58+
*
59+
* @param label Label for the action. Max: 20 characters.
60+
* @param data String returned via webhook in the postback.data property of the postback event.
61+
* Max: 300 characters.
62+
* @param richMenuAliasId RichMenuAliasId to switch rich menu to.
63+
*/
64+
@JsonCreator
65+
public RichMenuSwitchAction(
66+
@JsonProperty("label") String label,
67+
@JsonProperty("data") String data,
68+
@JsonProperty("richMenuAliasId") String richMenuAliasId) {
69+
this.label = label;
70+
this.data = data;
71+
this.richMenuAliasId = richMenuAliasId;
72+
}
73+
74+
public RichMenuSwitchAction(String data, String richMenuAliasId) {
75+
this(null, data, richMenuAliasId);
76+
}
77+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2021 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.richmenualias;
18+
19+
import lombok.Builder;
20+
import lombok.Value;
21+
22+
@Value
23+
@Builder
24+
public class CreateRichMenuAliasRequest {
25+
String richMenuAliasId;
26+
String richMenuId;
27+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2021 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.richmenualias;
18+
19+
import java.util.List;
20+
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
24+
25+
import com.linecorp.bot.model.richmenualias.RichMenuAliasListResponse.RichMenuAliasListResponseBuilder;
26+
27+
import lombok.Builder;
28+
import lombok.Singular;
29+
import lombok.Value;
30+
31+
@Value
32+
@Builder
33+
@JsonDeserialize(builder = RichMenuAliasListResponseBuilder.class)
34+
public class RichMenuAliasListResponse {
35+
@JsonProperty("aliases")
36+
@Singular
37+
List<RichMenuAliasResponse> aliases;
38+
39+
@JsonPOJOBuilder(withPrefix = "")
40+
public static class RichMenuAliasListResponseBuilder {
41+
// Filled by lombok
42+
}
43+
}

0 commit comments

Comments
 (0)