I
I
InternetMaster2021-11-14 21:31:07
Python
InternetMaster, 2021-11-14 21:31:07

Why does Telegram Bot format text incompletely?

I have a text (~2500 characters) which is dynamically calculated each time. It has HTML tags for bold text (<b>). Somewhere after about 1700-hundred characters, Telegram no longer displays the boldness of the text, but simply removes the < b > tag. At the same time, how many characters, at least 4000, at least 1800 Telegram anyway. Why is it so?
Library - PyTelegramBotAPI

bot.send_message(message.chat.id, text, parse_mode='HTML')

I also thought that the problem is in the content that does not work, but I sent it separately, and everything is fine.
I can attach text.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-11-15
@shabelski89

Sending large text messages
Sometimes you must send messages that exceed 5000 characters. The Telegram API can not handle that many characters in one request, so we need to split the message in multiples. Here is how to do that using the API:

from telebot import util
large_text = open("large_text.txt", "rb").read()

# Split the text each 3000 characters.
# split_string returns a list with the splitted text.
splitted_text = util.split_string(large_text, 3000)

for text in splitted_text:
  tb.send_message(chat_id, text)

I
InternetMaster, 2022-01-03
@InternetMaster

The question is closed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question