pexels-photo-887751.jpeg
Photo by AS Photography on Pexels.com

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

  1. Log in to the LINE Developers Console.
  2. Click the Create Provider button.
  3. Enter a provider name (e.g., MyCompanyBot) and create it.

2. Create a Channel

  1. Within your new provider, select Create Channel.
  2. Choose Messaging API as the channel type.
  3. Enter the required information:
    • App name
    • App description
    • Email address
    • Agree to the Terms of Use
  4. After creation, note down the following from the Channel Basic Settings page:
    • Channel ID
    • Channel Secret

3. Issue an Access Token

  1. Open the Messaging API Settings tab.
  2. Issue a Long-lived Access Token.
  3. Note down the issued Channel Access Token.

4. Configure the Webhook URL

  1. Run your server locally (e.g., on port 3000).
  2. Expose it over HTTPS with ngrok (e.g., https://xxxx.ngrok.io/webhook).
  3. In the LINE Developers Console under Messaging API Settings, enter the Webhook URL and click Update.
  4. 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

  1. Add your LINE Official Account as a friend
  2. 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.).

By greeden

Leave a Reply

Your email address will not be published. Required fields are marked *

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)