Merge branch 'Mayuri-Chan:main' into main

This commit is contained in:
naya1503 2024-07-17 15:38:25 +07:00 committed by GitHub
commit f036ca58a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 252 additions and 156 deletions

View file

@ -374,6 +374,10 @@ def pyrogram_api():
set_bot_info set_bot_info
get_collectible_item_info get_collectible_item_info
""", """,
business="""
Telegram Business
get_business_connection
""",
authorization=""" authorization="""
Authorization Authorization
connect connect

View file

@ -112,6 +112,19 @@ Stickers
{stickers} {stickers}
Telegram Business
-------------
.. autosummary::
:nosignatures:
{business}
.. toctree::
:hidden:
{business}
Users Users
----- -----

View file

@ -18,7 +18,7 @@
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
__fork_name__ = "PyroFork" __fork_name__ = "PyroFork"
__version__ = "2.3.32" __version__ = "2.3.36"
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
__copyright__ = "Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>" __copyright__ = "Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>"

View file

@ -203,6 +203,14 @@ class Client(Methods):
A value that is too high may result in network related issues. A value that is too high may result in network related issues.
Defaults to 1. Defaults to 1.
max_message_cache_size (``int``, *optional*):
Set the maximum size of the message cache.
Defaults to 10000.
max_business_user_connection_cache_size (``int``, *optional*):
Set the maximum size of the message cache.
Defaults to 10000.
client_platform (:obj:`~pyrogram.enums.ClientPlatform`, *optional*): client_platform (:obj:`~pyrogram.enums.ClientPlatform`, *optional*):
The platform where this client is running. The platform where this client is running.
Defaults to 'other' Defaults to 'other'
@ -224,6 +232,7 @@ class Client(Methods):
UPDATES_WATCHDOG_INTERVAL = 15 * 60 UPDATES_WATCHDOG_INTERVAL = 15 * 60
MAX_CONCURRENT_TRANSMISSIONS = 1 MAX_CONCURRENT_TRANSMISSIONS = 1
MAX_CACHE_SIZE = 10000
mimetypes = MimeTypes() mimetypes = MimeTypes()
mimetypes.readfp(StringIO(mime_types)) mimetypes.readfp(StringIO(mime_types))
@ -259,7 +268,9 @@ class Client(Methods):
sleep_threshold: int = Session.SLEEP_THRESHOLD, sleep_threshold: int = Session.SLEEP_THRESHOLD,
hide_password: Optional[bool] = False, hide_password: Optional[bool] = False,
max_concurrent_transmissions: int = MAX_CONCURRENT_TRANSMISSIONS, max_concurrent_transmissions: int = MAX_CONCURRENT_TRANSMISSIONS,
client_platform: "enums.ClientPlatform" = enums.ClientPlatform.OTHER client_platform: "enums.ClientPlatform" = enums.ClientPlatform.OTHER,
max_message_cache_size: int = MAX_CACHE_SIZE,
max_business_user_connection_cache_size: int = MAX_CACHE_SIZE
): ):
super().__init__() super().__init__()
@ -292,6 +303,9 @@ class Client(Methods):
self.hide_password = hide_password self.hide_password = hide_password
self.max_concurrent_transmissions = max_concurrent_transmissions self.max_concurrent_transmissions = max_concurrent_transmissions
self.client_platform = client_platform self.client_platform = client_platform
self.max_message_cache_size = max_message_cache_size
self.max_message_cache_size = max_message_cache_size
self.max_business_user_connection_cache_size = max_business_user_connection_cache_size
self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler") self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler")
@ -341,7 +355,8 @@ class Client(Methods):
self.me: Optional[User] = None self.me: Optional[User] = None
self.message_cache = Cache(10000) self.message_cache = Cache(self.max_message_cache_size)
self.business_user_connection_cache = Cache(self.max_business_user_connection_cache_size)
# Sometimes, for some reason, the server will stop sending updates and will only respond to pings. # Sometimes, for some reason, the server will stop sending updates and will only respond to pings.
# This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again # This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again

View file

@ -30,6 +30,7 @@ from .pyromod import Pyromod
from .stickers import Stickers from .stickers import Stickers
from .users import Users from .users import Users
from .utilities import Utilities from .utilities import Utilities
from .business import TelegramBusiness
class Methods( class Methods(
@ -46,5 +47,6 @@ class Methods(
Decorators, Decorators,
Utilities, Utilities,
InviteLinks, InviteLinks,
TelegramBusiness,
): ):
pass pass

View file

@ -0,0 +1,25 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .get_business_connection import GetBusinessConnection
class TelegramBusiness(
GetBusinessConnection,
):
pass

View file

@ -0,0 +1,58 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from typing import Union, List
import pyrogram
from pyrogram import types, utils, raw
class GetBusinessConnection:
async def get_business_connection(
self: "pyrogram.Client",
business_connection_id: str
) -> "types.Message":
"""Use this method to get information about the connection of the bot with a business account.
.. include:: /_includes/usable-by/bots.rst
Parameters:
business_connection_id (``str``):
Unique identifier of the business connection
Returns:
:obj:`~pyrogram.types.BusinessConnection`: On success, the the connection of the bot with a business account is returned.
"""
r = await self.invoke(
raw.functions.account.GetBotBusinessConnection(
connection_id=business_connection_id
)
)
for i in r.updates:
if isinstance(
i,
(
raw.types.UpdateBotBusinessConnect
)
):
return await types.BotBusinessConnection._parse(
client=self,
bot_connection=i.connection
)

View file

@ -66,7 +66,8 @@ class EditMessageCaption:
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*): business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned. :obj:`~pyrogram.types.Message`: On success, the edited message is returned.

View file

@ -28,8 +28,6 @@ from pyrogram import types
from pyrogram import utils from pyrogram import utils
from pyrogram.file_id import FileType from pyrogram.file_id import FileType
from .inline_session import get_session
class EditMessageMedia: class EditMessageMedia:
async def edit_message_media( async def edit_message_media(
@ -73,7 +71,8 @@ class EditMessageMedia:
Inverts the position of the media and caption. Inverts the position of the media and caption.
business_connection_id (``str``, *optional*): business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned. :obj:`~pyrogram.types.Message`: On success, the edited message is returned.
@ -288,24 +287,13 @@ class EditMessageMedia:
entities=entities, entities=entities,
invert_media=invert_media invert_media=invert_media
) )
session = None if business_connection_id is not None:
business_connection = None r = await self.invoke(
if business_connection_id:
business_connection = self.business_user_connection_cache[business_connection_id]
if not business_connection:
business_connection = await self.get_business_connection(business_connection_id)
session = await get_session(
self,
business_connection._raw.connection.dc_id
)
if business_connection_id:
r = await session.invoke(
raw.functions.InvokeWithBusinessConnection( raw.functions.InvokeWithBusinessConnection(
query=rpc, connection_id=business_connection_id,
connection_id=business_connection_id query=rpc
) )
) )
# await session.stop()
else: else:
r = await self.invoke(rpc) r = await self.invoke(rpc)
@ -316,18 +304,3 @@ class EditMessageMedia:
{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}
) )
elif isinstance(
i,
(
raw.types.UpdateBotEditBusinessMessage
)
):
return await types.Message._parse(
self,
i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
business_connection_id=getattr(i, "connection_id", business_connection_id),
raw_reply_to_message=i.reply_to_message,
replies=0
)

View file

@ -20,9 +20,8 @@
from typing import Union from typing import Union
import pyrogram import pyrogram
from pyrogram import raw, types from pyrogram import raw
from pyrogram import types
from .inline_session import get_session
class EditMessageReplyMarkup: class EditMessageReplyMarkup:
@ -51,7 +50,8 @@ class EditMessageReplyMarkup:
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*): business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned. :obj:`~pyrogram.types.Message`: On success, the edited message is returned.
@ -70,54 +70,22 @@ class EditMessageReplyMarkup:
rpc = raw.functions.messages.EditMessage( rpc = raw.functions.messages.EditMessage(
peer=await self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
id=message_id, id=message_id,
reply_markup=await reply_markup.write(self) if reply_markup else None, reply_markup=await reply_markup.write(self) if reply_markup else None
) )
session = None if business_connection_id is not None:
business_connection = None r = await self.invoke(
if business_connection_id:
business_connection = self.business_user_connection_cache[business_connection_id]
if not business_connection:
business_connection = await self.get_business_connection(business_connection_id)
session = await get_session(
self,
business_connection._raw.connection.dc_id
)
if business_connection_id:
r = await session.invoke(
raw.functions.InvokeWithBusinessConnection( raw.functions.InvokeWithBusinessConnection(
query=rpc, connection_id=business_connection_id,
connection_id=business_connection_id query=rpc
) )
) )
# await session.stop()
else: else:
r = await self.invoke(rpc) r = await self.invoke(rpc)
for i in r.updates: for i in r.updates:
if isinstance( if isinstance(i, (raw.types.UpdateEditMessage, raw.types.UpdateEditChannelMessage)):
i,
(
raw.types.UpdateEditMessage,
raw.types.UpdateEditChannelMessage
)
):
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}
) )
elif isinstance(
i,
(
raw.types.UpdateBotEditBusinessMessage
)
):
return await types.Message._parse(
self,
i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
business_connection_id=getattr(i, "connection_id", business_connection_id),
raw_reply_to_message=i.reply_to_message,
replies=0
)

View file

@ -72,7 +72,8 @@ class EditMessageText:
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*): business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned. :obj:`~pyrogram.types.Message`: On success, the edited message is returned.
@ -97,24 +98,13 @@ class EditMessageText:
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, text, parse_mode, entities) **await utils.parse_text_entities(self, text, parse_mode, entities)
) )
session = None if business_connection_id is not None:
business_connection = None r = await self.invoke(
if business_connection_id:
business_connection = self.business_user_connection_cache[business_connection_id]
if not business_connection:
business_connection = await self.get_business_connection(business_connection_id)
session = await get_session(
self,
business_connection._raw.connection.dc_id
)
if business_connection_id:
r = await session.invoke(
raw.functions.InvokeWithBusinessConnection( raw.functions.InvokeWithBusinessConnection(
query=rpc, connection_id=business_connection_id,
connection_id=business_connection_id query=rpc
) )
) )
# await session.stop()
else: else:
r = await self.invoke(rpc) r = await self.invoke(rpc)
@ -125,18 +115,3 @@ class EditMessageText:
{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}
) )
elif isinstance(
i,
(
raw.types.UpdateBotEditBusinessMessage
)
):
return await types.Message._parse(
self,
i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
business_connection_id=getattr(i, "connection_id", business_connection_id),
raw_reply_to_message=i.reply_to_message,
replies=0
)

View file

@ -40,6 +40,9 @@ async def get_session(client: "pyrogram.Client", dc_id: int):
await session.start() await session.start()
if dc_id == await client.storage.dc_id():
return session
for _ in range(3): for _ in range(3):
exported_auth = await client.invoke( exported_auth = await client.invoke(
raw.functions.auth.ExportAuthorization( raw.functions.auth.ExportAuthorization(

View file

@ -20,9 +20,8 @@
from typing import Union from typing import Union
import pyrogram import pyrogram
from pyrogram import raw, types from pyrogram import raw
from pyrogram import types
from .inline_session import get_session
class StopPoll: class StopPoll:
@ -53,7 +52,7 @@ class StopPoll:
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*): business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent Unique identifier of the business connection.
Returns: Returns:
:obj:`~pyrogram.types.Poll`: On success, the stopped poll with the final results is returned. :obj:`~pyrogram.types.Poll`: On success, the stopped poll with the final results is returned.
@ -78,24 +77,13 @@ class StopPoll:
), ),
reply_markup=await reply_markup.write(self) if reply_markup else None reply_markup=await reply_markup.write(self) if reply_markup else None
) )
session = None if business_connection_id is not None:
business_connection = None r = await self.invoke(
if business_connection_id:
business_connection = self.business_user_connection_cache[business_connection_id]
if not business_connection:
business_connection = await self.get_business_connection(business_connection_id)
session = await get_session(
self,
business_connection._raw.connection.dc_id
)
if business_connection_id:
r = await session.invoke(
raw.functions.InvokeWithBusinessConnection( raw.functions.InvokeWithBusinessConnection(
query=rpc, connection_id=business_connection_id,
connection_id=business_connection_id query=rpc
) )
) )
# await session.stop()
else: else:
r = await self.invoke(rpc) r = await self.invoke(rpc)

View file

@ -33,7 +33,7 @@ from pyrogram.errors import (
RPCError, InternalServerError, AuthKeyDuplicated, RPCError, InternalServerError, AuthKeyDuplicated,
FloodWait, FloodPremiumWait, FloodWait, FloodPremiumWait,
ServiceUnavailable, BadMsgNotification, ServiceUnavailable, BadMsgNotification,
SecurityCheckMismatch SecurityCheckMismatch, Unauthorized
) )
from pyrogram.raw.all import layer from pyrogram.raw.all import layer
from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts
@ -309,6 +309,12 @@ class Session:
if packet: if packet:
error_code = -Int.read(BytesIO(packet)) error_code = -Int.read(BytesIO(packet))
if error_code == 404:
raise Unauthorized(
"Auth key not found in the system. You must delete your session file "
"and log in again with your phone number or bot token."
)
log.warning( log.warning(
"Server sent transport error: %s (%s)", "Server sent transport error: %s (%s)",
error_code, Session.TRANSPORT_ERRORS.get(error_code, "unknown error") error_code, Session.TRANSPORT_ERRORS.get(error_code, "unknown error")

View file

@ -107,11 +107,10 @@ class CallbackQuery(Object, Update):
client, client,
callback_query.message, callback_query.message,
users, users,
chats, {},
is_scheduled=False, is_scheduled=False,
replies=0, replies=0,
business_connection_id=callback_query.connection_id, business_connection_id=callback_query.connection_id
raw_reply_to_message=getattr(callback_query, "reply_to_message", None)
) )
# Try to decode callback query data into string. If that fails, fallback to bytes instead of decoding by # Try to decode callback query data into string. If that fails, fallback to bytes instead of decoding by
# ignoring/replacing errors, this way, button clicks will still work. # ignoring/replacing errors, this way, button clicks will still work.
@ -182,7 +181,8 @@ class CallbackQuery(Object, Update):
text: str, text: str,
parse_mode: Optional["enums.ParseMode"] = None, parse_mode: Optional["enums.ParseMode"] = None,
disable_web_page_preview: bool = None, disable_web_page_preview: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]: ) -> Union["types.Message", bool]:
"""Edit the text of messages attached to callback queries. """Edit the text of messages attached to callback queries.
@ -202,6 +202,10 @@ class CallbackQuery(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited :obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited
message is returned, otherwise True is returned (message sent via the bot, as inline query result). message is returned, otherwise True is returned (message sent via the bot, as inline query result).
@ -217,7 +221,7 @@ class CallbackQuery(Object, Update):
parse_mode=parse_mode, parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview, disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=self.message.business_connection_id business_connection_id=getattr(self.message, "business_connection_id", None)
) )
else: else:
return await self._client.edit_inline_text( return await self._client.edit_inline_text(
@ -232,7 +236,8 @@ class CallbackQuery(Object, Update):
self, self,
caption: str, caption: str,
parse_mode: Optional["enums.ParseMode"] = None, parse_mode: Optional["enums.ParseMode"] = None,
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]: ) -> Union["types.Message", bool]:
"""Edit the caption of media messages attached to callback queries. """Edit the caption of media messages attached to callback queries.
@ -249,6 +254,10 @@ class CallbackQuery(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited :obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited
message is returned, otherwise True is returned (message sent via the bot, as inline query result). message is returned, otherwise True is returned (message sent via the bot, as inline query result).
@ -256,12 +265,22 @@ class CallbackQuery(Object, Update):
Raises: Raises:
RPCError: In case of a Telegram RPC error. RPCError: In case of a Telegram RPC error.
""" """
return await self.edit_message_text(caption, parse_mode, reply_markup=reply_markup) return await self.edit_message_text(
caption,
parse_mode,
reply_markup=reply_markup,
business_connection_id=getattr(
self.message,
"business_connection_id",
None
) if business_connection_id is None else business_connection_id
)
async def edit_message_media( async def edit_message_media(
self, self,
media: "types.InputMedia", media: "types.InputMedia",
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]: ) -> Union["types.Message", bool]:
"""Edit animation, audio, document, photo or video messages attached to callback queries. """Edit animation, audio, document, photo or video messages attached to callback queries.
@ -274,6 +293,10 @@ class CallbackQuery(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited :obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited
message is returned, otherwise True is returned (message sent via the bot, as inline query result). message is returned, otherwise True is returned (message sent via the bot, as inline query result).
@ -287,7 +310,11 @@ class CallbackQuery(Object, Update):
message_id=self.message.id, message_id=self.message.id,
media=media, media=media,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=self.message.business_connection_id business_connection_id=getattr(
self.message,
"business_connection_id",
None
) if business_connection_id is None else business_connection_id
) )
else: else:
return await self._client.edit_inline_media( return await self._client.edit_inline_media(
@ -298,7 +325,8 @@ class CallbackQuery(Object, Update):
async def edit_message_reply_markup( async def edit_message_reply_markup(
self, self,
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]: ) -> Union["types.Message", bool]:
"""Edit only the reply markup of messages attached to callback queries. """Edit only the reply markup of messages attached to callback queries.
@ -308,6 +336,10 @@ class CallbackQuery(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
:obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited :obj:`~pyrogram.types.Message` | ``bool``: On success, if the edited message was sent by the bot, the edited
message is returned, otherwise True is returned (message sent via the bot, as inline query result). message is returned, otherwise True is returned (message sent via the bot, as inline query result).
@ -320,7 +352,11 @@ class CallbackQuery(Object, Update):
chat_id=self.message.chat.id, chat_id=self.message.chat.id,
message_id=self.message.id, message_id=self.message.id,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=self.message.business_connection_id, business_connection_id=getattr(
self.message,
"business_connection_id",
None
) if business_connection_id is None else business_connection_id
) )
else: else:
return await self._client.edit_inline_reply_markup( return await self._client.edit_inline_reply_markup(

View file

@ -4066,7 +4066,8 @@ class Message(Object, Update):
entities: List["types.MessageEntity"] = None, entities: List["types.MessageEntity"] = None,
disable_web_page_preview: bool = None, disable_web_page_preview: bool = None,
invert_media: bool = None, invert_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: str = None
) -> "Message": ) -> "Message":
"""Bound method *edit_text* of :obj:`~pyrogram.types.Message`. """Bound method *edit_text* of :obj:`~pyrogram.types.Message`.
@ -4107,6 +4108,10 @@ class Message(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
On success, the edited :obj:`~pyrogram.types.Message` is returned. On success, the edited :obj:`~pyrogram.types.Message` is returned.
@ -4122,7 +4127,7 @@ class Message(Object, Update):
disable_web_page_preview=disable_web_page_preview, disable_web_page_preview=disable_web_page_preview,
invert_media=invert_media, invert_media=invert_media,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=self.business_connection_id business_connection_id=self.business_connection_id if business_connection_id is None else business_connection_id
) )
edit = edit_text edit = edit_text
@ -4133,7 +4138,8 @@ class Message(Object, Update):
parse_mode: Optional["enums.ParseMode"] = None, parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None, caption_entities: List["types.MessageEntity"] = None,
invert_media: bool = None, invert_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: str = None
) -> "Message": ) -> "Message":
"""Bound method *edit_caption* of :obj:`~pyrogram.types.Message`. """Bound method *edit_caption* of :obj:`~pyrogram.types.Message`.
@ -4169,6 +4175,10 @@ class Message(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
On success, the edited :obj:`~pyrogram.types.Message` is returned. On success, the edited :obj:`~pyrogram.types.Message` is returned.
@ -4182,14 +4192,16 @@ class Message(Object, Update):
parse_mode=parse_mode, parse_mode=parse_mode,
caption_entities=caption_entities, caption_entities=caption_entities,
invert_media=invert_media, invert_media=invert_media,
reply_markup=reply_markup reply_markup=reply_markup,
business_connection_id=self.business_connection_id if business_connection_id is None else business_connection_id
) )
async def edit_media( async def edit_media(
self, self,
media: "types.InputMedia", media: "types.InputMedia",
invert_media: bool = None, invert_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: str = None
) -> "Message": ) -> "Message":
"""Bound method *edit_media* of :obj:`~pyrogram.types.Message`. """Bound method *edit_media* of :obj:`~pyrogram.types.Message`.
@ -4218,6 +4230,10 @@ class Message(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
On success, the edited :obj:`~pyrogram.types.Message` is returned. On success, the edited :obj:`~pyrogram.types.Message` is returned.
@ -4230,10 +4246,14 @@ class Message(Object, Update):
media=media, media=media,
invert_media=invert_media, invert_media=invert_media,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=self.business_connection_id business_connection_id=self.business_connection_id if business_connection_id is None else business_connection_id
) )
async def edit_reply_markup(self, reply_markup: "types.InlineKeyboardMarkup" = None) -> "Message": async def edit_reply_markup(
self,
reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: str = None
) -> "Message":
"""Bound method *edit_reply_markup* of :obj:`~pyrogram.types.Message`. """Bound method *edit_reply_markup* of :obj:`~pyrogram.types.Message`.
Use as a shortcut for: Use as a shortcut for:
@ -4255,6 +4275,10 @@ class Message(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection.
for business bots only.
Returns: Returns:
On success, if edited message is sent by the bot, the edited On success, if edited message is sent by the bot, the edited
:obj:`~pyrogram.types.Message` is returned, otherwise True is returned. :obj:`~pyrogram.types.Message` is returned, otherwise True is returned.
@ -4266,7 +4290,7 @@ class Message(Object, Update):
chat_id=self.chat.id, chat_id=self.chat.id,
message_id=self.id, message_id=self.id,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=self.business_connection_id business_connection_id=self.business_connection_id if business_connection_id is None else business_connection_id
) )
async def forward( async def forward(

View file

@ -237,7 +237,7 @@ class Poll(Object, Update):
An InlineKeyboardMarkup object. An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*): business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent Unique identifier of the business connection.
Example: Example:
.. code-block:: python .. code-block:: python
@ -255,5 +255,5 @@ class Poll(Object, Update):
chat_id=self.chat.id, chat_id=self.chat.id,
message_id=self.id, message_id=self.id,
reply_markup=reply_markup, reply_markup=reply_markup,
business_connection_id=business_connection_id business_connection_id=self.business_connection_id if business_connection_id is None else business_connection_id
) )

View file

@ -954,7 +954,7 @@ class Chat(Object):
self, self,
user_id: Union[int, str], user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None, privileges: "types.ChatPrivileges" = None,
title: Optional[str] = None, title: Optional[str] = "",
) -> bool: ) -> bool:
"""Bound method *promote_member* of :obj:`~pyrogram.types.Chat`. """Bound method *promote_member* of :obj:`~pyrogram.types.Chat`.

View file

@ -281,15 +281,20 @@ MAX_USER_ID_OLD = 2147483647
MAX_USER_ID = 999999999999 MAX_USER_ID = 999999999999
def get_raw_peer_id(peer: raw.base.Peer) -> Optional[int]: def get_raw_peer_id(
peer: Union[
raw.base.Peer,
raw.base.RequestedPeer
]
) -> Optional[int]:
"""Get the raw peer id from a Peer object""" """Get the raw peer id from a Peer object"""
if isinstance(peer, raw.types.PeerUser): if isinstance(peer, raw.types.PeerUser) or isinstance(peer, raw.types.RequestedPeerUser):
return peer.user_id return peer.user_id
if isinstance(peer, raw.types.PeerChat): if isinstance(peer, raw.types.PeerChat) or isinstance(peer, raw.types.RequestedPeerChat):
return peer.chat_id return peer.chat_id
if isinstance(peer, raw.types.PeerChannel): if isinstance(peer, raw.types.PeerChannel) or isinstance(peer, raw.types.RequestedPeerChannel):
return peer.channel_id return peer.channel_id
return None return None