How to Create a LINE Official App
This guide explains the basic steps for creating a LINE Official App (using the Messaging API for Bots and Webhook integration).
Prerequisites
- A registered LINE Developers account
- Node.js (or your preferred language) and npm installed
- A method to expose your local development environment over HTTPS (e.g., using ngrok)
1. Create a Provider
- Log in to the LINE Developers Console.
- Click the Create Provider button.
- Enter a provider name (e.g.,
MyCompanyBot
) and create it.
2. Create a Channel
- Within your new provider, select Create Channel.
- Choose Messaging API as the channel type.
- Enter the required information:
- App name
- App description
- Email address
- Agree to the Terms of Use
- After creation, note down the following from the Channel Basic Settings page:
- Channel ID
- Channel Secret
3. Issue an Access Token
- Open the Messaging API Settings tab.
- Issue a Long-lived Access Token.
- Note down the issued Channel Access Token.
4. Configure the Webhook URL
- Run your server locally (e.g., on port
3000
). - Expose it over HTTPS with ngrok (e.g.,
https://xxxx.ngrok.io/webhook
). - In the LINE Developers Console under Messaging API Settings, enter the Webhook URL and click Update.
- Switch Webhook Sending to Enabled.
5. Sample App Implementation (Node.js + Express)
const express = require('express');
const line = require('@line/bot-sdk');
const config = {
channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN,
channelSecret: process.env.LINE_CHANNEL_SECRET
};
const app = express();
app.post('/webhook', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result))
.catch((err) => {
console.error(err);
res.status(500).end();
});
});
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
return Promise.resolve(null);
}
return client.replyMessage(event.replyToken, {
type: 'text',
text: `You sent: “${event.message.text}”`
});
}
const client = new line.Client(config);
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on ${port}`);
});
Example Environment Variable Setup (macOS/Linux)
export LINE_CHANNEL_ACCESS_TOKEN='YOUR_CHANNEL_ACCESS_TOKEN'
export LINE_CHANNEL_SECRET='YOUR_CHANNEL_SECRET'
6. Deployment
- Deploy to Heroku, AWS, GCP, or another serverless/container environment
- Configure your environment variables with the Channel Access Token and Secret
- Update the Webhook URL to your production domain
7. Verification
- Add your LINE Official Account as a friend
- Send a message and confirm the Bot’s reply
That’s it! You’ve completed the basic setup for a LINE Official App.
As extensions, consider adding Rich Menus, LIFF integration, and handling additional Webhook events (Follow/Unfollow, etc.).