I’m currently working on with telegram Bot API, but I have to validate the markdown syntax to prevent parse errors. But telegram bot api’s markdown doesn’t follow the regular markdown syntax so I’m kind of struggling how to do it. Is there a proper way to validate it? Or is there such kind of library that I can use?
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
2
Answers
Probably not the answer OP was expecting, but still sharing so others may find this useful.
I’ve been trying to ‘validate’ the MarkDown messages to prevent the
Bad Request: can't parse entities:
error received by Telegram. For example, the same issue this user encounteredUnfortunately I was unable to parse this with 100% accuracy, probably because (as you already mentioned) Telegram doesn’t use the default Markdown syntax.
My ‘solution’ as I’ve implemented in quite some bots, and is working decent.
After sending a message (I’ve created a custom function to prevent duplicate code), check if Telegram responded with the
Bad Request: can't parse entities
error, If so, send the same message again, but this time withHTML
parse_mode
, this way there won’t be any parse errors.Not the most clean solution, but it gets the message to the user, and that was my greatest concern.
I have implemented this validation function (Golang). Works pretty good for telegram’s markdown: