教程

OpenClaw Matrix 接入指南:去中心化消息协议、E2EE 加密与多账号配置

OpenClaw Matrix 接入完整教程:插件安装、Access Token 获取、E2EE 端对端加密(Rust crypto SDK)与设备验证流程、多账号配置(不同 Homeserver)、DM 与房间双层访问控制、线程 Session 隔离,以及 Beeper 兼容配置与故障排查。

2026/3/124分钟 阅读ClaudeEagle

Matrix 是开放的去中心化消息协议。OpenClaw 以 Matrix 用户身份连接到任意 Homeserver,支持 DM、房间(群组)、线程、媒体和端对端加密(E2EE)。

安装插件

bash
openclaw plugins install @openclaw/matrix

快速接入(6 步)

1. 安装 Matrix 插件

2. 创建 Matrix 账号

在任意 Homeserver 上注册账号,可选托管方案:https://matrix.org/ecosystem/hosting/ 或自托管。

3. 获取 Access Token

bash
curl --request POST \
  --url https://matrix.example.org/_matrix/client/v3/login \
  --header 'Content-Type: application/json' \
  --data '{
    "type": "m.login.password",
    "identifier": { "type": "m.id.user", "user": "your-user-name" },
    "password": "your-password"
  }'

也可以直接在配置中填写 userId + password,OpenClaw 会自动登录并缓存 Token。

4. 配置 OpenClaw

最简配置(Access Token)

json
{
  "channels": {
    "matrix": {
      "enabled": true,
      "homeserver": "https://matrix.example.org",
      "accessToken": "syt_***",
      "dm": { "policy": "pairing" }
    }
  }
}

E2EE 加密配置

json
{
  "channels": {
    "matrix": {
      "enabled": true,
      "homeserver": "https://matrix.example.org",
      "accessToken": "syt_***",
      "encryption": true,
      "dm": { "policy": "pairing" }
    }
  }
}

环境变量方式:

bash
export MATRIX_HOMESERVER=https://matrix.example.org
export MATRIX_ACCESS_TOKEN=syt_***

5. 重启 Gateway

bash
openclaw gateway restart

6. 完成配对

bash
openclaw pairing list matrix
openclaw pairing approve matrix <CODE>

用 Element、Beeper 等任意 Matrix 客户端向 Bot 发送 DM 或邀请 Bot 进入房间。

注意:Beeper 需要启用 E2EE。

E2EE 端对端加密

json
{
  "channels": {
    "matrix": {
      "encryption": true
    }
  }
}

启用后:

  • 加密房间的消息自动解密
  • 向加密房间发送媒体时自动加密
  • 首次连接时,OpenClaw 向其他 Session 请求设备验证
  • 在 Element 等客户端中批准验证请求,建立信任后 Bot 才能解密消息

Crypto 状态存储位置

~/.openclaw/matrix/accounts/<account>/<homeserver>__<user>/<token-hash>/crypto/

如果出现 @matrix-org/matrix-sdk-crypto-nodejs-* 模块缺失错误,运行: pnpm rebuild @matrix-org/matrix-sdk-crypto-nodejs

多账号配置

json
{
  "channels": {
    "matrix": {
      "enabled": true,
      "dm": { "policy": "pairing" },
      "accounts": {
        "assistant": {
          "name": "Main assistant",
          "homeserver": "https://matrix.example.org",
          "accessToken": "syt_assistant_***",
          "encryption": true
        },
        "alerts": {
          "name": "Alerts bot",
          "homeserver": "https://matrix.example.org",
          "accessToken": "syt_alerts_***",
          "dm": { "policy": "allowlist", "allowFrom": ["@admin:example.org"] }
        }
      }
    }
  }
}

多账号注意事项

  • 环境变量(MATRIX_HOMESERVER 等)只对默认账号生效
  • 顶层配置对所有账号生效,可在各账号下覆盖
  • 使用 bindings[].match.accountId 将不同账号路由到不同 Agent
  • 每个账号+Token 有独立的 Crypto 密钥存储

访问控制

DM 访问

json
{
  "channels": {
    "matrix": {
      "dm": {
        "policy": "allowlist",
        "allowFrom": ["@user:example.org"]
      }
    }
  }
}

重要:只接受完整的 Matrix 用户 ID(@user:server),不接受显示名或短用户名。

策略说明
pairing(默认)未知用户收到配对码
allowlist仅白名单用户(完整 Matrix ID)
openallowFrom: ["*"] 时开放

房间(群组)控制

json
{
  "channels": {
    "matrix": {
      "groupPolicy": "allowlist",
      "groups": {
        "!roomId:example.org": { "allow": true },
        "#alias:example.org": { "allow": true, "requireMention": false }
      },
      "groupAllowFrom": ["@owner:example.org"]
    }
  }
}
  • requireMention: false:无需 @ 提及 Bot 即自动回复
  • groups."*":设置所有房间的默认 mention 策略
  • 房间 ID 和别名都支持(别名会自动解析为 ID)

Session 路由模型

场景Session Key
DMagent:<id>:matrix:dm:<userId>
房间agent:<id>:matrix:group:<roomId>
线程agent:<id>:matrix:group:<roomId>:thread:<eventId>

支持的功能

功能支持
文字消息
媒体(图片/文件/音频)
E2EE 端对端加密
线程(Threads)
Reactions
投票(Poll)✅(发送/接收)
位置信息
Beeper 兼容✅(需开启 E2EE)

故障排查

Bot 无响应:确认插件已安装;检查 homeserveraccessToken 正确;openclaw logs --follow

加密消息无法解密:确认 encryption: true;在 Element 中批准设备验证请求;检查 Crypto 模块是否正确安装

DM 被忽略openclaw pairing list matrix 查看待审批请求;检查 dm.allowFrom 使用完整 Matrix ID

房间消息被忽略:检查房间 ID 在 groups 白名单中;确认 requireMention 设置


原文:Matrix - OpenClaw | 来源:OpenClaw 官方文档

相关文章推荐

教程OpenClaw 接入 Matrix:去中心化加密聊天协议 AI 助手完全配置指南OpenClaw 接入 Matrix 协议的完整教程:Matrix 的去中心化联邦架构特点、插件安装(@openclaw/matrix)、创建 Matrix Bot 账户(homeserver + accessToken/password 两种认证方式)、E2EE 端对端加密配置与设备验证流程、DM 私信与房间(Room)两种使用模式、线程(Thread)会话绑定、表情反应支持、私有/LAN homeserver 配置、多账户管理,以及 Matrix 与 Signal 的端到端加密对比。2026/3/23教程OpenClaw 接入 Matrix:去中心化开放协议、E2EE 加密与 Beeper 支持OpenClaw 接入 Matrix 去中心化协议完整教程:安装插件、创建 Matrix Bot 账号(Access Token 或密码方式)、基础配置、端到端加密(E2EE)启用、多账号配置、访问控制,以及 Beeper 客户端的特殊注意事项。2026/3/2教程OpenClaw 接入 Nostr:去中心化社交协议的 AI 助手配置指南OpenClaw 接入 Nostr 去中心化通信协议的完整教程:Nostr 是什么(基于密钥对的去中心化社交协议)、OpenClaw Nostr 插件安装、私钥配置方式(nsec 格式或 hex 格式)、Relay 服务器配置(推荐 Relay 列表)、NIP-04 加密私信(DM)工作原理、允许哪些 npub 公钥发起对话、Nostr 与 Signal 的隐私对比,以及 Nostr AI 助手的独特使用场景(去中心化、抗审查的 AI 对话)。2026/3/22教程OpenClaw 接入 Tlon(Urbit):去中心化 Urbit 舰队配置、群组频道与自动审批OpenClaw 接入 Tlon(Urbit)去中心化平台完整教程:舰队连接配置(ship/url/code)、ownerShip 主人舰队设置、内网私有舰队 SSRF 防护豁免、群组频道自动发现与手动配置、DM 访问策略、自动审批,以及内置 /tlon:dm Skill 主动发起 DM。2026/3/3教程OpenClaw 接入 Nostr:去中心化社交协议 DM、密钥管理与中继服务器配置OpenClaw 接入 Nostr 去中心化协议完整教程:密钥对生成(nsec/hex 格式)、NIP-04 加密私信配置、三种 DM 访问策略(pairing/open/allowlist)、公钥白名单、多中继服务器配置,以及本地测试方法和 MVP 版本已知限制。2026/3/3教程OpenClaw Standing Orders 完全指南:让 AI 记住你的长期规则和行为偏好OpenClaw Standing Orders(常驻指令)功能完整教程:Standing Orders 与 SOUL.md 的区别(动态运行时规则 vs 静态人格文件)、通过对话动态添加/查看/删除常驻指令、指令的持久化存储与跨会话生效机制、适合写入 Standing Orders 的内容类型(格式偏好/禁止行为/固定工作流)、与 Hooks 的协同使用、按渠道/Agent 设置不同的 Standing Orders,以及常驻指令的最佳实践(写清晰的规则、避免矛盾冲突、定期清理过时规则)。2026/3/26