Skip to content

Commit 817f2ad

Browse files
Added upgrade_gift and transfer_gift methods
1 parent 3d238a4 commit 817f2ad

4 files changed

Lines changed: 161 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6600,6 +6600,71 @@ def convert_gift_to_stars(self, business_connection_id: str, owned_gift_id: str)
66006600
:rtype: :obj:`bool`
66016601
"""
66026602
return apihelper.convert_gift_to_stars(self.token, business_connection_id, owned_gift_id)
6603+
6604+
def upgrade_gift(
6605+
self, business_connection_id: str, owned_gift_id: str,
6606+
keep_original_details: Optional[bool]=None,
6607+
star_count: Optional[int]=None) -> bool:
6608+
"""
6609+
Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right.
6610+
Additionally requires the can_transfer_stars business bot right if the upgrade is paid. Returns True on success.
6611+
6612+
Telegram documentation: https://core.telegram.org/bots/api#upgradegift
6613+
6614+
:param business_connection_id: Unique identifier of the business connection
6615+
:type business_connection_id: :obj:`str`
6616+
6617+
:param owned_gift_id: Unique identifier of the regular gift that should be upgraded to a unique one
6618+
:type owned_gift_id: :obj:`str`
6619+
6620+
:param keep_original_details: Pass True to keep the original gift text, sender and receiver in the upgraded gift
6621+
:type keep_original_details: :obj:`bool`
6622+
6623+
:param star_count: The amount of Telegram Stars that will be paid for the upgrade from the business account balance.
6624+
If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required and gift.upgrade_star_count must be passed.
6625+
:type star_count: :obj:`int`
6626+
6627+
:return: Returns True on success.
6628+
:rtype: :obj:`bool`
6629+
"""
6630+
return apihelper.upgrade_gift(
6631+
self.token, business_connection_id, owned_gift_id,
6632+
keep_original_details=keep_original_details,
6633+
star_count=star_count
6634+
)
6635+
6636+
def transfer_gift(
6637+
self, business_connection_id: str, owned_gift_id: str,
6638+
new_owner_chat_id: Union[int, str],
6639+
star_count: Optional[int]=None) -> bool:
6640+
"""
6641+
Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right.
6642+
Requires can_transfer_stars business bot right if the transfer is paid. Returns True on success.
6643+
6644+
Telegram documentation: https://core.telegram.org/bots/api#transfergift
6645+
6646+
:param business_connection_id: Unique identifier of the business connection
6647+
:type business_connection_id: :obj:`str`
6648+
6649+
:param owned_gift_id: Unique identifier of the regular gift that should be transferred
6650+
:type owned_gift_id: :obj:`str`
6651+
6652+
:param new_owner_chat_id: Unique identifier of the chat which will own the gift. The chat must be active in the last 24 hours.
6653+
:type new_owner_chat_id: :obj:`int` | :obj:`str`
6654+
6655+
:param star_count: The amount of Telegram Stars that will be paid for the transfer from the business account balance.
6656+
If positive, then the can_transfer_stars business bot right is required.
6657+
:type star_count: :obj:`int`
6658+
6659+
:return: Returns True on success.
6660+
:rtype: :obj:`bool`
6661+
"""
6662+
return apihelper.transfer_gift(
6663+
self.token, business_connection_id, owned_gift_id,
6664+
new_owner_chat_id=new_owner_chat_id,
6665+
star_count=star_count
6666+
)
6667+
66036668

66046669
def get_available_gifts(self) -> types.Gifts:
66056670
"""

telebot/apihelper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,22 @@ def convert_gift_to_stars(token, business_connection_id, owned_gift_id):
20742074
payload = {'business_connection_id': business_connection_id, 'owned_gift_id': owned_gift_id}
20752075
return _make_request(token, method_url, params=payload, method='post')
20762076

2077+
def upgrade_gift(token, business_connection_id, owned_gift_id, keep_original_details=None, star_count=None):
2078+
method_url = 'upgradeGift'
2079+
payload = {'business_connection_id': business_connection_id, 'owned_gift_id': owned_gift_id}
2080+
if keep_original_details is not None:
2081+
payload['keep_original_details'] = keep_original_details
2082+
if star_count is not None:
2083+
payload['star_count'] = star_count
2084+
return _make_request(token, method_url, params=payload, method='post')
2085+
2086+
def transfer_gift(token, business_connection_id, owned_gift_id, new_owner_chat_id, star_count=None):
2087+
method_url = 'transferGift'
2088+
payload = {'business_connection_id': business_connection_id, 'owned_gift_id': owned_gift_id, 'new_owner_chat_id': new_owner_chat_id}
2089+
if star_count is not None:
2090+
payload['star_count'] = star_count
2091+
return _make_request(token, method_url, params=payload, method='post')
2092+
20772093
def create_new_sticker_set(
20782094
token, user_id, name, title, stickers, sticker_type=None, needs_repainting=None):
20792095
method_url = 'createNewStickerSet'

telebot/async_telebot.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8056,6 +8056,70 @@ async def convert_gift_to_stars(self, business_connection_id: str, owned_gift_id
80568056
:rtype: :obj:`bool`
80578057
"""
80588058
return await asyncio_helper.convert_gift_to_stars(self.token, business_connection_id, owned_gift_id)
8059+
8060+
async def upgrade_gift(
8061+
self, business_connection_id: str, owned_gift_id: str,
8062+
keep_original_details: Optional[bool]=None,
8063+
star_count: Optional[int]=None) -> bool:
8064+
"""
8065+
Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right.
8066+
Additionally requires the can_transfer_stars business bot right if the upgrade is paid. Returns True on success.
8067+
8068+
Telegram documentation: https://core.telegram.org/bots/api#upgradegift
8069+
8070+
:param business_connection_id: Unique identifier of the business connection
8071+
:type business_connection_id: :obj:`str`
8072+
8073+
:param owned_gift_id: Unique identifier of the regular gift that should be upgraded to a unique one
8074+
:type owned_gift_id: :obj:`str`
8075+
8076+
:param keep_original_details: Pass True to keep the original gift text, sender and receiver in the upgraded gift
8077+
:type keep_original_details: :obj:`bool`
8078+
8079+
:param star_count: The amount of Telegram Stars that will be paid for the upgrade from the business account balance.
8080+
If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required and gift.upgrade_star_count must be passed.
8081+
:type star_count: :obj:`int`
8082+
8083+
:return: Returns True on success.
8084+
:rtype: :obj:`bool`
8085+
"""
8086+
return await asyncio_helper.upgrade_gift(
8087+
self.token, business_connection_id, owned_gift_id,
8088+
keep_original_details=keep_original_details,
8089+
star_count=star_count
8090+
)
8091+
8092+
async def transfer_gift(
8093+
self, business_connection_id: str, owned_gift_id: str,
8094+
new_owner_chat_id: Union[int, str],
8095+
star_count: Optional[int]=None) -> bool:
8096+
"""
8097+
Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right.
8098+
Requires can_transfer_stars business bot right if the transfer is paid. Returns True on success.
8099+
8100+
Telegram documentation: https://core.telegram.org/bots/api#transfergift
8101+
8102+
:param business_connection_id: Unique identifier of the business connection
8103+
:type business_connection_id: :obj:`str`
8104+
8105+
:param owned_gift_id: Unique identifier of the regular gift that should be transferred
8106+
:type owned_gift_id: :obj:`str`
8107+
8108+
:param new_owner_chat_id: Unique identifier of the chat which will own the gift. The chat must be active in the last 24 hours.
8109+
:type new_owner_chat_id: :obj:`int` | :obj:`str`
8110+
8111+
:param star_count: The amount of Telegram Stars that will be paid for the transfer from the business account balance.
8112+
If positive, then the can_transfer_stars business bot right is required.
8113+
:type star_count: :obj:`int`
8114+
8115+
:return: Returns True on success.
8116+
:rtype: :obj:`bool`
8117+
"""
8118+
return await asyncio_helper.transfer_gift(
8119+
self.token, business_connection_id, owned_gift_id,
8120+
new_owner_chat_id=new_owner_chat_id,
8121+
star_count=star_count
8122+
)
80598123

80608124
async def get_available_gifts(self) -> types.Gifts:
80618125
"""

telebot/asyncio_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,22 @@ async def convert_gift_to_stars(token, business_connection_id, owned_gift_id):
20472047
payload = {'business_connection_id': business_connection_id, 'owned_gift_id': owned_gift_id}
20482048
return await _process_request(token, method_url, params=payload, method='post')
20492049

2050+
async def upgrade_gift(token, business_connection_id, owned_gift_id, keep_original_details=None, star_count=None):
2051+
method_url = 'upgradeGift'
2052+
payload = {'business_connection_id': business_connection_id, 'owned_gift_id': owned_gift_id}
2053+
if keep_original_details is not None:
2054+
payload['keep_original_details'] = keep_original_details
2055+
if star_count is not None:
2056+
payload['star_count'] = star_count
2057+
return await _process_request(token, method_url, params=payload, method='post')
2058+
2059+
async def transfer_gift(token, business_connection_id, owned_gift_id, new_owner_chat_id, star_count=None):
2060+
method_url = 'transferGift'
2061+
payload = {'business_connection_id': business_connection_id, 'owned_gift_id': owned_gift_id, 'new_owner_chat_id': new_owner_chat_id}
2062+
if star_count is not None:
2063+
payload['star_count'] = star_count
2064+
return await _process_request(token, method_url, params=payload, method='post')
2065+
20502066
async def get_available_gifts(token):
20512067
method_url = 'getAvailableGifts'
20522068
return await _process_request(token, method_url)

0 commit comments

Comments
 (0)