Skip to content

Commit e3d7f96

Browse files
Added gift_premium_subscription
1 parent 6fedece commit e3d7f96

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

telebot/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6785,6 +6785,42 @@ def delete_story(self, business_connection_id: str, story_id: int) -> bool:
67856785
"""
67866786
return apihelper.delete_story(self.token, business_connection_id, story_id)
67876787

6788+
def gift_premium_subscription(
6789+
self, user_id: int, month_count: int, star_count: int,
6790+
text: Optional[str]=None, text_parse_mode: Optional[str]=None,
6791+
text_entities: Optional[List[types.MessageEntity]]=None) -> bool:
6792+
"""
6793+
Gifts a Telegram Premium subscription to the given user. Returns True on success.
6794+
6795+
Telegram documentation: https://core.telegram.org/bots/api#giftpremiumsubscription
6796+
6797+
:param user_id: Unique identifier of the target user who will receive a Telegram Premium subscription
6798+
:type user_id: :obj:`int`
6799+
6800+
:param month_count: Number of months the Telegram Premium subscription will be active for the user; must be one of 3, 6, or 12
6801+
:type month_count: :obj:`int`
6802+
6803+
:param star_count: Number of Telegram Stars to pay for the Telegram Premium subscription; must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months
6804+
:type star_count: :obj:`int`
6805+
6806+
:param text: Text that will be shown along with the service message about the subscription; 0-128 characters
6807+
:type text: :obj:`str`
6808+
6809+
:param text_parse_mode: Mode for parsing entities in the text. See formatting options for more details. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
6810+
:type text_parse_mode: :obj:`str`
6811+
6812+
:param text_entities: A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
6813+
:type text_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
6814+
6815+
:return: Returns True on success.
6816+
:rtype: :obj:`bool`
6817+
"""
6818+
return apihelper.gift_premium_subscription(
6819+
self.token, user_id, month_count, star_count,
6820+
text=text, text_parse_mode=text_parse_mode,
6821+
text_entities=text_entities
6822+
)
6823+
67886824
def get_available_gifts(self) -> types.Gifts:
67896825
"""
67906826
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.

telebot/apihelper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,18 @@ def delete_story(token, business_connection_id, story_id):
21352135
payload = {'business_connection_id': business_connection_id, 'story_id': story_id}
21362136
return _make_request(token, method_url, params=payload, method='post')
21372137

2138+
def gift_premium_subscription(token, user_id, month_count, star_count, text=None, text_parse_mode=None,
2139+
text_entities=None):
2140+
method_url = 'giftPremiumSubscription'
2141+
payload = {'user_id': user_id, 'month_count': month_count, 'star_count': star_count}
2142+
if text:
2143+
payload['text'] = text
2144+
if text_parse_mode:
2145+
payload['text_parse_mode'] = text_parse_mode
2146+
if text_entities:
2147+
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
2148+
return _make_request(token, method_url, params=payload, method='post')
2149+
21382150
def create_new_sticker_set(
21392151
token, user_id, name, title, stickers, sticker_type=None, needs_repainting=None):
21402152
method_url = 'createNewStickerSet'

telebot/async_telebot.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8240,6 +8240,42 @@ async def delete_story(self, business_connection_id: str, story_id: int) -> bool
82408240
:rtype: :obj:`bool`
82418241
"""
82428242
return await asyncio_helper.delete_story(self.token, business_connection_id, story_id)
8243+
8244+
async def gift_premium_subscription(
8245+
self, user_id: int, month_count: int, star_count: int,
8246+
text: Optional[str]=None, text_parse_mode: Optional[str]=None,
8247+
text_entities: Optional[List[types.MessageEntity]]=None) -> bool:
8248+
"""
8249+
Gifts a Telegram Premium subscription to the given user. Returns True on success.
8250+
8251+
Telegram documentation: https://core.telegram.org/bots/api#giftpremiumsubscription
8252+
8253+
:param user_id: Unique identifier of the target user who will receive a Telegram Premium subscription
8254+
:type user_id: :obj:`int`
8255+
8256+
:param month_count: Number of months the Telegram Premium subscription will be active for the user; must be one of 3, 6, or 12
8257+
:type month_count: :obj:`int`
8258+
8259+
:param star_count: Number of Telegram Stars to pay for the Telegram Premium subscription; must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months
8260+
:type star_count: :obj:`int`
8261+
8262+
:param text: Text that will be shown along with the service message about the subscription; 0-128 characters
8263+
:type text: :obj:`str`
8264+
8265+
:param text_parse_mode: Mode for parsing entities in the text. See formatting options for more details. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
8266+
:type text_parse_mode: :obj:`str`
8267+
8268+
:param text_entities: A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
8269+
:type text_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
8270+
8271+
:return: Returns True on success.
8272+
:rtype: :obj:`bool`
8273+
"""
8274+
return await asyncio_helper.gift_premium_subscription(
8275+
self.token, user_id, month_count, star_count,
8276+
text=text, text_parse_mode=text_parse_mode,
8277+
text_entities=text_entities
8278+
)
82438279

82448280
async def get_available_gifts(self) -> types.Gifts:
82458281
"""

telebot/asyncio_helper.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,19 @@ async def delete_story(token, business_connection_id, story_id):
21082108
payload = {'business_connection_id': business_connection_id, 'story_id': story_id}
21092109
return await _process_request(token, method_url, params=payload, method='post')
21102110

2111+
async def gift_premium_subscription(token, user_id, month_count, star_count, text=None, text_parse_mode=None,
2112+
text_entities=None):
2113+
method_url = 'giftPremiumSubscription'
2114+
payload = {'user_id': user_id, 'month_count': month_count, 'star_count': star_count}
2115+
if text:
2116+
payload['text'] = text
2117+
if text_parse_mode:
2118+
payload['text_parse_mode'] = text_parse_mode
2119+
if text_entities:
2120+
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
2121+
return await _process_request(token, method_url, params=payload, method='post')
2122+
2123+
21112124
async def get_available_gifts(token):
21122125
method_url = 'getAvailableGifts'
21132126
return await _process_request(token, method_url)

0 commit comments

Comments
 (0)