agentscope-ai / agentscope-ai/AgentTeams
CoPaw Worker Matrix 消息缺少 formatted_body 字段导致 Markdown 无法渲染 || CoPaw Worker Matrix message is missing the formatted_body field, causing Markdown to fail to render
- Dominant language
- Go
- Stars
- 5.6k
- Forks
- 692
- Avg merge
- 5d 4h
- Merged PRs (30d)
- 23
Description
## 问题描述
CoPaw Worker 在 Matrix 群聊中发送的消息缺少 `formatted_body` 字段,导致 Element Desktop 客户端无法渲染 Markdown 格式,显示为源码而非格式化后的内容。
## 复现步骤
1. 创建 CoPaw Worker(使用 `create-worker.sh --runtime copaw`)
2. Worker 加入 Matrix 群聊房间
3. Worker 发送包含 Markdown 格式的消息(如表格、粗体、列表等)
4. 在 Element Desktop 中查看该消息
## 预期行为
Worker 发送的 Matrix 消息应包含 `formatted_body` 字段,Element Desktop 能正确渲染 Markdown 格式:
```json
{
"msgtype": "m.text",
"body": "**粗体** 和 *斜体*",
"format": "org.matrix.custom.html",
"formatted_body": "
粗体 和 斜体
"}
```
## 实际行为
Worker 发送的消息只有纯文本 `body` 字段,缺少格式化字段:
```json
{
"msgtype": "m.text",
"body": "**粗体** 和 *斜体*"
// 缺少 format 和 formatted_body ❌
}
```
导致 Element Desktop 显示为 Markdown 源码。
## 环境信息
- **HiClaw 版本**: 2026.2.2-3(根据 openclaw.json meta.lastTouchedVersion)
- **Worker 运行时**: CoPaw (copaw-worker-agent)
- **Matrix 服务器**: 自建 Matrix homeserver
- **客户端**: Element Desktop
- **安装方式**: 本地容器化部署
## 技术排查
### 已确认正确的部分
1. **OpenClaw Matrix 插件代码正确**:
- `/opt/openclaw/extensions/matrix/src/matrix/send/formatting.ts` 中的 `buildTextContent()` 函数正确调用了 `applyMatrixFormatting()`
- `applyMatrixFormatting()` 正确调用 `markdownToMatrixHtml()` 转换 Markdown 为 HTML
- 正确设置 `format: "org.matrix.custom.html"` 和 `formatted_body`
2. **Worker 配置已更新**:
- Worker 的 `openclaw.json` 已添加 `channels.matrix.markdown.tables: "bullets"` 配置
- 配置已推送到 MinIO (`hiclaw/hiclaw-storage/agents//openclaw.json`)
- Worker 已通过 file-sync 技能拉取最新配置
### 可能的问题根因
**CoPaw Worker 可能使用独立的 Python Matrix 客户端发送消息**,没有经过 OpenClaw 的 Node.js Matrix 插件的格式化逻辑:
1. CoPaw Worker 是 Python 运行时(`/opt/hiclaw/agent/copaw-worker-agent/`)
2. 可能使用了 `matrix-nio` 或其他 Python Matrix 库直接发送消息
3. 绕过了 OpenClaw 的 `sendMessageMatrix()` → `buildTextContent()` → `applyMatrixFormatting()` 流程
4. 导致消息缺少 `formatted_body` 字段
## 建议修复方案
### 方案 A:修复 CoPaw Worker 的消息发送实现
在 CoPaw Worker 的消息发送代码中添加 Markdown 格式化支持:
1. 定位 CoPaw Worker 的 Matrix 消息发送代码
2. 集成 `markdown` Python 库或使用类似的 Markdown 转 HTML 逻辑
3. 发送消息时同时设置 `body`(纯文本)和 `formatted_body`(HTML)
参考 OpenClaw Node.js 实现:
```typescript
// /opt/openclaw/extensions/matrix/src/matrix/send/formatting.ts
export function applyMatrixFormatting(content: MatrixFormattedContent, body: string): void {
const formatted = markdownToMatrixHtml(body ?? "");
if (!formatted) return;
content.format = "org.matrix.custom.html";
content.formatted_body = formatted;
}
```
### 方案 B:CoPaw Worker 通过 Gateway HTTP API 发送消息
如果 CoPaw Worker 通过 OpenClaw Gateway 的 HTTP API 发送消息,Gateway 会正确使用 Matrix 插件的格式化逻辑。
### 方案 C:文档说明
在 CoPaw Worker 的文档中说明:
- 当前不支持 Markdown 格式化
- 建议使用纯文本或简单格式
- 或指导用户配置 Element 客户端的 Markdown 渲染
## 影响范围
- **受影响用户**: 所有使用 CoPaw Worker + Element Desktop 的用户
- **受影响功能**: Matrix 群聊中的消息格式渲染
- **严重程度**: 中等(影响用户体验,但不影响功能)
## 附加信息
### Worker 配置示例
```json
{
"channels": {
"matrix": {
"enabled": true,
"homeserver": "http://matrix-local.hiclaw.io:8080",
"accessToken": "xxx",
"markdown": {
"tables": "bullets"
}
}
}
}
```
### 相关代码位置
- OpenClaw Matrix 插件:`/opt/openclaw/extensions/matrix/src/matrix/send/formatting.ts`
- Markdown 转 HTML:`/opt/openclaw/extensions/matrix/src/matrix/format.ts`
- CoPaw Worker Agent:`/opt/hiclaw/agent/copaw-worker-agent/`
- CoPaw file-sync 技能:`/opt/hiclaw/agent/copaw-worker-agent/skills/file-sync/`
## 标签
- `bug`
- `matrix`
- `copaw`
- `markdown`
- `ui/rendering`
---
## Problem description
The message sent by CoPaw Worker in the Matrix group chat lacks the `formatted_body` field, causing the Element Desktop client to be unable to render the Markdown format and display it as source code instead of formatted content.
## Reproduction steps
1. Create CoPaw Worker (use `create-worker.sh --runtime copaw`)
2. Worker joins Matrix group chat room
3. Worker sends messages containing Markdown format (such as tables, bold, lists, etc.)
4. View the message in Element Desktop
## expected behavior
The Matrix message sent by the Worker should contain the `formatted_body` field, and Element Desktop can render the Markdown format correctly:
```json
{
"msgtype": "m.text",
"body": "**bold** and *italic*",
"format": "org.matrix.custom.html",
"formatted_body": "
Bold and Italic
"}
```
## Actual behavior
The message sent by the Worker only has the plain text `body` field and lacks the formatting field:
```json
{
"msgtype": "m.text",
"body": "**bold** and *italic*"
// Missing format and formatted_body ❌
}
```
Causes Element Desktop to display as Markdown source code.
## Environment information
- **HiClaw version**: 2026.2.2-3 (according to openclaw.json meta.lastTouchedVersion)
- **Worker runtime**: CoPaw (copaw-worker-agent)
- **Matrix server**: self-built Matrix homeserver
- **Client**: Element Desktop
- **Installation method**: Local containerized deployment
## Technical troubleshooting
### Confirmed correct part
1. **OpenClaw Matrix plug-in code is correct**:
- The `buildTextContent()` function in `/opt/openclaw/extensions/matrix/src/matrix/send/formatting.ts` correctly calls `applyMatrixFormatting()`
- `applyMatrixFormatting()` correctly calls `markdownToMatrixHtml()` to convert Markdown to HTML
- Correctly set `format: "org.matrix.custom.html"` and `formatted_body`
2. **Worker configuration updated**:
- Worker's `openclaw.json` has added `channels.matrix.markdown.tables: "bullets"` configuration
- Configuration pushed to MinIO (`hiclaw/hiclaw-storage/agents//openclaw.json`)
- Worker has pulled the latest configuration through file-sync skill
### Possible root cause of the problem
**CoPaw Worker may use a standalone Python Matrix client to send messages** without going through the formatting logic of OpenClaw's Node.js Matrix plug-in:
1. CoPaw Worker is a Python runtime (`/opt/hiclaw/agent/copaw-worker-agent/`)
2. You may use `matrix-nio` or other Python Matrix library to send messages directly
3. Bypassing OpenClaw’s `sendMessageMatrix()` → `buildTextContent()` → `applyMatrixFormatting()` process
4. The message is missing the `formatted_body` field
## Suggested fixes
### Solution A: Fix the message sending implementation of CoPaw Worker
Add Markdown formatting support in CoPaw Worker's message sending code:
1. Locate the Matrix message sending code of CoPaw Worker
2. Integrate the `markdown` Python library or use similar Markdown to HTML logic
3. Set both `body` (plain text) and `formatted_body` (HTML) when sending a message
Reference OpenClaw Node.js implementation:
```typescript
// /opt/openclaw/extensions/matrix/src/matrix/send/formatting.ts
export function applyMatrixFormatting(content: MatrixFormattedContent, body: string): void {
const formatted = markdownToMatrixHtml(body ?? "");
if (!formatted) return;
content.format = "org.matrix.custom.html";
content.formatted_body = formatted;
}
```
### Option B: CoPaw Worker sends messages through Gateway HTTP API
If a CoPaw Worker sends a message via the OpenClaw Gateway's HTTP API, the Gateway correctly uses the Matrix plug-in's formatting logic.
### Solution C: Documentation
According to the documentation for CoPaw Worker:
- Markdown formatting is not currently supported
- It is recommended to use plain text or simple format
- Or guide users to configure Markdown rendering on the Element client
## Scope of influence
- **Affected Users**: All users using CoPaw Worker + Element Desktop
- **Affected Features**: Message format rendering in Matrix group chat
- **Severity**: Moderate (affects user experience, but does not affect functionality)
## Additional information
### Worker configuration example
```json
{
"channels": {
"matrix": {
"enabled": true,
"homeserver": "http://matrix-local.hiclaw.io:8080",
"accessToken": "xxx",
"markdown": {
"tables": "bullets"
}
}
}
}
```
### Relevant code location
- OpenClaw Matrix plugin: `/opt/openclaw/extensions/matrix/src/matrix/send/formatting.ts`
- Markdown to HTML: `/opt/openclaw/extensions/matrix/src/matrix/format.ts`
- CoPaw Worker Agent: `/opt/hiclaw/agent/copaw-worker-agent/`
- CoPaw file-sync skill: `/opt/hiclaw/agent/copaw-worker-agent/skills/file-sync/`
## Tags
- `bug`
- `matrix`
- `copaw`
- `markdown`
- `ui/rendering`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.