Skip to content

Commit 3d740ff

Browse files
Added the classes Gift and Gifts and the method getAvailableGifts, allowing bots to get all gifts available for sending.
1 parent bee6bab commit 3d740ff

5 files changed

Lines changed: 96 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6249,7 +6249,19 @@ def delete_sticker_set(self, name:str) -> bool:
62496249
:rtype: :obj:`bool`
62506250
"""
62516251
return apihelper.delete_sticker_set(self.token, name)
6252+
6253+
def get_available_gifts(self) -> types.Gifts:
6254+
"""
6255+
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
6256+
6257+
Telegram documentation: https://core.telegram.org/bots/api#getavailablegifts
62526258
6259+
:return: On success, a Gifts object is returned.
6260+
:rtype: :class:`telebot.types.Gifts`
6261+
"""
6262+
return types.Gifts.de_json(
6263+
apihelper.get_available_gifts(self.token)
6264+
)
62536265

62546266
def replace_sticker_in_set(self, user_id: int, name: str, old_sticker: str, sticker: types.InputSticker) -> bool:
62556267
"""

telebot/apihelper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,11 @@ def delete_sticker_set(token, name):
19241924
return _make_request(token, method_url, params=payload, method='post')
19251925

19261926

1927+
def get_available_gifts(token):
1928+
method_url = 'getAvailableGifts'
1929+
return _make_request(token, method_url)
1930+
1931+
19271932
def set_sticker_emoji_list(token, sticker, emoji_list):
19281933
method_url = 'setStickerEmojiList'
19291934
payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)}

telebot/async_telebot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7707,6 +7707,18 @@ async def delete_sticker_set(self, name:str) -> bool:
77077707

77087708
return await asyncio_helper.delete_sticker_set(self.token, name)
77097709

7710+
async def get_available_gifts(self) -> types.Gifts:
7711+
"""
7712+
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
7713+
7714+
Telegram documentation: https://core.telegram.org/bots/api#getavailablegifts
7715+
7716+
:return: On success, a Gifts object is returned.
7717+
:rtype: :class:`telebot.types.Gifts`
7718+
"""
7719+
7720+
return types.Gifts.de_json(await asyncio_helper.get_available_gifts(self.token))
7721+
77107722
async def replace_sticker_in_set(self, user_id: int, name: str, old_sticker: str, sticker: types.InputSticker) -> bool:
77117723
"""
77127724
Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet,

telebot/asyncio_helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,10 @@ async def delete_sticker_set(token, name):
19161916
payload = {'name': name}
19171917
return await _process_request(token, method_url, params=payload, method='post')
19181918

1919+
async def get_available_gifts(token):
1920+
method_url = 'getAvailableGifts'
1921+
return await _process_request(token, method_url)
1922+
19191923
async def set_custom_emoji_sticker_set_thumbnail(token, name, custom_emoji_id=None):
19201924
method_url = 'setCustomEmojiStickerSetThumbnail'
19211925
payload = {'name': name}

telebot/types.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11025,3 +11025,66 @@ def de_json(cls, json_string):
1102511025
obj = cls.check_json(json_string)
1102611026
return cls(**obj)
1102711027

11028+
11029+
class Gift(JsonDeserializable):
11030+
"""
11031+
This object represents a gift that can be sent by the bot.
11032+
11033+
Telegram documentation: https://core.telegram.org/bots/api#gift
11034+
11035+
:param id: Unique identifier of the gift
11036+
:type id: :obj:`str`
11037+
11038+
:param sticker: The sticker that represents the gift
11039+
:type sticker: :class:`Sticker`
11040+
11041+
:param star_count: The number of Telegram Stars that must be paid to send the sticker
11042+
:type star_count: :obj:`int`
11043+
11044+
:param total_count: Optional. The total number of the gifts of this type that can be sent; for limited gifts only
11045+
:type total_count: :obj:`int`
11046+
11047+
:param remaining_count: Optional. The number of remaining gifts of this type that can be sent; for limited gifts only
11048+
:type remaining_count: :obj:`int`
11049+
11050+
:return: Instance of the class
11051+
:rtype: :class:`Gift`
11052+
"""
11053+
11054+
def __init__(self, id, sticker, star_count, total_count=None, remaining_count=None, **kwargs):
11055+
self.id: str = id
11056+
self.sticker: Sticker = sticker
11057+
self.star_count: int = star_count
11058+
self.total_count: Optional[int] = total_count
11059+
self.remaining_count: Optional[int] = remaining_count
11060+
11061+
@classmethod
11062+
def de_json(cls, json_string):
11063+
if json_string is None: return None
11064+
obj = cls.check_json(json_string)
11065+
obj['sticker'] = Sticker.de_json(obj['sticker'])
11066+
return cls(**obj)
11067+
11068+
class Gifts(JsonDeserializable):
11069+
"""
11070+
This object represent a list of gifts.
11071+
11072+
Telegram documentation: https://core.telegram.org/bots/api#gifts
11073+
11074+
:param gifts: The list of gifts
11075+
:type gifts: :obj:`list` of :class:`Gift`
11076+
11077+
:return: Instance of the class
11078+
:rtype: :class:`Gifts`
11079+
"""
11080+
11081+
def __init__(self, gifts, **kwargs):
11082+
self.gifts: List[Gift] = gifts
11083+
11084+
@classmethod
11085+
def de_json(cls, json_string):
11086+
if json_string is None: return None
11087+
obj = cls.check_json(json_string)
11088+
obj['gifts'] = [Gift.de_json(gift) for gift in obj['gifts']]
11089+
return cls(**obj)
11090+

0 commit comments

Comments
 (0)