I’m working on a Telegram bot using C# and the Telegram.Bot library with the TelegramBotClient class. I can successfully send formatted messages using the SendTextMessageAsync method with HTML parsing enabled.
This works fine, but I need to add line breaks and create lists in my messages. I’ve seen Telegram’s official notifications use these formatting options. When I try using <br>, <br/>, or </br> tags, I get an error saying “Bad Request: can’t parse entities: Unexpected end tag”.
Is there a way to create new lines and lists using HTML formatting in Telegram messages? Also, can I create clickable phone number links?
Telegram’s Bot API only supports a handful of HTML tags, which is much less than standard HTML. To create line breaks, avoid using HTML altogether and instead insert \n in your strings; the API handles newlines correctly when processing HTML.
Unfortunately, there are no list tags like <ul> or <li>, so if you want to create lists, you will have to simulate them using newlines along with bullet points or numbers. You can create clickable phone number links using the format <a href="tel:+1234567890">call me</a>, although whether they are clickable will depend on the client being used.
Keep in mind that <pre> tags can include a language parameter (e.g., <pre language="python">) for syntax highlighting. You can also nest tags, such as using <b><i>bold italic</i></b>, but remember that Telegram’s parser is more sensitive than web browsers, so an incorrectly formatted tag will disrupt your entire message.
Telegram’s HTML support is pretty limited compared to regular web HTML. For line breaks, just use \n in your strings - Telegram doesn’t recognize <br> tags. There’s no native list support either, so you’ll have to format them manually with Unicode characters or ASCII symbols. Something like “• Item 1\n• Item 2\n• Item 3” works great for bullet points. I found out through testing that <tg-spoiler> tags actually work for hiding text, which is handy for sensitive info. <u> and <s> also work for underlined and strikethrough text, though you won’t find these in all the docs. Phone number links with tel: do work, but different clients handle them differently. I’ve seen mixed results between mobile and desktop Telegram users.
Just use \n for line breaks - Telegram completely ignores HTML br tags. For lists I do 1. first item\n2. second item or bullets like ▪️ item one\n▪️ item two. The <u> tag works for underline too, dunno why people always forget that. Phone links work with <a href="tel:+123">number</a> but it depends on the user’s device.