Skip to main content

MarkdownV2

MarkdownV2 is Telegram's rich-text formatting syntax for messages, supporting bold, italic, links, inline code, and more. Posts published through the Bot API can use it to render styled text in a channel. Autogram produces correctly-escaped MarkdownV2 so generated posts keep their formatting without breaking on special characters.

Why the V2 exists

Telegram’s original Markdown mode was ambiguous about where formatting started and stopped, so Telegram kept it only for backward compatibility. MarkdownV2 resolved that ambiguity by requiring a much stricter escaping discipline. The cost of the added precision is that it is far less forgiving of text that was not written with it in mind.

The escaping trap

MarkdownV2 reserves a long list of characters — among them the underscore, hyphen, period, parenthesis and exclamation mark — and any of them appearing literally must be escaped with a backslash. A post ending in an ordinary sentence with a period will be rejected outright if that period is unescaped, which is why hand-written MarkdownV2 fails so often.

Why generated text makes it worse

AI-drafted copy is full of exactly the characters MarkdownV2 reserves: hyphens, parentheses, decimal points, underscores in URLs. Escaping has to happen after the text is written and before it is sent, applied to the literal characters but not to the markup you actually intended — which is precisely the step Autogram handles so a generated post keeps its formatting instead of failing to send.

Which characters need a backslash, and where does the rule change?

Outside code and links, 18 characters must carry a backslash: _ * [ ] ( ) ~ ` > # + - = | { } . ! and the backslash itself is doubled. Inside pre and code entities only the backtick and the backslash need one. Inside the URL part of an inline link, only the closing parenthesis and the backslash need one. Telegram also accepts a backslash before any character with code 1 to 126 and then reads that character as plain text. For example, the text Price: 9.99 (sale)! must be sent as Price: 9\.99 \(sale\)\!. The length limits, 4096 for text and 1024 for a caption, count characters after parsing, so the backslashes do not use up the budget. A common mistake is to escape only the obvious marks. Telegram answers with a parse error when one reserved character stays bare, and then it sends nothing.

How Autogram escapes your text

In the Autogram editor you format text with bold, italic, underline, strikethrough, code and links, and you do not type any backslashes. Before sending, Autogram converts that formatting to MarkdownV2 and escapes every reserved character in the plain text. If you paste text that already has MarkdownV2 marks, Autogram keeps these marks: bold, italic, underline, strikethrough, code, spoilers, links and block quotes. It escapes the punctuation inside them. Autogram also checks length before it sends. The editor refuses text over 4096 characters, or over 1024 when the post has images. When an automation writes a post that is too long, Autogram asks the AI to shorten it, and if that fails it holds the post as a draft and notifies you instead of sending it.

A worked example: building a styled post

Say you want a short announcement with a bold title, a link and a closing line. Start with the plain words: New guide is live. Add a sentence: Setup takes five minutes - no extra tools needed. Wrap the title in single asterisks to make it bold. Write the link as a label in square brackets followed by the address in parentheses. Now go through the plain text. Each period, hyphen and exclamation mark outside the markup needs a backslash, so the sentence becomes Setup takes five minutes \- no extra tools needed\. The asterisks, brackets and parentheses that make the markup stay bare. The address inside the parentheses follows the URL rule instead: only a closing parenthesis and a backslash need escaping there, so its periods stay as they are. Read the result once more before sending.

Common mistakes that break a post

Three errors cause most failures. The first is a mark that is opened and never closed, such as a single underscore in a word like snake_case. Telegram cannot tell it from the start of italics, so it must be escaped. The second is escaping the markup itself, which turns your bold title into text with visible asterisks. The third is escaping twice, which leaves stray backslashes in the published post. If a post fails, read the error text. It names the problem character and, for some errors such as an unclosed mark, a byte offset. Look at that character in your text. If a post publishes with backslashes showing, the text was escaped more than once.

How to test a post before publishing

Do not trust a long post you have never sent. Send a short version first and check it on your phone. Look at the title, the links and the last line, because punctuation at the end is easiest to miss. Tap each link to confirm it opens the right page. Then add the remaining text in parts, so a failure points to a small area. In Autogram you can skip most of this, since you format in the editor and the escaping is done for you. If an automated post is held as a draft, open it and check its length first.

Put these concepts to work

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