Bubble API reference
Exports of @gramforge/bubble. Back to the module
Functions
entitiesToHtml
functionRender 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
functionRender a `BubblePayload` as an outgoing- or incoming-direction chat bubble.
TelegramBubble(props: TelegramBubbleProps): JSX.Element
Types
BubblePayload
typeEither preview payload shape `entitiesToHtml`/`TelegramBubble` accept.
type BubblePayload = BubbleEntityPayload | BubbleCaptionPayload
DeliveryStatus
typeThe 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
interfaceA captioned image: an `imageUrl` to display plus caption text/entities.
interface BubbleCaptionPayload
kind
propertykind: "caption"
text
propertytext: string
entities
propertyentities: readonly MessageEntity[]
imageUrl
propertyimageUrl: string
BubbleEntityPayload
interfaceA plain text message: rendered text plus its formatting entities.
interface BubbleEntityPayload
kind
propertykind: "message"
text
propertytext: string
entities
propertyentities: readonly MessageEntity[]
Constants
BubbleCaptionPayloadSchema
constValidates a {@link BubbleCaptionPayload} (≤1024 UTF-16 code units — the Bot API caption limit).
const BubbleCaptionPayloadSchema: z.ZodType<BubbleCaptionPayload, z.ZodTypeDef, BubbleCaptionPayload>
BubbleEntityPayloadSchema
constValidates a {@link BubbleEntityPayload} (≤4096 UTF-16 code units — the Bot API message limit).
const BubbleEntityPayloadSchema: z.ZodType<BubbleEntityPayload, z.ZodTypeDef, BubbleEntityPayload>
BubblePayloadSchema
constValidates either {@link BubblePayload} variant, dispatching on `kind`.
const BubblePayloadSchema: z.ZodType<BubblePayload, z.ZodTypeDef, BubblePayload>