monolog icon indicating copy to clipboard operation
monolog copied to clipboard

TelegramBotHandler: API returns error when truncating/splitting in HTML parse mode

Open MacDada opened this issue 3 months ago • 2 comments

Monolog 3.9

I set $parseMode to 'HTML' and keep the default $splitLongMessages as false.

When the message is looooong, it gets truncated. If the truncation happens inside HTML tag, the Telegram API returns error 400:

Bad Request: can't parse entities: Can't find end tag corresponding to start tag "code"

In my example the loooong string has <code>blah blah</code>. Lets say it gets truncated at first blah, then the </code> is gone and API complains.

  • Possible solution 1: would need to fix (actually parse?) HTML if truncating?
  • Possible solution 2: strip HTML tags when truncating? (kinda ugly)
  • Low hanging fruit: at least want about that in the (php) docs?

EDIT: actually, with $splitLongMessages=true same kind of problem – the message splits inside HTML causing Telegram API error(s).

MacDada avatar Sep 19 '25 10:09 MacDada

@MacDada I can work on this issue. Can I get it assigned as part of Hacktober fest 2025?

akilesh1706 avatar Oct 05 '25 10:10 akilesh1706

Yeah, well… why not… we can compare results as I've actually got splitting (almost) done :D

MacDada avatar Oct 05 '25 10:10 MacDada