Skip to content

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

Class: MessageDraft<Bot>

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

A handle to a streaming plain-text message draft — the await using companion to SendMixin.streamMessage's iterable form, mirroring RichMessageDraft.

Append pieces (strings or FormattableString-shaped { text, entities }); throttled previews go out via sendMessageDraft, and text past MESSAGE_TEXT_LIMIT | 4096 chars rolls over into a new message. finalize persists every segment via sendMessage; await using finalizes on scope exit.

Example

ts
await using draft = ctx.streamMessage();
for await (const token of llm) draft.append(token); // or draft.append(format`…`)
// scope exit → one (or more, if long) sendMessage calls persist the output

Type Parameters

Type Parameter
Bot extends BotLike

Constructors

Constructor

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

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

Parameters

ParameterType
botBot
chatIdnumber
options?StreamMessageOptions
draftIdBase?number
businessConnectionId?string
threadId?number

Returns

MessageDraft<Bot>

Accessors

finalized

Get Signature

get finalized(): boolean

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

Whether finalize has already run.

Returns

boolean


text

Get Signature

get text(): string

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

Accumulated text of the current (not-yet-finalized) segment.

Returns

string

Methods

[asyncDispose]()

[asyncDispose](): Promise<void>

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

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

Returns

Promise<void>


append()

append(piece): this

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

Append a piece (string or { text, entities }); entity offsets are relative to the piece.

Parameters

ParameterType
pieceMessageDraftAppend

Returns

this


finalize()

finalize(): Promise<MessageContext<Bot>[]>

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

Persist every segment via sendMessage, in order. Idempotent — repeated calls return the same array. Returns [] if nothing was appended.

Returns

Promise<MessageContext<Bot>[]>