Telegram notification error when log entry is > 4096 chars
See original GitHub issueDescribe the bug
When using the telegram notifier, if the log message is too long for a Telegram text message (> 4096 characters) a NotificationError
with the message Notification errors: Bad Request: message is too long
is raised.
To Reproduce
import logging
from notifiers.logging import NotificationHandler
message = "-" * 4097
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s")
defaults = {"token": bot_token, "chat_id": chat_id}
notification_handler = NotificationHandler("telegram", defaults=defaults)
notification_handler.setLevel(logging.ERROR)
logging.getLogger().addHandler(notification_handler)
logging.error(message)
Expected behavior Maybe the notification handler should split the log entry into parts each <= 4096 characters long. Then it can send the parts.
Additional context Python version: 3.8.10 OS: Windows 7 64-Bit
I don’t use the Telegram notifier (get_notifier("telegram")
), but I also tried sending the same long message and instead of an exception being raised, the call ended successfully and no actual message was sent to the chat ID. But maybe another issue should be opened for that.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Telegram notifications are not sent when longer than 4096 chars
A simple fix would be to split the message once it reaches 4096 characters (preferably when there is a newline before the 4096...
Read more >Telegram Notifications Not Working? [2022 Pro Fixes] - AirDroid
If you have issues with Telegram notifications not working as they ... Step 3: Tap on Log Out in the right-side menu of...
Read more >BadHTTPResponse(response.status, text, response) telegram ...
@CBroe I test the question code with sending 4096 a character as text.It works fine so i Think the problem is with persian...
Read more >pm2-telegram - NPM Package Overview - Socket.dev
combine short messages to one message (the resultant big message shorter than 4096 characters) to avoid impact of Telegram messages frequency ...
Read more >telegram-send - PyPI
There is a maximum message length of 4096 characters, larger messages will be automatically split up into smaller ones and sent separately. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@allerter I given this some thought and research and I don’t think this issue should be handled by notifiers. I just supply a logger which redirects the logs to a provider, the responsibility for how to handle/cut the content should belong to the client. That being said, I limited the msg size for telegram to 4096 in #404, so now you would get a validation error and the message will not be sent
any updates?
i suggest to add some config to notifer, maybe split_long=True, and send_as_file=True?
i can put some PR for this