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

    For the purpose of building a sample bot, we recommend using the long-lived channel access token due to its simplicity. However, we recommend using the latest version (expiry-specified channel access token) in real environments due to security enhancements.

  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. Select the Messaging API tab.

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

  6. Enable Use webhook.

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

  7. Add the LINE Official Account associated with your bot as a friend on LINE by scanning the QR code on the Messaging API tab of your channel settings on the console.

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