What HTML tags can be used to send a message on Telegram Bot?
Asked Answered
S

3

13

I´m developing a telegram bot in c#. Using the class TelegramBotClient in Telegram.Bot library.

I want to send a message with SendTextMessageAsync using HTML option. In the official documentation (https://core.telegram.org/bots/api#markdown-style) I can see this:

string texto = @"<b>bold</b>, <strong> bold </strong>" +
               @"<i> italic </i>, <em> italic </em>" +
               @"<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>";

 Bot.SendTextMessageAsync(chatId: id_chat,
                          text: texto,
                          parseMode: ParseMode.HTML);

It works corretly but I want to use "New Lines" and "List". I have seen them on telegram official notificacion like in this photo:

enter image description here

I have tried <br>, </br>, <br/>... etc.

But I have get the

Telegram.Bot.Exceptions.ApiRequestException: 'Bad Request: can't parse entities: Unexpected end tag at byte offset 36

Does anyone know if it´s possible to do it?

Also if possible to link a telephone number?

Sou answered 7/8, 2019 at 12:8 Comment(2)
possible duplicate: https://mcmap.net/q/539813/-using-html-in-telegram-botWiggins
I do this replace in PHP before sending the HTML message: str_replace('<br>', chr(10), $msg)Vigen
G
5

If you read the next paragraph below the html-examples in the documentation, you can see that it says that only the tags mentioned mentioned above are currently supported.

Therefore, I would suggest you use markdown, since there are no restrictions mentioned for this way of parsing. A linebreak in MD is achieved by either two spaces or <br/>. A list in MD can be created by using *, + or - in front of the list's items, for more information refer to this documentation on MD for example.

For the second part of your question, phone numbers get highlighted by the Telegram phone app automatically, but there is no such function for Desktop-clients and no built-in way in the API/libraries. Also, it only works for messages within the range of 0-200 characters, as stated here: How to make phone number a link in Telegram Bot?

Gallous answered 7/8, 2019 at 12:32 Comment(2)
Thank you Daniel for your answer. I have tried MarkDown opcion as you said. I overviewed MD documentation for create list using *, + or - but it doesn`t work. I can conclude that Telegram doesn´t allow as so many options as MD standar support. For list implementation a workarround could be to use · character (the one over the number 3 in qwerty keyboard). Thank you very muck for your time. Also for telephone detection. Now I understand it perfectly!Sou
No problem at all! If the normal list operators for MD don't work, it's probably the Telegram documentation which is a bit fuzzy there...Gallous
C
4

I am working with PHP and using parse_mode=HTML

I had the same problem but solved with.

"\n"
Clarsach answered 16/7, 2020 at 8:15 Comment(0)
R
1

The following HTML can be used for new lines:

&#10;


Reiterant answered 17/7, 2023 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.