教程

OpenClaw LINE 接入指南:Messaging API 配置、Webhook 接收与 Flex 消息发送

OpenClaw LINE 接入完整教程:插件安装、LINE Messaging API 创建与 Webhook 配置(HTTPS 必须)、多账号独立路径设置、DM 与群组访问控制、Flex 消息卡片与快捷回复按钮、位置信息发送,以及 /card 命令预设模板。

2026/3/123分钟 阅读ClaudeEagle

OpenClaw 通过 LINE Messaging API 接入 LINE,支持私信、群聊、媒体文件、位置信息、Flex 消息卡片和快捷回复按钮。需要安装 LINE 插件。

安装插件

bash
openclaw plugins install @openclaw/line

快速接入

1. 创建 LINE 应用

  1. 访问 LINE Developers Console
  2. 创建 Provider 并添加 Messaging API 频道
  3. 复制:
    • Channel access token
    • Channel secret
  4. 在 Messaging API 设置中开启 Use webhook
  5. 设置 Webhook URL(需要 HTTPS):
https://your-gateway-host/line/webhook

2. 配置 OpenClaw

json
{
  "channels": {
    "line": {
      "enabled": true,
      "channelAccessToken": "YOUR_TOKEN",
      "channelSecret": "YOUR_SECRET",
      "dmPolicy": "pairing"
    }
  }
}

环境变量方式:

bash
export LINE_CHANNEL_ACCESS_TOKEN="YOUR_TOKEN"
export LINE_CHANNEL_SECRET="YOUR_SECRET"

文件路径方式(更安全):

json
{
  "channels": {
    "line": {
      "tokenFile": "/path/to/line-token.txt",
      "secretFile": "/path/to/line-secret.txt"
    }
  }
}

注意:tokenFilesecretFile 必须是普通文件,不接受软链接。

3. 完成配对

bash
openclaw pairing list line
openclaw pairing approve line <CODE>

多账号配置

json
{
  "channels": {
    "line": {
      "accounts": {
        "marketing": {
          "channelAccessToken": "...",
          "channelSecret": "...",
          "webhookPath": "/line/marketing"
        },
        "support": {
          "channelAccessToken": "...",
          "channelSecret": "...",
          "webhookPath": "/line/support"
        }
      }
    }
  }
}

每个账号使用独立的 Webhook 路径,避免冲突。

访问控制

json
{
  "channels": {
    "line": {
      "dmPolicy": "allowlist",
      "allowFrom": ["Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"],
      "groupPolicy": "open",
      "groupAllowFrom": ["Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
    }
  }
}

LINE ID 格式(区分大小写):

  • 用户:U + 32 位十六进制
  • 群组:C + 32 位十六进制
  • 聊天室:R + 32 位十六进制
策略说明
pairing(默认)未知用户收到配对码
allowlist仅白名单用户 ID
open允许所有用户
disabled禁止 DM

消息行为

  • 文本分块:最大 5000 字符
  • Markdown 格式自动转换为 Flex 卡片(代码块和表格)
  • 流式回复:缓冲后整块发送,发送期间显示加载动画
  • 媒体大小上限:mediaMaxMb(默认 10MB)

富消息(Flex 卡片 / 快捷回复)

使用 channelData.line 发送富消息:

json
{
  "text": "请选择:",
  "channelData": {
    "line": {
      "quickReplies": ["状态查询", "帮助", "重置"],
      "flexMessage": {
        "altText": "状态卡片",
        "contents": {}
      },
      "templateMessage": {
        "type": "confirm",
        "text": "确认继续?",
        "confirmLabel": "确认",
        "confirmData": "yes",
        "cancelLabel": "取消",
        "cancelData": "no"
      }
    }
  }
}

/card 命令

LINE 插件内置 /card 命令用于 Flex 消息预设:

/card info "欢迎" "感谢加入!"

位置信息发送

json
{
  "channelData": {
    "line": {
      "location": {
        "title": "办公室",
        "address": "北京市朝阳区xxx路",
        "latitude": 39.9042,
        "longitude": 116.4074
      }
    }
  }
}

故障排查

Webhook 验证失败:确认 Webhook URL 是 HTTPS;确认 channelSecret 与 LINE Console 一致

收不到事件:确认 Webhook 路径与 channels.line.webhookPath 一致;确认 Gateway 可从 LINE 服务器访问

媒体下载失败:适当增加 channels.line.mediaMaxMb


原文:LINE - OpenClaw | 来源:OpenClaw 官方文档

相关文章推荐

教程OpenClaw 接入 LINE:Messaging API 配置、Flex 消息与多账号管理OpenClaw 接入 LINE 完整教程:安装 LINE 插件、在 LINE Developers Console 创建 Messaging API 频道、配置 Webhook、多账号管理,以及访问控制(配对/开放/白名单)、群组 @提及限制和 Flex 富文本消息支持。2026/3/2教程OpenClaw Google Chat 接入指南:Service Account 配置、Webhook 公网暴露与空间访问控制OpenClaw Google Chat 接入完整教程:8 步配置流程(Cloud 项目/Service Account/JSON Key/Chat 应用创建)、三种公网暴露方式(Tailscale Funnel/Caddy/Cloudflare Tunnel)、Bearer Token 验证机制、DM 与 Space 访问控制、空间特定系统提示,以及故障排查。2026/3/12教程OpenClaw Google Chat 接入指南:Service Account 配置、Webhook 公网暴露与空间访问控制OpenClaw Google Chat 接入完整教程:8 步配置流程(Cloud 项目/Service Account/JSON Key/Chat 应用创建)、三种公网暴露方式(Tailscale Funnel/Caddy/Cloudflare Tunnel)、Bearer Token 验证机制、DM 与 Space 访问控制、空间特定系统提示,以及故障排查。2026/3/12教程OpenClaw Google Chat 接入指南:Service Account 配置、Webhook 公网暴露与空间访问控制OpenClaw Google Chat 接入完整教程:8 步配置流程(Cloud 项目/Service Account/JSON Key/Chat 应用创建)、三种公网暴露方式(Tailscale Funnel/Caddy/Cloudflare Tunnel)、Bearer Token 验证机制、DM 与 Space 访问控制、空间特定系统提示,以及故障排查。2026/3/12教程OpenClaw 接入 Synology Chat:NAS 内网 Bot 的 Webhook 配置与访问控制OpenClaw 接入 Synology Chat 完整教程:双向 Webhook 配置(outgoing token + incoming URL)、访问控制策略(allowlist/open/disabled)、allowedUserIds 用户白名单、主动消息发送格式,以及内网自签 SSL 证书和多账号配置。2026/3/3教程OpenClaw 接入 Google Chat:Chat API 配置、Webhook 公网暴露与 Tailscale Funnel 方案OpenClaw 接入 Google Chat 完整教程:服务账号创建与 JSON 密钥配置、Google Chat API 应用设置、三种公网暴露方案(Tailscale Funnel 推荐/Caddy 反向代理/Cloudflare Tunnel)、Bot 添加步骤,以及消息目标格式和常见问题排查。2026/3/3