Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

Is there a way to validate telegram bot api's markdown syntax?

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 from:https://stackoverflow.com/questions/66057470/is-there-a-way-to-validate-telegram-bot-apis-markdown-syntax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 encountered

Unfortunately 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 with HTML 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...