Utilities¶
- bot.utils.cut_text(text, max_length)[source]¶
Cut text to max_length characters and add ellipsis if text is longer.
- Parameters:
- Return type:
- Returns:
Cut text with ellipsis if it is longer than max_length.
Example:
>>> cut_text("Hello, world!", 5) 'Hello...' >>> cut_text("Hello, world!", 12) 'Hello, world!'
- bot.utils.escape_html(text)[source]¶
Escape HTML special characters for Telegram HTML mode.
- Parameters:
text (
str
) – Raw text possibly containing&
,<
and>
.- Return type:
- Returns:
A safe string for Telegram
parse_mode=HTML
.
Example:
>>> escape_html('<b>Hi & welcome</b>') '<b>Hi & welcome</b>'