LINE(外掛)
LINE 透過 LINE Messaging API 連接 OpenClaw。此外掛在 Gateway 上作為 webhook 接收器運行,使用你的 channel access token 和 channel secret 進行認證。
狀態:透過外掛支援。私訊、群組聊天、媒體、位置、Flex 訊息、範本訊息和快速回覆皆已支援。表情回應和討論串不支援。
需要外掛
安裝 LINE 外掛:
openclaw plugins install @openclaw/line
本機 checkout(在 git repo 中開發):
openclaw plugins install ./extensions/line
設定
- 建立 LINE Developers 帳號並開啟控制台: https://developers.line.biz/console/
- 建立(或選擇)一個 Provider 並新增 Messaging API 頻道。
- 從頻道設定中複製 Channel access token 和 Channel secret。
- 在 Messaging API 設定中啟用 Use webhook。
- 將 webhook URL 設定為你的 Gateway 端點(需要 HTTPS):
https://gateway-host/line/webhook
Gateway 會回應 LINE 的 webhook 驗證(GET)和接收事件(POST)。
如需自訂路徑,請設定 channels.line.webhookPath 或 channels.line.accounts.<id>.webhookPath 並相應更新 URL。
安全注意事項:
- LINE 簽章驗證依賴請求本體(HMAC over raw body),因此 OpenClaw 在驗證前會套用嚴格的預認證本體限制和逾時。
設定
最小設定:
{
channels: {
line: {
enabled: true,
channelAccessToken: "LINE_CHANNEL_ACCESS_TOKEN",
channelSecret: "LINE_CHANNEL_SECRET",
dmPolicy: "pairing",
},
},
}
環境變數(僅預設帳號):
LINE_CHANNEL_ACCESS_TOKENLINE_CHANNEL_SECRET
Token/secret 檔案:
{
channels: {
line: {
tokenFile: "/path/to/line-token.txt",
secretFile: "/path/to/line-secret.txt",
},
},
}
tokenFile 和 secretFile 必須指向一般檔案。符號連結會被拒絕。
多帳號:
{
channels: {
line: {
accounts: {
marketing: {
channelAccessToken: "...",
channelSecret: "...",
webhookPath: "/line/marketing",
},
},
},
},
}
存取控制
私訊預設為配對模式。未知發送者會收到配對代碼,在核准前訊息會被忽略。
openclaw pairing list line
openclaw pairing approve line <CODE>
許可清單與政策:
channels.line.dmPolicy:pairing | allowlist | open | disabledchannels.line.allowFrom:私訊的 LINE 使用者 ID 許可清單channels.line.groupPolicy:allowlist | open | disabledchannels.line.groupAllowFrom:群組的 LINE 使用者 ID 許可清單- 按群組覆寫:
channels.line.groups.<groupId>.allowFrom - 執行時備註:如果
channels.line完全缺失,執行時會備援為groupPolicy="allowlist"用於群組檢查(即使channels.defaults.groupPolicy已設定)。
LINE ID 區分大小寫。有效的 ID 格式如下:
- 使用者:
U+ 32 個十六進位字元 - 群組:
C+ 32 個十六進位字元 - 聊天室:
R+ 32 個十六進位字元
訊息行為
- 文字以 5000 字元為單位分段。
- Markdown 格式會被移除;程式碼區塊和表格會盡可能轉換為 Flex 卡片。
- 串流回覆會被緩衝;LINE 在代理工作時會收到完整的分段並顯示載入動畫。
- 媒體下載受
channels.line.mediaMaxMb(預設 10)限制。
頻道資料(豐富訊息)
使用 channelData.line 發送快速回覆、位置、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 控制台匹配。 - 沒有接收事件: 確認 webhook 路徑與
channels.line.webhookPath匹配,且 Gateway 可從 LINE 連線。 - 媒體下載錯誤: 如果媒體超過預設限制,請提高
channels.line.mediaMaxMb。