GramIO API Reference / @gramio/contexts/dist / CallbackQueryContext
Class: CallbackQueryContext<Bot>
Defined in: contexts/index.d.ts:6022
Called when callback_query event occurs
Extends
Context<Bot>.Constructor<CallbackQueryContext<Bot>>.CallbackQuery.SendMixin<Bot>.CloneMixin<Bot,CallbackQueryContext<Bot>,CallbackQueryContextOptions<Bot>>
Type Parameters
| Type Parameter |
|---|
Bot extends BotLike |
Constructors
Constructor
new CallbackQueryContext<
Bot>(options):CallbackQueryContext<Bot>
Defined in: contexts/index.d.ts:6025
Parameters
| Parameter | Type |
|---|---|
options | CallbackQueryContextOptions<Bot> |
Returns
CallbackQueryContext<Bot>
Overrides
Constructor
new CallbackQueryContext(...
args):CallbackQueryContext
Defined in: contexts/index.d.ts:6022
Parameters
| Parameter | Type |
|---|---|
...args | any[] |
Returns
CallbackQueryContext
Overrides
Context<Bot>.constructor
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
bot | public | Bot | - | Context.bot | contexts/index.d.ts:5240 |
payload | public | TelegramCallbackQuery | The raw data that is used for this Context | CallbackQuery.payload | contexts/index.d.ts:6024 |
update? | public | TelegramUpdate | - | Context.update | contexts/index.d.ts:5242 |
updateId? | public | number | - | Context.updateId | contexts/index.d.ts:5241 |
updateType | protected | UpdateName | - | Context.updateType | contexts/index.d.ts:5243 |
Accessors
[toStringTag]
Get Signature
get [toStringTag]():
string
Defined in: contexts/index.d.ts:5246
Returns
string
Inherited from
businessConnectionId
Get Signature
get businessConnectionId():
string
Defined in: contexts/index.d.ts:5455
Returns
string
Inherited from
SendMixin.businessConnectionId
chatId
Get Signature
get chatId():
number
Defined in: contexts/index.d.ts:6037
Chat identifier of the message with the callback button that originated the query.
Returns
number
Inherited from
chatInstance
Get Signature
get chatInstance():
string
Defined in: contexts/index.d.ts:3668
Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
Returns
string
Inherited from
data
Get Signature
get data():
string
Defined in: contexts/index.d.ts:3673
Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
Returns
string
Set Signature
set data(
data):void
Defined in: contexts/index.d.ts:3674
Parameters
| Parameter | Type |
|---|---|
data | string |
Returns
void
Inherited from
from
Get Signature
get from():
User
Defined in: contexts/index.d.ts:3652
Sender
Returns
Inherited from
gameShortName
Get Signature
get gameShortName():
string
Defined in: contexts/index.d.ts:3679
Short name of a Game to be returned, serves as the unique identifier for the game
Returns
string
Inherited from
id
Get Signature
get id():
string
Defined in: contexts/index.d.ts:3650
Unique identifier for this query
Returns
string
Inherited from
inlineMessageId
Get Signature
get inlineMessageId():
string
Defined in: contexts/index.d.ts:3663
Identifier of the message sent via the bot in inline mode, that originated the query.
Returns
string
Inherited from
message
Get Signature
get message():
MessageContext<Bot>
Defined in: contexts/index.d.ts:6033
Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
Returns
MessageContext<Bot>
Inherited from
queryPayload
Get Signature
get queryPayload():
unknown
Defined in: contexts/index.d.ts:6058
Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
Returns
unknown
senderId
Get Signature
get senderId():
number
Defined in: contexts/index.d.ts:3654
Sender ID
Returns
number
Inherited from
threadId
Get Signature
get threadId():
number
Defined in: contexts/index.d.ts:6044
Identifier of the thread the originating message belongs to, or undefined if it isn't in one. Exposed — together with CallbackQueryContext.isTopicMessage — so SendMixin auto-forwards message_thread_id on send/reply from inside a callback handler, keeping replies in the same thread as the tapped button.
Returns
number
Inherited from
Methods
answer()
answer(
params?):Promise<true>
Defined in: contexts/index.d.ts:6070
Answers to current callback query. An alias for answerCallbackQuery
Parameters
| Parameter | Type |
|---|---|
params? | string | Partial<AnswerCallbackQueryParams> |
Returns
Promise<true>
answerCallbackQuery()
answerCallbackQuery(
params?):Promise<true>
Defined in: contexts/index.d.ts:6066
Answers to current callback query
Parameters
| Parameter | Type |
|---|---|
params? | string | Partial<AnswerCallbackQueryParams> |
Returns
Promise<true>
answerWebAppQuery()
answerWebAppQuery(
params):Promise<TelegramSentWebAppMessage>
Defined in: contexts/index.d.ts:6068
Sets the result of an interaction with a Web App and sends a corresponding message
Parameters
| Parameter | Type |
|---|---|
params | AnswerWebAppQueryParams |
Returns
Promise<TelegramSentWebAppMessage>
clone()
clone(
options?):CallbackQueryContext
Defined in: contexts/index.d.ts:5935
Parameters
| Parameter | Type |
|---|---|
options? | CallbackQueryContextOptions |
Returns
CallbackQueryContext
Inherited from
editCaption()
editCaption(
caption,params?):Promise<true|TelegramMessage> |Promise<true|MessageContext<Bot>>
Defined in: contexts/index.d.ts:6074
Edits a callback query messages caption
Parameters
| Parameter | Type |
|---|---|
caption | NonNullable<string | { toString: string; }> |
params? | Partial<EditMessageCaptionParams> |
Returns
Promise<true | TelegramMessage> | Promise<true | MessageContext<Bot>>
editLiveLocation()
editLiveLocation(
params):Promise<true|TelegramMessage> |Promise<true|MessageContext<Bot>>
Defined in: contexts/index.d.ts:6078
Edits a callback query messages live location
Parameters
| Parameter | Type |
|---|---|
params | EditMessageLiveLocationParams |
Returns
Promise<true | TelegramMessage> | Promise<true | MessageContext<Bot>>
editMedia()
editMedia(
media,params?):Promise<true|TelegramMessage> |Promise<true|MessageContext<Bot>>
Defined in: contexts/index.d.ts:6076
Edits a callback query messages media
Parameters
| Parameter | Type |
|---|---|
media | TelegramInputMedia |
params? | Partial<EditMessageMediaParams> |
Returns
Promise<true | TelegramMessage> | Promise<true | MessageContext<Bot>>
editReplyMarkup()
editReplyMarkup(
replyMarkup,params?):Promise<true|TelegramMessage> |Promise<true|MessageContext<Bot>>
Defined in: contexts/index.d.ts:6082
Edits a callback query messages reply markup
Parameters
| Parameter | Type |
|---|---|
replyMarkup | TelegramInlineKeyboardMarkup | { toJSON: TelegramInlineKeyboardMarkup; } |
params? | Partial<EditMessageReplyMarkupParams> |
Returns
Promise<true | TelegramMessage> | Promise<true | MessageContext<Bot>>
editText()
editText(
text,params?):Promise<true|TelegramMessage> |Promise<true|MessageContext<Bot>>
Defined in: contexts/index.d.ts:6072
Edits a callback query messages text
Parameters
| Parameter | Type |
|---|---|
text | string | { toString: string; } | RichStringLike |
params? | Partial<EditMessageTextParams> |
Returns
Promise<true | TelegramMessage> | Promise<true | MessageContext<Bot>>
getChatBoosts()
getChatBoosts(
userId):Promise<TelegramUserChatBoosts>
Defined in: contexts/index.d.ts:5586
Returns chat boosts by the user
Parameters
| Parameter | Type |
|---|---|
userId | number |
Returns
Promise<TelegramUserChatBoosts>
Inherited from
hasData()
hasData():
this is Require<CallbackQueryContext<Bot>, "data">
Defined in: contexts/index.d.ts:6062
Checks if the query has data property
Returns
this is Require<CallbackQueryContext<Bot>, "data">
hasGameShortName()
hasGameShortName():
this is Require<CallbackQueryContext<Bot>, "gameShortName">
Defined in: contexts/index.d.ts:6064
Checks if the query has gameShortName property
Returns
this is Require<CallbackQueryContext<Bot>, "gameShortName">
hasInlineMessageId()
hasInlineMessageId():
this is Require<CallbackQueryContext<Bot>, "inlineMessageId">
Defined in: contexts/index.d.ts:6060
Checks if the query has inlineMessageId property
Returns
this is Require<CallbackQueryContext<Bot>, "inlineMessageId">
hasMessage()
hasMessage():
this is Require<CallbackQueryContext<Bot>, "message">
Defined in: contexts/index.d.ts:6027
Checks if the query has message property
Returns
this is Require<CallbackQueryContext<Bot>, "message">
hasQueryPayload()
hasQueryPayload():
this is Require<CallbackQueryContext<Bot>, "queryPayload">
Defined in: contexts/index.d.ts:6053
Checks if the query has queryPayload property
Returns
this is Require<CallbackQueryContext<Bot>, "queryPayload">
is()
is<
T>(rawTypes):this is InstanceType<ContextsMapping<Bot>[T]> & GetDerives<Bot, T> & (IsAny<Bot["__Derives"]> extends true ? {} : Bot["__Derives"] extends {} ? Bot["__Derives"]["global"] & Bot["__Derives"][T] : {})
Defined in: contexts/index.d.ts:5249
Type Parameters
| Type Parameter |
|---|
T extends UpdateName |
Parameters
| Parameter | Type |
|---|---|
rawTypes | MaybeArray<SoftString<T>> |
Returns
this is InstanceType<ContextsMapping<Bot>[T]> & GetDerives<Bot, T> & (IsAny<Bot["__Derives"]> extends true ? {} : Bot["__Derives"] extends {} ? Bot["__Derives"]["global"] & Bot["__Derives"][T] : {})
Inherited from
isTopicMessage()
isTopicMessage():
boolean
Defined in: contexts/index.d.ts:6051
Whether the originating message belongs to a forum topic or a private-chat thread. Mirrors MessageContext.isTopicMessage so the SendMixin thread-forwarding guard behaves identically in callback handlers (Bot API 10.1 sets is_topic_message for private-chat Threaded Mode too, so this covers it without dropping the guard).
Returns
boolean
send()
send(
text,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5469
Sends message to current chat.
Pass a branded @gramio/format rich value (Markdown RichString or a native structured block/message from @gramio/format/rich) and it is sent via sendRichMessage instead — bot.api.* stays 1:1; the method is chosen here.
Parameters
| Parameter | Type |
|---|---|
text | string | { toString: string; } | RichStringLike |
params? | Optional<SendMessageParams, "text" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendAnimation()
sendAnimation(
animation,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5517
Sends animation to current chat
Parameters
| Parameter | Type |
|---|---|
animation | string | Blob |
params? | Optional<SendAnimationParams, "animation" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendAudio()
sendAudio(
audio,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5513
Sends audio to current chat
Parameters
| Parameter | Type |
|---|---|
audio | string | Blob |
params? | Optional<SendAudioParams, "audio" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendChatAction()
sendChatAction(
action,params?):Promise<true>
Defined in: contexts/index.d.ts:5541
Sends chat action to current chat
Parameters
| Parameter | Type |
|---|---|
action | SendChatActionAction |
params? | Optional<SendChatActionParams, "chat_id" | "action"> |
Returns
Promise<true>
Inherited from
sendChecklist()
sendChecklist(
params):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5533
Sends checklist to current chat
Parameters
| Parameter | Type |
|---|---|
params | Optional<SendChecklistParams, "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendContact()
sendContact(
params):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5529
Sends contact to current chat
Parameters
| Parameter | Type |
|---|---|
params | Optional<SendContactParams, "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendDice()
sendDice(
emoji,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5543
Sends dice
Parameters
| Parameter | Type |
|---|---|
emoji | SendDiceEmoji |
params? | Partial<SendDiceParams> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendDocument()
sendDocument(
document,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5511
Sends document to current chat
Parameters
| Parameter | Type |
|---|---|
document | string | Blob |
params? | Optional<SendDocumentParams, "document" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendInvoice()
sendInvoice(
params):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5525
Sends invoice to current user
Parameters
| Parameter | Type |
|---|---|
params | Optional<SendInvoiceParams, "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendLivePhoto()
sendLivePhoto(
livePhoto,photo,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5509
Sends live photo to current chat
Parameters
| Parameter | Type |
|---|---|
livePhoto | string | Blob |
photo | string | Blob |
params? | Optional<SendLivePhotoParams, "photo" | "live_photo" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendLocation()
sendLocation(
latitude,longitude,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5523
Sends location to current chat
Parameters
| Parameter | Type |
|---|---|
latitude | number |
longitude | number |
params? | Optional<SendLocationParams, "chat_id" | "latitude" | "longitude"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendMedia()
sendMedia<
T>(query):ReturnType<Textends"animation"? (animation,params?) =>Promise<MessageContext<Bot>> :Textends"audio"? (audio,params?) =>Promise<MessageContext<Bot>> :Textends"document"? (document,params?) =>Promise<MessageContext<Bot>> :Textends"photo"? (photo,params?) =>Promise<MessageContext<Bot>> :Textends"sticker"? (sticker,params?) =>Promise<MessageContext<Bot>> :Textends"video_note"? (videoNote,params?) =>Promise<MessageContext<Bot>> :Textends"video"? (video,params?) =>Promise<MessageContext<...>> :Textends"voice"? (voice,params?) =>Promise<...> : () =>never>
Defined in: contexts/index.d.ts:5560
Automatically uses correct media method to send media
Type Parameters
| Type Parameter |
|---|
T extends string |
Parameters
| Parameter | Type |
|---|---|
query | object & tSendMethods |
Returns
ReturnType<T extends "animation" ? (animation, params?) => Promise<MessageContext<Bot>> : T extends "audio" ? (audio, params?) => Promise<MessageContext<Bot>> : T extends "document" ? (document, params?) => Promise<MessageContext<Bot>> : T extends "photo" ? (photo, params?) => Promise<MessageContext<Bot>> : T extends "sticker" ? (sticker, params?) => Promise<MessageContext<Bot>> : T extends "video_note" ? (videoNote, params?) => Promise<MessageContext<Bot>> : T extends "video" ? (video, params?) => Promise<MessageContext<...>> : T extends "voice" ? (voice, params?) => Promise<...> : () => never>
Example
context.sendMedia({
type: 'photo',
photo: MediaUpload.path('./image.png'),
caption: 'good image yes yes'
})Inherited from
sendMediaGroup()
sendMediaGroup(
mediaGroup,params?):Promise<MessageContext<Bot>[]>
Defined in: contexts/index.d.ts:5547
Sends media group to current chat
Parameters
| Parameter | Type |
|---|---|
mediaGroup | (TelegramInputMediaAudio | TelegramInputMediaDocument | TelegramInputMediaLivePhoto | TelegramInputMediaPhoto | TelegramInputMediaVideo)[] |
params? | Optional<SendMediaGroupParams, "media" | "chat_id"> |
Returns
Promise<MessageContext<Bot>[]>
Inherited from
sendMessageDraft()
sendMessageDraft(
params):Promise<true>
Defined in: contexts/index.d.ts:5539
Sends a message draft to the current private chat
Parameters
| Parameter | Type |
|---|---|
params | Optional<SendMessageDraftParams, "chat_id"> |
Returns
Promise<true>
Inherited from
sendPaidMedia()
sendPaidMedia(
paidMedia,starCount,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5545
Sends paid media to current chat
Parameters
| Parameter | Type |
|---|---|
paidMedia | TelegramInputPaidMedia[] |
starCount | number |
params? | Optional<SendPaidMediaParams, "media" | "chat_id" | "star_count"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendPhoto()
sendPhoto(
photo,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5507
Sends photo to current chat
Parameters
| Parameter | Type |
|---|---|
photo | string | Blob |
params? | Optional<SendPhotoParams, "photo" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendPoll()
sendPoll(
params):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5531
Sends poll to current chat
Parameters
| Parameter | Type |
|---|---|
params | Optional<SendPollParams, "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendRichMessage()
sendRichMessage(
richMessage,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5471
Sends rich message to current chat
Parameters
| Parameter | Type |
|---|---|
richMessage | TelegramInputRichMessage |
params? | Optional<SendRichMessageParams, "chat_id" | "rich_message"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendRichMessageDraft()
sendRichMessageDraft(
richMessage,draftId,params?):Promise<true>
Defined in: contexts/index.d.ts:5478
Streams a partial rich message draft to the current chat. The streamed draft is ephemeral and acts as a temporary 30-second preview — once the output is finalized, you must call sendRichMessage with the complete message to persist it.
Parameters
| Parameter | Type |
|---|---|
richMessage | TelegramInputRichMessage |
draftId | number |
params? | Optional<SendRichMessageDraftParams, "chat_id" | "rich_message" | "draft_id"> |
Returns
Promise<true>
Inherited from
SendMixin.sendRichMessageDraft
sendSticker()
sendSticker(
sticker,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5535
Sends sticker
Parameters
| Parameter | Type |
|---|---|
sticker | string | Blob |
params? | Optional<SendStickerParams, "sticker" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendVenue()
sendVenue(
params):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5527
Sends venue to current chat
Parameters
| Parameter | Type |
|---|---|
params | Optional<SendVenueParams, "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendVideo()
sendVideo(
video,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5515
Sends video to current chat
Parameters
| Parameter | Type |
|---|---|
video | string | Blob |
params? | Optional<SendVideoParams, "video" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendVideoNote()
sendVideoNote(
videoNote,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5519
Sends video note to current chat
Parameters
| Parameter | Type |
|---|---|
videoNote | string | Blob |
params? | Optional<SendVideoNoteParams, "video_note" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
sendVoice()
sendVoice(
voice,params?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5521
Sends voice to current chat
Parameters
| Parameter | Type |
|---|---|
voice | string | Blob |
params? | Optional<SendVoiceParams, "voice" | "chat_id"> |
Returns
Promise<MessageContext<Bot>>
Inherited from
stopLiveLocation()
stopLiveLocation(
params?):Promise<true|TelegramMessage> |Promise<true|MessageContext<Bot>>
Defined in: contexts/index.d.ts:6080
Stops a callback query messages live location
Parameters
| Parameter | Type |
|---|---|
params? | StopMessageLiveLocationParams |
Returns
Promise<true | TelegramMessage> | Promise<true | MessageContext<Bot>>
stopPoll()
stopPoll(
messageId,params?):Promise<Poll>
Defined in: contexts/index.d.ts:5537
Stops poll in current chat
Parameters
| Parameter | Type |
|---|---|
messageId | number |
params? | Partial<StopPollParams> |
Returns
Promise<Poll>
Inherited from
streamMessage()
Call Signature
streamMessage(
options?):MessageDraft<Bot>
Defined in: contexts/index.d.ts:5583
Streams message drafts to the current chat, finalizing each completed draft as a sent message.
Two forms (mirroring SendMixin.streamRichMessage):
- Iterable — pass an Iterable/AsyncIterable of
MessageDraftPiece; it's drained and the array of sent messages is returned. - Handle — call with no iterable to get a MessageDraft:
append()pieces andfinalize(), or useawait usingto finalize on scope exit.
Both use sendMessageDraft for live previews and sendMessage to finalize each 4096-char segment.
Parameters
| Parameter | Type |
|---|---|
options? | StreamMessageOptions |
Returns
MessageDraft<Bot>
Example
// iterable form
const messages = await context.streamMessage(llmStream);
// handle form (auto-finalize)
await using draft = context.streamMessage();
for await (const token of llm) draft.append(token);Inherited from
Call Signature
streamMessage(
stream,options?):Promise<MessageContext<Bot>[]>
Defined in: contexts/index.d.ts:5584
Streams message drafts to the current chat, finalizing each completed draft as a sent message.
Two forms (mirroring SendMixin.streamRichMessage):
- Iterable — pass an Iterable/AsyncIterable of
MessageDraftPiece; it's drained and the array of sent messages is returned. - Handle — call with no iterable to get a MessageDraft:
append()pieces andfinalize(), or useawait usingto finalize on scope exit.
Both use sendMessageDraft for live previews and sendMessage to finalize each 4096-char segment.
Parameters
| Parameter | Type |
|---|---|
stream | Iterable<MessageDraftPiece, any, any> | AsyncIterable<MessageDraftPiece, any, any> |
options? | StreamMessageOptions |
Returns
Promise<MessageContext<Bot>[]>
Example
// iterable form
const messages = await context.streamMessage(llmStream);
// handle form (auto-finalize)
await using draft = context.streamMessage();
for await (const token of llm) draft.append(token);Inherited from
streamRichMessage()
Call Signature
streamRichMessage(
options?):RichMessageDraft<Bot>
Defined in: contexts/index.d.ts:5504
Stream a rich message to the current chat, draft-first.
The hard part of sendRichMessageDraft is the contract: the draft is an ephemeral ~30-second preview, and you must finalize it with sendRichMessage or the message vanishes. This helper owns that lifecycle (throttled previews, a single finalize), so you can't forget it.
Two forms:
- Handle —
const draft = ctx.streamRichMessage(); draft.append(chunk); … await draft.finalize(). Withawait using, finalize runs automatically on scope exit. - Iterable — pass an (async) iterable of chunks; it's drained, finalized, and the sent message is returned.
A chunk is a @gramio/format RichString or a raw rich-markdown string.
Parameters
| Parameter | Type |
|---|---|
options? | StreamRichMessageOptions |
Returns
RichMessageDraft<Bot>
Example
// handle form (auto-finalize)
await using draft = ctx.streamRichMessage();
for await (const token of llm) draft.append(rich`${token}`);
// iterable form
const message = await ctx.streamRichMessage(llmStream);Inherited from
Call Signature
streamRichMessage(
stream,options?):Promise<MessageContext<Bot>>
Defined in: contexts/index.d.ts:5505
Stream a rich message to the current chat, draft-first.
The hard part of sendRichMessageDraft is the contract: the draft is an ephemeral ~30-second preview, and you must finalize it with sendRichMessage or the message vanishes. This helper owns that lifecycle (throttled previews, a single finalize), so you can't forget it.
Two forms:
- Handle —
const draft = ctx.streamRichMessage(); draft.append(chunk); … await draft.finalize(). Withawait using, finalize runs automatically on scope exit. - Iterable — pass an (async) iterable of chunks; it's drained, finalized, and the sent message is returned.
A chunk is a @gramio/format RichString or a raw rich-markdown string.
Parameters
| Parameter | Type |
|---|---|
stream | Iterable<RichChunk, any, any> | AsyncIterable<RichChunk, any, any> |
options? | StreamRichMessageOptions |
Returns
Promise<MessageContext<Bot>>
Example
// handle form (auto-finalize)
await using draft = ctx.streamRichMessage();
for await (const token of llm) draft.append(rich`${token}`);
// iterable form
const message = await ctx.streamRichMessage(llmStream);