From e55b0971f65f74738c17d264291398da178101a5 Mon Sep 17 00:00:00 2001 From: _run Date: Sun, 17 Nov 2024 18:01:48 +0400 Subject: [PATCH] Added the method setUserEmojiStatus. The user must allow the bot to manage their emoji status. --- telebot/__init__.py | 20 ++++++++++++++++++++ telebot/apihelper.py | 10 ++++++++++ telebot/async_telebot.py | 20 ++++++++++++++++++++ telebot/asyncio_helper.py | 10 ++++++++++ 4 files changed, 60 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index 142d71193..494c0ec5d 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1512,6 +1512,26 @@ def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None, apihelper.get_user_profile_photos(self.token, user_id, offset=offset, limit=limit) ) + def set_user_emoji_status(self, user_id: int, emoji_status_custom_emoji_id: Optional[str]=None, emoji_status_expiration_date: Optional[int]=None) -> bool: + """ + Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. Returns True on success. + + Telegram documentation: https://core.telegram.org/bots/api#setuseremojistatus + + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + + :param emoji_status_custom_emoji_id: Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status. + :type emoji_status_custom_emoji_id: :obj:`str` + + :param emoji_status_expiration_date: Expiration date of the emoji status, if any + :type emoji_status_expiration_date: :obj:`int` + + :return: :obj:`bool` + """ + return apihelper.set_user_emoji_status( + self.token, user_id, emoji_status_custom_emoji_id=emoji_status_custom_emoji_id, emoji_status_expiration_date=emoji_status_expiration_date) + def get_chat(self, chat_id: Union[int, str]) -> types.ChatFullInfo: """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 69fa5bf4f..68623922f 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -341,6 +341,16 @@ def get_user_profile_photos(token, user_id, offset=None, limit=None): payload['limit'] = limit return _make_request(token, method_url, params=payload) + +def set_user_emoji_status(token, user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None): + method_url = r'setUserEmojiStatus' + payload = {'user_id': user_id} + if emoji_status_custom_emoji_id: + payload['emoji_status_custom_emoji_id'] = emoji_status_custom_emoji_id + if emoji_status_expiration_date: + payload['emoji_status_expiration_date'] = emoji_status_expiration_date + return _make_request(token, method_url, params=payload) + def set_message_reaction(token, chat_id, message_id, reaction=None, is_big=None): method_url = r'setMessageReaction' payload = {'chat_id': chat_id, 'message_id': message_id} diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index f82c7238e..6ab489756 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -2987,6 +2987,26 @@ async def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None """ result = await asyncio_helper.get_user_profile_photos(self.token, user_id, offset, limit) return types.UserProfilePhotos.de_json(result) + + async def set_user_emoji_status(self, user_id: int, emoji_status_custom_emoji_id: Optional[str]=None, emoji_status_expiration_date: Optional[int]=None) -> bool: + """ + Use this method to change the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. + + Telegram documentation: https://core.telegram.org/bots/api#setuseremojistatus + + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + + :param emoji_status_custom_emoji_id: Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status. + :type emoji_status_custom_emoji_id: :obj:`str`, optional + + :param emoji_status_expiration_date: Expiration date of the emoji status, if any + :type emoji_status_expiration_date: :obj:`int`, optional + + :return: :obj:`bool` + """ + result = await asyncio_helper.set_user_emoji_status(self.token, user_id, emoji_status_custom_emoji_id, emoji_status_expiration_date) + return result async def get_chat(self, chat_id: Union[int, str]) -> types.ChatFullInfo: """ diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 3e1a68a1d..41d94d0bd 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -325,6 +325,16 @@ async def get_user_profile_photos(token, user_id, offset=None, limit=None): payload['limit'] = limit return await _process_request(token, method_url, params=payload) + +async def set_user_emoji_status(token, user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None): + method_url = r'setUserEmojiStatus' + payload = {'user_id': user_id} + if emoji_status_custom_emoji_id: + payload['emoji_status_custom_emoji_id'] = emoji_status_custom_emoji_id + if emoji_status_expiration_date: + payload['emoji_status_expiration_date'] = emoji_status_expiration_date + return await _process_request(token, method_url, params=payload) + async def set_message_reaction(token, chat_id, message_id, reaction=None, is_big=None): method_url = r'setMessageReaction' payload = {'chat_id': chat_id, 'message_id': message_id}