You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram发送附件时如何实现标题文本换行?

Telegram sendDocument 标题换行解决方案

问题出在sendDocument的caption参数默认是纯文本模式,不会解析%0A这类URL编码的换行符,也不会识别裸换行。要实现换行,必须指定解析模式并使用对应格式的换行语法:

方法1:使用HTML解析模式

用<br>标签作为换行符,同时设置parse_mode=HTML:

curl -F "chat_id=你的目标聊天ID" \
     -F "document=@./scorelist.txt" \
     -F "caption=成绩列表<br>2024年秋季学期" \
     -F "parse_mode=HTML" \
     https://api.telegram.org/bot你的BotToken/sendDocument

方法2:使用MarkdownV2解析模式

用\n作为换行符,设置parse_mode=MarkdownV2。注意在shell中要确保\n被正确解析为换行,可使用ANSI-C引号($'...')包裹caption内容:

curl -F "chat_id=你的目标聊天ID" \
     -F "document=@./scorelist.txt" \
     -F "caption=$'成绩列表\n2024年秋季学期'" \
     -F "parse_mode=MarkdownV2" \
     https://api.telegram.org/bot你的BotToken/sendDocument

关键注意点

  • sendDocument使用multipart/form-data格式传递参数(因为要上传文件),所以不能用URL编码的%0A,必须传递实际的换行符或对应解析模式的标签。
  • 若使用MarkdownV2,部分特殊字符需要转义,但换行符\n直接使用即可。

内容的提问来源于stack exchange,提问作者user18767111

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 17:17:23