# Building a bot
This guide describes how to use the Messaging API to build a LINE bot. If you'd like to start by deploying a sample bot, go to Building a sample bot with Heroku.
# Before you begin
Make sure you have completed the following:
- Created a dedicated Messaging API channel for your bot
- Prepared a server to host your bot. You can use a cloud platform service such as Heroku (opens new window).
# Setting up your bot on the LINE Developers Console
Your bot app requires a channel access token to make API calls and a webhook URL to receive webhook payloads from the LINE Platform.
When using the Messaging API, make sure that the settings for Auto-reply messages and Greeting messages on the channel are set to Disabled.
# Issue a channel access token
Channel access tokens are access tokens that are used for the Messaging API. You can issue any of these tokens:
- Short-lived channel access token
- Long-lived channel access token
- A channel access token in which the user can specify the expiration (recommended)
# Set a Webhook URL
The webhook URL is the endpoint of your bot server where webhook payloads are sent.
Log in to the LINE Developers Console, and click the provider in which the channel for the Messaging API is present.
Click the channel for the Messaging API.
Select the Messaging API tab.
Click Edit under Webhook URL, enter the Webhook URL (the destination URL for events sent from the LINE platform to the bot), and then click Update.
The webhook URL must use HTTPS and have an SSL/TLS certificate issued by a certificate authority widely trusted by general web browsers. Also note that self-signed certificates are not acceptable. If you encounter issues related to your SSL/TLS configuration, you should check whether your SSL/TLS certificate chain is complete and whether your intermediate certificates are correctly installed on your server.
If the webhook URL accepts requests, Success is displayed.
Enable Use webhook.
# Add your LINE Official Account as a friend
Add the LINE Official Account associated with the channel for your bot as a friend on LINE. To do so, scan the QR code on the Messaging API tab in the LINE Developers Console.
# Configure security settings (optional)
To improve security, you can specify servers that can call APIs of the LINE Platform on the Security tab of your channel settings in the LINE Developers Console. You can register IP addresses individually or, if you have multiple servers, you can use classless inter-domain routing (CIDR) notation to register your network address.
# Confirming the webhook behavior
When a user interacts with your LINE Official Account such as adding the LINE Official Account as a friend or sending the LINE Official Account a message, the LINE Platform sends an HTTP POST request that contains a webhook event object to the bot server specified in the Webhook URL field on the Messaging API tab. The request header contains a signature.
This section explains how to check if your server can receive webhook events and how to validate the signature of webhook events.
# Receiving webhook events
To confirm that your server can receive webhook events, block your LINE Official Account on LINE and check your server logs to confirm that your bot server receives an unfollow event from the LINE Platform. The following is an example log.
2017-07-21T09:18:46.755256+00:00 app[web.1]: 2017-07-21 09:18:46.737 INFO 4 --- [io-13386-exec-2] c.e.bot.spring.KitchenSinkController : unfollowed this bot: UnfollowEvent(source=UserSource(userId=Uxxxxxxxxxx...), timestamp=2017-07-21T09:18:46.031Z)
After you have confirmed that the webhook works normally, add your LINE Official Account as a friend again.
# Setting with LINE Official Account Manager
LINE Official Account Manager (opens new window) is a tool for managing your LINE Official Account. In addition to using features provided by the Messaging API, you can improve the user experience by customizing the account page, creating Timeline posts, and using other features of LINE Official Account Manager.
For a complete list of features available to LINE Official Accounts, see the LINE for Business (opens new window).
# Customize the account page
The account page is used to set the basic information about your LINE Official Account. The information set here is displayed to the user.
Go to LINE Official Account Manager to add basic information about your LINE Official Account. You can customize the cover image, logo, buttons, and information provided.
# Set a greeting message (optional)
On the Messaging API tab of your channel settings on the LINE Developers Console, under Greeting messages, click Edit to go to LINE Official Account Manager and set a greeting message to send users when they first add your LINE Official Account as a friend. Alternatively, you can do this programmatically by responding to users after receiving a follow webhook event.
# Set auto reply messages (optional)
On the Messaging API tab of your channel settings on the LINE Developers Console, under Auto-reply messages, click Edit to go to LINE Official Account Manager and set automated reply messages to respond to messages sent by users. However, you can do more with the Messaging API as you can program your bot to reply in different ways to various webhook events.
# Next steps
After you set up your bot, you can receive messages from users or send messages to users from your LINE Official Account. You can also use rich menus and quick replies to create a personalized experience.
For more information about features available within the Messaging API, see the rest of the Messaging API documentation.
If you created your bot for the purpose of handling LINE Things webhook events, follow the instructions in Receiving messages (webhook).