Skip to content

Commit 0249aef

Browse files
Added the class UserProfileAudios and the method getUserProfileAudios, allowing bots to fetch a list of audios added to the profile of a user.
1 parent 84012c4 commit 0249aef

5 files changed

Lines changed: 91 additions & 1 deletion

File tree

telebot/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,29 @@ def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None,
15121512
apihelper.get_user_profile_photos(self.token, user_id, offset=offset, limit=limit)
15131513
)
15141514

1515+
def get_user_profile_audios(self, user_id: int, offset: Optional[int]=None,
1516+
limit: Optional[int]=None) -> types.UserProfileAudios:
1517+
"""
1518+
Use this method to get a list of profile audios for a user. Returns a :class:`telebot.types.UserProfileAudios` object.
1519+
1520+
Telegram documentation: https://core.telegram.org/bots/api#getuserprofileaudios
1521+
1522+
:param user_id: Unique identifier of the target user
1523+
:type user_id: :obj:`int`
1524+
1525+
:param offset: Sequential number of the first audio to be returned. By default, all audios are returned.
1526+
:type offset: :obj:`int`
1527+
1528+
:param limit: Limits the number of audios to be retrieved. Values between 1-100 are accepted. Defaults to 100.
1529+
:type limit: :obj:`int`
1530+
1531+
:return: If the request is successful, a UserProfileAudios object is returned.
1532+
:rtype: :class:`telebot.types.UserProfileAudios`
1533+
"""
1534+
return types.UserProfileAudios.de_json(
1535+
apihelper.get_user_profile_audios(self.token, user_id, offset=offset, limit=limit)
1536+
)
1537+
15151538
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:
15161539
"""
15171540
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.

telebot/apihelper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ def get_user_profile_photos(token, user_id, offset=None, limit=None):
349349
return _make_request(token, method_url, params=payload)
350350

351351

352+
def get_user_profile_audios(token, user_id, offset=None, limit=None):
353+
method_url = r'getUserProfileAudios'
354+
payload = {'user_id': user_id}
355+
if offset:
356+
payload['offset'] = offset
357+
if limit:
358+
payload['limit'] = limit
359+
return _make_request(token, method_url, params=payload)
360+
361+
352362
def set_user_emoji_status(token, user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None):
353363
method_url = r'setUserEmojiStatus'
354364
payload = {'user_id': user_id}

telebot/async_telebot.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,6 +2989,26 @@ async def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None
29892989
result = await asyncio_helper.get_user_profile_photos(self.token, user_id, offset, limit)
29902990
return types.UserProfilePhotos.de_json(result)
29912991

2992+
async def get_user_profile_audios(self, user_id: int, offset: Optional[int]=None, limit: Optional[int]=None) -> types.UserProfileAudios:
2993+
"""
2994+
Use this method to get a list of profile audios for a user. Returns a UserProfileAudios object.
2995+
2996+
Telegram documentation: https://core.telegram.org/bots/api#getuserprofileaudios
2997+
2998+
:param user_id: Unique identifier of the target user
2999+
:type user_id: :obj:`int`
3000+
3001+
:param offset: Sequential number of the first audio to be returned. By default, all audios are returned.
3002+
:type offset: :obj:`int`
3003+
3004+
:param limit: Limits the number of audios to be retrieved. Values between 1-100 are accepted. Defaults to 100.
3005+
:type limit: :obj:`int`
3006+
3007+
:return: If successful, returns a UserProfileAudios object.
3008+
:rtype: :class:`telebot.types.UserProfileAudios`
3009+
"""
3010+
return types.UserProfileAudios.de_json(await asyncio_helper.get_user_profile_audios(self.token, user_id, offset, limit))
3011+
29923012
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:
29933013
"""
29943014
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.

telebot/asyncio_helper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ async def get_user_profile_photos(token, user_id, offset=None, limit=None):
330330
return await _process_request(token, method_url, params=payload)
331331

332332

333+
async def get_user_profile_audios(token, user_id, offset=None, limit=None):
334+
method_url = r'getUserProfileAudios'
335+
payload = {'user_id': user_id}
336+
if offset:
337+
payload['offset'] = offset
338+
if limit:
339+
payload['limit'] = limit
340+
return await _process_request(token, method_url, params=payload)
341+
342+
333343
async def set_user_emoji_status(token, user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None):
334344
method_url = r'setUserEmojiStatus'
335345
payload = {'user_id': user_id}

telebot/types.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13618,4 +13618,31 @@ def de_json(cls, json_string):
1361813618
if json_string is None: return None
1361913619
obj = cls.check_json(json_string)
1362013620
return cls(**obj)
13621-
13621+
13622+
13623+
class UserProfileAudios(JsonDeserializable):
13624+
"""
13625+
This object represents the audios displayed on a user's profile.
13626+
13627+
Telegram documentation: https://core.telegram.org/bots/api#userprofileaudios
13628+
13629+
:param total_count: Total number of profile audios for the target user
13630+
:type total_count: :obj:`int`
13631+
13632+
:param audios: Requested profile audios
13633+
:type audios: :obj:`list` of :class:`Audio`
13634+
13635+
:return: Instance of the class
13636+
:rtype: :class:`UserProfileAudios`
13637+
"""
13638+
def __init__(self, total_count: int, audios: List[Audio], **kwargs):
13639+
self.total_count: int = total_count
13640+
self.audios: List[Audio] = audios
13641+
13642+
@classmethod
13643+
def de_json(cls, json_string):
13644+
if json_string is None: return None
13645+
obj = cls.check_json(json_string)
13646+
obj['audios'] = [Audio.de_json(audio) for audio in obj['audios']]
13647+
return cls(**obj)
13648+

0 commit comments

Comments
 (0)