Unclear error message
Closed this issue · 3 comments
First of all, thank you for building this library. Very nice. I recently encountered this error message
[error] telegramium.bots.high.FailedRequest: method=sendMessage code=400 description=Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 1499
[error] at telegramium.bots.high.FailedRequest$.apply(BotApiError.scala:7)
[error] at telegramium.bots.high.BotApi.handleResponse$$anonfun$1(BotApi.scala:83)
[error] at map @ telegramium.bots.high.BotApi.handleResponse$$anonfun$1(BotApi.scala:85)
It is unclear what the real cause is. My first guess was that the message was over the maximum character count. The message was 1710
characters, the limit is 4096
right? Up until this point it has worked flawlessly. I thought to ask because as the creator(s) of the library maybe you have encountered this message before.
I haven't encountered this error before, but I can guess that it has to do with message entities and message markup. Perhaps the message being sent contains an unclosed HTML or Markdown tag. If the message includes user input, it should be sanitized to avoid markup issues.
I was indeed using the Markdown parse mode option. I should have thought of that, will make sure to add some sanitisation code to prevent this.
Now that I am thinking, it would be nice to have that as an option inside this library since, if I am not mistaken, the Markdown flavour that Telegram uses is slightly different from the standard.
https://core.telegram.org/bots/api#formatting-options
But I understand if you might not want to maintain more code. I wonder if any of the libraries listed here might have this code already. Will do some investigation when I have time.
Thanks again! (please close this ticket)
Telegram now recommends using the improved Markdown2 mode. In general, I would use HTML for programmatic markup, it's easier to work with in code and you can use any existing library for sanitization.
I've added Markdown sanitization to the list of features for Telegramium, thanks for the idea, but it's unlikely to be implemented anytime soon tbh.