Skip to content

Commit 3f55e7a

Browse files
feat: Add send_message_draft method
1 parent 320bdc1 commit 3f55e7a

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def get_title_list(s: str) -> list:
243243
send_voice
244244
send_video_note
245245
send_media_group
246+
send_message_draft
246247
send_location
247248
send_venue
248249
send_contact

pyrogram/methods/messages/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from .send_document import SendDocument
7575
from .send_location import SendLocation
7676
from .send_media_group import SendMediaGroup
77+
from .send_message_draft import SendMessageDraft
7778
from .send_message import SendMessage
7879
from .send_paid_media import SendPaidMedia
7980
from .send_paid_reaction import SendPaidReaction
@@ -128,6 +129,7 @@ class Messages(
128129
SendAnimation,
129130
SendLocation,
130131
SendMediaGroup,
132+
SendMessageDraft,
131133
SendMessage,
132134
SendPaidMedia,
133135
SendPaidReaction,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)