Matrix(外掛)
Matrix is an open, decentralized messaging protocol. Matrix 是一種開放、去中心化的即時通訊協定。OpenClaw 會以 Matrix 使用者 身分連線到任何 homeserver,因此你需要一個 Matrix 帳號給機器人使用。登入完成後,你可以直接私訊 機器人,或邀請它加入房間(Matrix「群組」)。Beeper 也是可行的用戶端選項,但需要啟用 E2EE。 Once it is logged in, you can DM the bot directly or invite it to rooms (Matrix “groups”). Once it is logged in, you can DM the bot directly or invite it to rooms (Matrix “groups”). Beeper is a valid client option too, but it requires E2EE to be enabled. Status: supported via plugin (@vector-im/matrix-bot-sdk). Direct messages, rooms, threads, media, reactions, polls (send + poll-start as text), location, and E2EE (with crypto support).Plugin required
Matrix 以外掛形式提供,未隨核心安裝一併提供。 透過 CLI 安裝(npm registry):設定
-
安裝 Matrix 外掛:
- 從 npm:
openclaw plugins install @openclaw/matrix - 從本機檢出:
openclaw plugins install ./extensions/matrix
- 從 npm:
-
在 homeserver 上建立 Matrix 帳號:
- 瀏覽託管選項:https://matrix.org/ecosystem/hosting/
- Or host it yourself.
-
Get an access token for the bot account:
- 在你的 homeserver 上使用 Matrix 登入 API,搭配
curl:
- 將
matrix.example.org替換為你的 homeserver URL。 - 或設定
channels.matrix.userId+channels.matrix.password:OpenClaw 會呼叫相同的 登入端點,將存取權杖儲存在~/.openclaw/credentials/matrix/credentials.json, 並在下次啟動時重用。
- 在你的 homeserver 上使用 Matrix 登入 API,搭配
-
設定認證資訊:
- 環境變數:
MATRIX_HOMESERVER、MATRIX_ACCESS_TOKEN(或MATRIX_USER_ID+MATRIX_PASSWORD) - 或設定檔:
channels.matrix.* - If both are set, config takes precedence.
- 使用存取權杖時,使用者 ID 會透過
/whoami自動取得。 - 設定時,
channels.matrix.userId應為完整的 Matrix ID(範例:@bot:example.org)。
- 環境變數:
- 重新啟動 gateway(或完成入門設定)。
-
Start a DM with the bot or invite it to a room from any Matrix client
(Element, Beeper, etc.; see https://matrix.org/ecosystem/clients/). Beeper requires E2EE,
so set
channels.matrix.encryption: trueand verify the device.
加密(E2EE)
端對端加密透過 Rust crypto SDK 已支援。 使用channels.matrix.encryption: true 啟用:
- 若成功載入加密模組,會自動解密加密房間。
- 對加密房間送出的媒體會進行加密。
- 初次連線時,OpenClaw 會向你其他工作階段請求裝置驗證。
- Verify the device in another Matrix client (Element, etc.) to enable key sharing.
- 若無法載入加密模組,將停用 E2EE,且無法解密加密房間; OpenClaw 會記錄警告。
- 若看到遺失加密模組的錯誤(例如
@matrix-org/matrix-sdk-crypto-nodejs-*), 請允許@matrix-org/matrix-sdk-crypto-nodejs的建置指令碼,並執行pnpm rebuild @matrix-org/matrix-sdk-crypto-nodejs,或使用node node_modules/@matrix-org/matrix-sdk-crypto-nodejs/download-lib.js取得二進位檔。
~/.openclaw/matrix/accounts/<account>/<homeserver>__<user>/<token-hash>/crypto/
(SQLite database). Sync state lives alongside it in bot-storage.json.
If the access token (device) changes, a new store is created and the bot must be
re-verified for encrypted rooms.
Device verification:
When E2EE is enabled, the bot will request verification from your other sessions on startup.
Open Element (or another client) and approve the verification request to establish trust.1) 驗證完成後,機器人即可在加密房間中解密訊息。1) 驗證完成後,機器人即可在加密房間中解密訊息。
多帳號
多帳號支援:使用channels.matrix.accounts 設定各帳號的憑證與可選的 name。 請參閱 gateway/configuration 了解共用模式。
每個帳號會在任意 homeserver 上以獨立的 Matrix 使用者身分執行。 各帳號設定
繼承自最上層的 channels.matrix 設定,並可覆寫任何選項
(DM 政策、群組、加密等)。
- 為避免並行模組匯入造成競態條件,帳號啟動會以序列方式進行。
- 環境變數(
MATRIX_HOMESERVER、MATRIX_ACCESS_TOKEN等) 僅適用於預設帳號。 - 基礎頻道設定(DM 政策、群組政策、提及門檻等) 除非在個別帳號中覆寫,否則會套用至所有帳號。
- 使用
bindings[].match.accountId將各帳號路由至不同的 agent。 - 加密狀態會依帳號 + access token 分別儲存(每個帳號各自獨立的金鑰儲存)。
路由模型
- 回覆一律返回 Matrix。
-
- 私訊(DM)共用代理的主要工作階段;房間會對應到群組工作階段。
3. 存取控制(私訊)
- 預設:
channels.matrix.dm.policy = "pairing"。未知的寄件者會取得配對碼。 4. 未知的傳送者會取得一組配對碼。 -
- 透過以下方式核准:
openclaw pairing list matrixopenclaw pairing approve matrix <CODE>
- 公開私訊:
channels.matrix.dm.policy="open"加上channels.matrix.dm.allowFrom=["*"]。 channels.matrix.dm.allowFrom接受完整的 Matrix 使用者 ID(範例:@user:server)。當目錄搜尋找到單一且完全符合的結果時,精靈會將顯示名稱解析為使用者 ID。 6. 當目錄搜尋找到單一且完全相符的結果時,精靈會將顯示名稱解析為使用者 ID。- 請勿使用顯示名稱或僅本地部分(例如:
"Alice"或"alice")。 它們具有歧義,且在允許清單比對時會被忽略。 請使用完整的@user:serverID。
房間(群組)
- 預設:
channels.matrix.groupPolicy = "allowlist"(提及觸發)。若未設定,使用channels.defaults.groupPolicy覆寫預設。 7. 在未設定時,使用channels.defaults.groupPolicy來覆寫預設值。 - 使用
channels.matrix.groups將房間加入允許清單(房間 ID 或別名;當目錄搜尋找到單一且完全符合的結果時,名稱會解析為 ID):
requireMention: false啟用該房間的自動回覆。groups."*"可設定跨房間的提及觸發預設值。groupAllowFrom限制哪些寄件者可在房間中觸發機器人(完整 Matrix 使用者 ID)。- 每個房間的
users允許清單可進一步限制特定房間內的寄件者(使用完整 Matrix 使用者 ID)。 -
- 設定精靈會提示設定房間允許清單(房間 ID、別名或名稱),且僅在完全且唯一相符時才解析名稱。
- 啟動時,OpenClaw 會將允許清單中的房間/使用者名稱解析為 ID 並記錄對應;無法解析的項目會被忽略,不用於允許清單比對。
- 預設會自動加入邀請;可使用
channels.matrix.autoJoin與channels.matrix.autoJoinAllowlist控制。 - 若要不允許任何房間,請設定
channels.matrix.groupPolicy: "disabled"(或保持允許清單為空)。 - 舊版鍵值:
channels.matrix.rooms(結構與groups相同)。
Threads
-
- 支援回覆串接(執行緒)。
channels.matrix.threadReplies控制回覆是否維持在執行緒中:off、inbound(預設)、always
channels.matrix.replyToMode控制在非執行緒回覆時的 reply-to 中繼資料:off(預設)、first、all
功能
| 功能 | Status |
|---|---|
| 10. 私人訊息 | ✅ 支援 |
| 房間 | ✅ 支援 |
| Threads | ✅ 支援 |
| 媒體 | ✅ 支援 |
| E2EE | ✅ 支援(需要加密模組) |
| 反應 | ✅ 支援(透過工具傳送/讀取) |
| 投票 | ✅ 支援傳送;接收的投票開始事件會轉為文字(忽略回應/結束) |
| 位置 | ✅ 支援(geo URI;忽略高度) |
| 原生命令 | ✅ 支援 |
11. 疑難排解
請先執行此階梯:- 然後在需要時確認私訊配對狀態:
- 已登入但房間訊息被忽略:房間被
groupPolicy或房間允許清單阻擋。 - 私訊被忽略:在
channels.matrix.dm.policy="pairing"時寄件者尚待核准。 - 加密房間失敗:加密支援或加密設定不相符。
設定參考(Matrix)
完整設定:Configuration 提供者選項:channels.matrix.enabled:啟用/停用頻道啟動。channels.matrix.homeserver:homeserver URL。channels.matrix.userId:Matrix 使用者 ID(使用存取權杖時可選)。channels.matrix.accessToken:存取權杖。channels.matrix.password:登入用密碼(會儲存權杖)。channels.matrix.deviceName:裝置顯示名稱。channels.matrix.encryption:啟用 E2EE(預設:false)。channels.matrix.initialSyncLimit:初始同步限制。channels.matrix.threadReplies:off | inbound | always(預設:inbound)。channels.matrix.textChunkLimit:外送文字分塊大小(字元)。channels.matrix.chunkMode:length(預設)或newline,在長度分塊前先依空白行(段落邊界)分割。channels.matrix.dm.policy:pairing | allowlist | open | disabled(預設:pairing)。channels.matrix.dm.allowFrom:私訊允許清單(完整的 Matrix 使用者 ID)。 14.open需要使用"*"。 15. 精靈會在可行時將名稱解析為 ID。channels.matrix.groupPolicy:allowlist | open | disabled(預設:allowlist)。channels.matrix.groupAllowFrom:群組訊息的允許寄件者(完整 Matrix 使用者 ID)。channels.matrix.allowlistOnly:對私訊 + 房間強制套用允許清單規則。channels.matrix.groups:群組允許清單 + 各房間設定對應表。channels.matrix.rooms:舊版群組允許清單/設定。channels.matrix.replyToMode:執行緒/標記的 reply-to 模式。channels.matrix.mediaMaxMb:入站/出站媒體上限(MB)。channels.matrix.autoJoin:邀請處理(always | allowlist | off,預設:always)。channels.matrix.autoJoinAllowlist:允許自動加入的房間 ID/別名。channels.matrix.accounts:以帳號 ID 為鍵的多帳號設定(每個帳號繼承最上層設定)。channels.matrix.actions:依動作的工具門檻(reactions/messages/pins/memberInfo/channelInfo)。