Skip to content

Commit 6ae80da

Browse files
authored
NON-ISSUE Support RedeliveryRecipient. (#577)
1 parent ed911a9 commit 6ae80da

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

line-bot-model/src/main/java/com/linecorp/bot/model/narrowcast/recipient/Recipient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
@JsonTypeInfo(use = Id.NAME, property = "type")
2525
@JsonSubTypes({
2626
@JsonSubTypes.Type(AudienceRecipient.class),
27-
@JsonSubTypes.Type(LogicalOperatorRecipient.class)
27+
@JsonSubTypes.Type(LogicalOperatorRecipient.class),
28+
@JsonSubTypes.Type(RedeliveryRecipient.class)
2829
})
2930
public interface Recipient {
3031
String getType();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2020 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+
18+
package com.linecorp.bot.model.narrowcast.recipient;
19+
20+
import com.fasterxml.jackson.annotation.JsonTypeName;
21+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
23+
24+
import lombok.Builder;
25+
import lombok.Value;
26+
27+
/**
28+
* By setting the request ID (X-Line-Request-Id) obtained when the narrowcast message was delivered to the
29+
* requestId property, you can specify the users who received the narrowcast message as the target.
30+
*
31+
* @see <a href="https://developers.line.biz/en/docs/messaging-api/sending-messages/#redelivery-object">Redelivery object</a>
32+
*/
33+
@Value
34+
@Builder
35+
@JsonTypeName("redelivery")
36+
@JsonDeserialize(builder = RedeliveryRecipient.RedeliveryRecipientBuilder.class)
37+
public class RedeliveryRecipient implements Recipient {
38+
String requestId;
39+
40+
@Override
41+
public String getType() {
42+
return "redelivery";
43+
}
44+
45+
@JsonPOJOBuilder(withPrefix = "")
46+
public static class RedeliveryRecipientBuilder {
47+
// Filled by lombok
48+
}
49+
}

line-bot-model/src/test/java/com/linecorp/bot/model/NarrowcastTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.linecorp.bot.model.narrowcast.recipient.AudienceRecipient;
3434
import com.linecorp.bot.model.narrowcast.recipient.LogicalOperatorRecipient;
3535
import com.linecorp.bot.model.narrowcast.recipient.Recipient;
36+
import com.linecorp.bot.model.narrowcast.recipient.RedeliveryRecipient;
3637
import com.linecorp.bot.model.objectmapper.ModelObjectMapper;
3738

3839
public class NarrowcastTest {
@@ -90,6 +91,23 @@ public void testRecipientDeserializeOperator() throws JsonProcessingException {
9091
assertThat(((LogicalOperatorRecipient) recipient).getAnd())
9192
.isEqualTo(singletonList(AudienceRecipient.builder()
9293
.audienceGroupId(5963L)
93-
.build()));
94+
.build()));
95+
}
96+
97+
@Test
98+
public void testRecipientDeserializeRedelivery() throws JsonProcessingException {
99+
ObjectMapper objectMapper = ModelObjectMapper.createNewObjectMapper();
100+
Recipient recipient = objectMapper.readValue(
101+
//language=JSON
102+
"{\n"
103+
+ " \"type\": \"redelivery\",\n"
104+
+ " \"requestId\": \"5b59509c-c57b-11e9-aa8c-2a2ae2dbcce4\"\n"
105+
+ "}", Recipient.class);
106+
107+
assertThat(recipient)
108+
.isInstanceOf(RedeliveryRecipient.class)
109+
.isEqualTo(RedeliveryRecipient.builder()
110+
.requestId("5b59509c-c57b-11e9-aa8c-2a2ae2dbcce4")
111+
.build());
94112
}
95113
}

0 commit comments

Comments
 (0)