Skip to content

Commit b9f2161

Browse files
tokuhiromimasahiro
authored andcommitted
use the "Group member profile API" in kitchensink example. (#321)
1 parent 839b487 commit b9f2161

File tree

1 file changed

+54
-31
lines changed

1 file changed

+54
-31
lines changed

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

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ public void handleVideoMessageEvent(MessageEvent<VideoMessageContent> event) thr
191191
@EventMapping
192192
public void handleFileMessageEvent(MessageEvent<FileMessageContent> event) {
193193
this.reply(event.getReplyToken(),
194-
new TextMessage(String.format("Received '%s'(%d bytes)",
195-
event.getMessage().getFileName(),
196-
event.getMessage().getFileSize())));
194+
new TextMessage(String.format("Received '%s'(%d bytes)",
195+
event.getMessage().getFileName(),
196+
event.getMessage().getFileSize())));
197197
}
198198

199199
@EventMapping
@@ -280,28 +280,50 @@ private void handleTextContent(String replyToken, Event event, TextMessageConten
280280
throws Exception {
281281
String text = content.getText();
282282

283-
log.info("Got text message from {}: {}", replyToken, text);
283+
log.info("Got text message from replyToken:{}: text:{}", replyToken, text);
284284
switch (text) {
285285
case "profile": {
286+
log.info("Invoking 'profile' command: source:{}",
287+
event.getSource());
286288
String userId = event.getSource().getUserId();
287289
if (userId != null) {
288-
lineMessagingClient
289-
.getProfile(userId)
290-
.whenComplete((profile, throwable) -> {
291-
if (throwable != null) {
292-
this.replyText(replyToken, throwable.getMessage());
293-
return;
294-
}
295-
296-
this.reply(
297-
replyToken,
298-
Arrays.asList(new TextMessage(
299-
"Display name: " + profile.getDisplayName()),
300-
new TextMessage("Status message: "
301-
+ profile.getStatusMessage()))
302-
);
303-
304-
});
290+
if (event.getSource() instanceof GroupSource) {
291+
lineMessagingClient
292+
.getGroupMemberProfile(((GroupSource) event.getSource()).getGroupId(), userId)
293+
.whenComplete((profile, throwable) -> {
294+
if (throwable != null) {
295+
this.replyText(replyToken, throwable.getMessage());
296+
return;
297+
}
298+
299+
this.reply(
300+
replyToken,
301+
Arrays.asList(new TextMessage("(from group)"),
302+
new TextMessage(
303+
"Display name: " + profile.getDisplayName()),
304+
new ImageMessage(profile.getPictureUrl(),
305+
profile.getPictureUrl()))
306+
);
307+
});
308+
} else {
309+
lineMessagingClient
310+
.getProfile(userId)
311+
.whenComplete((profile, throwable) -> {
312+
if (throwable != null) {
313+
this.replyText(replyToken, throwable.getMessage());
314+
return;
315+
}
316+
317+
this.reply(
318+
replyToken,
319+
Arrays.asList(new TextMessage(
320+
"Display name: " + profile.getDisplayName()),
321+
new TextMessage("Status message: "
322+
+ profile.getStatusMessage()))
323+
);
324+
325+
});
326+
}
305327
} else {
306328
this.replyText(replyToken, "Bot can't use profile API without user ID");
307329
}
@@ -463,16 +485,17 @@ private void handleTextContent(String replyToken, Event event, TextMessageConten
463485
.baseSize(new ImagemapBaseSize(722, 1040))
464486
.video(
465487
ImagemapVideo.builder()
466-
.originalContentUrl(URI.create(
467-
createUri("/static/imagemap_video/originalContent.mp4")))
468-
.previewImageUrl(URI.create(
469-
createUri("/static/imagemap_video/previewImage.jpg")))
470-
.area(new ImagemapArea(40, 46, 952, 536))
471-
.externalLink(
472-
new ImagemapExternalLink(
473-
URI.create("https://example.com/see_more.html"), "See More")
474-
)
475-
.build()
488+
.originalContentUrl(URI.create(
489+
createUri("/static/imagemap_video/originalContent.mp4")))
490+
.previewImageUrl(URI.create(
491+
createUri("/static/imagemap_video/previewImage.jpg")))
492+
.area(new ImagemapArea(40, 46, 952, 536))
493+
.externalLink(
494+
new ImagemapExternalLink(
495+
URI.create("https://example.com/see_more.html"),
496+
"See More")
497+
)
498+
.build()
476499
)
477500
.actions(Stream.of(
478501
new MessageImagemapAction(

0 commit comments

Comments
 (0)