OpenClaw LINE 渠道
通过官方 Messaging API 将 OpenClaw 连接到 LINE。此基于插件的集成让你的 AI 助手可以在 LINE 上收发消息 —— LINE 是日本、台湾、泰国和东南亚最受欢迎的即时通讯平台之一。OpenClaw 通过 Webhook 接收事件并通过 Messaging API 回复,支持丰富的消息类型,包括 Flex 消息、模板消息、快捷回复和媒体分享。
LINE 支持的功能
文本消息
支持
媒体与文件
支持
消息反应
不支持
消息线程
不支持
语音消息
不支持
群聊
支持
LINE 前置条件
- LINE Developers 账号(可在 developers.line.biz 免费注册)
- 在 LINE Developers Console 中创建 Provider 和 Messaging API 渠道
- 从 Messaging API 渠道设置中获取 Channel access token 和 Channel secret
- OpenClaw Gateway 已运行并可通过公共 HTTPS URL 访问(Webhook 所需)
- 已安装 LINE 插件:openclaw plugins install @openclaw/line
LINE 快速设置
创建 LINE Messaging API 渠道
登录 LINE Developers Console,创建 Provider(或选择已有的),然后创建新的 Messaging API 渠道。记录你的 Channel ID、Channel secret,并从渠道设置页面签发 Channel access token。
安装 LINE 插件并添加配置
运行 'openclaw plugins install @openclaw/line' 安装 LINE 插件。然后在 ~/.openclaw/openclaw.json 中添加 LINE 渠道配置,填入你的 channelAccessToken 和 channelSecret。你也可以使用环境变量 LINE_CHANNEL_ACCESS_TOKEN 和 LINE_CHANNEL_SECRET。
配置 Webhook URL
在 LINE Developers Console 中,导航到渠道的 Messaging API 标签。将 Webhook URL 设置为 'https://<your-gateway-host>/line/webhook' 并启用 'Use webhook'。点击 Verify 确认端点可达。在 LINE Official Account Manager 中禁用自动回复和问候消息,以防止重复回复。
发送测试消息
通过扫描 LINE 机器人的二维码(可在 Console 中找到)将其添加为好友。向机器人发送一条消息。如果使用默认的 pairing 策略,需在终端通过 'openclaw pairing approve line <code>' 审批发送者。
LINE 配置示例
{
"channels": {
"line": {
"enabled": true,
"channelAccessToken": "YOUR_CHANNEL_ACCESS_TOKEN",
"channelSecret": "YOUR_CHANNEL_SECRET",
"dmPolicy": "pairing"
}
}
}LINE 深入了解
架构概述
LINE Developers Console 设置
{
"channels": {
"line": {
"channelAccessToken": "YOUR_TOKEN",
"channelSecret": "YOUR_SECRET"
}
}
}Channel Access Token
私信策略
{
"channels": {
"line": {
"dmPolicy": "allowlist",
"allowFrom": ["U1234567890abcdef1234567890abcdef"]
}
}
}群聊管理
{
"channels": {
"line": {
"groupPolicy": "open",
"historyLimit": 50
}
}
}富消息:Flex 与模板
媒体与附件
{
"channels": {
"line": {
"mediaMaxMb": 10
}
}
}Webhook 安全
加载指示器与消息发送
{
"channels": {
"line": {
"textChunkLimit": 5000,
"chunkMode": "newline"
}
}
}多账号设置
{
"channels": {
"line": {
"accounts": {
"main": {
"channelAccessToken": "TOKEN_1",
"channelSecret": "SECRET_1",
"webhookPath": "/line/main/webhook"
},
"support": {
"channelAccessToken": "TOKEN_2",
"channelSecret": "SECRET_2",
"webhookPath": "/line/support/webhook"
}
}
}
}
}LINE 配置参考
| Key | Type | Default | Description |
|---|---|---|---|
| enabled | boolean | true | 启用或禁用 LINE 渠道 |
| channelAccessToken | string | "" | LINE Messaging API 的 Channel access token。也可使用 LINE_CHANNEL_ACCESS_TOKEN 环境变量 |
| channelSecret | string | "" | 用于 Webhook 签名验证的 LINE Channel secret。也可使用 LINE_CHANNEL_SECRET 环境变量 |
| tokenFile | string | "" | 包含 Channel access token 的文件路径(替代内联配置) |
| secretFile | string | "" | 包含 Channel secret 的文件路径(替代内联配置) |
| dmPolicy | string | "pairing" | 控制谁可以私信机器人。选项:pairing、allowlist、open、disabled |
| allowFrom | string[] | [] | dmPolicy 为 allowlist 时允许给机器人发消息的 LINE 用户 ID(U + 32 位十六进制) |
| dmHistoryLimit | number | 50 | 每个对话中包含的最近私信消息数量,作为 AI 上下文 |
| groupPolicy | string | "disabled" | 群聊策略。选项:disabled、allowlist、open |
| groupAllowFrom | string[] | [] | 允许在群组中触发机器人的 LINE 用户 ID(groupPolicy 为 allowlist 时使用) |
| historyLimit | number | 50 | 包含的最大群消息数量,作为 AI 上下文。设为 0 禁用 |
| textChunkLimit | number | 5000 | 分块前每条出站消息的最大字符数 |
| chunkMode | string | "length" | 文本分块模式。选项:length(硬性拆分)、newline(段落感知) |
| mediaMaxMb | number | 10 | 最大入站媒体文件大小(兆字节) |
| webhookPath | string | "/line/webhook" | 此账号的自定义 Webhook 路径(适用于多账号设置) |
| accounts.<id>.channelAccessToken | string | "" | 多账号设置中每个账号的 Channel access token |
| accounts.<id>.channelSecret | string | "" | 多账号设置中每个账号的 Channel secret |
| accounts.<id>.webhookPath | string | "/line/<id>/webhook" | 多账号设置中每个账号的 Webhook 路径 |
| configWrites | boolean | true | 允许 /config 命令在运行时修改渠道设置 |
启用或禁用 LINE 渠道
LINE Messaging API 的 Channel access token。也可使用 LINE_CHANNEL_ACCESS_TOKEN 环境变量
用于 Webhook 签名验证的 LINE Channel secret。也可使用 LINE_CHANNEL_SECRET 环境变量
包含 Channel access token 的文件路径(替代内联配置)
包含 Channel secret 的文件路径(替代内联配置)
控制谁可以私信机器人。选项:pairing、allowlist、open、disabled
dmPolicy 为 allowlist 时允许给机器人发消息的 LINE 用户 ID(U + 32 位十六进制)
每个对话中包含的最近私信消息数量,作为 AI 上下文
群聊策略。选项:disabled、allowlist、open
允许在群组中触发机器人的 LINE 用户 ID(groupPolicy 为 allowlist 时使用)
包含的最大群消息数量,作为 AI 上下文。设为 0 禁用
分块前每条出站消息的最大字符数
文本分块模式。选项:length(硬性拆分)、newline(段落感知)
最大入站媒体文件大小(兆字节)
此账号的自定义 Webhook 路径(适用于多账号设置)
多账号设置中每个账号的 Channel access token
多账号设置中每个账号的 Channel secret
多账号设置中每个账号的 Webhook 路径
允许 /config 命令在运行时修改渠道设置
LINE 常见问题
LINE 故障排查
Gateway 无法从互联网访问,URL 不正确,或 SSL 证书有问题。
Console 中未启用 Webhook,自动回复在干扰,或发送者尚未通过 pairing 策略审批。
Channel access token 无效、已过期或已被撤销。
LINE 回复令牌在 Webhook 事件发送后 1 分钟过期。如果 AI 处理时间更长,令牌将失效。
配置中的 channelSecret 与 LINE Developers Console 中的 Channel secret 不匹配,或反向代理修改了请求体。