|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import List, Optional, Union |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import enums, raw, types |
| 23 | + |
| 24 | + |
| 25 | +class SendMessageDraft: |
| 26 | + async def send_message_draft( |
| 27 | + self: "pyrogram.Client", |
| 28 | + chat_id: Union[int, str], |
| 29 | + draft_id: int, |
| 30 | + text: str, |
| 31 | + message_thread_id: Optional[int] = None, |
| 32 | + parse_mode: Optional["enums.ParseMode"] = None, |
| 33 | + entities: Optional[List["types.MessageEntity"]] = None, |
| 34 | + ) -> bool: |
| 35 | + """Use this method to stream a partial message to a user while the message is being generated. |
| 36 | +
|
| 37 | + .. include:: /_includes/usable-by/bots.rst |
| 38 | +
|
| 39 | + Parameters: |
| 40 | + chat_id (``int`` | ``str``): |
| 41 | + Unique identifier (int) or username (str) of the target chat. |
| 42 | + For your personal cloud (Saved Messages) you can simply use "me" or "self". |
| 43 | + For a contact that exists in your Telegram address book you can use his phone number (str). |
| 44 | +
|
| 45 | + draft_id (``int``): |
| 46 | + Unique identifier of the message draft, must be non-zero. |
| 47 | + Changes of drafts with the same identifier are animated. |
| 48 | +
|
| 49 | + text (``str``): |
| 50 | + Text of the message to be sent. |
| 51 | +
|
| 52 | + message_thread_id (``int``, *optional*): |
| 53 | + Unique identifier for the target message thread. |
| 54 | +
|
| 55 | + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): |
| 56 | + By default, texts are parsed using both Markdown and HTML styles. |
| 57 | + You can combine both syntaxes together. |
| 58 | +
|
| 59 | + entities (List of :obj:`~pyrogram.types.MessageEntity`): |
| 60 | + List of special entities that appear in message text, which can be specified instead of *parse_mode*. |
| 61 | +
|
| 62 | + Returns: |
| 63 | + ``bool``: On success, True is returned. |
| 64 | + """ |
| 65 | + return await self.invoke( |
| 66 | + raw.functions.messages.SetTyping( |
| 67 | + peer=await self.resolve_peer(chat_id), |
| 68 | + action=raw.types.SendMessageTextDraftAction( |
| 69 | + random_id=draft_id, |
| 70 | + text=await types.FormattedText( |
| 71 | + text=text, parse_mode=parse_mode, entities=entities |
| 72 | + ).write(), |
| 73 | + ), |
| 74 | + top_msg_id=message_thread_id, |
| 75 | + ) |
| 76 | + ) |
0 commit comments