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}.herokuapp.com/callback
    Note: {HEROKU_APP_NAME} is the app name from step 3.
  5. Enable Use webhooks.

Note: This is set to "Disabled" by default.

  1. 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
  2. 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.

  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 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.

  1. 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.
  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 a template for the configuration file. Make a copy called `application.yml` and change the values below."

  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}.herokuapp.com/callback.

  9. 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.
note Response delay

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.

{{ $t("form.question.helpful") }}

{{ $t("form.question.detail") }}

{{ $t("form.question.improve") }}

{{ $t("form.info.start") }}{{ $t("form.info.link") }}{{ $t("form.info.end") }}


{{ $t("form.result.success") }}
{{ $t("form.result.error") }}
{{ $t("form.result.errorLink") }}