Rich¶
Rich-message construction: a builder, inline helpers, a Markdown converter, and blocks.
Rich messages are this library's headline feature. Build one with RichMessage plus the inline helpers, convert existing Markdown with markdown_to_rich, or describe it as a list of InputRichBlock* structured blocks (Bot API 10.2); every form feeds Bot.send_rich_message.
InputRichBlockAnchor
dataclass
¶
A named anchor that other content can link to.
InputRichBlockAnimation
dataclass
¶
A block holding an animation. The media's own caption is ignored.
InputRichBlockAudio
dataclass
¶
A block holding a music file. The media's own caption is ignored.
InputRichBlockBlockQuotation
dataclass
¶
A block quotation wrapping nested blocks.
InputRichBlockCollage
dataclass
¶
A collage of nested blocks.
InputRichBlockDetails
dataclass
¶
An expandable details block with an always-visible summary.
InputRichBlockDivider
dataclass
¶
A horizontal divider.
InputRichBlockFooter
dataclass
¶
A footer line.
InputRichBlockList
dataclass
¶
An ordered or unordered list of items.
InputRichBlockListItem
dataclass
¶
An item in a list block.
type sets the ordered-list label style and must be "1", "a", "A", "i", or "I"; Telegram rejects the whole message on any other value.
InputRichBlockMap
dataclass
¶
A map centered on a location. location is a {latitude, longitude} mapping.
The width and height must not exceed 10000 in total, with a ratio of at most 20.
InputRichBlockMathematicalExpression
dataclass
¶
A block mathematical expression in LaTeX format.
InputRichBlockParagraph
dataclass
¶
A text paragraph.
InputRichBlockPhoto
dataclass
¶
A block holding a photo. The media's own caption is ignored.
InputRichBlockPreformatted
dataclass
¶
A preformatted code block, optionally tagged with a language.
InputRichBlockPullQuotation
dataclass
¶
A pull quotation with centered text.
InputRichBlockSectionHeading
dataclass
¶
A section heading. size runs 1 (largest) to 6 (smallest).
InputRichBlockSlideshow
dataclass
¶
A slideshow of nested blocks.
InputRichBlockTable
dataclass
¶
A table. cells is a list of rows, each a list of RichBlockTableCell.
InputRichBlockThinking
dataclass
¶
A "Thinking…" placeholder. Valid only in send_rich_message_draft.
InputRichBlockVideo
dataclass
¶
A block holding a video. The media's own caption is ignored.
InputRichBlockVoiceNote
dataclass
¶
A block holding a voice note. The media's own caption is ignored.
InputRichMessageMedia
dataclass
¶
A media element referenced from a rich message's html or markdown text.
id is the identifier used in the tg://photo?id=, tg://video?id=, or tg://audio?id= link inside the text; media carries the file itself.
RichBlockCaption
dataclass
¶
Caption of a rich block, with an optional cite-style credit.
RichBlockTableCell
dataclass
¶
One cell of a table block. An empty cell (no text) renders invisible.
Inline ¶
A run of inline rich text whose .html is already escaped and tag-wrapped.
RichMessage ¶
A builder for a rich message.
Each method appends a block and returns self, so calls chain. Inline content arguments accept plain strings (escaped automatically) or Inline runs from the helpers in this module. Call to_html() for the payload, or pass the builder straight to Bot.send_rich_message.
heading ¶
Add a heading; level 1 renders as h1, anything else as h2.
code_block ¶
Add a fenced code block, optionally tagged with a language.
table ¶
Add a bordered, striped table from a header row and data rows.
Rows shorter than the header are padded with empty cells; extra cells beyond the header width are dropped.
collapsible ¶
collapsible(summary: InlineContent, body: 'RichMessage', *, expanded: bool = False) -> 'RichMessage'
Add a collapsible section (details/summary) wrapping a nested message.
raw ¶
Append a pre-built HTML fragment verbatim (escape hatch; not escaped).
link ¶
A hyperlink whose visible text is content and whose target is url.
text ¶
Combine parts into one inline run (plain strings are escaped).
markdown_to_rich ¶
Convert a Markdown string to rich-message HTML.