LINE
LINE Messaging API 插件:安装、配置与用法
LINE 通过 LINE Messaging API 与 OpenClaw 对接。该插件在 gateway 上作为 webhook 接收器运行,并使用你的 channel access token 与 channel secret 做鉴权。
状态:通过插件支持。支持私信、群聊、媒体、位置、Flex 消息、模板消息与 quick replies。不支持 reactions 与 threads。
需要安装插件
安装 LINE 插件:
openclaw plugins install @openclaw/line
本地安装(当你从 git 仓库运行时):
openclaw plugins install ./extensions/line
设置
1. 注册 LINE Developers 并打开 Console:
https://developers.line.biz/console/
2. 创建(或选择)一个 Provider,并添加一个 Messaging API channel。
3. 在 channel 设置中复制 Channel access token 与 Channel secret。
4. 在 Messaging API 设置中启用 Use webhook。
5. 将 webhook URL 设置为你的 gateway 地址(必须是 HTTPS):
https://gateway-host/line/webhook
gateway 会响应 LINE 的 webhook 校验(GET)与入站事件(POST)。
如果你需要自定义路径,设置 ''channels.line.webhookPath'' 或 ''channels.line.accounts.'',并相应更新 URL。
配置
最小配置:
{
channels: {
line: {
enabled: true,
channelAccessToken: "LINE_CHANNEL_ACCESS_TOKEN",
channelSecret: "LINE_CHANNEL_SECRET",
dmPolicy: "pairing",
},
},
}环境变量(仅 default account):
- LINE_CHANNEL_ACCESS_TOKEN
- LINE_CHANNEL_SECRET
从文件读取 token/secret:
{
channels: {
line: {
tokenFile: "/path/to/line-token.txt",
secretFile: "/path/to/line-secret.txt",
},
},
}多账号:
{
channels: {
line: {
accounts: {
marketing: {
channelAccessToken: "...",
channelSecret: "...",
webhookPath: "/line/marketing",
},
},
},
},
}访问控制
LINE 私信默认使用 pairing。未知发送者会收到配对码,在批准之前其消息不会被处理。
openclaw pairing list line openclaw pairing approve line '<CODE>'
allowlist 与策略:
- channels.line.dmPolicy:pairing | allowlist | open | disabled
- channels.line.allowFrom:私信允许的 LINE 用户 ID
- channels.line.groupPolicy:allowlist | open | disabled
- channels.line.groupAllowFrom:群聊允许触发的 LINE 用户 ID
- 按群覆盖:''channels.line.groups.''
LINE 的 ID 区分大小写。合法 ID 形态通常是:
- 用户:U + 32 位十六进制
- 群:C + 32 位十六进制
- Room:R + 32 位十六进制
消息行为
- 文本会按 5000 字符分段。
- Markdown 格式会被移除;代码块与表格会在可能时转换为 Flex 卡片。
- 流式回复会被缓冲;agent 工作时,LINE 会收到带 loading 动画的完整分段文本。
- 媒体下载上限由 channels.line.mediaMaxMb 控制(默认 10MB)。
通道数据(富消息)
使用 channelData.line 发送 quick replies、位置、Flex 卡片或模板消息。
{
text: "Here you go",
channelData: {
line: {
quickReplies: ["Status", "Help"],
location: {
title: "Office",
address: "123 Main St",
latitude: 35.681236,
longitude: 139.767125,
},
flexMessage: {
altText: "Status card",
contents: {
/* Flex payload */
},
},
templateMessage: {
type: "confirm",
text: "Proceed?",
confirmLabel: "Yes",
confirmData: "yes",
cancelLabel: "No",
cancelData: "no",
},
},
},
}LINE 插件还提供了 /card 命令,用于 Flex 预设卡片:
/card info "Welcome" "Thanks for joining!"
排障
- Webhook 校验失败: 确认 webhook URL 为 HTTPS,并且 channelSecret 与 LINE Console 一致。
- 没有入站事件: 确认 webhook path 与 channels.line.webhookPath 一致,并确保 gateway 对 LINE 可达。
- 媒体下载错误: 如果媒体超过默认上限,提高 channels.line.mediaMaxMb。