[GH-ISSUE #1542] TelegramBotHandler throws when Telegram API returns "message is too long" error #660

Closed
opened 2026-03-04 02:16:46 +03:00 by kerem · 2 comments
Owner

Originally created by @sergiks on GitHub (Mar 17, 2021).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1542

Monolog version 2.0.0

Telegram Bot API sendMessage() method has a message length limit of "4096 characters after entities parsing"

Added logging to my Telegram bot. Since stack trace might get long, Telegram API returns an error which is thrown unhandled by TelegramBotHandler:

Fatal error: Uncaught RuntimeException: Telegram API error.
Description: Bad Request: message is too long 
in /var/www/prod/lumen/vendor/monolog/monolog/src/Monolog/Handler/TelegramBotHandler.php:96

Solution options:

  • trim message length to 4096
  • split long message into multiple messages
  • attach long messages as a text file attachment to a message
  • strip stack trace from message
Originally created by @sergiks on GitHub (Mar 17, 2021). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1542 Monolog version 2.0.0 Telegram Bot API [sendMessage()][1] method has a message length limit of "4096 characters after entities parsing" Added logging to my Telegram bot. Since stack trace might get long, Telegram API returns an error which is thrown unhandled by TelegramBotHandler: Fatal error: Uncaught RuntimeException: Telegram API error. Description: Bad Request: message is too long in /var/www/prod/lumen/vendor/monolog/monolog/src/Monolog/Handler/TelegramBotHandler.php:96 Solution options: * trim message length to 4096 * split long message into multiple messages * attach long messages as a text file attachment to a message * strip stack trace from message [1]: https://core.telegram.org/bots/api#sendmessage
kerem 2026-03-04 02:16:46 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@alexandrmazur96 commented on GitHub (Mar 30, 2021):

Hi!

I have introduced PR some time ago. Before (and if!) it will be merged you can alternatively handle this by yourself:

Create a new TelegramBotHandler class in your project and extend it from Monolog\TelegramBotHandler, then override proper methods in your class (you can use code from my PR).

<!-- gh-comment-id:810104153 --> @alexandrmazur96 commented on GitHub (Mar 30, 2021): Hi! I have introduced PR some time ago. Before (**and if!**) it will be merged you can alternatively handle this by yourself: Create a new `TelegramBotHandler` class in your project and extend it from `Monolog\TelegramBotHandler`, then override proper methods in your class (you can use code from my PR).
Author
Owner

@Seldaek commented on GitHub (Mar 13, 2022):

Fixed by #1616

<!-- gh-comment-id:1066179476 --> @Seldaek commented on GitHub (Mar 13, 2022): Fixed by #1616
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#660
No description provided.