Skip to content

Commit 407d85e

Browse files
authored
Support unsend event. (#565)
* Support unsend event. * Add missing copyright header.
1 parent 06362d9 commit 407d85e

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed

line-bot-model/src/main/java/com/linecorp/bot/model/event/Event.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
@JsonSubTypes.Type(AccountLinkEvent.class),
3838
@JsonSubTypes.Type(ThingsEvent.class),
3939
@JsonSubTypes.Type(MemberJoinedEvent.class),
40-
@JsonSubTypes.Type(MemberLeftEvent.class)
40+
@JsonSubTypes.Type(MemberLeftEvent.class),
41+
@JsonSubTypes.Type(UnsendEvent.class)
4142
})
4243
@JsonTypeInfo(
4344
use = JsonTypeInfo.Id.NAME,
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
package com.linecorp.bot.model.event;
18+
19+
import java.time.Instant;
20+
21+
import com.fasterxml.jackson.annotation.JsonTypeName;
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
24+
25+
import com.linecorp.bot.model.event.source.Source;
26+
27+
import lombok.Builder;
28+
import lombok.Value;
29+
30+
/**
31+
* Event object for when the user unsends a message in a group or room.
32+
*/
33+
@JsonTypeName("unsend")
34+
@Value
35+
@Builder(toBuilder = true)
36+
@JsonDeserialize(builder = UnsendEvent.UnsendEventBuilder.class)
37+
public class UnsendEvent implements Event {
38+
@JsonPOJOBuilder(withPrefix = "")
39+
public static class UnsendEventBuilder {
40+
// Providing builder instead of public constructor. Class body is filled by lombok.
41+
}
42+
43+
/**
44+
* JSON object which contains the source of the event.
45+
*/
46+
Source source;
47+
48+
/**
49+
* Time of the event.
50+
*/
51+
Instant timestamp;
52+
53+
/**
54+
* Channel state.
55+
* <dl>
56+
* <dt>active</dt>
57+
* <dd>The channel is active. You can send a reply message or push message from the bot server that received
58+
* this webhook event.</dd>
59+
* <dt>standby (under development)</dt>
60+
* <dd>The channel is waiting. The bot server that received this webhook event shouldn't send any messages.
61+
* </dd>
62+
* </dl>
63+
*/
64+
EventMode mode;
65+
66+
UnsendDetail unsend;
67+
68+
@Value
69+
@Builder(toBuilder = true)
70+
@JsonDeserialize(builder = UnsendDetail.UnsendDetailBuilder.class)
71+
public static class UnsendDetail {
72+
@JsonPOJOBuilder(withPrefix = "")
73+
public static class UnsendDetailBuilder {
74+
// Providing builder instead of public constructor. Class body is filled by lombok.
75+
}
76+
77+
/**
78+
* The message ID of the unsent message.
79+
*/
80+
String messageId;
81+
}
82+
}

line-bot-model/src/test/java/com/linecorp/bot/model/event/CallbackRequestTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,22 @@ public void testMemberLeft() throws IOException {
563563
});
564564
}
565565

566+
@Test
567+
public void testUnsend() throws IOException {
568+
parse("callback/unsend.json", callbackRequest -> {
569+
assertDestination(callbackRequest);
570+
Event event = callbackRequest.getEvents().get(0);
571+
assertThat(event.getSource()).isInstanceOf(UserSource.class);
572+
assertThat(event).isInstanceOf(UnsendEvent.class);
573+
assertThat(event.getMode())
574+
.isEqualTo(EventMode.ACTIVE);
575+
576+
UnsendEvent unsendEvent = (UnsendEvent) event;
577+
String messageId = unsendEvent.getUnsend().getMessageId();
578+
assertThat(messageId).isEqualTo("325708");
579+
});
580+
}
581+
566582
// Event, that has brand new eventType
567583
@Test
568584
public void testUnknown() throws IOException {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"destination": "Uab012345678901234567890123456789",
3+
"events": [
4+
{
5+
"type": "unsend",
6+
"timestamp": 1462629479859,
7+
"mode": "active",
8+
"source": {
9+
"type": "user",
10+
"userId": "u206d25c2ea6bd87c17655609a1c37cb8"
11+
},
12+
"unsend": {
13+
"messageId": "325708"
14+
}
15+
}
16+
]
17+
}

sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.linecorp.bot.model.event.MessageEvent;
5757
import com.linecorp.bot.model.event.PostbackEvent;
5858
import com.linecorp.bot.model.event.UnfollowEvent;
59+
import com.linecorp.bot.model.event.UnsendEvent;
5960
import com.linecorp.bot.model.event.message.AudioMessageContent;
6061
import com.linecorp.bot.model.event.message.ContentProvider;
6162
import com.linecorp.bot.model.event.message.FileMessageContent;
@@ -254,6 +255,11 @@ public void handleMemberLeft(MemberLeftEvent event) {
254255
.collect(Collectors.joining(",")));
255256
}
256257

258+
@EventMapping
259+
public void handleMemberLeft(UnsendEvent event) {
260+
log.info("Got unsend event: {}", event);
261+
}
262+
257263
@EventMapping
258264
public void handleOtherEvent(Event event) {
259265
log.info("Received message(Ignored): {}", event);

0 commit comments

Comments
 (0)