OpenClaw Matrix 頻道
將 OpenClaw 連接到 Matrix——一個開放的聯邦通訊協定。此整合讓您的 AI 助理可以參與任何 Homeserver(matrix.org、Element 或自架)上的 Matrix 房間和私訊。OpenClaw 透過 Matrix Client-Server API 連接,並透過 Rust crypto SDK 提供可選的端對端加密(E2EE)支援。Matrix 頻道作為外掛發布,支援聯邦、執行緒、表情回應和豐富媒體。
Matrix 支援功能
文字訊息
支援
媒體與檔案
支援
表情回應
支援
討論串
支援
語音訊息
不支援
群組聊天
支援
Matrix 前置條件
- 在任何 Homeserver(matrix.org、Element 或自架)上擁有活躍的 Matrix 帳戶
- 已安裝 Matrix 外掛:openclaw plugins install @openclaw/matrix
- OpenClaw Gateway 正在執行並已設定
- 伺服器上已安裝 Node.js 18+
Matrix 快速設定
安裝 Matrix 外掛
Matrix 頻道作為獨立外掛發布。透過 'openclaw plugins install @openclaw/matrix' 安裝。外掛將從 npm 倉庫下載並自動啟用。
取得 Matrix 憑證
您需要存取權杖或使用者名稱/密碼。對於存取權杖:使用 curl 呼叫 Homeserver 的登入端點並複製權杖。對於使用者名稱/密碼:Gateway 將自動登入並將權杖儲存在 ~/.openclaw/credentials/matrix/credentials.json 中。
新增 Matrix 頻道設定
將 Matrix 頻道設定新增到 ~/.openclaw/openclaw.json,包含您的 Homeserver URL 和憑證。您也可以使用環境變數 MATRIX_HOMESERVER、MATRIX_ACCESS_TOKEN、MATRIX_USER_ID 和 MATRIX_PASSWORD。
啟動 Gateway 並測試
執行 'openclaw gateway' 啟動服務。從另一個帳戶向您的 Matrix 機器人使用者傳送私訊。如果使用預設的配對策略,透過終端機中的 'openclaw pairing approve matrix <code>' 批准傳送者。
Matrix 設定範例
{
"channels": {
"matrix": {
"enabled": true,
"homeserver": "https://matrix.org",
"accessToken": "your_access_token_here",
"dmPolicy": "pairing"
}
}
}Matrix 深入了解
架構概覽
驗證方法
# 存取權杖方法
{
"channels": {
"matrix": {
"homeserver": "https://matrix.example.org",
"accessToken": "syt_xxx..."
}
}
}
# 使用者名稱/密碼方法
{
"channels": {
"matrix": {
"homeserver": "https://matrix.example.org",
"userId": "@bot:example.org",
"password": "your_password"
}
}
}私訊策略
{
"channels": {
"matrix": {
"dmPolicy": "allowlist",
"dm": {
"allowFrom": ["@alice:matrix.org", "@bob:example.org"]
}
}
}
}群組聊天(房間)支援
{
"channels": {
"matrix": {
"groupPolicy": "allowlist",
"groups": {
"!abc123:matrix.org": {
"allow": true,
"requireMention": false,
"users": ["@alice:matrix.org"]
},
"#team-chat:example.org": {
"allow": true
}
},
"autoJoin": "allowlist"
}
}
}端對端加密(E2EE)
{
"channels": {
"matrix": {
"encryption": true
}
}
}聯邦與 Homeserver 選擇
執行緒與回覆模式
{
"channels": {
"matrix": {
"threadReplies": "always",
"replyToMode": "reference"
}
}
}媒體處理與檔案上傳
{
"channels": {
"matrix": {
"mediaMaxMb": 50
}
}
}表情回應與豐富功能
{
"channels": {
"matrix": {
"actions": {
"reactions": true,
"messages": true,
"pins": false
}
}
}
}為什麼選擇 Matrix 作為自架 AI?
Matrix 設定參考
| Key | Type | Default | Description |
|---|---|---|---|
| enabled | boolean | true | 啟用或停用 Matrix 頻道 |
| homeserver | string | "https://matrix.org" | Matrix Homeserver URL(如 https://matrix.org、https://element.io) |
| accessToken | string | "" | 用於驗證的 Matrix 存取權杖(推薦方法) |
| userId | string | "" | Matrix 使用者 ID(如 @bot:matrix.org)—— 與密碼驗證一起使用 |
| password | string | "" | Matrix 帳戶密碼——與 userId 一起用於登入 |
| encryption | boolean | false | 透過 Rust crypto SDK 啟用端對端加密 |
| dmPolicy | string | "pairing" | 私訊存取策略:pairing、allowlist、open 或 disabled |
| dm.allowFrom | array | [] | 允許私訊的 Matrix 使用者 ID(如 [@alice:matrix.org]) |
| groupPolicy | string | "allowlist" | 房間策略:allowlist 或 disabled |
| groups | object | {} | 特定房間設定(房間 ID 或別名作為鍵) |
| groups.<roomId>.allow | boolean | false | 允許機器人參與此房間 |
| groups.<roomId>.requireMention | boolean | true | 在此房間中需要提及機器人才能觸發回應 |
| groups.<roomId>.users | array | [] | 每個房間的使用者白名單(Matrix 使用者 ID) |
| autoJoin | string | "allowlist" | 自動加入房間邀請:always、allowlist 或 off |
| textChunkLimit | number | 4096 | 每條出站訊息的最大字元數 |
| chunkMode | string | "length" | 如何分割長回應:length(硬限制)或 newline(段落邊界) |
| threadReplies | string | "inbound" | 執行緒行為:off、inbound(唯讀)或 always(讀取+建立) |
| replyToMode | string | "reference" | 回覆中繼資料附加模式 |
| mediaMaxMb | number | 50 | 最大媒體檔案大小(MB) |
| actions.reactions | boolean | true | 允許代理傳送/讀取表情回應 |
| actions.messages | boolean | true | 允許代理讀取/傳送/編輯/刪除訊息 |
| actions.pins | boolean | true | 允許代理釘選/取消釘選訊息 |
| actions.memberInfo | boolean | true | 允許代理查詢房間成員資訊 |
| actions.channelInfo | boolean | true | 允許代理檢索房間/頻道資訊 |
啟用或停用 Matrix 頻道
Matrix Homeserver URL(如 https://matrix.org、https://element.io)
用於驗證的 Matrix 存取權杖(推薦方法)
Matrix 使用者 ID(如 @bot:matrix.org)—— 與密碼驗證一起使用
Matrix 帳戶密碼——與 userId 一起用於登入
透過 Rust crypto SDK 啟用端對端加密
私訊存取策略:pairing、allowlist、open 或 disabled
允許私訊的 Matrix 使用者 ID(如 [@alice:matrix.org])
房間策略:allowlist 或 disabled
特定房間設定(房間 ID 或別名作為鍵)
允許機器人參與此房間
在此房間中需要提及機器人才能觸發回應
每個房間的使用者白名單(Matrix 使用者 ID)
自動加入房間邀請:always、allowlist 或 off
每條出站訊息的最大字元數
如何分割長回應:length(硬限制)或 newline(段落邊界)
執行緒行為:off、inbound(唯讀)或 always(讀取+建立)
回覆中繼資料附加模式
最大媒體檔案大小(MB)
允許代理傳送/讀取表情回應
允許代理讀取/傳送/編輯/刪除訊息
允許代理釘選/取消釘選訊息
允許代理查詢房間成員資訊
允許代理檢索房間/頻道資訊
Matrix 常見問題
Matrix 故障排除
私訊策略阻止訊息,或機器人不在房間中
裝置未驗證或加密模組載入失敗
權杖在 Homeserver 上被撤銷或失效
房間不在白名單中或 requireMention 已啟用
Homeserver 連接或聯邦問題
npm 倉庫存取或 Node.js 版本不相容