Skip to content

Telegram: Agent messages lack paragraph breaks and CJK table misalignment #59562

Description

@Songhpeng1202

问题描述

Telegram 接收到的 Agent 消息存在两个格式问题:

问题 1:段落未分段(Wall of Text)

现象:Agent 回复的长文本全部挤在一起,没有段落间距,看起来像一面墙。

原因:Markdown 规范要求用 \n\n 分隔段落,但 LLM 生成的内容使用单个 \n,Telegram 将其视为同一段落渲染。

示例

当前(错误):
风险评估:当前股价\$1780元...流动性较好...当前持仓建议控制在3-5层仓位...建议采用定投方式分散风险

期望(正确):
风险评估:当前股价\$1780元...

流动性较好...

当前持仓建议控制在3-5层仓位...

建议采用定投方式分散风险...

复现方式:让 Agent 生成任何超过 3 段的回复,都能观察到。


问题 2:表格与 CJK 字符对齐问题

现象:包含中文的表格在 Telegram 中显示错位。

原因:Telegram 使用 <pre> 块渲染 Markdown 表格,String.length 计算字符宽度,而 CJK 字符(如中文、日文)占 2 个显示列但只计为 1 个长度,导致对齐偏移。

OpenClaw 相关 Issue#55512(已确认)

当前 Workaround:配置 channels.telegram.markdown.tables: "code" 将表格渲染为代码块,但无法根本解决对齐问题。

上游 PR#55596(DRAFT)— 使用 string-width 包修复,但尚未合并。


环境信息

  • OpenClaw 版本:[当前版本]
  • Telegram Bot API
  • Agent 配置:markdown.parse_mode 配置

期望行为

  1. 段落分隔:所有 Agent 消息中的段落应使用空行分隔,确保在 Telegram 中正确渲染为多个段落
  2. CJK 表格对齐:中文表格应正确对齐,不出现字符重叠或错位

可能的解决方案

问题 1:

  • 在 Agent 系统提示中注入格式要求(始终使用 \n\n 分隔段落)
  • 或在 Gateway 层做后处理,将单 \n 转换为 \n\n

问题 2:


参考资料

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions