Description
Symfony version(s) affected: 5.3.6 and below
Description
When sending notification to Telegram that contains any special characters from the list _ * [ ] ( ) ~` > # + - = | { } . ! , except dot which is already escaped, throws exception:
Message: "Handling "Symfony\Component\Notifier\Message\ChatMessage" failed: Unable to post the Telegram message: Bad Request: can't parse entities: Character '-' is reserved and must be escaped with the preceding '\' (code 400)
It is for default parse_mode
or TelegramOptions::PARSE_MODE_MARKDOWN_V2
How to reproduce
Send a notification via telegram with any of the special characters listed above using default parse_mode
or TelegramOptions::PARSE_MODE_MARKDOWN_V2
Possible Solution
In the documentation of Telegram Bot API https://core.telegram.org/bots/api#markdownv2-style we can see that we need to escape those characters. I have prepared a Regex for this which we can put here https://github.com/symfony/telegram-notifier/blob/5.3/TelegramTransport.php#L85 , replace str_replace
with preg_replace
that will escape those characters with \
.
If you think this is a good solution please let me know, I will Pull a request.