Skip to content

Commit 0d1e515

Browse files
Added set_business_account_profile_photo and remove_business_account_profile_photo
1 parent 9fb4fdd commit 0d1e515

File tree

5 files changed

+202
-1
lines changed

5 files changed

+202
-1
lines changed

telebot/__init__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,6 +6820,48 @@ def gift_premium_subscription(
68206820
text=text, text_parse_mode=text_parse_mode,
68216821
text_entities=text_entities
68226822
)
6823+
6824+
def set_business_account_profile_photo(
6825+
self, business_connection_id: str, photo: types.InputProfilePhoto,
6826+
is_public: Optional[bool]=None) -> bool:
6827+
"""
6828+
Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.
6829+
6830+
Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
6831+
6832+
:param business_connection_id: Unique identifier of the business connection
6833+
:type business_connection_id: :obj:`str`
6834+
6835+
:param photo: The new profile photo to set
6836+
:type photo: :class:`telebot.types.InputProfilePhoto`
6837+
6838+
:param is_public: Pass True to set the public photo, which will be visible even if the main photo is hidden by the business account's privacy settings. An account can have only one public photo.
6839+
:type is_public: :obj:`bool`
6840+
6841+
:return: Returns True on success.
6842+
:rtype: :obj:`bool`
6843+
"""
6844+
return apihelper.set_business_account_profile_photo(self.token, business_connection_id, photo, is_public=is_public)
6845+
6846+
6847+
def remove_business_account_profile_photo(
6848+
self, business_connection_id: str,
6849+
is_public: Optional[bool]=None) -> bool:
6850+
"""
6851+
Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.
6852+
6853+
Telegram documentation: https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
6854+
6855+
:param business_connection_id: Unique identifier of the business connection
6856+
:type business_connection_id: :obj:`str`
6857+
6858+
:param is_public: Pass True to remove the public photo, which is visible even if the main photo is hidden by the business account's privacy settings. After the main photo is removed, the previous profile photo (if present) becomes the main photo.
6859+
:type is_public: :obj:`bool`
6860+
6861+
:return: Returns True on success.
6862+
:rtype: :obj:`bool`
6863+
"""
6864+
return apihelper.remove_business_account_profile_photo(self.token, business_connection_id, is_public=is_public)
68236865

68246866
def get_available_gifts(self) -> types.Gifts:
68256867
"""

telebot/apihelper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,22 @@ def gift_premium_subscription(token, user_id, month_count, star_count, text=None
21472147
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
21482148
return _make_request(token, method_url, params=payload, method='post')
21492149

2150+
def set_business_account_profile_photo(token, business_connection_id, photo, is_public=None):
2151+
method_url = 'setBusinessAccountProfilePhoto'
2152+
payload = {'business_connection_id': business_connection_id}
2153+
photo_json, files = photo.convert_input_profile_photo()
2154+
payload['photo'] = photo_json
2155+
if is_public is not None:
2156+
payload['is_public'] = is_public
2157+
return _make_request(token, method_url, params=payload, files=files, method='post')
2158+
2159+
def remove_business_account_profile_photo(token, business_connection_id, is_public=None):
2160+
method_url = 'removeBusinessAccountProfilePhoto'
2161+
payload = {'business_connection_id': business_connection_id}
2162+
if is_public is not None:
2163+
payload['is_public'] = is_public
2164+
return _make_request(token, method_url, params=payload, method='post')
2165+
21502166
def create_new_sticker_set(
21512167
token, user_id, name, title, stickers, sticker_type=None, needs_repainting=None):
21522168
method_url = 'createNewStickerSet'

telebot/async_telebot.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8241,6 +8241,48 @@ async def delete_story(self, business_connection_id: str, story_id: int) -> bool
82418241
"""
82428242
return await asyncio_helper.delete_story(self.token, business_connection_id, story_id)
82438243

8244+
async def set_business_account_profile_photo(
8245+
self, business_connection_id: str, photo: types.InputProfilePhoto,
8246+
is_public: Optional[bool]=None) -> bool:
8247+
"""
8248+
Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.
8249+
8250+
Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
8251+
8252+
:param business_connection_id: Unique identifier of the business connection
8253+
:type business_connection_id: :obj:`str`
8254+
8255+
:param photo: The new profile photo to set
8256+
:type photo: :class:`telebot.types.InputProfilePhoto`
8257+
8258+
:param is_public: Pass True to set the public photo, which will be visible even if the main photo is hidden by the business account's privacy settings. An account can have only one public photo.
8259+
:type is_public: :obj:`bool`
8260+
8261+
:return: Returns True on success.
8262+
:rtype: :obj:`bool`
8263+
"""
8264+
return await asyncio_helper.set_business_account_profile_photo(self.token, business_connection_id, photo, is_public=is_public)
8265+
8266+
8267+
async def remove_business_account_profile_photo(
8268+
self, business_connection_id: str,
8269+
is_public: Optional[bool]=None) -> bool:
8270+
"""
8271+
Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.
8272+
8273+
Telegram documentation: https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
8274+
8275+
:param business_connection_id: Unique identifier of the business connection
8276+
:type business_connection_id: :obj:`str`
8277+
8278+
:param is_public: Pass True to remove the public photo, which is visible even if the main photo is hidden by the business account's privacy settings. After the main photo is removed, the previous profile photo (if present) becomes the main photo.
8279+
:type is_public: :obj:`bool`
8280+
8281+
:return: Returns True on success.
8282+
:rtype: :obj:`bool`
8283+
"""
8284+
return await asyncio_helper.remove_business_account_profile_photo(self.token, business_connection_id, is_public=is_public)
8285+
82448286
async def gift_premium_subscription(
82458287
self, user_id: int, month_count: int, star_count: int,
82468288
text: Optional[str]=None, text_parse_mode: Optional[str]=None,

telebot/asyncio_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,22 @@ async def gift_premium_subscription(token, user_id, month_count, star_count, tex
21202120
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
21212121
return await _process_request(token, method_url, params=payload, method='post')
21222122

2123+
async def set_business_account_profile_photo(token, business_connection_id, photo, is_public=None):
2124+
method_url = 'setBusinessAccountProfilePhoto'
2125+
payload = {'business_connection_id': business_connection_id}
2126+
photo_json, files = photo.convert_input_profile_photo()
2127+
payload['photo'] = photo_json
2128+
if is_public is not None:
2129+
payload['is_public'] = is_public
2130+
return await _process_request(token, method_url, params=payload, files=files, method='post')
2131+
2132+
async def remove_business_account_profile_photo(token, business_connection_id, is_public=None):
2133+
method_url = 'removeBusinessAccountProfilePhoto'
2134+
payload = {'business_connection_id': business_connection_id}
2135+
if is_public is not None:
2136+
payload['is_public'] = is_public
2137+
return await _process_request(token, method_url, params=payload, method='post')
2138+
21232139

21242140
async def get_available_gifts(token):
21252141
method_url = 'getAvailableGifts'

telebot/types.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12327,4 +12327,89 @@ def de_json(cls, json_string):
1232712327
if json_string is None: return None
1232812328
obj = cls.check_json(json_string)
1232912329
return cls(**obj)
12330-
12330+
12331+
12332+
class InputProfilePhoto(JsonSerializable):
12333+
"""
12334+
This object describes a profile photo to set. Currently, it can be one of
12335+
InputProfilePhotoStatic
12336+
InputProfilePhotoAnimated
12337+
12338+
Telegram documentation: https://core.telegram.org/bots/api#inputprofilephoto
12339+
12340+
:return: Instance of the class
12341+
:rtype: :class:`InputProfilePhoto`
12342+
"""
12343+
12344+
class InputProfilePhotoStatic(InputProfilePhoto):
12345+
"""
12346+
This object describes a static profile photo to set.
12347+
12348+
Telegram documentation: https://core.telegram.org/bots/api#inputprofilephotostatic
12349+
12350+
:param type: Type of the profile photo, must be static
12351+
:type type: :obj:`str`
12352+
12353+
:param photo: The static profile photo. Profile photos can't be reused and can only be uploaded as a new file, so you can pass “attach://<file_attach_name>” if the photo was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files
12354+
:type photo: :obj:`str`
12355+
12356+
:return: Instance of the class
12357+
:rtype: :class:`InputProfilePhotoStatic`
12358+
12359+
"""
12360+
def __init__(self, photo: InputFile, **kwargs):
12361+
self.type: str = "static"
12362+
self.photo: InputFile = photo
12363+
12364+
self._photo_name = service_utils.generate_random_token()
12365+
self._photo_dic = "attach://{}".format(self._photo_name)
12366+
def to_json(self):
12367+
return json.dumps(self.to_dict())
12368+
12369+
def to_dict(self):
12370+
data = {
12371+
'type': self.type,
12372+
'photo': self._photo_dic
12373+
}
12374+
return data
12375+
def convert_input_profile_photo(self):
12376+
return self.to_json(), {self._photo_name: self.photo}
12377+
12378+
12379+
class InputProfilePhotoAnimated(InputProfilePhoto):
12380+
"""
12381+
This object describes an animated profile photo to set.
12382+
12383+
Telegram documentation: https://core.telegram.org/bots/api#inputprofilephotoanimated
12384+
12385+
:param type: Type of the profile photo, must be animated
12386+
:type type: :obj:`str`
12387+
12388+
:param animation: The animated profile photo. Profile photos can't be reused and can only be uploaded as a new file, so you can pass “attach://<file_attach_name>” if the photo was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files
12389+
:type animation: :obj:`str`
12390+
12391+
:param main_frame_timestamp: Optional. Timestamp in seconds of the frame that will be used as the static profile photo. Defaults to 0.0.
12392+
:type main_frame_timestamp: :obj:`float`
12393+
12394+
:return: Instance of the class
12395+
:rtype: :class:`InputProfilePhotoAnimated`
12396+
12397+
"""
12398+
def __init__(self, animation: InputFile, main_frame_timestamp: Optional[float] = None, **kwargs):
12399+
self.type: str = "animated"
12400+
self.animation: InputFile = animation
12401+
self._animation_name = service_utils.generate_random_token()
12402+
self._animation_dic = "attach://{}".format(self._animation_name)
12403+
self.main_frame_timestamp: Optional[float] = main_frame_timestamp
12404+
def to_json(self):
12405+
return json.dumps(self.to_dict())
12406+
def to_dict(self):
12407+
data = {
12408+
'type': self.type,
12409+
'animation': self._animation_dic
12410+
}
12411+
if self.main_frame_timestamp is not None:
12412+
data['main_frame_timestamp'] = self.main_frame_timestamp
12413+
return data
12414+
def convert_input_profile_photo(self):
12415+
return self.to_json(), {self._animation_name: self.animation}

0 commit comments

Comments
 (0)