send_rich_message_draft()¶
- Client.send_rich_message_draft(chat_id: int | str, draft_id: int, rich_message: InputRichMessage, message_thread_id: int | None = None, can_stop: bool | None = None, keep_on_stop: bool | None = None) bool¶
Use this method to stream a partial rich message to a user while the message is being generated.
Usable by ❌ Users ✅ BotsNote
The streamed draft is ephemeral and acts as a temporary 30-second preview - once the output is finalized, you must call
send_rich_message()with the complete message to persist it in the user’s chat.- Parameters:
chat_id (
int|str) – Unique identifier (int) or username (str) of the target chat.draft_id (
int) – Unique identifier of the message draft, must be non-zero. Changes of drafts with the same identifier are animated.rich_message (
ftmgram.types.InputRichMessage) – The partial message to be streamed.message_thread_id (
int, optional) – Unique identifier for the target message thread.can_stop (
bool, optional) – Pass True if the user can stop the generation (Bot API 10.3).keep_on_stop (
bool, optional) – Pass True to keep the draft message when generation is stopped (Bot API 10.3).
- Returns:
bool– On success, True is returned.
Example
text = "Hello! I'm your <b>Pyrogram bot</b>! How can I help you?" words = text.split() draft_id = app.rnd_id() # Send thinking placeholder await app.send_rich_message_draft(chat_id, draft_id) await asyncio.sleep(5) for i, word in enumerate(words): await app.send_rich_message_draft( chat_id=chat_id, draft_id=draft_id, rich_message=types.InputRichMessage(html=" ".join(words[:i+1])), ) await asyncio.sleep(0.33) await app.send_rich_message(chat_id, text)