send_message_draft()#

Client.send_message_draft()[source]#

Sends a draft for a being generated text message.

Use this method to stream a partial message to a user while the message is being generated. This method shows a live text preview as it is being composed. To achieve a smooth AI-streaming effect, call this method repeatedly with progressively longer text, passing a consistent draft_id for all frames of the same stream.

Usable by Users Bots
Parameters:
  • chat_id (int | str) – Unique identifier 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.

  • text (str) – Text of the message to be sent, 1-4096 characters after entities parsing.

  • parse_mode (ParseMode, optional) – Mode for parsing entities in the message text. By default, texts are parsed using Markdown and HTML styles.

  • entities (List of MessageEntity, optional) – List of special entities that appear in the text, which can be specified instead of parse_mode.

  • message_thread_id (int, optional) – Unique identifier for the target message thread.

Returns:

bool – On success, True is returned.

Raises:
  • ValueError – If the text is empty or the chat type is not a private chat.

  • RPCError – In case of a Telegram RPC error.

Example

text = "Hello! I'm your Pyrogram bot! How can I help you?"
words = text.split()
draft_id = 1
for i, word in enumerate(words):
    await app.send_message_draft(
        chat_id=chat_id,
        draft_id=draft_id,
        text=" ".join(words[:i+1]),
    )
await app.send_message(chat_id, text)