Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HTML in Telegram bot

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);
}
like image 940
mojtaba.zamani Avatar asked Apr 07 '18 09:04

mojtaba.zamani


1 Answers

If you need to format using html you need to set "parse_mode" as "html";

https://api.telegram.org/bot1328912345:BBCCDDExVAKD2GOEA1mXWfXfhQ_z8Y6rRh8/sendmessage?chat_id=12345678&amp;text=Sample message&amp;parse_mode=html)

As of now only following tags are supported by Bot:

<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<u>underline</u>, <ins>underline</ins>
<s>strikethrough</s>, <strike>strikethrough</strike>, <del>strikethrough</del>
<b>bold <i>italic bold <s>italic bold strikethrough</s> <u>underline italic bold</u></i> bold</b>
<a href="http://www.example.com/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>
<pre><code class="language-python">pre-formatted fixed-width code block written in the Python programming language</code></pre>

Source: https://core.telegram.org/bots/api#formatting-options

like image 153
Suresh Kamrushi Avatar answered Oct 22 '22 13:10

Suresh Kamrushi