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

如何通过HTTP POST请求设置Telegram消息为等宽字体?

如何通过Telegram API原生HTTP请求发送等宽字体消息

要实现等宽字体,你需要利用Telegram API支持的格式化解析模式,通过指定parse_mode参数并使用对应语法包裹文本即可,以下是两种可行的方案:

方案1:使用MarkdownV2格式

Telegram的MarkdownV2语法中,用单个反引号`包裹的文本会被渲染为等宽字体。你需要在请求中添加parse_mode=MarkdownV2参数。

示例HTTP请求(URL参数方式)

POST /bot123:token123/sendMessage?chat_id=123&text=`hello`&parse_mode=MarkdownV2

注意:如果文本包含MarkdownV2特殊字符(如_、*、[等),需要用反斜杠\转义,比如要发送hello_world,需将文本写为`hello\_world`。

示例HTTP请求(JSON请求体方式)

POST /bot123:token123/sendMessage
Content-Type: application/json

{
  "chat_id": 123,
  "text": "`hello`",
  "parse_mode": "MarkdownV2"
}

方案2:使用HTML格式

HTML模式下,用<code>标签包裹的文本会被渲染为等宽字体,请求中需指定parse_mode=HTML。

示例HTTP请求(URL参数方式)

POST /bot123:token123/sendMessage?chat_id=123&text=<code>hello</code>&parse_mode=HTML

注意:如果文本包含HTML特殊字符(如<、>、&),需要转换为HTML实体(比如&转成&amp;)。

示例HTTP请求(JSON请求体方式)

POST /bot123:token123/sendMessage
Content-Type: application/json

{
  "chat_id": 123,
  "text": "<code>hello</code>",
  "parse_mode": "HTML"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 11:03:15