From 2531e8371a1d0eb251a457d9e78c54fc526551b3 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:26:36 +0200 Subject: [PATCH 1/4] Add new parameters `business_connection_id` --- docs/substitutions/global.rst | 2 ++ telegram/_bot.py | 35 +++++++++++++++++++++++++++++++++++ telegram/ext/_extbot.py | 14 ++++++++++++++ tests/test_bot.py | 11 +++++++---- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/docs/substitutions/global.rst b/docs/substitutions/global.rst index 37edc74a446..4a75fc25ace 100644 --- a/docs/substitutions/global.rst +++ b/docs/substitutions/global.rst @@ -82,6 +82,8 @@ .. |business_id_str| replace:: Unique identifier of the business connection on behalf of which the message will be sent. +.. |business_id_str_edit| replace:: Unique identifier of the business connection on behalf of which the message to be edited was sent + .. |message_effect_id| replace:: Unique identifier of the message effect to be added to the message; for private chats only. .. |show_cap_above_med| replace:: :obj:`True`, if the caption must be shown above the message media. diff --git a/telegram/_bot.py b/telegram/_bot.py index ebc7817b9d2..d79d1e08800 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -2802,6 +2802,7 @@ async def edit_message_live_location( heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None, live_period: Optional[int] = None, + business_connection_id: Optional[str] = None, *, location: Optional[Location] = None, read_timeout: ODVInput[float] = DEFAULT_NONE, @@ -2849,6 +2850,9 @@ async def edit_message_live_location( remains unchanged .. versionadded:: 21.2. + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Keyword Args: location (:class:`telegram.Location`, optional): The location to send. @@ -2888,6 +2892,7 @@ async def edit_message_live_location( "editMessageLiveLocation", data, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -2901,6 +2906,7 @@ async def stop_message_live_location( message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -2920,6 +2926,9 @@ async def stop_message_live_location( :paramref:`message_id` are not specified. Identifier of the inline message. reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): An object for a new inline keyboard. + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Returns: :class:`telegram.Message`: On success, if edited message is not an inline message, the @@ -2935,6 +2944,7 @@ async def stop_message_live_location( "stopMessageLiveLocation", data, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -3945,6 +3955,7 @@ async def edit_message_text( reply_markup: Optional["InlineKeyboardMarkup"] = None, entities: Optional[Sequence["MessageEntity"]] = None, link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE, + business_connection_id: Optional[str] = None, *, disable_web_page_preview: Optional[bool] = None, read_timeout: ODVInput[float] = DEFAULT_NONE, @@ -3988,6 +3999,9 @@ async def edit_message_text( reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): An object for an inline keyboard. + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Keyword Args: disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in @@ -4029,6 +4043,7 @@ async def edit_message_text( reply_markup=reply_markup, parse_mode=parse_mode, link_preview_options=link_preview_options, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -4046,6 +4061,7 @@ async def edit_message_caption( parse_mode: ODVInput[str] = DEFAULT_NONE, caption_entities: Optional[Sequence["MessageEntity"]] = None, show_caption_above_media: Optional[bool] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -4080,6 +4096,9 @@ async def edit_message_caption( show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med| .. versionadded:: 21.3 + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Returns: :class:`telegram.Message`: On success, if edited message is not an inline message, the @@ -4103,6 +4122,7 @@ async def edit_message_caption( caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -4117,6 +4137,7 @@ async def edit_message_media( message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -4147,6 +4168,9 @@ async def edit_message_media( specified. Identifier of the inline message. reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): An object for an inline keyboard. + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Returns: :class:`telegram.Message`: On success, if edited message is not an inline message, the @@ -4166,6 +4190,7 @@ async def edit_message_media( "editMessageMedia", data, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -4179,6 +4204,7 @@ async def edit_message_reply_markup( message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -4202,6 +4228,9 @@ async def edit_message_reply_markup( specified. Identifier of the inline message. reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): An object for an inline keyboard. + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Returns: :class:`telegram.Message`: On success, if edited message is not an inline message, the @@ -4221,6 +4250,7 @@ async def edit_message_reply_markup( "editMessageReplyMarkup", data, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -7119,6 +7149,7 @@ async def stop_poll( chat_id: Union[int, str], message_id: int, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -7134,6 +7165,9 @@ async def stop_poll( message_id (:obj:`int`): Identifier of the original message with the poll. reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): An object for a new message inline keyboard. + business_connection_id (:obj:`str`, optional): |business_id_str_edit| + + .. versionadded:: NEXT.VERSION Returns: :class:`telegram.Poll`: On success, the stopped Poll is returned. @@ -7146,6 +7180,7 @@ async def stop_poll( "chat_id": chat_id, "message_id": message_id, "reply_markup": reply_markup, + "business_connection_id": business_connection_id, } result = await self._post( diff --git a/telegram/ext/_extbot.py b/telegram/ext/_extbot.py index 917e9d8ef97..67139a96379 100644 --- a/telegram/ext/_extbot.py +++ b/telegram/ext/_extbot.py @@ -767,6 +767,7 @@ async def stop_poll( chat_id: Union[int, str], message_id: int, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -780,6 +781,7 @@ async def stop_poll( chat_id=chat_id, message_id=message_id, reply_markup=self._replace_keyboard(reply_markup), + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -1511,6 +1513,7 @@ async def edit_message_caption( parse_mode: ODVInput[str] = DEFAULT_NONE, caption_entities: Optional[Sequence["MessageEntity"]] = None, show_caption_above_media: Optional[bool] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -1527,6 +1530,7 @@ async def edit_message_caption( reply_markup=reply_markup, parse_mode=parse_mode, caption_entities=caption_entities, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -1547,6 +1551,7 @@ async def edit_message_live_location( heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None, live_period: Optional[int] = None, + business_connection_id: Optional[str] = None, *, location: Optional[Location] = None, read_timeout: ODVInput[float] = DEFAULT_NONE, @@ -1568,6 +1573,7 @@ async def edit_message_live_location( proximity_alert_radius=proximity_alert_radius, live_period=live_period, location=location, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -1582,6 +1588,7 @@ async def edit_message_media( message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -1596,6 +1603,7 @@ async def edit_message_media( message_id=message_id, inline_message_id=inline_message_id, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -1609,6 +1617,7 @@ async def edit_message_reply_markup( message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -1622,6 +1631,7 @@ async def edit_message_reply_markup( message_id=message_id, inline_message_id=inline_message_id, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -1639,6 +1649,7 @@ async def edit_message_text( reply_markup: Optional["InlineKeyboardMarkup"] = None, entities: Optional[Sequence["MessageEntity"]] = None, link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE, + business_connection_id: Optional[str] = None, *, disable_web_page_preview: Optional[bool] = None, read_timeout: ODVInput[float] = DEFAULT_NONE, @@ -1657,6 +1668,7 @@ async def edit_message_text( disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup, entities=entities, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, @@ -3633,6 +3645,7 @@ async def stop_message_live_location( message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional["InlineKeyboardMarkup"] = None, + business_connection_id: Optional[str] = None, *, read_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE, @@ -3646,6 +3659,7 @@ async def stop_message_live_location( message_id=message_id, inline_message_id=inline_message_id, reply_markup=reply_markup, + business_connection_id=business_connection_id, read_timeout=read_timeout, write_timeout=write_timeout, connect_timeout=connect_timeout, diff --git a/tests/test_bot.py b/tests/test_bot.py index d22ea96db2e..08c5d4ea0fe 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -2171,14 +2171,17 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs): async def test_business_connection_id_argument(self, bot, monkeypatch): """We can't connect to a business acc, so we just test that the correct data is passed. - We also can't test every single method easily, so we just test one. Our linting will catch - any unused args with the others.""" + We also can't test every single method easily, so we just test a few. Our linting will + catch any unused args with the others.""" async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return request_data.parameters.get("business_connection_id") == 42 + assert request_data.parameters.get("business_connection_id") == 42 + return {} monkeypatch.setattr(bot.request, "post", make_assertion) - assert await bot.send_message(2, "text", business_connection_id=42) + + await bot.send_message(2, "text", business_connection_id=42) + await bot.stop_poll(chat_id=1, message_id=2, business_connection_id=42) async def test_message_effect_id_argument(self, bot, monkeypatch): """We can't test every single method easily, so we just test one. Our linting will catch From 72312fddc4d90ebed3f4534203d4ff9ae9d3b781 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:58:25 +0200 Subject: [PATCH 2/4] Update `Message` Shortcuts --- telegram/_message.py | 60 ++++++++++++++++++++++++++++++++++++++----- tests/test_message.py | 36 ++++++++++++++++---------- 2 files changed, 75 insertions(+), 21 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index b0605cd094d..539a1674b4c 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -3578,7 +3578,10 @@ async def edit_text( """Shortcut for:: await bot.edit_message_text( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see :meth:`telegram.Bot.edit_message_text`. @@ -3588,6 +3591,9 @@ async def edit_text( of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram. + .. versionchanged:: NEXT.VERSION + New also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the edited Message is returned, otherwise ``True`` is returned. @@ -3608,6 +3614,7 @@ async def edit_text( api_kwargs=api_kwargs, entities=entities, inline_message_id=None, + business_connection_id=self.business_connection_id, ) async def edit_caption( @@ -3627,7 +3634,10 @@ async def edit_caption( """Shortcut for:: await bot.edit_message_caption( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see @@ -3638,6 +3648,9 @@ async def edit_caption( of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram. + .. versionchanged:: NEXT.VERSION + New also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the edited Message is returned, otherwise ``True`` is returned. @@ -3657,6 +3670,7 @@ async def edit_caption( caption_entities=caption_entities, inline_message_id=None, show_caption_above_media=show_caption_above_media, + business_connection_id=self.business_connection_id, ) async def edit_media( @@ -3673,7 +3687,10 @@ async def edit_media( """Shortcut for:: await bot.edit_message_media( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see @@ -3684,6 +3701,9 @@ async def edit_media( of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram. + .. versionchanged:: NEXT.VERSION + New also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Message`: On success, if edited message is not an inline message, the edited Message is returned, otherwise ``True`` is returned. @@ -3700,6 +3720,7 @@ async def edit_media( pool_timeout=pool_timeout, api_kwargs=api_kwargs, inline_message_id=None, + business_connection_id=self.business_connection_id, ) async def edit_reply_markup( @@ -3715,7 +3736,10 @@ async def edit_reply_markup( """Shortcut for:: await bot.edit_message_reply_markup( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see @@ -3740,6 +3764,7 @@ async def edit_reply_markup( pool_timeout=pool_timeout, api_kwargs=api_kwargs, inline_message_id=None, + business_connection_id=self.business_connection_id, ) async def edit_live_location( @@ -3762,7 +3787,10 @@ async def edit_live_location( """Shortcut for:: await bot.edit_message_live_location( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see @@ -3773,6 +3801,9 @@ async def edit_live_location( of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram. + .. versionchanged:: NEXT.VERSION + New also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the edited Message is returned, otherwise :obj:`True` is returned. @@ -3794,6 +3825,7 @@ async def edit_live_location( proximity_alert_radius=proximity_alert_radius, live_period=live_period, inline_message_id=None, + business_connection_id=self.business_connection_id, ) async def stop_live_location( @@ -3809,7 +3841,10 @@ async def stop_live_location( """Shortcut for:: await bot.stop_message_live_location( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see @@ -3820,6 +3855,9 @@ async def stop_live_location( of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram. + .. versionchanged:: NEXT.VERSION + New also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the edited Message is returned, otherwise :obj:`True` is returned. @@ -3834,6 +3872,7 @@ async def stop_live_location( pool_timeout=pool_timeout, api_kwargs=api_kwargs, inline_message_id=None, + business_connection_id=self.business_connection_id, ) async def set_game_score( @@ -3964,11 +4003,17 @@ async def stop_poll( """Shortcut for:: await bot.stop_poll( - chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs + chat_id=message.chat_id, + message_id=message.message_id, + business_connection_id=message.business_connection_id, + *args, **kwargs ) For the documentation of the arguments, please see :meth:`telegram.Bot.stop_poll`. + .. versionchanged:: NEXT.VERSION + New also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Poll`: On success, the stopped Poll with the final results is returned. @@ -3983,6 +4028,7 @@ async def stop_poll( connect_timeout=connect_timeout, pool_timeout=pool_timeout, api_kwargs=api_kwargs, + business_connection_id=self.business_connection_id, ) async def pin( diff --git a/tests/test_message.py b/tests/test_message.py index 075d7089d3a..8bfc632769d 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -2347,7 +2347,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( Message.edit_text, Bot.edit_message_text, - ["chat_id", "message_id", "inline_message_id"], + ["chat_id", "message_id", "inline_message_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -2355,7 +2355,7 @@ async def make_assertion(*_, **kwargs): message.get_bot(), "edit_message_text", skip_params=["inline_message_id"], - shortcut_kwargs=["message_id", "chat_id"], + shortcut_kwargs=["message_id", "chat_id", "business_connection_id"], ) assert await check_defaults_handling(message.edit_text, message.get_bot()) @@ -2372,7 +2372,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( Message.edit_caption, Bot.edit_message_caption, - ["chat_id", "message_id", "inline_message_id"], + ["chat_id", "message_id", "inline_message_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -2380,7 +2380,7 @@ async def make_assertion(*_, **kwargs): message.get_bot(), "edit_message_caption", skip_params=["inline_message_id"], - shortcut_kwargs=["message_id", "chat_id"], + shortcut_kwargs=["message_id", "chat_id", "business_connection_id"], ) assert await check_defaults_handling(message.edit_caption, message.get_bot()) @@ -2397,7 +2397,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( Message.edit_media, Bot.edit_message_media, - ["chat_id", "message_id", "inline_message_id"], + ["chat_id", "message_id", "inline_message_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -2405,7 +2405,7 @@ async def make_assertion(*_, **kwargs): message.get_bot(), "edit_message_media", skip_params=["inline_message_id"], - shortcut_kwargs=["message_id", "chat_id"], + shortcut_kwargs=["message_id", "chat_id", "business_connection_id"], ) assert await check_defaults_handling(message.edit_media, message.get_bot()) @@ -2422,7 +2422,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( Message.edit_reply_markup, Bot.edit_message_reply_markup, - ["chat_id", "message_id", "inline_message_id"], + ["chat_id", "message_id", "inline_message_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -2430,7 +2430,7 @@ async def make_assertion(*_, **kwargs): message.get_bot(), "edit_message_reply_markup", skip_params=["inline_message_id"], - shortcut_kwargs=["message_id", "chat_id"], + shortcut_kwargs=["message_id", "chat_id", "business_connection_id"], ) assert await check_defaults_handling(message.edit_reply_markup, message.get_bot()) @@ -2449,7 +2449,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( Message.edit_live_location, Bot.edit_message_live_location, - ["chat_id", "message_id", "inline_message_id"], + ["chat_id", "message_id", "inline_message_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -2457,7 +2457,7 @@ async def make_assertion(*_, **kwargs): message.get_bot(), "edit_message_live_location", skip_params=["inline_message_id"], - shortcut_kwargs=["message_id", "chat_id"], + shortcut_kwargs=["message_id", "chat_id", "business_connection_id"], ) assert await check_defaults_handling(message.edit_live_location, message.get_bot()) @@ -2473,7 +2473,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( Message.stop_live_location, Bot.stop_message_live_location, - ["chat_id", "message_id", "inline_message_id"], + ["chat_id", "message_id", "inline_message_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -2481,7 +2481,7 @@ async def make_assertion(*_, **kwargs): message.get_bot(), "stop_message_live_location", skip_params=["inline_message_id"], - shortcut_kwargs=["message_id", "chat_id"], + shortcut_kwargs=["message_id", "chat_id", "business_connection_id"], ) assert await check_defaults_handling(message.stop_live_location, message.get_bot()) @@ -2561,9 +2561,17 @@ async def make_assertion(*_, **kwargs): return chat_id and message_id assert check_shortcut_signature( - Message.stop_poll, Bot.stop_poll, ["chat_id", "message_id"], [] + Message.stop_poll, + Bot.stop_poll, + ["chat_id", "message_id", "business_connection_id"], + [], + ) + assert await check_shortcut_call( + message.stop_poll, + message.get_bot(), + "stop_poll", + shortcut_kwargs=["business_connection_id"], ) - assert await check_shortcut_call(message.stop_poll, message.get_bot(), "stop_poll") assert await check_defaults_handling(message.stop_poll, message.get_bot()) monkeypatch.setattr(message.get_bot(), "stop_poll", make_assertion) From fb784fe4ee4a5cacad36b3b9375d87923d0d05d3 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 21 Jun 2024 20:41:02 +0200 Subject: [PATCH 3/4] Update `CallbackQuery` Shortcuts --- telegram/_callbackquery.py | 12 ++++++++++++ tests/test_callbackquery.py | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/telegram/_callbackquery.py b/telegram/_callbackquery.py index af89c784b10..4adf0e03ac1 100644 --- a/telegram/_callbackquery.py +++ b/telegram/_callbackquery.py @@ -260,6 +260,8 @@ async def edit_message_text( entities=entities, chat_id=None, message_id=None, + # inline messages can not be sent on behalf of a bcid + business_connection_id=None, ) return await self._get_message().edit_text( text=text, @@ -328,6 +330,8 @@ async def edit_message_caption( chat_id=None, message_id=None, show_caption_above_media=show_caption_above_media, + # inline messages can not be sent on behalf of a bcid + business_connection_id=None, ) return await self._get_message().edit_caption( caption=caption, @@ -388,6 +392,8 @@ async def edit_message_reply_markup( api_kwargs=api_kwargs, chat_id=None, message_id=None, + # inline messages can not be sent on behalf of a bcid + business_connection_id=None, ) return await self._get_message().edit_reply_markup( reply_markup=reply_markup, @@ -445,6 +451,8 @@ async def edit_message_media( api_kwargs=api_kwargs, chat_id=None, message_id=None, + # inline messages can not be sent on behalf of a bcid + business_connection_id=None, ) return await self._get_message().edit_media( media=media, @@ -516,6 +524,8 @@ async def edit_message_live_location( live_period=live_period, chat_id=None, message_id=None, + # inline messages can not be sent on behalf of a bcid + business_connection_id=None, ) return await self._get_message().edit_live_location( latitude=latitude, @@ -579,6 +589,8 @@ async def stop_message_live_location( api_kwargs=api_kwargs, chat_id=None, message_id=None, + # inline messages can not be sent on behalf of a bcid + business_connection_id=None, ) return await self._get_message().stop_live_location( reply_markup=reply_markup, diff --git a/tests/test_callbackquery.py b/tests/test_callbackquery.py index 66dc6856924..5e41b5993cf 100644 --- a/tests/test_callbackquery.py +++ b/tests/test_callbackquery.py @@ -68,8 +68,8 @@ class TestCallbackQueryWithoutRequest(TestCallbackQueryBase): @staticmethod def skip_params(callback_query: CallbackQuery): if callback_query.inline_message_id: - return {"message_id", "chat_id"} - return {"inline_message_id"} + return {"message_id", "chat_id", "business_connection_id"} + return {"inline_message_id", "business_connection_id"} @staticmethod def shortcut_kwargs(callback_query: CallbackQuery): @@ -178,7 +178,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( CallbackQuery.edit_message_text, Bot.edit_message_text, - ["inline_message_id", "message_id", "chat_id"], + ["inline_message_id", "message_id", "chat_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -210,7 +210,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( CallbackQuery.edit_message_caption, Bot.edit_message_caption, - ["inline_message_id", "message_id", "chat_id"], + ["inline_message_id", "message_id", "chat_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -242,7 +242,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( CallbackQuery.edit_message_reply_markup, Bot.edit_message_reply_markup, - ["inline_message_id", "message_id", "chat_id"], + ["inline_message_id", "message_id", "chat_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -274,7 +274,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( CallbackQuery.edit_message_media, Bot.edit_message_media, - ["inline_message_id", "message_id", "chat_id"], + ["inline_message_id", "message_id", "chat_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -308,7 +308,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( CallbackQuery.edit_message_live_location, Bot.edit_message_live_location, - ["inline_message_id", "message_id", "chat_id"], + ["inline_message_id", "message_id", "chat_id", "business_connection_id"], [], ) assert await check_shortcut_call( @@ -340,7 +340,7 @@ async def make_assertion(*_, **kwargs): assert check_shortcut_signature( CallbackQuery.stop_message_live_location, Bot.stop_message_live_location, - ["inline_message_id", "message_id", "chat_id"], + ["inline_message_id", "message_id", "chat_id", "business_connection_id"], [], ) assert await check_shortcut_call( From a46caf5022fcbb54a106ad74fa693c0e5f35efcc Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:12:37 +0200 Subject: [PATCH 4/4] Review --- telegram/_message.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index 539a1674b4c..b60ad1ce55a 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -3592,7 +3592,7 @@ async def edit_text( behaviour is undocumented and might be changed by Telegram. .. versionchanged:: NEXT.VERSION - New also passes :attr:`business_connection_id`. + Now also passes :attr:`business_connection_id`. Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the @@ -3649,7 +3649,7 @@ async def edit_caption( behaviour is undocumented and might be changed by Telegram. .. versionchanged:: NEXT.VERSION - New also passes :attr:`business_connection_id`. + Now also passes :attr:`business_connection_id`. Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the @@ -3702,7 +3702,7 @@ async def edit_media( behaviour is undocumented and might be changed by Telegram. .. versionchanged:: NEXT.VERSION - New also passes :attr:`business_connection_id`. + Now also passes :attr:`business_connection_id`. Returns: :class:`telegram.Message`: On success, if edited message is not an inline message, the @@ -3750,6 +3750,9 @@ async def edit_reply_markup( of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram. + .. versionchanged:: NEXT.VERSION + Now also passes :attr:`business_connection_id`. + Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the edited Message is returned, otherwise ``True`` is returned. @@ -3802,7 +3805,7 @@ async def edit_live_location( behaviour is undocumented and might be changed by Telegram. .. versionchanged:: NEXT.VERSION - New also passes :attr:`business_connection_id`. + Now also passes :attr:`business_connection_id`. Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the @@ -3856,7 +3859,7 @@ async def stop_live_location( behaviour is undocumented and might be changed by Telegram. .. versionchanged:: NEXT.VERSION - New also passes :attr:`business_connection_id`. + Now also passes :attr:`business_connection_id`. Returns: :class:`telegram.Message`: On success, if edited message is sent by the bot, the @@ -4012,7 +4015,7 @@ async def stop_poll( For the documentation of the arguments, please see :meth:`telegram.Bot.stop_poll`. .. versionchanged:: NEXT.VERSION - New also passes :attr:`business_connection_id`. + Now also passes :attr:`business_connection_id`. Returns: :class:`telegram.Poll`: On success, the stopped Poll with the final results is