Matrix 是一个开放的去中心化通信协议, 支持端到端加密(E2EE),任何人都可以运行自己的 homeserver。 Element(前身 Riot.im)是最流行的 Matrix 客户端。
Matrix 的核心特点
联邦架构(Federation):
matrix.org ←→ your-company.org ←→ privacyguides.org
不同 homeserver 的用户可以互相通信,像 Email 一样
端对端加密(E2EE):
所有消息在设备端加密
homeserver 只存储加密后的密文,无法查看内容
去中心化:
没有单一控制方,即使 matrix.org 宕机
其他 homeserver 仍然正常运行
安装 Matrix 插件
openclaw plugins install @openclaw/matrix创建 Matrix Bot 账户
在你的 homeserver 注册一个专用 Bot 账户:
方法一:通过 Element 客户端注册
- 打开 Element(app.element.io 或自托管)
- 注册新账户(选择你的 homeserver)
- 记住用户名:
@openclaw-bot:your-homeserver.org - 在账户设置 → 访问令牌 → 获取 Access Token
方法二:通过 homeserver API
curl -X POST "https://your-homeserver.org/_matrix/client/v3/register" -H "Content-Type: application/json" -d '{"username":"openclaw-bot","password":"your-password","kind":"user"}'基础配置
{
"channels": {
"matrix": {
"enabled": true,
"homeserver": "https://matrix.org",
"userId": "@openclaw-bot:matrix.org",
"accessToken": "syt_xxx_xxxxxxxxxxxxx"
}
}
}也可以用密码登录(不推荐,安全性低):
{
"matrix": {
"homeserver": "https://matrix.org",
"userId": "@openclaw-bot:matrix.org",
"password": "your-password"
}
}E2EE 端对端加密配置
Matrix 支持 E2EE,但需要额外的设置步骤:
{
"matrix": {
"enabled": true,
"homeserver": "https://matrix.org",
"userId": "@openclaw-bot:matrix.org",
"accessToken": "syt_xxx_xxxxxxxxxxxxx",
"e2ee": {
"enabled": true,
"storagePath": "./data/matrix-crypto"
}
}
}设备验证流程
首次启动后,Bot 设备需要被验证(Verified):
# 1. 启动 Gateway,Bot 会自动连接到 Matrix
openclaw gateway start
# 2. 在 Element 中查看 Bot 的设备列表
# 用户设置 → 安全 → 设备 → 找到 openclaw-bot
# 3. 手动验证(通过 Emoji 验证或二维码)
# 或者接受 Bot 的自动验证请求
# 4. 验证完成后,E2EE 房间的消息可以正常解密bootstrap 机制:
首次启动时,Bot 会自动 bootstrap 加密密钥:
- 生成新的设备密钥对
- 创建备份密钥(存储在 storagePath)
- 与房间内其他用户交换密钥
备份密钥很重要:
如果 storagePath 丢失,需要重新验证所有加密房间
定期备份 storagePath 目录!
DM 私信使用
用户直接给 Bot 发 DM(Matrix 术语:Direct Message Room):
{
"matrix": {
"dmPolicy": "pairing",
"allowedUsers": [
"@alice:matrix.org",
"@bob:your-company.org"
]
}
}用户在 Element 中搜索 @openclaw-bot:your-homeserver.org 发起私信。
房间(Room)使用
邀请 Bot 加入房间后,在房间里与 AI 互动:
{
"matrix": {
"rooms": {
"#project:your-company.org": {
"requireMention": true,
"threadPerSession": true
}
}
}
}requireMention: true:只有 @ Bot 才触发threadPerSession: true:每次对话创建独立线程,保持整洁
线程(Thread)会话绑定
Matrix 线程与会话绑定,支持多用户并行对话:
#engineering 房间:
Alice: @bot 帮我分析这段代码
[Thread 1]
Bot: 这段代码存在以下问题...
Alice: 那应该怎么改?
Bot: 建议改为...
Bob(同时): @bot 文档怎么写
[Thread 2]
Bot: 技术文档建议包含...
每个线程是独立会话,Bob 和 Alice 互不干扰。
私有 homeserver 配置
自托管 homeserver(如 Synapse/Dendrite):
{
"matrix": {
"homeserver": "https://matrix.your-company.internal",
"userId": "@openclaw-bot:your-company.internal",
"accessToken": "your-token",
"verifyTls": false
}
}Matrix vs Signal 对比
| 对比 | Matrix + OpenClaw | Signal + OpenClaw |
|---|---|---|
| 去中心化 | ✅ 联邦架构 | ❌ 依赖 Signal 服务器 |
| E2EE | ✅ 可选 | ✅ 默认强制 |
| 自托管 | ✅ 自建 homeserver | ❌ 不支持 |
| 多设备 | ✅ 优秀 | ⭐⭐⭐ |
| 群组支持 | ✅ 房间(Room) | ✅ 群组 |
| 易用性 | ⭐⭐⭐(需了解协议) | ⭐⭐⭐⭐⭐ |
来源:OpenClaw 官方文档 - docs.openclaw.ai/channels/matrix