Skip to content

GramIO API Reference / @gramio/contexts/dist / RichMessageDraft

Class: RichMessageDraft<Bot>

Defined in: contexts/index.d.ts:5399

A handle to a streaming rich-message draft.

Append fragments as they are generated — preview updates are sent (throttled) via sendRichMessageDraft. The draft is ephemeral (a ~30-second preview), so you MUST finalize it to persist a real message. await using finalizes automatically on scope exit.

Example

ts
await using draft = ctx.streamRichMessage();
for await (const token of llm) draft.append(token); // token = RichString | rich-markdown
// scope exit → one sendRichMessage persists the full message

Type Parameters

Type Parameter
Bot extends BotLike

Constructors

Constructor

new RichMessageDraft<Bot>(bot, chatId, options?, businessConnectionId?, threadId?): RichMessageDraft<Bot>

Defined in: contexts/index.d.ts:5401

Parameters

ParameterType
botBot
chatIdnumber
options?StreamRichMessageOptions
businessConnectionId?string
threadId?number

Returns

RichMessageDraft<Bot>

Accessors

draftId

Get Signature

get draftId(): number

Defined in: contexts/index.d.ts:5405

The draft id used for every preview update.

Returns

number


finalized

Get Signature

get finalized(): boolean

Defined in: contexts/index.d.ts:5407

Whether finalize has already run.

Returns

boolean


markdown

Get Signature

get markdown(): string

Defined in: contexts/index.d.ts:5403

Current accumulated rich-markdown.

Returns

string

Methods

[asyncDispose]()

[asyncDispose](): Promise<void>

Defined in: contexts/index.d.ts:5418

await using hook — finalizes on scope exit unless the stream was aborted.

Returns

Promise<void>


append()

append(chunk): this

Defined in: contexts/index.d.ts:5409

Append a fragment (a RichString or raw rich-markdown) and schedule a throttled preview.

Parameters

ParameterType
chunkRichChunk

Returns

this


finalize()

finalize(params?): Promise<MessageContext<Bot>>

Defined in: contexts/index.d.ts:5416

Persist the streamed draft as a real message via sendRichMessage. Idempotent — repeated calls return the same MessageContext. Pass params to override the finalizing call.

Parameters

ParameterType
params?Optional<SendRichMessageParams, "chat_id" | "rich_message">

Returns

Promise<MessageContext<Bot>>


set()

set(content): this

Defined in: contexts/index.d.ts:5411

Replace the entire draft content and schedule a preview.

Parameters

ParameterType
contentRichChunk

Returns

this