Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 526
David Con Avatar asked Aug 07 '19 12:08

David Con


People also ask

How to send a message to a Telegram channel using bot API?

T oday, we will learn some simple steps to send a message to a telegram channel using the Bot API. We just need a Telegram account. Click here if you don’t have one. Click here or search for the username “@ botfather” in Telegram and click on it to start the chat. Then, click on the START button at the bottom of the chat.

What are telegram chatbots?

Telegram bots are opening up new opportunities for businesses to acquire, engage and retain their customers. After reading this article, you might be excited to try a telegram chatbot yourself, so to make your quest easy, here are some of the most popular telegram chatbots:

What is Telegram and how does it work?

These people can now exchange messages, media, audio, and video calls, subscribe to telegram channels, and use the Telegram bot. Telegram groups form when more than one user is added in a chat and can interact with each other, share media, and even use the Telegram bot if they want to. The person who creates the group is referred to as the owner.

Why should you use Telegram bot for travel?

You can also help get the proper vacation as per their budget and other preferences. A telegram bot can offer answers to their queries and share information like bookings, cancellation policies, and much more. Several studies have also shown that by decreasing steps for conversion, the conversion rate can increase significantly.


2 Answers

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?

like image 149
Daniel Avatar answered Sep 29 '22 19:09

Daniel


I am working with PHP and using parse_mode=HTML

I had the same problem but solved with.

"\n"
like image 32
user13940686 Avatar answered Sep 29 '22 21:09

user13940686