Skip to content

Commit 78158ba

Browse files
Added the methods setMyProfilePhoto and removeMyProfilePhoto, allowing bots to manage their profile picture.
1 parent 742c0ae commit 78158ba

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,6 +5048,31 @@ def get_my_short_description(self, language_code: Optional[str]=None):
50485048
return types.BotShortDescription.de_json(
50495049
apihelper.get_my_short_description(self.token, language_code=language_code))
50505050

5051+
def set_my_profile_photo(self, photo: Any) -> bool:
5052+
"""
5053+
Use this method to change the profile photo of the bot. Returns True on success.
5054+
5055+
Telegram documentation: https://core.telegram.org/bots/api#setmyprofilephoto
5056+
5057+
:param photo: New profile photo for the bot, uploaded using multipart/form-data
5058+
:type photo: :obj:`typing.Union[file_like, str]`
5059+
5060+
:return: True on success.
5061+
:rtype: :obj:`bool`
5062+
"""
5063+
return apihelper.set_my_profile_photo(self.token, photo)
5064+
5065+
def remove_my_profile_photo(self) -> bool:
5066+
"""
5067+
Use this method to remove the profile photo of the bot. Requires no parameters. Returns True on success.
5068+
5069+
Telegram documentation: https://core.telegram.org/bots/api#removemyprofilephoto
5070+
5071+
:return: True on success.
5072+
:rtype: :obj:`bool`
5073+
"""
5074+
return apihelper.remove_my_profile_photo(self.token)
5075+
50515076

50525077
def set_chat_menu_button(self, chat_id: Union[int, str]=None, menu_button: types.MenuButton=None) -> bool:
50535078
"""

telebot/apihelper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,22 @@ def get_my_name(token, language_code=None):
15261526
payload['language_code'] = language_code
15271527
return _make_request(token, method_url, params=payload)
15281528

1529+
def set_my_profile_photo(token, photo):
1530+
method_url = r'setMyProfilePhoto'
1531+
files = None
1532+
payload = {}
1533+
if util.is_string(photo):
1534+
payload['photo'] = photo
1535+
elif util.is_pil_image(photo):
1536+
files = {'photo': util.pil_image_to_file(photo)}
1537+
else:
1538+
files = {'photo': photo}
1539+
return _make_request(token, method_url, params=payload, files=files, method='post')
1540+
1541+
def delete_my_profile_photo(token):
1542+
method_url = r'deleteMyProfilePhoto'
1543+
return _make_request(token, method_url, method='post')
1544+
15291545
def set_chat_menu_button(token, chat_id=None, menu_button=None):
15301546
method_url = r'setChatMenuButton'
15311547
payload = {}

telebot/async_telebot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6533,6 +6533,31 @@ async def get_my_name(self, language_code: Optional[str]=None):
65336533
result = await asyncio_helper.get_my_name(self.token, language_code)
65346534
return types.BotName.de_json(result)
65356535

6536+
async def set_my_profile_photo(self, photo: Any) -> bool:
6537+
"""
6538+
Use this method to change the profile photo of the bot. Returns True on success.
6539+
6540+
Telegram documentation: https://core.telegram.org/bots/api#setmyprofilephoto
6541+
6542+
:param photo: InputProfilePhoto: The new profile photo to set
6543+
:type photo: :obj:`typing.Union[file_like, str]`
6544+
6545+
:return: True on success.
6546+
:rtype: :obj:`bool`
6547+
"""
6548+
return await asyncio_helper.set_my_profile_photo(self.token, photo)
6549+
6550+
async def remove_my_profile_photo(self) -> bool:
6551+
"""
6552+
Use this method to remove the profile photo of the bot. Requires no parameters. Returns True on success.
6553+
6554+
Telegram documentation: https://core.telegram.org/bots/api#removemyprofilephoto
6555+
6556+
:return: True on success.
6557+
:rtype: :obj:`bool`
6558+
"""
6559+
return await asyncio_helper.remove_my_profile_photo(self.token)
6560+
65366561
async def set_chat_menu_button(self, chat_id: Union[int, str]=None,
65376562
menu_button: types.MenuButton=None) -> bool:
65386563
"""

telebot/asyncio_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,22 @@ async def get_my_name(token, language_code=None):
15171517
payload['language_code'] = language_code
15181518
return await _process_request(token, method_url, params=payload)
15191519

1520+
async def set_my_profile_photo(token, photo):
1521+
method_url = r'setMyProfilePhoto'
1522+
payload = {}
1523+
files = None
1524+
if util.is_string(photo):
1525+
payload['photo'] = photo
1526+
elif util.is_pil_image(photo):
1527+
files = {'photo': util.pil_image_to_file(photo)}
1528+
else:
1529+
files = {'photo': photo}
1530+
return await _process_request(token, method_url, params=payload, files=files, method='post')
1531+
1532+
async def remove_my_profile_photo(token):
1533+
method_url = r'removeMyProfilePhoto'
1534+
return await _process_request(token, method_url, method='post')
1535+
15201536
async def set_chat_menu_button(token, chat_id=None, menu_button=None):
15211537
method_url = r'setChatMenuButton'
15221538
payload = {}

0 commit comments

Comments
 (0)