Feature: Sanitize message string when using MarkdownV2 parse mode
Example:
var message = "A message!";
await botClient.SendTextMessageAsync(chatId, message, parseMode: ParseMode.MarkdownV2);
I frequently bump into this exception:
Telegram.Bot: Bad Request: can't parse entities: Character '!' is reserved and must be escaped with the preceding '\'.
It'd be nice to automatically sanitize the message string so that the code doesn't have to do this manually.
I think this kind of stuff is out of the scope of an SDK. Different ways of sanitization must be opted-out so the developer can decide to use different strategies or libraries of its favor.
We'll consider adding something to help with this
Something like; ``` private string getEscsapedMarkdown(string input) { var response = input; var list = new List<String> { "_", "*", "[", "]", "(", ")", "~", "`", "<", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!" };
foreach (var special in list)
{
response = response.Replace(special, $"\\{special}");
}
return response;
}
?
Try this Tools.EscapeMarkdown