Community translations by veiseule.ai — Help improve them on Crowdin
Skip to main content

LINE(外掛程式)

LINE 透過 LINE Messaging API 連接至 OpenClaw。此外掛程式在 Gateway 閘道器 上以 webhook 接收器的形式執行,並使用你的 channel access token 與 channel secret 進行 身分驗證。 The plugin runs as a webhook receiver on the gateway and uses your channel access token + channel secret for authentication.

狀態:透過外掛支援。直接訊息、群組聊天、媒體、位置資訊、Flex messages, template messages, and quick replies are supported. Reactions and threads are not supported.

需要外掛

安裝 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 tokenChannel secret
  4. 在 Messaging API 設定中啟用 Use webhook
  5. 將 webhook URL 設為你的 Gateway 閘道器 端點(必須為 HTTPS):
https://gateway-host/line/webhook

Gateway 閘道器 會回應 LINE 的 webhook 驗證(GET)與傳入事件(POST)。 如果你需要自訂路徑,請設定 channels.line.webhookPathchannels.line.accounts.<id> If you need a custom path, setchannels.line.webhookPathorchannels.line.accounts..webhookPath`,並相應更新 URL。

設定

最小設定:

{
  channels: {
    line: {
      enabled: true,
      channelAccessToken: "LINE_CHANNEL_ACCESS_TOKEN",
      channelSecret: "LINE_CHANNEL_SECRET",
      dmPolicy: "pairing",
    },
  },
}

環境變數(僅限預設帳號):

  • LINE_CHANNEL_ACCESS_TOKEN
  • LINE_CHANNEL_SECRET

權杖/密鑰檔案:

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

多帳號:

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

存取控制

Direct messages default to pairing. 私訊預設需要配對。未知的寄件者會收到配對碼,其訊息在核准前將被忽略。

openclaw pairing list line
openclaw pairing approve line <CODE>

允許清單與政策:

  • channels.line.dmPolicypairing | allowlist | open | disabled
  • channels.line.allowFrom:用於私訊的允許清單 LINE 使用者 ID
  • channels.line.groupPolicyallowlist | open | disabled
  • channels.line.groupAllowFrom:用於群組的允許清單 LINE 使用者 ID
  • 每個群組的覆寫設定:channels.line.groups.<groupId>.allowFrom

LINE ID 區分大小寫。有效的 ID 範例如下:

  • 使用者:U + 32 個十六進位字元
  • 群組:C + 32 個十六進位字元
  • Room:R + 32 個十六進位字元

訊息行為

  • 文字會在 5000 個字元處分段。
  • Markdown 格式會被移除;程式碼區塊與表格在可能的情況下會轉換為 Flex 卡片。
  • 串流回應會先緩衝;在代理程式運作期間,LINE 會收到完整的區塊並顯示載入 動畫。
  • 媒體下載數量受 channels.line.mediaMaxMb 限制(預設為 10)。

Channel 資料(豐富訊息)

使用 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 外掛程式也提供一個用於 Flex 訊息預設的 /card 指令:

/card info "Welcome" "Thanks for joining!"

疑難排解

  • Webhook 驗證失敗: 確保 webhook URL 為 HTTPS,且 channelSecret 與 LINE Console 中的設定一致。
  • 沒有傳入事件: 確認 webhook 路徑與 channels.line.webhookPath 相符,且 Gateway 閘道器 可從 LINE 存取。
  • 媒體下載錯誤: 若媒體超過預設限制,請提高 channels.line.mediaMaxMb