TextPiece

sealed interface TextPiece

One node of a MessageText.

The set is Telegram's, minus what a library cannot offer everyone: custom emoji are gated behind a username bought on Fragment or the bot owner's Premium, so a bot that used them would work for its author and fail for whoever copied the code.

Styled and Link nest, because Telegram's entities do — bold inside a blockquote is two overlapping ranges over the same text. Code and CodeBlock do not: Telegram ignores entities inside them, so allowing children here would be an API that quietly drops what it was given.

Inheritors

Types

Link copied to clipboard
data class Code(val text: String) : TextPiece

Inline monospace. Does not nest — Telegram drops entities inside code.

Link copied to clipboard
data class CodeBlock(val text: String, val language: String? = null) : TextPiece

A monospace block, optionally tagged with a language for the client's highlighter.

Link copied to clipboard
data class Link(val url: String, val text: List<TextPiece>) : TextPiece

An inline link. url is sent as an entity and never appears in the text.

Link copied to clipboard
data class Plain(val text: String) : TextPiece

Literal text, rendered as written.

Link copied to clipboard
data class Styled(val style: TextStyle, val text: List<TextPiece>) : TextPiece

text with a style applied to all of it, including anything nested inside.