Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c448bba
Update types.py
coder2020official Apr 12, 2025
805c78f
Add business account methods
coder2020official Apr 12, 2025
1d32718
Added AcceptedGiftTypes and set_business_account_gift_settings
coder2020official Apr 12, 2025
3e0f06a
Add get_business_account_star_balance
coder2020official Apr 12, 2025
af858de
Added transfer_business_account_stars
coder2020official Apr 12, 2025
c012a59
Added get_business_account_gifts, OwnedGiftRegular, OwnedGiftUnique, …
coder2020official Apr 12, 2025
3d238a4
Added convert_gift_to_stars
coder2020official Apr 12, 2025
817f2ad
Added upgrade_gift and transfer_gift methods
coder2020official Apr 12, 2025
b47c73f
Added InputStoryContent
coder2020official Apr 12, 2025
1713909
Stories
coder2020official Apr 12, 2025
1c08163
posting, editing, deleting stories(needs testing)
coder2020official Apr 12, 2025
b05d209
Replaced the field can_send_gift with the field accepted_gift_types …
coder2020official Apr 12, 2025
6fedece
Added unique_gift and gift
coder2020official Apr 12, 2025
e3d7f96
Added gift_premium_subscription
coder2020official Apr 12, 2025
f76cac8
Added premium_subscription_duration to TransactionPartnerUser
coder2020official Apr 12, 2025
0bd9133
Added transaction_type to TransactionPartnerUser
coder2020official Apr 12, 2025
950d7c6
Added paid_message_price_changed
coder2020official Apr 12, 2025
9fb4fdd
Added paid_star_count
coder2020official Apr 12, 2025
0d1e515
Added set_business_account_profile_photo and remove_business_account_…
coder2020official Apr 12, 2025
d63b07a
Fix issues with posting stories
coder2020official Apr 13, 2025
49684b5
Fix stories for async
coder2020official Apr 13, 2025
533b52c
Fix issues related with Bot api 9.0
coder2020official Apr 19, 2025
d4f5ead
Fix typehints
coder2020official Apr 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added set_business_account_profile_photo and remove_business_account_…
…profile_photo
  • Loading branch information
coder2020official committed Apr 12, 2025
commit 0d1e51519c012fcb5f8cc6899f01a1e01fe914fa
42 changes: 42 additions & 0 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6820,6 +6820,48 @@ def gift_premium_subscription(
text=text, text_parse_mode=text_parse_mode,
text_entities=text_entities
)

def set_business_account_profile_photo(
self, business_connection_id: str, photo: types.InputProfilePhoto,
is_public: Optional[bool]=None) -> bool:
"""
Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountprofilephoto

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param photo: The new profile photo to set
:type photo: :class:`telebot.types.InputProfilePhoto`

: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.
:type is_public: :obj:`bool`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.set_business_account_profile_photo(self.token, business_connection_id, photo, is_public=is_public)


def remove_business_account_profile_photo(
self, business_connection_id: str,
is_public: Optional[bool]=None) -> bool:
"""
Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#removebusinessaccountprofilephoto

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

: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.
:type is_public: :obj:`bool`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.remove_business_account_profile_photo(self.token, business_connection_id, is_public=is_public)

def get_available_gifts(self) -> types.Gifts:
"""
Expand Down
16 changes: 16 additions & 0 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,22 @@ def gift_premium_subscription(token, user_id, month_count, star_count, text=None
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_business_account_profile_photo(token, business_connection_id, photo, is_public=None):
method_url = 'setBusinessAccountProfilePhoto'
payload = {'business_connection_id': business_connection_id}
photo_json, files = photo.convert_input_profile_photo()
payload['photo'] = photo_json
if is_public is not None:
payload['is_public'] = is_public
return _make_request(token, method_url, params=payload, files=files, method='post')

def remove_business_account_profile_photo(token, business_connection_id, is_public=None):
method_url = 'removeBusinessAccountProfilePhoto'
payload = {'business_connection_id': business_connection_id}
if is_public is not None:
payload['is_public'] = is_public
return _make_request(token, method_url, params=payload, method='post')

def create_new_sticker_set(
token, user_id, name, title, stickers, sticker_type=None, needs_repainting=None):
method_url = 'createNewStickerSet'
Expand Down
42 changes: 42 additions & 0 deletions telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8241,6 +8241,48 @@ async def delete_story(self, business_connection_id: str, story_id: int) -> bool
"""
return await asyncio_helper.delete_story(self.token, business_connection_id, story_id)

async def set_business_account_profile_photo(
self, business_connection_id: str, photo: types.InputProfilePhoto,
is_public: Optional[bool]=None) -> bool:
"""
Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountprofilephoto

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param photo: The new profile photo to set
:type photo: :class:`telebot.types.InputProfilePhoto`

: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.
:type is_public: :obj:`bool`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.set_business_account_profile_photo(self.token, business_connection_id, photo, is_public=is_public)


async def remove_business_account_profile_photo(
self, business_connection_id: str,
is_public: Optional[bool]=None) -> bool:
"""
Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#removebusinessaccountprofilephoto

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

: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.
:type is_public: :obj:`bool`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.remove_business_account_profile_photo(self.token, business_connection_id, is_public=is_public)

async def gift_premium_subscription(
self, user_id: int, month_count: int, star_count: int,
text: Optional[str]=None, text_parse_mode: Optional[str]=None,
Expand Down
16 changes: 16 additions & 0 deletions telebot/asyncio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,22 @@ async def gift_premium_subscription(token, user_id, month_count, star_count, tex
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 set_business_account_profile_photo(token, business_connection_id, photo, is_public=None):
method_url = 'setBusinessAccountProfilePhoto'
payload = {'business_connection_id': business_connection_id}
photo_json, files = photo.convert_input_profile_photo()
payload['photo'] = photo_json
if is_public is not None:
payload['is_public'] = is_public
return await _process_request(token, method_url, params=payload, files=files, method='post')

async def remove_business_account_profile_photo(token, business_connection_id, is_public=None):
method_url = 'removeBusinessAccountProfilePhoto'
payload = {'business_connection_id': business_connection_id}
if is_public is not None:
payload['is_public'] = is_public
return await _process_request(token, method_url, params=payload, method='post')


async def get_available_gifts(token):
method_url = 'getAvailableGifts'
Expand Down
87 changes: 86 additions & 1 deletion telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12327,4 +12327,89 @@ def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
return cls(**obj)



class InputProfilePhoto(JsonSerializable):
"""
This object describes a profile photo to set. Currently, it can be one of
InputProfilePhotoStatic
InputProfilePhotoAnimated

Telegram documentation: https://core.telegram.org/bots/api#inputprofilephoto

:return: Instance of the class
:rtype: :class:`InputProfilePhoto`
"""

class InputProfilePhotoStatic(InputProfilePhoto):
"""
This object describes a static profile photo to set.

Telegram documentation: https://core.telegram.org/bots/api#inputprofilephotostatic

:param type: Type of the profile photo, must be static
:type type: :obj:`str`

: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
:type photo: :obj:`str`

:return: Instance of the class
:rtype: :class:`InputProfilePhotoStatic`

"""
def __init__(self, photo: InputFile, **kwargs):
self.type: str = "static"
self.photo: InputFile = photo

self._photo_name = service_utils.generate_random_token()
self._photo_dic = "attach://{}".format(self._photo_name)
def to_json(self):
return json.dumps(self.to_dict())

def to_dict(self):
data = {
'type': self.type,
'photo': self._photo_dic
}
return data
def convert_input_profile_photo(self):
return self.to_json(), {self._photo_name: self.photo}


class InputProfilePhotoAnimated(InputProfilePhoto):
"""
This object describes an animated profile photo to set.

Telegram documentation: https://core.telegram.org/bots/api#inputprofilephotoanimated

:param type: Type of the profile photo, must be animated
:type type: :obj:`str`

: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
:type animation: :obj:`str`

:param main_frame_timestamp: Optional. Timestamp in seconds of the frame that will be used as the static profile photo. Defaults to 0.0.
:type main_frame_timestamp: :obj:`float`

:return: Instance of the class
:rtype: :class:`InputProfilePhotoAnimated`

"""
def __init__(self, animation: InputFile, main_frame_timestamp: Optional[float] = None, **kwargs):
self.type: str = "animated"
self.animation: InputFile = animation
self._animation_name = service_utils.generate_random_token()
self._animation_dic = "attach://{}".format(self._animation_name)
self.main_frame_timestamp: Optional[float] = main_frame_timestamp
def to_json(self):
return json.dumps(self.to_dict())
def to_dict(self):
data = {
'type': self.type,
'animation': self._animation_dic
}
if self.main_frame_timestamp is not None:
data['main_frame_timestamp'] = self.main_frame_timestamp
return data
def convert_input_profile_photo(self):
return self.to_json(), {self._animation_name: self.animation}