# Message formatting in Telegram

## Markdown markup

To mark up the text correctly in the desired block (the markup is located under the text input field of the message), strictly follow the following steps:

<div data-with-frame="true"><figure><img src="/files/P1KY27dCbHiVYzhyYhJ2" alt="" width="563"><figcaption></figcaption></figure></div>

1. Put the required text in the response field.

If you're using variables in the text, you <mark style="color:red;">**should not**</mark> specify them at this stage. Otherwise, the variable syntax will be broken and the #{} characters will also be escaped, and the variable will not appear in the text.

2. We turn on "Markdown in Telegram". This way, escape characters will be added to your text.
3. We select the text \*\* or \_ \_, etc.

{% hint style="danger" %}
if any of the following characters occur in this block: '\_', '\*', '\[', ']', '(', ')', '\~', '\`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'  — they need to be escaped by adding a backslash in front of them \\&#x20;

Otherwise, the message will not be sent at all. It doesn't matter which part of the text you mark up.

Example: hi\\. Glad to see \*you\* \\!
{% endhint %}

Special characters:

**Bold text** — put asterisks on both sides: \* here is the text\*\
**Italics** — underlining:  \_tex&#x74;*\_*\
**Underlined text** — two lower underscores on both sides: \_\_text\_\_\
**Strikethrough text -** is a tilde on both sides of the text: \~text\~\
Link in the text: \[text in square brackets]\(link in parentheses):\
\[inline URL] ([http://www.example.com/](https://vk.com/away.php?to=http%3A%2F%2Fwww.example.com%2F\&cc_key=)) \
**Mention of the user Telegram:** \[text in square brackets] (link to the user in parentheses). You can use #{platform\_id} after the equals sign in the link.\
\[inline mention of a user]\(tg://user?id=123456789)\
**Text in the code form** — put a reverse apostrophe on both sides of the text: `inline fixed-width code`\
**Hidden text or spoiler** - use || on both sides of the text

4. Next, mark up the desired text using special characters.

**Example:**

<div data-with-frame="true"><figure><img src="/files/rj1YjoCC5hBGtgjcB4Px" alt="" width="563"><figcaption><p>Markup example</p></figcaption></figure></div>

Result:

<div data-with-frame="true"><figure><img src="/files/kUylXv4DH9BMh4sikzOh" alt="" width="425"><figcaption></figcaption></figure></div>

When working with Markdown, it is necessary not to forget that special characters should be escaped, and control characters in the text should be replaced with appropriate text substitutions. This is done quite simply by adding a **backslash \\** before the special character or using the Calculator function.

**txt = tg\_escape(s), где** **s** - source text string&#x20;

{% hint style="info" %}
To assign a multi-line text value to a variable, specify it as follows:

`your_variable = "First line text" + "\n" + "Second line text" + "\n" +"Third line text"`
{% endhint %}

The output in the **txt** file is a line with slashes already inserted in the appropriate places.

**Example:**

<figure><img src="/files/qmVzKeOg4gPg2zhifmML" alt=""><figcaption><p>Escaping example</p></figcaption></figure>

<div data-with-frame="true"><figure><img src="/files/EG2arxLvqXdDRS8wcF9m" alt=""><figcaption><p>How Telegram text looks like</p></figcaption></figure></div>

Next, mark up the desired text.

#### An example with a long text:

<div data-with-frame="true"><figure><img src="/files/RRZN5Gdx1T0aqRCKJAoJ" alt="" width="364"><figcaption></figcaption></figure></div>

To do this, you need to use the calculator:

Step 1. Paste the text into the message field:

<div data-with-frame="true"><figure><img src="/files/FNR1N80Oy40lEatC251a" alt="" width="375"><figcaption></figcaption></figure></div>

Step 2. Enable the Markdown markup button:

<div data-with-frame="true"><figure><img src="/files/GBLmCJuHbQ2HNAkM5hm6" alt="" width="375"><figcaption><p>After enabling the markup button, special characters are escaped.</p></figcaption></figure></div>

Step 3. We arrange special characters for formatting the message in the text:

<div data-with-frame="true"><figure><img src="/files/O1brdip5fMyO9soRjaWg" alt="" width="375"><figcaption></figcaption></figure></div>

If, after sending the message, it did not reach the messenger, and you see an error in the dialog in the Clients section, it means that you escaped the characters incorrectly..&#x20;

At the same time, you will see an error when sending a message in the "Clients" section, it will contain a character that has not been escaped.

Error messages that you can see:

1. There is no closing character:

<div data-with-frame="true"><figure><img src="/files/gwCvDALk8ORfhoPxUb62" alt="" width="188"><figcaption></figcaption></figure></div>

<div data-full-width="true" data-with-frame="true"><figure><img src="/files/e9lykj443kZWh6FFzZvR" alt="" width="188"><figcaption></figcaption></figure></div>

2. Character escaping is missing:

<div data-with-frame="true"><figure><img src="/files/6Mj7tVbtSF9aq0HPUGMD" alt="" width="188"><figcaption></figcaption></figure></div>

## &#x20;HTML markup

To make the HTML markup work, don't forget to click on the HTML button under the text field for the message:

<div data-with-frame="true"><figure><img src="/files/gQvWUtnex4KuMUo0NVLQ" alt="" width="563"><figcaption></figcaption></figure></div>

1. \<a href="[https://google.com">ссылка\\](https://docs.mavibot.ai/chatbot/messengers/telegram/https:/google.com">ссылка\\)</a> -embeds a link into a single word.

Filling example:

<div data-with-frame="true"><figure><img src="/files/Sq2SCAV6tK8HMq8hChib" alt="" width="563"><figcaption></figcaption></figure></div>

2. \<u>underlined\</u> - underlined font

Example:

<div data-with-frame="true"><figure><img src="/files/hphW4b2YZ9wOzHitpTnO" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/wTI0D2G8rdRcQncFqoxQ" alt="" width="563"><figcaption></figcaption></figure></div>

3. \<ins>underlined\</ins> - underlined font

Example:

<div data-with-frame="true"><figure><img src="/files/HzUZq6RDcJSRO6g5q0h2" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/XzS6bK7veFRJ4oxtT6TQ" alt="" width="563"><figcaption></figcaption></figure></div>

4. \<em>italic\</em> - italic font

Example:

<div data-with-frame="true"><figure><img src="/files/cz6KgmMfjvFTm8I6RcTr" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/xLZw6StRzkYhYtcvdtSA" alt="" width="563"><figcaption></figcaption></figure></div>

5. \<i>italic\</i> - italic font

Example:

<div data-with-frame="true"><figure><img src="/files/CnygpRYpmdVkvIfYcoix" alt="" width="563"><figcaption></figcaption></figure></div>

\<strong>strong\</strong> - bold font

<div data-with-frame="true"><figure><img src="/files/iH2k5qBnF8vpOEp6zH9s" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/BXtkeJLs80LhciIiSdje" alt="" width="563"><figcaption></figcaption></figure></div>

\<strike>strike\</strike> - strikethrough text

<div data-with-frame="true"><figure><img src="/files/USHtEiP3Mjbqkj7Hv2A6" alt="" width="563"><figcaption></figcaption></figure></div>

\<span class="tg-spoiler">hidden\</span> - hidden text

Example:

<div data-with-frame="true"><figure><img src="/files/j675r14FuhPZiWX08eQT" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/Eu4fMjGfS62TykaQpm8P" alt="" width="563"><figcaption></figcaption></figure></div>

\<code>Prerfomatted\</code> - formatted text

Example:

<div data-with-frame="true"><figure><img src="/files/mK0PKltiI10KxzwFYN8n" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/eFXWRRB6MK0HcsBVA3tN" alt="" width="563"><figcaption></figcaption></figure></div>

\<pre>Preformatted\</pre> - formatted font

Example:

<div data-with-frame="true"><figure><img src="/files/NUdqcnmGmXRTN6Hpr1Ov" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/0YV19bZAokKxHnEJOiFv" alt="" width="526"><figcaption></figcaption></figure></div>

## How to enable protected mode for content

To protect content from being shared, you can enable protected mode for messages. To do this, go to the “Message” section and turn on “Protect content":

<div data-with-frame="true"><figure><img src="/files/wK0SeAt0spyrRxPwSrtl" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
Protected messages cannot be forwarded, and you cannot take a screenshot on your phone.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/chatbot/messengers/telegram/formatting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
