- Using quick replies
- Using rich menus
- Using Flex Messages
- Using the LINE URL scheme
- Using beacons
- Sharing your LINE official account with users
- Linking user accounts
- Messages
- Actions
- Flex Message elements
- Flex Message layout
- Group chats
- User consent
- Migration of LINE@ accounts
- LINE Developers
- Document top
- Messaging API
- Building a sample bot with Heroku
Building a sample bot with Heroku
This tutorial describes how to deploy a simple "echo" bot and a full-featured "kitchensink" bot on Heroku using the Messaging API SDK for Java.
If you'd like to deploy a sample bot in another language, see the following Messaging API SDK repositories.
Before you begin
Make sure you have the following:
- Created a dedicated Messaging API channel for your bot.
- A Heroku account (you can create one for free)
Deploy the "echo" sample bot
Follow the steps below to deploy a bot that echoes text messages that it receives.
- Get the channel secret and channel access token from the console
- Click the Deploy to Heroku button on the README file in the
sample-spring-boot-echo
GitHub directory - Using the values from step 1, fill in the "App name" (optional), "LINE_BOT_CHANNEL_TOKEN", and "LINE_BOT_CHANNEL_SECRET" fields and click Deploy app. Copy the app name because it will be used in the next step. As it may take some time, wait for the app to be deployed.
- Enter the webhook URL in the console using the following URL format:
https://{HEROKU_APP_NAME}.herokuapp.com/callback
Note: {HEROKU_APP_NAME} is the app name from step 3. - Enable Use webhooks.
Note: This is set to "Disabled" by default.
- Add the LINE official account associated with your bot as a friend on LINE by scanning the QR code on the Basic settings tab of your channel settings on the console
- Send your LINE official account a text message on LINE and confirm that it responds with the same message
Check logs with Heroku CLI
To see the logs of your bot on Heroku, follow the steps below.
- Download and install Heroku CLI
-
Log in to Heroku using a terminal or a command line application
$ heroku login
-
Check your logs. Note: {HEROKU_APP_NAME} is the app name from step 3 above.
$ heroku logs --tail --app {HEROKU_APP_NAME}
Deploy the kitchensink sample bot app
The kitchensink sample bot app includes the full set of features available with the Messaging API such as template and imagemap messages. To deploy the kitchensink bot, create a new Heroku app from the Heroku dashboard.
- Create a new channel on the console and get the channel secret and channel access token. Add the LINE official account associated with your bot as a friend by scanning the QR code on the Basic settings tab.
- Clone the line-bot-sdk-java GitHub repository onto your local machine
-
Open
Procfile
and replace all instances ofecho
withkitchensink
.// Before web: java $JAVA_OPTS -jar sample-spring-boot-echo/build/libs/sample-spring-boot-echo-*.jar --server.port=$PORT // After web: java $JAVA_OPTS -jar sample-spring-boot-kitchensink/build/libs/sample-spring-boot-kitchensink-*.jar --server.port=$PORT
-
Copy the
sample-spring-boot-kitchensink/src/main/resources/application-template.yml
file and rename asapplication.yml
. Fill in thechannel-secret
andchannel-token
fields using the values from step 1. Delete the part that says "This is a template for the configuration file. Make a copy called `application.yml` and change the values below." -
Create a new Heroku app from the Heroku dashboard and copy the app name.
-
Go to your
line-bot-sdk-java
directory and add a Gitâ„¢ remote. Note: {HEROKU_APP_NAME} is the app name from step 5.$ heroku git:remote -a {HEROKU_APP_NAME}
-
Push changes to Heroku
$ git add . $ git commit -m 'First commit' $ git push heroku master
-
Enter the webhook URL in the console using the following URL format:
https://{HEROKU_APP_NAME}.herokuapp.com/callback
. -
Try the following features with your LINE official account on LINE:
- Type "profile" to get your user profile
- Type "buttons", "confirm", or "carousel" to send a template message.
- Type "imagemap" to send an imagemap message.
- Invite the LINE official account to a group chat. Type "bye" to make it leave the chat.
- Send image, audio, video, or location information to the LINE official account. The bot then retrieves the content and sends it back to you.
Your bot may need some time to start up after deployment. If it doesn't immediately respond to your message with the expected reply, try again after a few minutes.
Next steps
For more information on how to develop your own bot with the Messaging API, see building a bot and the Messaging API reference.