diff --git a/telebot/__init__.py b/telebot/__init__.py index a274d2272..bb33f55b5 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -6249,6 +6249,32 @@ def delete_sticker_set(self, name:str) -> bool: :rtype: :obj:`bool` """ return apihelper.delete_sticker_set(self.token, name) + + def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_parse_mode: Optional[str]=None, text_entities: Optional[List[types.MessageEntity]]=None) -> bool: + """ + Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success. + + Telegram documentation: https://core.telegram.org/bots/api#sendgift + + :param user_id: Unique identifier of the target user that will receive the gift + :type user_id: :obj:`int` + + :param gift_id: Identifier of the gift + :type gift_id: :obj:`str` + + :param text: Text that will be shown along with the gift; 0-255 characters + :type text: :obj:`str` + + :param text_parse_mode: Mode for parsing entities in the text. See formatting options for more details. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + :type text_parse_mode: :obj:`str` + + :param text_entities: A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + :type text_entities: :obj:`list` of :obj:`types.MessageEntity` + + :return: Returns True on success. + :rtype: :obj:`bool` + """ + return apihelper.send_gift(self.token, user_id, gift_id, text=text, text_parse_mode=text_parse_mode, text_entities=text_entities) def get_available_gifts(self) -> types.Gifts: """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 83606f746..5ea37c4fd 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1929,6 +1929,17 @@ def get_available_gifts(token): return _make_request(token, method_url) +def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None): + method_url = 'sendGift' + payload = {'user_id': user_id, 'gift_id': gift_id} + if text: + payload['text'] = text + if text_parse_mode: + payload['text_parse_mode'] = text_parse_mode + if text_entities: + payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities)) + return _make_request(token, method_url, params=payload, method='post') + def set_sticker_emoji_list(token, sticker, emoji_list): method_url = 'setStickerEmojiList' payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)} diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 60719477d..7f50b1c86 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -7706,6 +7706,32 @@ async def delete_sticker_set(self, name:str) -> bool: """ return await asyncio_helper.delete_sticker_set(self.token, name) + + async def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_parse_mode: Optional[str]=None, text_entities: Optional[List[types.MessageEntity]]=None) -> bool: + """ + Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success. + + Telegram documentation: https://core.telegram.org/bots/api#sendgift + + :param user_id: Unique identifier of the target user that will receive the gift + :type user_id: :obj:`int` + + :param gift_id: Identifier of the gift + :type gift_id: :obj:`str` + + :param text: Text that will be shown along with the gift; 0-255 characters + :type text: :obj:`str` + + :param text_parse_mode: Mode for parsing entities in the text. See formatting options for more details. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + :type text_parse_mode: :obj:`str` + + :param text_entities: A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + :type text_entities: :obj:`list` of :obj:`types.MessageEntity` + + :return: Returns True on success. + :rtype: :obj:`bool` + """ + return await asyncio_helper.send_gift(self.token, user_id, gift_id, text, text_parse_mode, text_entities) async def get_available_gifts(self) -> types.Gifts: """ diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 47a1da1dc..56604c750 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -1916,6 +1916,17 @@ async def delete_sticker_set(token, name): payload = {'name': name} return await _process_request(token, method_url, params=payload, method='post') +async def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None): + method_url = 'sendGift' + payload = {'user_id': user_id, 'gift_id': gift_id} + if text: + payload['text'] = text + if text_parse_mode: + payload['text_parse_mode'] = text_parse_mode + if text_entities: + payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities)) + return await _process_request(token, method_url, params=payload, method='post') + async def get_available_gifts(token): method_url = 'getAvailableGifts' return await _process_request(token, method_url)