I want to make a ramen bot using the LINE API! so First of all, use Java LINE Bot SDK to create an "echo" bot that returns parrots. ▼ Implemented with reference to the following URL "Create a sample bot on Heroku" https://developers.line.me/ja/docs/messaging-api/building-sample-bot-with-heroku/
・ LINE Messaging API -Java LINE Bot SDK ・ Heroku ・ Java
1.pom.xml
pom.xml
.
.
.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>com.linecorp.bot</groupId>
<artifactId>line-bot-api-client</artifactId>
<version>1.12.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.linecorp.bot</groupId>
<artifactId>line-bot-model</artifactId>
<version>1.12.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.linecorp.bot</groupId>
<artifactId>line-bot-spring-boot</artifactId>
<version>1.11.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2.application.yml Acccess Token and Channel Secret are generated when you create a new channel with the LINE Messaging API
application.yml
line.bot:
channel-token: 'AcccessToken'
channel-secret: 'Channel Secret'
handler.path: /callback
3.Procfile ★ ☆ Point ☆ ★
Procfile
web: java $JAVA_OPTS -jar target/{APPNAME}-0.0.1-SNAPSHOT.jar --server.port=$PORT
4.App.java I copied the code in the Java LINE Bot SDK.
App.java
@SpringBootApplication
@LineMessageHandler
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
System.out.println("hello");
}
@EventMapping
public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
System.out.println("event: " + event);
return new TextMessage(event.getMessage().getText());
}
@EventMapping
public void handleDefaultMessageEvent(Event event) {
System.out.println("event: " + event);
}
}
//Local repository generation, commit
$ git init
$ git add -A
$ git commit
//Login to heroku from CLI tool
$ heroku login
//Web application generation in Heroku (remote repository is also generated at this time)
$ heroku create APPNAME
//Link local repository and remote repository
$ heroku git:remote --app APPNAME
git push heroku master
・ Send Webhook ⇒ Use ・ Webhook URL ⇒ https: // {APPNAME} .herokuapp.com / callback {APPNAME} is the name of the application you created
** OK if the connection is confirmed successfully! !! ** **
I thought it was easy, but I struggled because the LINE Message API and heroku didn't connect. Please refer to it ☆ Next time, we will implement Ramen BOT.
Recommended Posts