import { TelegramInputRichMessage } from '@gramio/types'; import { S as Stringable, F as FormattableString } from '../formattable-string-BKevNsLk.js'; /** * @module * * Rich Messages authoring for the Telegram Bot API ([rich messages](https://core.telegram.org/bots/api#rich-message-formatting-options)). * * Native to `@gramio/format`: the {@link rich} tag mirrors `format`, inline runs are reused * `format` {@link https://gramio.dev/formatting/ | helpers} (their entities render 1:1 to the * rich-markdown dialect), and only **block** helpers are new. The result is a {@link RichString} * — pass it to `ctx.send` / `ctx.reply` / `editText` and the context method routes it to * `sendRichMessage`. * * Unlike a normal message (`text` + `entities`), a rich message is sent as a server-parsed * **Markdown string** (`InputRichMessage.markdown`); the structured `RichBlock`/`RichText` tree is * the *received* shape (`Message.richMessage`). */ /** Brand key — lets consumers (e.g. `@gramio/contexts`) detect a {@link RichString} without importing this package. */ declare const RICH_STRING: unique symbol; interface RichOptions { /** Render the message right-to-left. */ isRtl?: boolean; /** Skip automatic detection of URLs, mentions, hashtags, phone numbers, etc. */ skipEntityDetection?: boolean; } /** * A composed rich message, ready to send. Carries the rendered rich-markdown string. * * Distinct from `FormattableString` — its send target is `rich_message`, not `text` + `entities`. * Pass it straight to `ctx.send(...)` / `ctx.reply(...)` / `ctx.editText(...)`. */ declare class RichString { /** The rendered rich-markdown string (the `InputRichMessage.markdown` field). */ markdown: string; /** Extra send options. */ options: RichOptions; constructor(markdown: string, options?: RichOptions); /** Brand so `value instanceof RichString` and external duck-typing both work across module instances. */ get [RICH_STRING](): true; /** Map onto the `rich_message` send param. */ toInputRichMessage(): TelegramInputRichMessage; toString(): string; toJSON(): string; static [Symbol.hasInstance](value: unknown): value is RichString; } /** Inline content accepted by block helpers — a string, a `format` `FormattableString`, or a rich inline node. */ type RichInline = Stringable | FormattableString | RichString | null | undefined | false; /** Anything interpolable in a `rich\`\`` template. */ type RichValue = RichInline | RichString | RichValue[]; /** * Compose a rich message. Mirrors `format`: literal template text and interpolated strings are * **escaped** (shown verbatim — `#`/`*` are literal); structure comes from the block helpers * ({@link heading}, {@link list}, {@link table}, …) and inline runs from reused `format` helpers. * * @example * ```ts * import { rich, heading, list, codeBlock } from "@gramio/format/rich"; * import { bold, format } from "@gramio/format"; * * ctx.send(rich` * ${heading(1, "Q1 Report")} * * ${format`Status: ${bold("shipped")}`} * * ${list([format`Revenue: ${bold("$1.2M")}`, "42k users"])} * * ${codeBlock("bun run build", "sh")} * `); * ``` * * Also callable with a block array — `rich([heading(1, t), list(items)])` — or with options: * `rich({ skipEntityDetection: true })\`…\``. */ declare function rich(strings: TemplateStringsArray, ...values: RichValue[]): RichString; declare function rich(blocks: RichValue[]): RichString; declare function rich(options: RichOptions): (strings: TemplateStringsArray, ...values: RichValue[]) => RichString; /** A heading, `# ` … `###### ` (levels 1–6). */ declare function heading(level: 1 | 2 | 3 | 4 | 5 | 6, content: RichInline): RichString; /** A paragraph (a standalone inline run). */ declare function paragraph(content: RichInline): RichString; /** An unordered list (`- item`). Items are inline runs. */ declare function list(items: RichInline[]): RichString; /** An ordered list (`1. item`). */ declare function orderedList(items: RichInline[]): RichString; interface QuoteOptions { /** Render a collapsed-by-default quotation that the user can expand. */ expandable?: boolean; /** Optional credit rendered as a `` element. */ credit?: RichInline; } /** A block quotation. Supports Bot API 10.3 expandable quotes and credits. */ declare function quote(content: RichInline, options?: QuoteOptions): RichString; /** A fenced code block (verbatim — not escaped). */ declare function codeBlock(code: string, language?: string): RichString; /** A thematic break (`---`). */ declare function divider(): RichString; /** A task / checklist list (`- [x]` / `- [ ]`). */ declare function taskList(items: { text: RichInline; done?: boolean; }[]): RichString; /** A block formula (`$$…$$`). Source is raw LaTeX (not escaped). */ declare function mathBlock(latex: string): RichString; /** Media to embed as a standalone block. Type is inferred by Telegram from the URL/MIME. HTTP(S) only. */ interface RichMedia { url: string; /** Optional caption shown under the media. */ caption?: string; } /** A single media block (photo / video / audio / animation — inferred from the URL). */ declare function media(item: RichMedia): RichString; interface RichDocument { url: string; caption?: RichInline; } /** A document block (``), optionally wrapped with a caption. */ declare function document(item: RichDocument): RichString; /** A collage of media blocks (``). */ declare function collage(items: RichMedia[]): RichString; /** A slideshow of media blocks (``). */ declare function slideshow(items: RichMedia[]): RichString; /** Column alignment for {@link table}. */ type TableAlign = "left" | "center" | "right"; type RichButtonStyle = "danger" | "success" | "primary" | "link"; type RichButtonAction = { type: "url"; url: string; } | { type: "callback_data"; data: string; } | { type: "web_app"; url: string; } | { type: "login_url"; url: string; forwardText?: string; requestWriteAccess?: boolean; } | { type: "switch_inline_query"; query?: string; } | { type: "switch_inline_query_current_chat"; query?: string; } | { type: "switch_inline_query_chosen_chat"; query?: string; allowUserChats?: boolean; allowBotChats?: boolean; allowGroupChats?: boolean; allowChannelChats?: boolean; } | { type: "copy_text"; text: string; } | { type: "disabled"; }; /** An inline or row-level rich-message button with exactly one action. */ declare function button(label: string, action: RichButtonAction, options?: { style?: RichButtonStyle; }): RichString; /** A row of rich-message buttons. */ declare function buttonRow(buttons: RichString[], options?: { align?: TableAlign; }): RichString; /** * A GFM table. The first row is the header. Cells may contain **inline** formatting only. * `|` inside cell text is escaped automatically. */ declare function table(rows: RichInline[][], options?: { align?: TableAlign[]; compact?: boolean; }): RichString; /** A collapsible block (`
`). `open` expands it by default. Body may contain blocks. */ declare function details(summary: RichInline, content: RichValue, options?: { open?: boolean; }): RichString; /** A footnote **definition** (`[^id]: …`). Reference it inline with {@link reference}. */ declare function footnote(id: string, definition: RichInline): RichString; /** * A "Thinking…" placeholder block (``). * * **Draft-only** — valid *only* inside a streaming draft (`ctx.streamRichMessage()` / * `sendRichMessageDraft`); it can't appear in a finalized {@link sendRichMessage | rich message} * and is never received. Use it to show the model's reasoning while output streams, then drop it * from the final message. Custom emoji from {@link https://t.me/addemoji/AIActions | AIActions} * are recommended for the text. * * @example * ```ts * await using draft = ctx.streamRichMessage(); * draft.append(rich`${thinking("Searching the docs…")}`); * // …stream tokens, then finalize without the thinking block * ``` */ declare function thinking(content: RichInline): RichString; /** ==marked== text. */ declare function marked(content: RichInline): RichString; /** Superscript text (``). */ declare function superscript(content: RichInline): RichString; /** Subscript text (``). */ declare function subscript(content: RichInline): RichString; /** An inline formula (`$…$`). Source is raw LaTeX (not escaped). */ declare function math(latex: string): RichString; /** A footnote **reference** (`[^id]`) — pair with {@link footnote}. */ declare function reference(id: string): RichString; export { RICH_STRING, RichString, button, buttonRow, codeBlock, collage, details, divider, document, footnote, heading, list, marked, math, mathBlock, media, orderedList, paragraph, quote, reference, rich, slideshow, subscript, superscript, table, taskList, thinking }; export type { QuoteOptions, RichButtonAction, RichButtonStyle, RichDocument, RichInline, RichMedia, RichOptions, RichValue, TableAlign };