Skip to content

Commit

Permalink
Update echo sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki-ma committed Dec 1, 2016
1 parent 810eece commit b5558ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
8 changes: 2 additions & 6 deletions README.md
Expand Up @@ -45,10 +45,6 @@ The line-bot-spring-boot module lets you build a bot application as a Spring Boo

package com.example.bot.spring.echo;

import static java.util.Collections.singletonList;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand All @@ -67,9 +63,9 @@ public class EchoApplication {
}

@EventMapping
public List<TextMessage> handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws Exception {
public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
System.out.println("event: " + event);
return singletonList(new TextMessage(event.getMessage().getText()));
return new TextMessage(event.getMessage().getText());
}

@EventMapping
Expand Down
27 changes: 6 additions & 21 deletions line-bot-spring-boot/README.md
Expand Up @@ -7,44 +7,33 @@ This is a Spring Boot auto-configuration for the LINE Messaging API.
```java
package com.example.bot.spring.echo;

import static java.util.Collections.singletonList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.linecorp.bot.client.LineMessagingClient;
import com.linecorp.bot.model.ReplyMessage;
import com.linecorp.bot.model.event.Event;
import com.linecorp.bot.model.event.MessageEvent;
import com.linecorp.bot.model.event.message.TextMessageContent;
import com.linecorp.bot.model.message.TextMessage;
import com.linecorp.bot.model.response.BotApiResponse;
import com.linecorp.bot.spring.boot.annotation.EventMapping;
import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;

@SpringBootApplication
@LineMessageHandler
public class EchoApplication {
@Autowired
private LineMessagingClient lineMessagingClient;

public static void main(String[] args) {
SpringApplication.run(EchoApplication.class, args);
}

@EventMapping
public void handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws Exception {
public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
System.out.println("event: " + event);
final BotApiResponse apiResponse = lineMessagingClient
.replyMessage(new ReplyMessage(event.getReplyToken(),
singletonList(new TextMessage(event.getMessage().getText()))))
.get();
System.out.println("Sent messages: " + apiResponse);
return new TextMessage(event.getMessage().getText());
}

@EventMapping
public void defaultMessageEvent(Event event) {
public void handleDefaultMessageEvent(Event event) {
System.out.println("event: " + event);
}
}
Expand All @@ -60,13 +49,9 @@ You can then get parsed messages like the following:
@LineMessageHandler
public class EchoApplication {
@EventMapping
public void handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws Exception {
public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws Exception {
System.out.println("event: " + event);
final BotApiResponse apiResponse = lineMessagingClient
.replyMessage(new ReplyMessage(event.getReplyToken(),
singletonList(new TextMessage(event.getMessage().getText()))))
.get();
System.out.println("Sent messages: " + apiResponse);
return new TextMessage(event.getMessage().getText());
}
}
```
Expand Down
Expand Up @@ -16,10 +16,6 @@

package com.example.bot.spring.echo;

import static java.util.Collections.singletonList;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand All @@ -38,9 +34,9 @@ public static void main(String[] args) {
}

@EventMapping
public List<TextMessage> handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws Exception {
public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
System.out.println("event: " + event);
return singletonList(new TextMessage(event.getMessage().getText()));
return new TextMessage(event.getMessage().getText());
}

@EventMapping
Expand Down

0 comments on commit b5558ae

Please sign in to comment.