Skip to main content

Parse mode

Parse mode is the Bot API field that tells Telegram how to read the formatting marks in a message. The accepted values are MarkdownV2, HTML and the legacy Markdown. Autogram sends posts with MarkdownV2, so the text it generates is escaped for that mode before it is sent.

The three modes

The Bot API accepts three values in the parse_mode field: MarkdownV2, HTML and Markdown. The Telegram documentation calls Markdown a legacy mode that is kept for backward compatibility, so new bots choose MarkdownV2 or HTML. If a bot sends no parse_mode, Telegram shows the text as plain text and does not read any marks in it.

Each mode has its own escaping rules

In MarkdownV2, a fixed list of characters must be escaped with a backslash when they appear as ordinary text, for example the period, the hyphen, the exclamation mark and the parentheses. In HTML mode, only the characters <, > and & must be replaced with the entities &lt;, &gt; and &amp;. Only a small set of tags is supported, such as b, i, u, s, a, code, pre and blockquote. A message with an escaping mistake is rejected by the API, so the sender must match the text to the mode it declares.

Entities as an alternative

A sender can skip parse_mode and pass a list of message entities instead. Each entity gives a type, an offset and a length, measured in UTF-16 code units, so the text itself needs no escaping. Telegram also limits a text message to 4096 characters after entities parsing, which means the visible length counts and the formatting marks do not. A long generated post must be measured after the marks are removed.

Put these concepts to work

Automate your Telegram publishing with AI content, quality scoring, and smart scheduling.