From f0c3e5aec97fb2c86efaa84104ff5c3cb599d176 Mon Sep 17 00:00:00 2001 From: _run Date: Wed, 31 Jul 2024 21:46:05 +0500 Subject: [PATCH] Bot api 7.8 --- README.md | 2 +- telebot/__init__.py | 15 +++++++++++---- telebot/apihelper.py | 8 ++++++-- telebot/async_telebot.py | 14 ++++++++++---- telebot/asyncio_helper.py | 8 ++++++-- telebot/types.py | 10 ++++++++-- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 98f8c389a..10d75993b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

A simple, but extensible Python implementation for the Telegram Bot API.

Both synchronous and asynchronous.

-##

Supported Bot API version: 7.7! +##

Supported Bot API version: 7.8!

Official documentation

Official ru documentation

diff --git a/telebot/__init__.py b/telebot/__init__.py index b154d04ca..70d59ddde 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -4640,7 +4640,7 @@ def set_chat_description(self, chat_id: Union[int, str], description: Optional[s def pin_chat_message( self, chat_id: Union[int, str], message_id: int, - disable_notification: Optional[bool]=False) -> bool: + disable_notification: Optional[bool]=False, business_connection_id: Optional[str]=None) -> bool: """ Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -4659,15 +4659,19 @@ def pin_chat_message( to all group members about the new pinned message :type disable_notification: :obj:`bool` + :param business_connection_id: Unique identifier of the business connection + :type business_connection_id: :obj:`str` + :return: True on success. :rtype: :obj:`bool` """ disable_notification = self.disable_notification if (disable_notification is None) else disable_notification - return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification=disable_notification) + return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification=disable_notification, + business_connection_id=business_connection_id) - def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None) -> bool: + def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None, business_connection_id: Optional[str]=None) -> bool: """ Use this method to unpin specific pinned message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -4682,10 +4686,13 @@ def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int] :param message_id: Int: Identifier of a message to unpin :type message_id: :obj:`int` + :param business_connection_id: Unique identifier of the business connection + :type business_connection_id: :obj:`str` + :return: True on success. :rtype: :obj:`bool` """ - return apihelper.unpin_chat_message(self.token, chat_id, message_id) + return apihelper.unpin_chat_message(self.token, chat_id, message_id, business_connection_id=business_connection_id) def unpin_all_chat_messages(self, chat_id: Union[int, str]) -> bool: diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 0bcb80a96..2ee86abab 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1386,19 +1386,23 @@ def set_chat_description(token, chat_id, description): return _make_request(token, method_url, params=payload, method='post') -def pin_chat_message(token, chat_id, message_id, disable_notification=None): +def pin_chat_message(token, chat_id, message_id, disable_notification=None, business_connection_id=None): method_url = 'pinChatMessage' payload = {'chat_id': chat_id, 'message_id': message_id} if disable_notification is not None: payload['disable_notification'] = disable_notification + if business_connection_id: + payload['business_connection_id'] = business_connection_id return _make_request(token, method_url, params=payload, method='post') -def unpin_chat_message(token, chat_id, message_id): +def unpin_chat_message(token, chat_id, message_id, business_connection_id=None): method_url = 'unpinChatMessage' payload = {'chat_id': chat_id} if message_id: payload['message_id'] = message_id + if business_connection_id: + payload['business_connection_id'] = business_connection_id return _make_request(token, method_url, params=payload, method='post') diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index d50cbf7e0..e702487f3 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -6023,7 +6023,7 @@ async def set_chat_description(self, chat_id: Union[int, str], description: Opti async def pin_chat_message( self, chat_id: Union[int, str], message_id: int, - disable_notification: Optional[bool]=False) -> bool: + disable_notification: Optional[bool]=False, business_connection_id: Optional[str]=None) -> bool: """ Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -6042,14 +6042,17 @@ async def pin_chat_message( to all group members about the new pinned message :type disable_notification: :obj:`bool` + :param business_connection_id: Unique identifier of the business connection + :type business_connection_id: :obj:`str` + :return: True on success. :rtype: :obj:`bool` """ disable_notification = self.disable_notification if (disable_notification is None) else disable_notification - return await asyncio_helper.pin_chat_message(self.token, chat_id, message_id, disable_notification) + return await asyncio_helper.pin_chat_message(self.token, chat_id, message_id, disable_notification, business_connection_id) - async def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None) -> bool: + async def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None, business_connection_id: Optional[str]=None) -> bool: """ Use this method to unpin specific pinned message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -6064,10 +6067,13 @@ async def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optiona :param message_id: Int: Identifier of a message to unpin :type message_id: :obj:`int` + :param business_connection_id: Unique identifier of the business connection + :type business_connection_id: :obj:`str` + :return: True on success. :rtype: :obj:`bool` """ - return await asyncio_helper.unpin_chat_message(self.token, chat_id, message_id) + return await asyncio_helper.unpin_chat_message(self.token, chat_id, message_id, business_connection_id) async def unpin_all_chat_messages(self, chat_id: Union[int, str]) -> bool: """ diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index b70508a2a..fa14f6123 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -1365,19 +1365,23 @@ async def set_chat_description(token, chat_id, description): return await _process_request(token, method_url, params=payload, method='post') -async def pin_chat_message(token, chat_id, message_id, disable_notification=None): +async def pin_chat_message(token, chat_id, message_id, disable_notification=None, business_connection_id=None): method_url = 'pinChatMessage' payload = {'chat_id': chat_id, 'message_id': message_id} if disable_notification is not None: payload['disable_notification'] = disable_notification + if business_connection_id: + payload['business_connection_id'] = business_connection_id return await _process_request(token, method_url, params=payload, method='post') -async def unpin_chat_message(token, chat_id, message_id): +async def unpin_chat_message(token, chat_id, message_id, business_connection_id=None): method_url = 'unpinChatMessage' payload = {'chat_id': chat_id} if message_id: payload['message_id'] = message_id + if business_connection_id: + payload['business_connection_id'] = business_connection_id return await _process_request(token, method_url, params=payload, method='post') diff --git a/telebot/types.py b/telebot/types.py index 9055091e9..c5abb13d4 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -494,6 +494,9 @@ class User(JsonDeserializable, Dictionaryable, JsonSerializable): :param can_connect_to_business: Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe. :type can_connect_to_business: :obj:`bool` + :param has_main_web_app: Optional. True, if the bot has a main Web App. Returned only in getMe. + :type has_main_web_app: :obj:`bool` + :return: Instance of the class :rtype: :class:`telebot.types.User` """ @@ -506,7 +509,8 @@ def de_json(cls, json_string): # noinspection PyShadowingBuiltins def __init__(self, id, is_bot, first_name, last_name=None, username=None, language_code=None, can_join_groups=None, can_read_all_group_messages=None, supports_inline_queries=None, - is_premium=None, added_to_attachment_menu=None, can_connect_to_business=None, **kwargs): + is_premium=None, added_to_attachment_menu=None, can_connect_to_business=None, + has_main_web_app=None, **kwargs): self.id: int = id self.is_bot: bool = is_bot self.first_name: str = first_name @@ -519,6 +523,7 @@ def __init__(self, id, is_bot, first_name, last_name=None, username=None, langua self.is_premium: bool = is_premium self.added_to_attachment_menu: bool = added_to_attachment_menu self.can_connect_to_business: bool = can_connect_to_business + self.has_main_web_app: bool = has_main_web_app @property def full_name(self): @@ -545,7 +550,8 @@ def to_dict(self): 'supports_inline_queries': self.supports_inline_queries, 'is_premium': self.is_premium, 'added_to_attachment_menu': self.added_to_attachment_menu, - 'can_connect_to_business': self.can_connect_to_business} + 'can_connect_to_business': self.can_connect_to_business, + 'has_main_web_app': self.has_main_web_app} # noinspection PyShadowingBuiltins