Telegram messages with html format

Ferchoes5 years ago

Hi Guys,
is it possible to send an alarm message (SOS) using html format with telegram notificator?. I know that telegram support only a few html tags and i know that velocity templates supports also html tags. I have tried to write in short/alarm.vm file the following < b >bold< / b > (the spaces are set only for the explanation, the tag in vm file has not spaces), but i get the whole text, and not the bold word in bold (like bold). Any information about it or tips would be great. Thanks in advance

Tony Shelver5 years ago

Disclaimer: I have no idea how Traccar configures the Telegram message.

Having said that, I have written my own app using a Telegram bot for messaging, status queries and reporting, and picked up a fair bit of experience.
For HTML (or markdown) tags to work, you will need to set the parsemode. This is 'parse_mode=Markdown or 'parse_mode=HTML I don't know if Traccar implements the pars_mode or not.

Secondly, don't believe what you will find about Telegram formatting on Google searches. The only ones I have found that are reliable in using Markdown are boldtext to bold the text, and italictext. To get a new line, use \n. Like in "\nAt the start of the line"
the red or spaced markdown format differed between web, linux client and Android client. In some places it spaced the text, in others it changed the colour a bit.

In my own testing, I had issues with HTML tags so switched to markdown.

Tony Shelver5 years ago

Apologies, it seems that Markdown here does not work like that in Telegram :) To bold text, you will need a single * on either side of the text, not a double ** like in some messages I saw.
For italics / emphasis, you will need _ (underscore) on either side of the text.
the ' (tick) symbol will give you differing results depending on the client platform. You can see here (above example) it makes the text red. In Telegram it will either spread the text spacing evenly, or else change the color to a more grey font.

For those that use Markdown quite extensively, this is a very limited approach, and also is converted / formatted in a very different manner than that used on some other Markdown implementations.

Ferchoes5 years ago

Thanks for your tips, i analyzed the code in traccar and the parse_mode is set to html. I have already tried all your tips but not working. I give not yet up, and i am still trying.

Tony Shelver5 years ago

My tips are strictly for Markdown. Try Googling telegram parse_mode formatting.

Here is the official documentation

It has to be exactly correct, otherwise things seem to not display or else bomb out.

The markdown formatting is a bit confusing as it is interpreted differently in other Markdown applications, such as github, Jekyll (kramdown) and even here.