diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index f6479d74..c2411639 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -374,6 +374,10 @@ def pyrogram_api():
set_bot_info
get_collectible_item_info
""",
+ business="""
+ Telegram Business
+ get_business_connection
+ """,
authorization="""
Authorization
connect
diff --git a/compiler/docs/template/methods.rst b/compiler/docs/template/methods.rst
index e69a89c2..c48e37ac 100644
--- a/compiler/docs/template/methods.rst
+++ b/compiler/docs/template/methods.rst
@@ -112,6 +112,19 @@ Stickers
{stickers}
+Telegram Business
+-------------
+
+.. autosummary::
+ :nosignatures:
+
+ {business}
+
+.. toctree::
+ :hidden:
+
+ {business}
+
Users
-----
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 6a9e4b04..dca63d41 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -18,7 +18,7 @@
# along with Pyrofork. If not, see .
__fork_name__ = "PyroFork"
-__version__ = "2.3.32"
+__version__ = "2.3.36"
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
__copyright__ = "Copyright (C) 2022-present Mayuri-Chan "
diff --git a/pyrogram/client.py b/pyrogram/client.py
index 761fd1b0..a6dffe2c 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -203,6 +203,14 @@ class Client(Methods):
A value that is too high may result in network related issues.
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*):
The platform where this client is running.
Defaults to 'other'
@@ -224,6 +232,7 @@ class Client(Methods):
UPDATES_WATCHDOG_INTERVAL = 15 * 60
MAX_CONCURRENT_TRANSMISSIONS = 1
+ MAX_CACHE_SIZE = 10000
mimetypes = MimeTypes()
mimetypes.readfp(StringIO(mime_types))
@@ -259,7 +268,9 @@ class Client(Methods):
sleep_threshold: int = Session.SLEEP_THRESHOLD,
hide_password: Optional[bool] = False,
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__()
@@ -292,6 +303,9 @@ class Client(Methods):
self.hide_password = hide_password
self.max_concurrent_transmissions = max_concurrent_transmissions
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")
@@ -341,7 +355,8 @@ class Client(Methods):
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.
# This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again
diff --git a/pyrogram/methods/__init__.py b/pyrogram/methods/__init__.py
index e788ab46..2da4627c 100644
--- a/pyrogram/methods/__init__.py
+++ b/pyrogram/methods/__init__.py
@@ -30,6 +30,7 @@ from .pyromod import Pyromod
from .stickers import Stickers
from .users import Users
from .utilities import Utilities
+from .business import TelegramBusiness
class Methods(
@@ -46,5 +47,6 @@ class Methods(
Decorators,
Utilities,
InviteLinks,
+ TelegramBusiness,
):
pass
diff --git a/pyrogram/methods/business/__init__.py b/pyrogram/methods/business/__init__.py
new file mode 100644
index 00000000..eda3b7f0
--- /dev/null
+++ b/pyrogram/methods/business/__init__.py
@@ -0,0 +1,25 @@
+# Pyrogram - Telegram MTProto API Client Library for Python
+# Copyright (C) 2017-present Dan
+#
+# 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 .
+
+from .get_business_connection import GetBusinessConnection
+
+
+class TelegramBusiness(
+ GetBusinessConnection,
+):
+ pass
diff --git a/pyrogram/methods/business/get_business_connection.py b/pyrogram/methods/business/get_business_connection.py
new file mode 100644
index 00000000..5fe7dc56
--- /dev/null
+++ b/pyrogram/methods/business/get_business_connection.py
@@ -0,0 +1,58 @@
+# Pyrogram - Telegram MTProto API Client Library for Python
+# Copyright (C) 2017-present Dan
+#
+# 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 .
+
+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
+ )
diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py
index 25f06366..c5ef508e 100644
--- a/pyrogram/methods/messages/edit_message_caption.py
+++ b/pyrogram/methods/messages/edit_message_caption.py
@@ -66,7 +66,8 @@ class EditMessageCaption:
An InlineKeyboardMarkup object.
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:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned.
diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py
index d14fcff7..c1c2a4e1 100644
--- a/pyrogram/methods/messages/edit_message_media.py
+++ b/pyrogram/methods/messages/edit_message_media.py
@@ -28,8 +28,6 @@ from pyrogram import types
from pyrogram import utils
from pyrogram.file_id import FileType
-from .inline_session import get_session
-
class EditMessageMedia:
async def edit_message_media(
@@ -73,7 +71,8 @@ class EditMessageMedia:
Inverts the position of the media and caption.
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:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned.
@@ -288,24 +287,13 @@ class EditMessageMedia:
entities=entities,
invert_media=invert_media
)
- session = None
- business_connection = None
- 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(
+ if business_connection_id is not None:
+ r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
- query=rpc,
- connection_id=business_connection_id
+ connection_id=business_connection_id,
+ query=rpc
)
)
- # await session.stop()
else:
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.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
- )
diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py
index 43717478..67349b3d 100644
--- a/pyrogram/methods/messages/edit_message_reply_markup.py
+++ b/pyrogram/methods/messages/edit_message_reply_markup.py
@@ -20,9 +20,8 @@
from typing import Union
import pyrogram
-from pyrogram import raw, types
-
-from .inline_session import get_session
+from pyrogram import raw
+from pyrogram import types
class EditMessageReplyMarkup:
@@ -51,7 +50,8 @@ class EditMessageReplyMarkup:
An InlineKeyboardMarkup object.
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:
:obj:`~pyrogram.types.Message`: On success, the edited message is returned.
@@ -70,54 +70,22 @@ class EditMessageReplyMarkup:
rpc = raw.functions.messages.EditMessage(
peer=await self.resolve_peer(chat_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
- business_connection = None
- 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(
+ if business_connection_id is not None:
+ r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
- query=rpc,
- connection_id=business_connection_id
+ connection_id=business_connection_id,
+ query=rpc
)
)
- # await session.stop()
else:
r = await self.invoke(rpc)
for i in r.updates:
- if isinstance(
- i,
- (
- raw.types.UpdateEditMessage,
- raw.types.UpdateEditChannelMessage
- )
- ):
+ if isinstance(i, (raw.types.UpdateEditMessage, raw.types.UpdateEditChannelMessage)):
return await types.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{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
- )
diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py
index bc0a30df..31f4eb47 100644
--- a/pyrogram/methods/messages/edit_message_text.py
+++ b/pyrogram/methods/messages/edit_message_text.py
@@ -72,7 +72,8 @@ class EditMessageText:
An InlineKeyboardMarkup object.
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:
: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,
**await utils.parse_text_entities(self, text, parse_mode, entities)
)
- session = None
- business_connection = None
- 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(
+ if business_connection_id is not None:
+ r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
- query=rpc,
- connection_id=business_connection_id
+ connection_id=business_connection_id,
+ query=rpc
)
)
- # await session.stop()
else:
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.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
- )
diff --git a/pyrogram/methods/messages/inline_session.py b/pyrogram/methods/messages/inline_session.py
index 4f09bc88..ed6e9980 100644
--- a/pyrogram/methods/messages/inline_session.py
+++ b/pyrogram/methods/messages/inline_session.py
@@ -40,6 +40,9 @@ async def get_session(client: "pyrogram.Client", dc_id: int):
await session.start()
+ if dc_id == await client.storage.dc_id():
+ return session
+
for _ in range(3):
exported_auth = await client.invoke(
raw.functions.auth.ExportAuthorization(
diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py
index c95ec0b5..8a20c8ab 100644
--- a/pyrogram/methods/messages/stop_poll.py
+++ b/pyrogram/methods/messages/stop_poll.py
@@ -20,9 +20,8 @@
from typing import Union
import pyrogram
-from pyrogram import raw, types
-
-from .inline_session import get_session
+from pyrogram import raw
+from pyrogram import types
class StopPoll:
@@ -53,7 +52,7 @@ class StopPoll:
An InlineKeyboardMarkup object.
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:
: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
)
- session = None
- business_connection = None
- 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(
+ if business_connection_id is not None:
+ r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
- query=rpc,
- connection_id=business_connection_id
+ connection_id=business_connection_id,
+ query=rpc
)
)
- # await session.stop()
else:
r = await self.invoke(rpc)
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index e023d88b..40625cfd 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -33,7 +33,7 @@ from pyrogram.errors import (
RPCError, InternalServerError, AuthKeyDuplicated,
FloodWait, FloodPremiumWait,
ServiceUnavailable, BadMsgNotification,
- SecurityCheckMismatch
+ SecurityCheckMismatch, Unauthorized
)
from pyrogram.raw.all import layer
from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts
@@ -309,6 +309,12 @@ class Session:
if 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(
"Server sent transport error: %s (%s)",
error_code, Session.TRANSPORT_ERRORS.get(error_code, "unknown error")
diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py
index cc709862..1491497b 100644
--- a/pyrogram/types/bots_and_keyboards/callback_query.py
+++ b/pyrogram/types/bots_and_keyboards/callback_query.py
@@ -107,11 +107,10 @@ class CallbackQuery(Object, Update):
client,
callback_query.message,
users,
- chats,
+ {},
is_scheduled=False,
replies=0,
- business_connection_id=callback_query.connection_id,
- raw_reply_to_message=getattr(callback_query, "reply_to_message", None)
+ business_connection_id=callback_query.connection_id
)
# 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.
@@ -182,7 +181,8 @@ class CallbackQuery(Object, Update):
text: str,
parse_mode: Optional["enums.ParseMode"] = 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]:
"""Edit the text of messages attached to callback queries.
@@ -202,6 +202,10 @@ class CallbackQuery(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
: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).
@@ -217,7 +221,7 @@ class CallbackQuery(Object, Update):
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup,
- business_connection_id=self.message.business_connection_id
+ business_connection_id=getattr(self.message, "business_connection_id", None)
)
else:
return await self._client.edit_inline_text(
@@ -232,7 +236,8 @@ class CallbackQuery(Object, Update):
self,
caption: str,
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]:
"""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*):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
: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).
@@ -256,12 +265,22 @@ class CallbackQuery(Object, Update):
Raises:
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(
self,
media: "types.InputMedia",
- reply_markup: "types.InlineKeyboardMarkup" = None
+ reply_markup: "types.InlineKeyboardMarkup" = None,
+ business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]:
"""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*):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
: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).
@@ -287,7 +310,11 @@ class CallbackQuery(Object, Update):
message_id=self.message.id,
media=media,
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:
return await self._client.edit_inline_media(
@@ -298,7 +325,8 @@ class CallbackQuery(Object, Update):
async def edit_message_reply_markup(
self,
- reply_markup: "types.InlineKeyboardMarkup" = None
+ reply_markup: "types.InlineKeyboardMarkup" = None,
+ business_connection_id: Optional[str] = None
) -> Union["types.Message", bool]:
"""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`):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
: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).
@@ -320,7 +352,11 @@ class CallbackQuery(Object, Update):
chat_id=self.message.chat.id,
message_id=self.message.id,
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:
return await self._client.edit_inline_reply_markup(
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index f1b56b37..d88a78bc 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -4066,7 +4066,8 @@ class Message(Object, Update):
entities: List["types.MessageEntity"] = None,
disable_web_page_preview: bool = None,
invert_media: bool = None,
- reply_markup: "types.InlineKeyboardMarkup" = None
+ reply_markup: "types.InlineKeyboardMarkup" = None,
+ business_connection_id: str = None
) -> "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*):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
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,
invert_media=invert_media,
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
@@ -4133,7 +4138,8 @@ class Message(Object, Update):
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None,
invert_media: bool = None,
- reply_markup: "types.InlineKeyboardMarkup" = None
+ reply_markup: "types.InlineKeyboardMarkup" = None,
+ business_connection_id: str = None
) -> "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*):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
On success, the edited :obj:`~pyrogram.types.Message` is returned.
@@ -4182,14 +4192,16 @@ class Message(Object, Update):
parse_mode=parse_mode,
caption_entities=caption_entities,
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(
self,
media: "types.InputMedia",
invert_media: bool = None,
- reply_markup: "types.InlineKeyboardMarkup" = None
+ reply_markup: "types.InlineKeyboardMarkup" = None,
+ business_connection_id: str = None
) -> "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*):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
On success, the edited :obj:`~pyrogram.types.Message` is returned.
@@ -4230,10 +4246,14 @@ class Message(Object, Update):
media=media,
invert_media=invert_media,
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`.
Use as a shortcut for:
@@ -4255,6 +4275,10 @@ class Message(Object, Update):
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`):
An InlineKeyboardMarkup object.
+ business_connection_id (``str``, *optional*):
+ Unique identifier of the business connection.
+ for business bots only.
+
Returns:
On success, if edited message is sent by the bot, the edited
:obj:`~pyrogram.types.Message` is returned, otherwise True is returned.
@@ -4266,7 +4290,7 @@ class Message(Object, Update):
chat_id=self.chat.id,
message_id=self.id,
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(
diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py
index 5c04cc79..c423e8b3 100644
--- a/pyrogram/types/messages_and_media/poll.py
+++ b/pyrogram/types/messages_and_media/poll.py
@@ -237,7 +237,7 @@ class Poll(Object, Update):
An InlineKeyboardMarkup object.
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:
.. code-block:: python
@@ -255,5 +255,5 @@ class Poll(Object, Update):
chat_id=self.chat.id,
message_id=self.id,
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
)
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index 380f4591..e3e7ee0a 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -954,7 +954,7 @@ class Chat(Object):
self,
user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None,
- title: Optional[str] = None,
+ title: Optional[str] = "",
) -> bool:
"""Bound method *promote_member* of :obj:`~pyrogram.types.Chat`.
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index 6b1857d7..bc0d1421 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -281,15 +281,20 @@ MAX_USER_ID_OLD = 2147483647
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"""
- if isinstance(peer, raw.types.PeerUser):
+ if isinstance(peer, raw.types.PeerUser) or isinstance(peer, raw.types.RequestedPeerUser):
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
- if isinstance(peer, raw.types.PeerChannel):
+ if isinstance(peer, raw.types.PeerChannel) or isinstance(peer, raw.types.RequestedPeerChannel):
return peer.channel_id
return None