Gramforge

Bubble API reference

Exports of @gramforge/bubble. Back to the module

Functions

entitiesToHtml

function

Render a validated {@link BubblePayload}'s `text`/`entities` to a Telegram-look HTML string. `payload.imageUrl` (caption payloads) is not consumed here — rendering the image reference is `<TelegramBubble>`'s job.

entitiesToHtml(payload: BubblePayload): string

TelegramBubble

function

Render a `BubblePayload` as an outgoing- or incoming-direction chat bubble.

TelegramBubble(props: TelegramBubbleProps): JSX.Element

Types

BubblePayload

type

Either preview payload shape `entitiesToHtml`/`TelegramBubble` accept.

type BubblePayload = BubbleEntityPayload | BubbleCaptionPayload

DeliveryStatus

type

The outgoing-bubble send/read-receipt tick state — a discriminated union, matched exhaustively via `ts-pattern` so every state renders a distinct affordance (never "nothing happened").

type DeliveryStatus = | { readonly kind: "sending" }
  | { readonly kind: "sent" }
  | { readonly kind: "delivered" }
  | { readonly kind: "read" }
  | { readonly kind: "failed"; readonly reason: string }

TelegramBubbleProps

type

`<TelegramBubble>` props. `direction` discriminates the whole prop set: `delivery` exists only for `"outgoing"` (no dead/always-undefined prop for the `"incoming"` variant, which never shows a read receipt).

type TelegramBubbleProps = | {
      readonly direction: "outgoing";
      readonly payload: BubblePayload;
      readonly timestamp: Date;
      readonly delivery: DeliveryStatus;
    }
  | {
      readonly direction: "incoming";
      readonly payload: BubblePayload;
      readonly timestamp: Date;
    }

Interfaces

BubbleCaptionPayload

interface

A captioned image: an `imageUrl` to display plus caption text/entities.

interface BubbleCaptionPayload

kind

property
kind: "caption"

text

property
text: string

entities

property
entities: readonly MessageEntity[]

imageUrl

property
imageUrl: string

BubbleEntityPayload

interface

A plain text message: rendered text plus its formatting entities.

interface BubbleEntityPayload

kind

property
kind: "message"

text

property
text: string

entities

property
entities: readonly MessageEntity[]

Constants

BubbleCaptionPayloadSchema

const

Validates a {@link BubbleCaptionPayload} (≤1024 UTF-16 code units — the Bot API caption limit).

const BubbleCaptionPayloadSchema: z.ZodType<BubbleCaptionPayload, z.ZodTypeDef, BubbleCaptionPayload>

BubbleEntityPayloadSchema

const

Validates a {@link BubbleEntityPayload} (≤4096 UTF-16 code units — the Bot API message limit).

const BubbleEntityPayloadSchema: z.ZodType<BubbleEntityPayload, z.ZodTypeDef, BubbleEntityPayload>

BubblePayloadSchema

const

Validates either {@link BubblePayload} variant, dispatching on `kind`.

const BubblePayloadSchema: z.ZodType<BubblePayload, z.ZodTypeDef, BubblePayload>