LINE Bot x Java (Spring Boot) construction procedure

This entry is the 21st day of GMO Advent Calendar 2018 ( The day before was @ thomi40's About the WebVR framework "A-Frame".

Hello, my name is @zakisanbaiman. I am usually in charge of the logic part (Java) of the ad delivery application.

I've been playing with LINE bot recently, so I'll show you how to build it.

Construction flow

  1. Create a LINE @ account
  2. Messaging API
  3. Preparing Heroku
  4. SDK preparation
  5. Deploy the bot
  6. Webhook settings in LINE Developer

1. Create a LINE @ account

First, create a LINE @ account There are two types of accounts, but if you are a hobby, you can use a general account. スクリーンショット_2018-12-09_15_32_14.png

This is the account creation screen. The type of business may be "individual". スクリーンショット 2018-12-09 15.40.24.png

Once your account is issued, you can log in to LINE @ MANAGER. Here you can set the bot icon and status message. However, I don't use this screen very much. スクリーンショット_2018-12-09_15_51_54.png

This time we will use the Messaging API for bots, so let's move on to "LINE Developers". ¥ スクリーンショット_2018-12-09_15_47_25.png

The following is the "LINE Developers" screen. I mainly use this site to set up bots.


  1. Messaging API

We will set the "provider". The provider here is the service provider of the bot.


The provider has been created. Then create a channel. ites01.png

I think the plan should be "Developer Trial" once. image.png

Set the app name and app icon here. Kobito.dv18ve.png

The app is now complete. There is a QR code for adding friends at the bottom of "Channel basic settings", so let's add friends.


If you register as a friend, they will only say hello by default.


If this is OK, let's continue to create a bot program.

3. Preparing Heroku

Prepare a server to put the program on. This time, we will use a cloud platform called heroku, which is free and easy to prepare. スクリーンショット 2018-12-18 10.59.50.png

Here, let's just sign up once. I'll set up heroku a little later. スクリーンショット 2018-12-19 23.36.13.png

4. SDK preparation

First, let's clone the SDK for LINE Bot development prepared by LINE from GitHub. This time I will introduce Java ones, but there are also PHP, Go, Perl, Ruby, Python, Node.js and so on.

The directory structure is complicated, but if you just want to give a simple reply All you have to do is mess with sample-spring-boot-echo. Since the parrot return process works even if the code is as it is, the Java file is not changed here.

There is a file that you have to create if you have one, which is application.yml. There is application-template.yml in resources, so let's copy it to make application.yml. (Path: line-bot-sdk-java / sample-spring-boot-echo / src / main / resources / application-template.yml)

Set the channel token and channel secret in application.yml. (Both are listed in the basic channel settings)

  channel-token: '{Channel token}'
  channel-secret: '{Channel secret}'
  handler.path: /callback

5. Deploy the bot

There is a button called "Deploy to Heroku" in line-bot-sdk-java / sample-spring-boot-echo /, so let's press it.


Then the browser will open and the login screen will open, so log in. Then enter the app name, channel secret and channel token and press "Deploy app".


It takes a few minutes to deploy, but if you see "Your app was successfully deployed.", The deployment is successful.


6. Webhook settings in LINE Developer

Set Webhook transmission to "Use".


Set the Webhook URL to "https: // $ {YOUR_HEROKU_APP_NAME} / callback". {YOUR_HEROKU_APP_NAME} is the app name you set on heroku.


Set the automatic response message to "Not used". If you do not set this, the created program will not be called.


↑ Even if the above settings are made, it may not be reflected properly. In that case, if you update the screen, it will be reflected, so let's update the screen.

For the time being, we have a bot that will return the parrot!


Reference site

I was addicted to

Next Advent Calendar 2018

Tomorrow is @ yoshishin's [Try Rails 6 action text]. have a nice Christmas~

Recommended Posts

LINE Bot x Java (Spring Boot) construction procedure
Spring Boot + Docker Java development environment construction
JAVA + STS (Spring Tool Suite) environment construction procedure
Spring Boot learning procedure
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
[LINE BOT] I made a ramen BOT with Java (Maven) + Heroku + Spring Boot (1)
[Spring Boot] Environment construction (macOS)
[Java] Thymeleaf Basic (Spring Boot)
CICS-Run Java application-(4) Spring Boot application
Docker × Spring Boot environment construction
[Java] [Spring] Spring Boot 1.4-> 1.2 Downgrade Note
Spring Boot 2.x context path settings
Spring Boot + Java + GitHub authentication login
◆ Spring Boot + gradle environment construction memo
Cassandra x Spring Boot struggle record
Java --Jersey Framework vs Spring Boot
[Java] [Spring] Spring Boot Dependency injection mysterious hamarineta
[Processing x Java] Construction of development environment
Spring Boot environment construction memo on mac
Create Java Spring Boot project in IntelliJ
Spring Java
line bot
Use cache with EhCashe 2.x with Spring Boot
Use Servlet filter in Spring Boot [Spring Boot 1.x, 2.x compatible]
[Java / Spring Boot] Spring security ④ --Implementation of login process
Java tips-Create a Spring Boot project in Gradle
[Java / Spring Boot] Spring security ⑤ --Implementation of logout processing
[Java] Article to add validation with Spring Boot 2.3.1.
Easy to make LINE BOT with Java Servlet
[Java] Environment construction
Java development environment construction (Mac + Pleiades All in One Eclipse 4.7 + Spring Boot + Gradle (Buildship))
Java environment construction
Challenge Spring Boot
Selenium x Java
Spring Boot Form
[Spring] Environment construction
Spring Boot Memorandum
gae + spring boot
[Java] Spring DI ③
Create a portfolio app using Java and Spring Boot
A memorandum of addiction to Spring Boot2 x Doma2
SSO with GitHub OAuth in Spring Boot 1.5.x environment
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
Database environment construction with Docker in Spring boot (IntellJ)
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)