Search code examples
telegramtelegram-botpython-telegram-bot

"telegram.error.BadRequest: Entities_too_long" error when trying to send long markdown message. What is the max string length limit?


This is the error i get when i try to send a long markdown message which has a ton of formatted hyperlinks in it:

context.bot.send_message(chat_id=update.effective_chat.id, text=longmsg, parse_mode="MARKDOWN")

#Output:
telegram.error.BadRequest: Entities_too_long

The actual message is hardly 500 characters long, but almost every word is hyperlinked which is making the string longmsg very long (>12k string length)

Now, I know that for normal messages 4096 characters is the limit, but when sending markdown messages, the Telegram API seems to be allowing > 4096 string length. So what is the exact string length limit for markdown messages? I'm using the python-telegram-bot library.


Solution

  • This limit seems to be undocumented. I only know that TG only parses 100 entities per message and just drops any further entities (which is also undocumented). You can try to contact TG about it via one of the following channels:

    Just to clarify: This is not an issue of the library you're using (here python-telegram-bot) - you'd get the same error when making the request manually