Matrix 集成
将 ClawdBot 连接到 Matrix 去中心化网络
概述
Matrix 是一个开源的去中心化通信协议。通过 Matrix 集成, 你可以在 Element 等客户端中与 ClawdBot 交流,支持端到端加密和自托管。
去中心化
开源协议,无单点故障
端到端加密
支持 E2EE 加密通信
可自托管
使用自己的服务器
创建 Matrix 账号
为 ClawdBot 创建一个 Matrix 账号:
方法 1: 使用公共服务器
- 访问 Element Web
- 点击 "Create Account"
- 选择 matrix.org 或其他公共服务器
- 创建账号(如 @clawdbot:matrix.org)
方法 2: 命令行注册
# 使用 matrix-commander 或类似工具
matrix-commander --register \
--user clawdbot \
--password "secure-password" \
--homeserver matrix.org获取 Access Token
# 登录获取 token
curl -X POST "https://matrix.org/_matrix/client/r0/login" \
-H "Content-Type: application/json" \
-d '{
"type": "m.login.password",
"user": "clawdbot",
"password": "your-password"
}'
# 返回的 access_token 用于配置配置连接
配置文件
# ~/.clawdbot/config.yaml
channels:
matrix:
enabled: true
homeserver: "https://matrix.org"
user_id: "@clawdbot:matrix.org"
access_token: "syt_xxx..."
# 可选配置
device_id: "CLAWDBOT"
display_name: "ClawdBot AI"
# 只在特定房间响应
allowed_rooms:
- "!abc123:matrix.org"环境变量
export CLAWDBOT_MATRIX_HOMESERVER="https://matrix.org"
export CLAWDBOT_MATRIX_USER_ID="@clawdbot:matrix.org"
export CLAWDBOT_MATRIX_TOKEN="syt_xxx..."
clawdbot gateway验证连接
clawdbot channels list
clawdbot matrix test端到端加密
Matrix 支持端到端加密(E2EE),确保消息安全:
启用加密
channels:
matrix:
encryption:
enabled: true
# 存储加密密钥
store_path: "~/.clawdbot/matrix-crypto"密钥备份
# 备份加密密钥
clawdbot matrix export-keys --output keys-backup.txt
# 恢复密钥
clawdbot matrix import-keys --input keys-backup.txt设备验证
首次使用加密房间时,可能需要验证设备。在 Element 中确认 ClawdBot 的设备。
功能特性
消息类型
- 文本消息 - 普通对话
- 图片 - 发送和接收图片
- 文件 - 文件传输
- 格式化消息 - Markdown 支持
房间功能
- 支持私聊和群组
- 可以被邀请加入房间
- 支持 @mention 触发
- 支持线程回复
自托管服务器
如果你运行自己的 Matrix 服务器(如 Synapse):
channels:
matrix:
homeserver: "https://matrix.yourdomain.com"
user_id: "@clawdbot:yourdomain.com"
access_token: "your-token"
# 如果使用自签名证书
verify_ssl: false故障排查
无法登录
- 检查 homeserver URL 是否正确
- 确认 access_token 有效
- 验证网络可以访问 Matrix 服务器
加密消息无法解密
- 确保加密密钥已正确存储
- 验证设备是否被信任
- 尝试重新导入密钥
# 诊断
clawdbot doctor --verbose
clawdbot matrix test