Home Tutorials Categories Skills About
ZH EN JA KO
Channels

Guide to Connecting OpenClaw with LINE

· 19 min read

Introduction

LINE is the dominant instant messaging app in regions such as Japan, Thailand, and Taiwan. By connecting OpenClaw to LINE, you can create an intelligent chatbot that automatically replies to friend messages or provides AI services in group chats. This article guides you through the entire integration process, starting from the LINE Developers console.

Prerequisites

  • OpenClaw is installed and running
  • You have a LINE account
  • The OpenClaw service is accessible via a public HTTPS URL (LINE Webhook requires HTTPS)

Step 1: Create a LINE Messaging API Channel

1.1 Register a LINE Developers Account

  1. Visit LINE Developers
  2. Log in with your LINE account
  3. If this is your first time, agree to the developer terms and create a Provider

1.2 Create a Provider

A Provider is the top-level organizational unit for managing channels:

  1. In the LINE Developers Console, click Create a new provider
  2. Enter a Provider name (e.g., "My OpenClaw Bot")
  3. Click Create

1.3 Create a Messaging API Channel

  1. On the Provider page, click Create a Messaging API channel
  2. Fill in the following information:
Field Description Example
Channel type Select Messaging API Messaging API
Channel name Bot display name AI Assistant
Channel description Bot description Smart assistant powered by OpenClaw
Category Select a category Tools/Utilities
Subcategory Select a subcategory Chatbot
Email address Contact email [email protected]
  1. Agree to the terms and click Create

1.4 Obtain Required Credentials

After creation, you need to note down two key pieces of information:

Channel Secret: Found on the Basic settings tab.

Channel Access Token:

  1. Go to the Messaging API tab
  2. Scroll to the Channel access token section at the bottom
  3. Click the Issue button to generate a long-lived token
  4. Copy and save it securely
Channel Secret: abc123def456ghi789jkl012
Channel Access Token: eyJhbGciOiJIUzI1NiJ9.xxxxx.xxxxx (a very long string)

Step 2: Configure the Webhook

2.1 Set the Webhook URL

On the Messaging API tab:

  1. Find the Webhook settings section
  2. Click the Edit button
  3. Enter your Webhook URL:
https://your-domain.com/webhook/line
  1. Click Update
  2. Toggle the Use webhook switch on

2.2 Verify the Webhook

Click the Verify button to test the Webhook connection. If OpenClaw is already configured and running, it should display Success.

2.3 Disable Auto-Reply

On the Messaging API tab:

  1. Find the LINE Official Account features section
  2. Click the Edit link next to Auto-reply messages
  3. This opens the LINE Official Account Manager
  4. Disable Auto-reply messages (otherwise they will conflict with OpenClaw's replies)
  5. Optionally disable Greeting messages as well (or keep LINE's default greeting)

Step 3: Configure OpenClaw

3.1 Via Configuration File

Edit ~/.config/openclaw/openclaw.json5:

{
  channels: {
    line: {
      enabled: true,
      // Channel Secret (from Basic settings)
      channelSecret: "abc123def456ghi789jkl012",
      // Channel Access Token (generated from Messaging API)
      channelAccessToken: "eyJhbGciOiJIUzI1NiJ9.xxxxx.xxxxx",

      // Webhook path (must match the LINE console setting)
      webhookPath: "/webhook/line",

      // Message handling configuration
      message: {
        // Reply mode: "reply" uses Reply API (free), "push" uses Push API (may incur charges)
        replyMode: "reply",
        // Whether to support group messages
        groupEnabled: true,
        // Trigger method in groups
        groupTrigger: "mention",  // "mention" | "keyword" | "all"
        // Group trigger keywords (effective when groupTrigger is "keyword")
        groupKeywords: ["@AI", "/ask"]
      },

      // Reply format
      reply: {
        // Auto-split long messages
        maxLength: 5000,
        // Whether to use Flex Message format (more visually appealing)
        useFlexMessage: false,
        // Loading animation before sending a message
        loadingAnimation: true
      }
    }
  }
}

3.2 Via Environment Variables

export LINE_CHANNEL_SECRET="abc123def456ghi789jkl012"
export LINE_CHANNEL_ACCESS_TOKEN="eyJhbGciOiJIUzI1NiJ9.xxxxx.xxxxx"

3.3 Restart and Verify

openclaw restart

# View connection logs
openclaw logs -f --component channel:line

Successful logs:

[INFO] [channel:line] LINE Messaging API channel started
[INFO] [channel:line] Webhook path: /webhook/line
[INFO] [channel:line] Bot name: AI Assistant
[INFO] [channel:line] Waiting for incoming messages...

Reply API vs. Push API

LINE has two APIs for sending messages, and understanding the difference is important:

Reply API

  • Trigger: Can only be used after receiving a user message
  • Time limit: Reply Token is valid for approximately 30 seconds
  • Cost: Completely free
  • Limitation: Each event can only be replied to once

Push API

  • Trigger: Can proactively send messages to users
  • Time limit: None
  • Cost: Free plan includes 200 messages/month; additional messages require payment
  • Limitation: Depends on the subscription plan
{
  channels: {
    line: {
      message: {
        // Recommended: use reply mode to save costs
        replyMode: "reply",
        // Enable push as a fallback for delayed replies (e.g., time-consuming tasks)
        fallbackToPush: true
      }
    }
  }
}

Message Quota

Plan Push API Messages/Month Cost
Free 200 Free
Light 5,000 ~800 TWD/month
Standard 25,000 ~4,000 TWD/month
Pro Custom Contact LINE

Reply API messages do not count toward the quota, so using Reply mode is recommended whenever possible.

Rich Menu Configuration

A Rich Menu is a customizable menu at the bottom of a LINE Bot conversation, providing quick-action shortcuts.

Creating a Rich Menu

Create one in the LINE Official Account Manager:

  1. Go to Chat > Rich menu
  2. Click Create
  3. Design the menu layout; common options:
┌─────────┬─────────┬─────────┐
│         │         │         │
│   Ask   │Translate│Summarize│
│         │         │         │
├─────────┼─────────┼─────────┤
│         │         │         │
│  Reset  │  Model  │  Help   │
│         │         │         │
└─────────┴─────────┴─────────┘
  1. Set each area's action type to Text and enter the corresponding trigger command

Creating a Rich Menu via API

You can also define a Rich Menu in the OpenClaw configuration:

{
  channels: {
    line: {
      richMenu: {
        enabled: true,
        areas: [
          { label: "Ask", action: "/ask" },
          { label: "Translate", action: "/translate" },
          { label: "Summarize", action: "/summarize" },
          { label: "Reset Chat", action: "/reset" },
          { label: "Switch Model", action: "/model" },
          { label: "Help", action: "/help" }
        ]
      }
    }
  }
}

Group Usage

Adding the Bot to a Group

  1. Open the group in LINE
  2. Go to group settings > Invite
  3. Search for and add your Bot

Group Behavior Configuration

{
  channels: {
    line: {
      group: {
        // Welcome message when joining a group
        welcomeMessage: "Hi everyone, I'm an AI assistant! @mention me or start with /ask to ask a question.",
        // Clean up data when removed from a group
        cleanOnLeave: true,
        // Separate context for each group
        separateContext: true
      }
    }
  }
}

HTTPS Requirement

LINE Webhook strictly requires HTTPS. If you haven't configured HTTPS yet, you can use one of the following methods:

Option 1: Nginx Reverse Proxy + Let's Encrypt

# Install certbot
sudo apt install certbot python3-certbot-nginx

# Obtain a certificate
sudo certbot --nginx -d your-domain.com

Option 2: ngrok Tunnel (for development and testing)

# Install ngrok
npm install -g ngrok

# Create a tunnel
ngrok http 18789

Enter the ngrok-generated HTTPS address as the LINE Webhook URL.

Option 3: Cloudflare Tunnel

cloudflared tunnel --url http://localhost:18789

Troubleshooting

Webhook Verification Failed

# Confirm OpenClaw is running
openclaw logs --level error

# Confirm the Webhook path is correct
curl -X POST https://your-domain.com/webhook/line -d '{}' -H "Content-Type: application/json"

# Check if the SSL certificate is valid
openssl s_client -connect your-domain.com:443

Bot Not Replying to Messages

# Check if the Channel Access Token is valid
openclaw logs --component channel:line --level debug

# Common causes:
# 1. Token expired — re-issue a new Token
# 2. Auto-reply not disabled — LINE's auto-reply consumes the Reply Token
# 3. Reply Token timeout — AI model response took too long (>30 seconds)

Reply Token Timeout

If the AI model takes more than 30 seconds to respond, the Reply Token will expire. Solutions:

{
  channels: {
    line: {
      message: {
        replyMode: "reply",
        fallbackToPush: true,  // Fall back to Push API if Reply fails
        // Or send a "processing" reply first
        thinkingMessage: "Thinking, please wait..."
      }
    }
  }
}

Summary

Key steps for LINE integration:

  1. Create a Messaging API channel in LINE Developers
  2. Obtain the Channel Secret and Channel Access Token
  3. Configure an HTTPS Webhook URL
  4. Enter the credentials in the OpenClaw configuration file
  5. Disable LINE's auto-reply feature
  6. Restart the service and test

It is recommended to use the Reply API whenever possible to save costs, and to enhance the user experience with a Rich Menu.

OpenClaw is a free, open-source personal AI assistant that supports WhatsApp, Telegram, Discord, and many more platforms