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:

Deploy the "echo" sample bot

Follow the steps below to deploy a bot that echoes text messages that it receives.

  1. Get the channel secret and channel access token from the console
  2. Click the Deploy to Heroku button on the README file in the sample-spring-boot-echo GitHub directory
  3. 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.
  4. Enter the webhook URL in the console using the following URL format: https://{HEROKU_APP_NAME}
    Note: {HEROKU_APP_NAME} is the app name from step 3
  5. Add your bot as a friend on LINE by scanning the QR code on the "Channel settings" page in the console
  6. Send your bot 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.

  1. Download and install Heroku CLI
  2. Log in to Heroku using a terminal or a command line application

    $ heroku login
  3. 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 application

The kitchensink sample bot application 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.

  1. Create a new channel on the console and get the channel secret and channel access token. Add the bot as a friend by scanning the QR code on the "Channel settings" page.
  2. Clone the line-bot-sdk-java GitHub repository onto your local machine
  3. Open Procfile and replace all instances of echo with kitchensink.

    // 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
  4. Copy the sample-spring-boot-kitchensink/src/main/resources/application-template.yml file and rename as application.yml. Fill in the channel-secret and channel-token fields using the values from step 1. Delete the part that says "This is tempalte file for configuration. Please copy as application.yml and change your value".

  5. Create a new Heroku app from the Heroku dashboard and copy the app name.

  6. 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}
  7. Push changes to Heroku

    $ git add .
    $ git commit -m 'First commit'
    $ git push heroku master
  8. Enter the webhook URL in the console using the following URL format: https://{HEROKU_APP_NAME}

  9. Try the following features with your bot 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 bot to a group chat. Type "bye" to make the bot leave the chat.
  • Send image, audio, video, or location information to the bot. The bot then retrieves the content and sends it back to you.

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.

Questions or suggestions?

If you have any questions about our LINE Platform products, first check our FAQ page and Community site. To share suggestions or feature requests regarding the documentation or the LINE Platform, click the buttom below or create an issue on the LINE Platform feedback GitHub repository.