Skip to content

Rich messages

Build HTML with pytdbot.utils helpers (they return strings; join with +), then send.

from pytdbot import utils

html = (
    utils.heading(1, "Title")
    + utils.paragraph("Hello ", utils.bold(name))
    + utils.unordered_list("one", "two")
    + utils.tg_button_row(
        utils.tg_button("OK", type="callback_data", data="ok", style="success"),
        utils.tg_button("Site", type="url", url="https://example.com"),
    )
)
await message.reply_rich_message(html=html)

Send with reply_rich_message or sendRichMessage (chat_id, html=). Pass markdown= instead of html= (not both). Edit later with edit_rich_message or editRichMessage. Convert a received RichMessage with rich_message_to_html (returns (html, media)).

Usual HTML helpers work inside rich HTML too: bold, italic, underline, strikethrough, spoiler, code, pre / pre_code, hyperlink, mention, custom_emoji, quote.

Buttons

On a rich message, use tg_button / tg_button_row. Do not attach reply_markup= ReplyMarkupInlineKeyboard unless you explicitly want a normal inline keyboard.

  • Inline (in the text): put tg_button(...) inside paragraph.
  • Row (full-width bar): tg_button_row(*buttons, align=None). align is "left", "center", or "right"; omit it for full-width buttons.

tg_button(*label, type, …):

type Extra args
url url=
callback_data data= (str or bytes; callback_data if you want a Python object)
web_app url=
login_url url=, optional forward_text=, request_write_access=
switch_inline_query / switch_inline_query_current_chat query=
copy_text text=
disabled none

style= (optional): "primary", "danger", "success", "link" ("link" only on callback buttons).

Callback presses still go through on_updateNewCallbackQuery + load_callback_data / update.answer.