Using HTML in Telegram bot

mojtaba.zamani picture mojtaba.zamani · Apr 7, 2018 · Viewed 16.5k times · Source

This is not a duplicated question. I want to use html codes in my telegram bot that is written by c#. I searched in SO but I did not find any answer. How to do that? I used TelegramBotSharp. Here is my code related to the part that I explained:

MessageTarget target = (MessageTarget)update.Chat ?? update.From;     
if(Text.StartsWith("Hello")) {
    bot.SendMessage(target, "Hello <a href='http://google.com'> dear</a>", true);
}

Answer

Morteza Jangjoo picture Morteza Jangjoo · Apr 8, 2018
Use the following syntax in your message:

*bold text*

_italic text_

[inline URL](http://www.example.com/)

[inline mention of a user](tg://user?id=123456789)

pre-formatted fixed-width code block

Note: Only the tags mentioned above are currently supported.

Tags must not be nested.

All <, > and & symbols that are not a part of a tag or an HTML entity must be replaced with the corresponding HTML entities (< with &lt;, > with &gt; and & with &amp;).

All numerical HTML entities are supported.

The API currently supports only the following named HTML entities: &lt;, &gt;, &amp; and &quot;.