Pyrofork: Add business_connection_id parameter to send_{animation,audio,chat_action,contact,dice,document,game,location,media_group,message,photo,poll,sticker,venue,video,video_note,voice,web_page}

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2024-04-06 13:13:04 +07:00
parent 48fed9347a
commit 7ddd53f61b
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
18 changed files with 544 additions and 289 deletions

View file

@ -31,6 +31,7 @@ class SendGame:
game_short_name: str, game_short_name: str,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
protect_content: bool = None, protect_content: bool = None,
reply_markup: Union[ reply_markup: Union[
@ -62,6 +63,10 @@ class SendGame:
Unique identifier of a message thread to which the message belongs. Unique identifier of a message thread to which the message belongs.
for supergroups only for supergroups only
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -87,28 +92,43 @@ class SendGame:
message_thread_id=message_thread_id message_thread_id=message_thread_id
) )
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaGame(
media=raw.types.InputMediaGame( id=raw.types.InputGameShortName(
id=raw.types.InputGameShortName( bot_id=raw.types.InputUserSelf(),
bot_id=raw.types.InputUserSelf(), short_name=game_short_name
short_name=game_short_name
),
), ),
message="", ),
silent=disable_notification or None, message="",
reply_to=reply_to, silent=disable_notification or None,
random_id=self.rnd_id(), reply_to=reply_to,
noforwards=protect_content, random_id=self.rnd_id(),
reply_markup=await reply_markup.write(self) if reply_markup else None noforwards=protect_content,
) reply_markup=await reply_markup.write(self) if reply_markup else None
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, raw.types.UpdateNewChannelMessage)): if isinstance(
i,
(
raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage,
raw.types.UpdateBotNewBusinessMessage
)
):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats},
business_connection_id=business_connection_id
) )

View file

@ -48,6 +48,7 @@ class SendAnimation:
file_name: str = None, file_name: str = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -126,6 +127,10 @@ class SendAnimation:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Unique identifier for the target business connection.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -265,31 +270,40 @@ class SendAnimation:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(animation, file_id=file.id, file_part=e.value) await self.save_file(animation, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
message = await types.Message._parse( message = await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
if unsave: if unsave:

View file

@ -46,6 +46,7 @@ class SendAudio:
file_name: str = None, file_name: str = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -119,6 +120,10 @@ class SendAudio:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -251,31 +256,40 @@ class SendAudio:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(audio, file_id=file.id, file_part=e.value) await self.save_file(audio, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except StopTransmission: except StopTransmission:
return None return None

View file

@ -28,7 +28,8 @@ class SendChatAction:
self: "pyrogram.Client", self: "pyrogram.Client",
chat_id: Union[int, str], chat_id: Union[int, str],
action: "enums.ChatAction", action: "enums.ChatAction",
message_thread_id: int = None message_thread_id: int = None,
business_connection_id: str = None
) -> bool: ) -> bool:
"""Tell the other party that something is happening on your side. """Tell the other party that something is happening on your side.
@ -48,6 +49,10 @@ class SendChatAction:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
Returns: Returns:
``bool``: On success, True is returned. ``bool``: On success, True is returned.
@ -78,11 +83,16 @@ class SendChatAction:
action = action.value(progress=0) action = action.value(progress=0)
else: else:
action = action.value() action = action.value()
rpc = raw.functions.messages.SetTyping(
return await self.invoke( peer=await self.resolve_peer(chat_id),
raw.functions.messages.SetTyping( action=action,
peer=await self.resolve_peer(chat_id), top_msg_id=message_thread_id
action=action,
top_msg_id=message_thread_id
)
) )
if business_connection_id:
return await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
return await self.invoke(rpc)

View file

@ -35,6 +35,7 @@ class SendContact:
vcard: str = None, vcard: str = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
quote_text: str = None, quote_text: str = None,
@ -80,6 +81,10 @@ class SendContact:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -131,32 +136,41 @@ class SendContact:
parse_mode=parse_mode parse_mode=parse_mode
) )
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaContact(
media=raw.types.InputMediaContact( phone_number=phone_number,
phone_number=phone_number, first_name=first_name,
first_name=first_name, last_name=last_name or "",
last_name=last_name or "", vcard=vcard or ""
vcard=vcard or "" ),
), message="",
message="", silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None
reply_markup=await reply_markup.write(self) if reply_markup else None
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )

View file

@ -32,6 +32,7 @@ class SendDice:
emoji: str = "🎲", emoji: str = "🎲",
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -73,6 +74,10 @@ class SendDice:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -135,27 +140,36 @@ class SendDice:
parse_mode=parse_mode parse_mode=parse_mode
) )
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaDice(emoticon=emoji),
media=raw.types.InputMediaDice(emoticon=emoji), silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, message=""
message=""
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )

View file

@ -44,6 +44,7 @@ class SendDocument:
force_document: bool = None, force_document: bool = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -111,6 +112,10 @@ class SendDocument:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -229,31 +234,40 @@ class SendDocument:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(document, file_id=file.id, file_part=e.value) await self.save_file(document, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except StopTransmission: except StopTransmission:
return None return None

View file

@ -33,6 +33,7 @@ class SendLocation:
longitude: float, longitude: float,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
quote_text: str = None, quote_text: str = None,
@ -72,6 +73,10 @@ class SendLocation:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_chat_id (``int`` | ``str``, *optional*): reply_to_chat_id (``int`` | ``str``, *optional*):
Unique identifier for the origin chat. Unique identifier for the origin chat.
for reply to message from another chat. for reply to message from another chat.
@ -123,32 +128,41 @@ class SendLocation:
parse_mode=parse_mode parse_mode=parse_mode
) )
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaGeoPoint(
media=raw.types.InputMediaGeoPoint( geo_point=raw.types.InputGeoPoint(
geo_point=raw.types.InputGeoPoint( lat=latitude,
lat=latitude, long=longitude
long=longitude )
) ),
), message="",
message="", silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None
reply_markup=await reply_markup.write(self) if reply_markup else None
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )

View file

@ -48,6 +48,7 @@ class SendMediaGroup:
]], ]],
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -79,6 +80,10 @@ class SendMediaGroup:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -454,28 +459,38 @@ class SendMediaGroup:
) )
) )
r = await self.invoke( rpc = raw.functions.messages.SendMultiMedia(
raw.functions.messages.SendMultiMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), multi_media=multi_media,
multi_media=multi_media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content
noforwards=protect_content ),
),
sleep_threshold=60 if business_connection_id is not None:
) r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
),
sleep_threshold=60
)
else:
r = await self.invoke(rpc, sleep_threshold=60)
return await utils.parse_messages( return await utils.parse_messages(
self, self,
raw.types.messages.Messages( raw.types.messages.Messages(
messages=[m.message for m in filter( messages=[m.message for m in filter(
lambda u: isinstance(u, (raw.types.UpdateNewMessage, lambda u: isinstance(u, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)), raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)),
r.updates r.updates
)], )],
users=r.users, users=r.users,
chats=r.chats chats=r.chats
) ),
business_connection_id=business_connection_id
) )

View file

@ -35,6 +35,7 @@ class SendMessage:
disable_web_page_preview: bool = None, disable_web_page_preview: bool = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: int = None, reply_to_chat_id: int = None,
@ -82,6 +83,10 @@ class SendMessage:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -166,21 +171,28 @@ class SendMessage:
parse_mode=parse_mode parse_mode=parse_mode
) )
r = await self.invoke( rpc = raw.functions.messages.SendMessage(
raw.functions.messages.SendMessage( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), no_webpage=disable_web_page_preview or None,
no_webpage=disable_web_page_preview or None, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, message=message,
message=message, entities=entities,
entities=entities, noforwards=protect_content,
noforwards=protect_content, invert_media=invert_media
invert_media=invert_media
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
if isinstance(r, raw.types.UpdateShortSentMessage): if isinstance(r, raw.types.UpdateShortSentMessage):
peer = await self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
@ -212,10 +224,12 @@ class SendMessage:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )

View file

@ -42,6 +42,7 @@ class SendPhoto:
ttl_seconds: int = None, ttl_seconds: int = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -102,6 +103,10 @@ class SendPhoto:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -214,31 +219,40 @@ class SendPhoto:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(photo, file_id=file.id, file_part=e.value) await self.save_file(photo, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except pyrogram.StopTransmission: except pyrogram.StopTransmission:
return None return None

View file

@ -44,6 +44,7 @@ class SendPoll:
disable_notification: bool = None, disable_notification: bool = None,
protect_content: bool = None, protect_content: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
quote_text: str = None, quote_text: str = None,
@ -125,6 +126,10 @@ class SendPoll:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -177,45 +182,54 @@ class SendPoll:
self, explanation, explanation_parse_mode, explanation_entities self, explanation, explanation_parse_mode, explanation_entities
)).values() )).values()
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaPoll(
media=raw.types.InputMediaPoll( poll=raw.types.Poll(
poll=raw.types.Poll( id=self.rnd_id(),
id=self.rnd_id(), question=question,
question=question, answers=[
answers=[ raw.types.PollAnswer(text=text, option=bytes([i]))
raw.types.PollAnswer(text=text, option=bytes([i])) for i, text in enumerate(options)
for i, text in enumerate(options) ],
], closed=is_closed,
closed=is_closed, public_voters=not is_anonymous,
public_voters=not is_anonymous, multiple_choice=allows_multiple_answers,
multiple_choice=allows_multiple_answers, quiz=type == enums.PollType.QUIZ or False,
quiz=type == enums.PollType.QUIZ or False, close_period=open_period,
close_period=open_period, close_date=utils.datetime_to_timestamp(close_date)
close_date=utils.datetime_to_timestamp(close_date)
),
correct_answers=[bytes([correct_option_id])] if correct_option_id is not None else None,
solution=solution,
solution_entities=solution_entities or []
), ),
message="", correct_answers=[bytes([correct_option_id])] if correct_option_id is not None else None,
silent=disable_notification, solution=solution,
reply_to=reply_to, solution_entities=solution_entities or []
random_id=self.rnd_id(), ),
schedule_date=utils.datetime_to_timestamp(schedule_date), message="",
noforwards=protect_content, silent=disable_notification,
reply_markup=await reply_markup.write(self) if reply_markup else None reply_to=reply_to,
) random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
reply_markup=await reply_markup.write(self) if reply_markup else None
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )

View file

@ -39,6 +39,7 @@ class SendSticker:
sticker: Union[str, BinaryIO], sticker: Union[str, BinaryIO],
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -82,6 +83,10 @@ class SendSticker:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -195,31 +200,40 @@ class SendSticker:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, message=""
message=""
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(sticker, file_id=file.id, file_part=e.value) await self.save_file(sticker, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except StopTransmission: except StopTransmission:
return None return None

View file

@ -37,6 +37,7 @@ class SendVenue:
foursquare_type: str = "", foursquare_type: str = "",
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
quote_text: str = None, quote_text: str = None,
@ -89,6 +90,10 @@ class SendVenue:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message If the message is a reply, ID of the original message
@ -142,37 +147,46 @@ class SendVenue:
parse_mode=parse_mode parse_mode=parse_mode
) )
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaVenue(
media=raw.types.InputMediaVenue( geo_point=raw.types.InputGeoPoint(
geo_point=raw.types.InputGeoPoint( lat=latitude,
lat=latitude, long=longitude
long=longitude
),
title=title,
address=address,
provider="",
venue_id=foursquare_id,
venue_type=foursquare_type
), ),
message="", title=title,
silent=disable_notification or None, address=address,
reply_to=reply_to, provider="",
random_id=self.rnd_id(), venue_id=foursquare_id,
schedule_date=utils.datetime_to_timestamp(schedule_date), venue_type=foursquare_type
noforwards=protect_content, ),
reply_markup=await reply_markup.write(self) if reply_markup else None message="",
) silent=disable_notification or None,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
reply_markup=await reply_markup.write(self) if reply_markup else None
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )

View file

@ -49,6 +49,7 @@ class SendVideo:
supports_streaming: bool = True, supports_streaming: bool = True,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -132,6 +133,10 @@ class SendVideo:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -271,31 +276,40 @@ class SendVideo:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(video, file_id=file.id, file_part=e.value) await self.save_file(video, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except StopTransmission: except StopTransmission:
return None return None

View file

@ -41,6 +41,7 @@ class SendVideoNote:
thumb: Union[str, BinaryIO] = None, thumb: Union[str, BinaryIO] = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -97,6 +98,10 @@ class SendVideoNote:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -229,31 +234,40 @@ class SendVideoNote:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, message=""
message=""
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(video_note, file_id=file.id, file_part=e.value) await self.save_file(video_note, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except StopTransmission: except StopTransmission:
return None return None

View file

@ -42,6 +42,7 @@ class SendVoice:
duration: int = 0, duration: int = 0,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -97,6 +98,10 @@ class SendVoice:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message If the message is a reply, ID of the original message
@ -216,31 +221,40 @@ class SendVoice:
while True: while True:
try: try:
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), media=media,
media=media, silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content,
noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
except FilePartMissing as e: except FilePartMissing as e:
await self.save_file(voice, file_id=file.id, file_part=e.value) await self.save_file(voice, file_id=file.id, file_part=e.value)
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )
except StopTransmission: except StopTransmission:
return None return None

View file

@ -36,6 +36,7 @@ class SendWebPage:
invert_media: bool = None, invert_media: bool = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
business_connection_id: str = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
@ -88,6 +89,10 @@ class SendWebPage:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only. for forum supergroups only.
business_connection_id (``str``, *optional*):
Business connection identifier.
for business bots only.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -146,21 +151,28 @@ class SendWebPage:
force_large_media=large_media, force_large_media=large_media,
force_small_media=not large_media force_small_media=not large_media
) )
r = await self.invoke( rpc = raw.functions.messages.SendMedia(
raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id),
peer=await self.resolve_peer(chat_id), silent=disable_notification or None,
silent=disable_notification or None, reply_to=reply_to,
reply_to=reply_to, random_id=self.rnd_id(),
random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date),
schedule_date=utils.datetime_to_timestamp(schedule_date), reply_markup=await reply_markup.write(self) if reply_markup else None,
reply_markup=await reply_markup.write(self) if reply_markup else None, message=message,
message=message, media=media,
media=media, invert_media=invert_media,
invert_media=invert_media, entities=entities,
entities=entities, noforwards=protect_content
noforwards=protect_content
)
) )
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
)
)
else:
r = await self.invoke(rpc)
if isinstance(r, raw.types.UpdateShortSentMessage): if isinstance(r, raw.types.UpdateShortSentMessage):
peer = await self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
@ -191,10 +203,12 @@ class SendWebPage:
for i in r.updates: for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage, if isinstance(i, (raw.types.UpdateNewMessage,
raw.types.UpdateNewChannelMessage, raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewScheduledMessage)): raw.types.UpdateNewScheduledMessage,
raw.types.UpdateBotNewBusinessMessage)):
return await types.Message._parse( return await types.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=business_connection_id
) )