Skip to content

Commit 80a5b94

Browse files
added 2 methods
1 parent 496cc7c commit 80a5b94

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

telebot/__init__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4199,6 +4199,62 @@ def edit_chat_invite_link(
41994199
apihelper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
42004200
)
42014201

4202+
def create_chat_subscription_invite_link(
4203+
self, chat_id: Union[int, str], subscription_period: int, subscription_price: int,
4204+
name: Optional[str]=None) -> types.ChatInviteLink:
4205+
"""
4206+
Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights.
4207+
The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink.
4208+
Returns the new invite link as a ChatInviteLink object.
4209+
4210+
Telegram documentation: https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
4211+
4212+
:param chat_id: Unique identifier for the target channel chat or username of the target channel
4213+
(in the format @channelusername)
4214+
:type chat_id: :obj:`int` or :obj:`str`
4215+
4216+
:param name: Invite link name; 0-32 characters
4217+
:type name: :obj:`str`
4218+
4219+
:param subscription_period: The number of seconds the subscription will be active for before the next payment.
4220+
Currently, it must always be 2592000 (30 days).
4221+
:type subscription_period: :obj:`int`
4222+
4223+
:param subscription_price: The amount of Telegram Stars a user must pay initially and after each subsequent
4224+
subscription period to be a member of the chat; 1-2500
4225+
:type subscription_price: :obj:`int`
4226+
4227+
:return: Returns the new invite link as a ChatInviteLink object.
4228+
:rtype: :class:`telebot.types.ChatInviteLink`
4229+
"""
4230+
return types.ChatInviteLink.de_json(
4231+
apihelper.create_chat_subscription_invite_link(self.token, chat_id, subscription_period, subscription_price, name)
4232+
)
4233+
4234+
def edit_chat_subscription_invite_link(
4235+
self, chat_id: Union[int, str], invite_link: str, name: Optional[str]=None) -> types.ChatInviteLink:
4236+
"""
4237+
Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights.
4238+
Returns the edited invite link as a ChatInviteLink object.
4239+
4240+
Telegram documentation: https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
4241+
4242+
:param chat_id: Unique identifier for the target chat or username of the target channel
4243+
(in the format @channelusername)
4244+
:type chat_id: :obj:`int` or :obj:`str`
4245+
4246+
:param invite_link: The invite link to edit
4247+
:type invite_link: :obj:`str`
4248+
4249+
:param name: Invite link name; 0-32 characters
4250+
:type name: :obj:`str`
4251+
4252+
:return: Returns the edited invite link as a ChatInviteLink object.
4253+
:rtype: :class:`telebot.types.ChatInviteLink`
4254+
"""
4255+
return types.ChatInviteLink.de_json(
4256+
apihelper.edit_chat_subscription_invite_link(self.token, chat_id, invite_link, name)
4257+
)
42024258

42034259
def revoke_chat_invite_link(
42044260
self, chat_id: Union[int, str], invite_link: str) -> types.ChatInviteLink:

telebot/apihelper.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,26 @@ def edit_chat_invite_link(token, chat_id, invite_link, name, expire_date, member
12051205

12061206
return _make_request(token, method_url, params=payload, method='post')
12071207

1208+
def create_chat_subscription_invite_link(token, chat_id, subscription_period, subscription_price, name=None):
1209+
method_url = 'createChatSubscriptionInviteLink'
1210+
payload = {
1211+
'chat_id': chat_id,
1212+
'subscription_period': subscription_period,
1213+
'subscription_price': subscription_price
1214+
}
1215+
if name:
1216+
payload['name'] = name
1217+
return _make_request(token, method_url, params=payload, method='post')
1218+
1219+
def edit_chat_subscription_invite_link(self.token, chat_id, invite_link, name=None):
1220+
method_url = 'editChatSubscriptionInviteLink'
1221+
payload = {
1222+
'chat_id': chat_id,
1223+
'invite_link': invite_link
1224+
}
1225+
if name:
1226+
payload['name'] = name
1227+
return _make_request(token, method_url, params=payload, method='post')
12081228

12091229
def revoke_chat_invite_link(token, chat_id, invite_link):
12101230
method_url = 'revokeChatInviteLink'

telebot/async_telebot.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5605,6 +5605,63 @@ async def edit_chat_invite_link(
56055605
return types.ChatInviteLink.de_json(
56065606
await asyncio_helper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
56075607
)
5608+
5609+
async def create_chat_subscription_invite_link(
5610+
self, chat_id: Union[int, str], subscription_period: int, subscription_price: int,
5611+
name: Optional[str]=None) -> types.ChatInviteLink:
5612+
"""
5613+
Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights.
5614+
The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink.
5615+
Returns the new invite link as a ChatInviteLink object.
5616+
5617+
Telegram documentation: https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
5618+
5619+
:param chat_id: Unique identifier for the target channel chat or username of the target channel
5620+
(in the format @channelusername)
5621+
:type chat_id: :obj:`int` or :obj:`str`
5622+
5623+
:param name: Invite link name; 0-32 characters
5624+
:type name: :obj:`str`
5625+
5626+
:param subscription_period: The number of seconds the subscription will be active for before the next payment.
5627+
Currently, it must always be 2592000 (30 days).
5628+
:type subscription_period: :obj:`int`
5629+
5630+
:param subscription_price: The amount of Telegram Stars a user must pay initially and after each subsequent
5631+
subscription period to be a member of the chat; 1-2500
5632+
:type subscription_price: :obj:`int`
5633+
5634+
:return: Returns the new invite link as a ChatInviteLink object.
5635+
:rtype: :class:`telebot.types.ChatInviteLink`
5636+
"""
5637+
return types.ChatInviteLink.de_json(
5638+
await asyncio_helper.create_chat_subscription_invite_link(self.token, chat_id, subscription_period, subscription_price, name)
5639+
)
5640+
5641+
async def edit_chat_subscription_invite_link(
5642+
self, chat_id: Union[int, str], invite_link: str, name: Optional[str]=None) -> types.ChatInviteLink:
5643+
"""
5644+
Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights.
5645+
Returns the edited invite link as a ChatInviteLink object.
5646+
5647+
Telegram documentation: https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
5648+
5649+
:param chat_id: Unique identifier for the target chat or username of the target channel
5650+
(in the format @channelusername)
5651+
:type chat_id: :obj:`int` or :obj:`str`
5652+
5653+
:param invite_link: The invite link to edit
5654+
:type invite_link: :obj:`str`
5655+
5656+
:param name: Invite link name; 0-32 characters
5657+
:type name: :obj:`str`
5658+
5659+
:return: Returns the edited invite link as a ChatInviteLink object.
5660+
:rtype: :class:`telebot.types.ChatInviteLink`
5661+
"""
5662+
return types.ChatInviteLink.de_json(
5663+
await asyncio_helper.edit_chat_subscription_invite_link(self.token, chat_id, invite_link, name)
5664+
)
56085665

56095666
async def revoke_chat_invite_link(
56105667
self, chat_id: Union[int, str], invite_link: str) -> types.ChatInviteLink:

telebot/asyncio_helper.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,28 @@ async def edit_chat_invite_link(token, chat_id, invite_link, name, expire_date,
11851185

11861186
return await _process_request(token, method_url, params=payload, method='post')
11871187

1188+
async def create_chat_subscription_invite_link(token, chat_id, subscription_period, subscription_price, name=None):
1189+
method_url = 'createChatSubscriptionInviteLink'
1190+
payload = {
1191+
'chat_id': chat_id,
1192+
'subscription_period': subscription_period,
1193+
'subscription_price': subscription_price
1194+
}
1195+
if name:
1196+
payload['name'] = name
1197+
return await _process_request(token, method_url, params=payload, method='post')
1198+
1199+
async def edit_chat_subscription_invite_link(token, chat_id, invite_link, name=None):
1200+
method_url = 'editChatSubscriptionInviteLink'
1201+
payload = {
1202+
'chat_id': chat_id,
1203+
'invite_link': invite_link
1204+
}
1205+
if name:
1206+
payload['name'] = name
1207+
return await _process_request(token, method_url, params=payload, method='post')
1208+
1209+
11881210
async def revoke_chat_invite_link(token, chat_id, invite_link):
11891211
method_url = 'revokeChatInviteLink'
11901212
payload = {

0 commit comments

Comments
 (0)