# 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.
# Setting up your bot on the 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.
# Issue a channel access token
The channel access token is a long-lived token that must be set in the authorization header when making API calls. You can reissue the channel access token at any time through the console.
To issue a channel access token, click Issue under Channel access token (long-lived) on the Messaging API tab of your channel settings on the console.
# 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 certificate issued by an authorized certificate authority (CA).
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 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 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 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 website.
# 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 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 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).