send_rich_message_draft()

async Client.send_rich_message_draft()

Send a rich message draft action, allowing bots to stream partial rich messages.

When generating a rich message progressively (e.g. during AI response streaming), this method shows the user a typing indicator with the partial rich message content. The block InputRichBlockThinking may be used as a placeholder while waiting for content to be generated.

Usable by Users Bots
Parameters:
  • chat_id (int | str) – Unique identifier (int) or username (str) of the target chat.

  • draft_id (int) – Unique identifier of the draft; must be non-zero. Keep it constant for the whole generation, updates sharing an identifier are animated by clients. A different identifier does not restart the draft, it adds a second concurrent draft, and some clients collapse them into one.

  • rich_message (InputRichMessage) – The partial rich message to stream. Use InputRichBlockThinking as a placeholder for content still being generated.

  • message_thread_id (int, optional) – Unique identifier for a forum topic thread.

Returns:

bool – On success, True is returned.

Note

The draft is ephemeral: clients drop it after message_typing_draft_ttl seconds (30 by default, server-configured) or as soon as a real message arrives, so call send_rich_message() to persist the result. Throttle the stream: setTyping is rate-limited to 20 calls per 5s and 40 per 30s per peer.

Example

draft_id = app.rnd_id()

for i, word in enumerate(words):
    await app.send_rich_message_draft(
        chat_id, draft_id,
        types.InputRichMessage(html=" ".join(words[:i + 1])),
    )
    await asyncio.sleep(0.33)

await app.send_rich_message(chat_id, text)