Skip to content

Commit a27d82c

Browse files
authored
Merge pull request #2377 from coder2020official/botapi-79
Bot API 7.9
2 parents e077d21 + 25266a1 commit a27d82c

File tree

6 files changed

+204
-10
lines changed

6 files changed

+204
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
1111
<p align="center">Both synchronous and asynchronous.</p>
1212

13-
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api-changelog#july-31-2024"><img src="https://img.shields.io/badge/Bot%20API-7.8-blue?logo=telegram" alt="Supported Bot API version"></a>
13+
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#august-14-2024"><img src="https://img.shields.io/badge/Bot%20API-7.9-blue?logo=telegram" alt="Supported Bot API version"></a>
1414

1515
<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
1616
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>

telebot/__init__.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,8 @@ def send_paid_media(
31363136
caption: Optional[str]=None, parse_mode: Optional[str]=None, caption_entities: Optional[List[types.MessageEntity]]=None,
31373137
show_caption_above_media: Optional[bool]=None, disable_notification: Optional[bool]=None,
31383138
protect_content: Optional[bool]=None, reply_parameters: Optional[types.ReplyParameters]=None,
3139-
reply_markup: Optional[REPLY_MARKUP_TYPES]=None) -> types.Message:
3139+
reply_markup: Optional[REPLY_MARKUP_TYPES]=None, business_connection_id: Optional[str]=None,
3140+
) -> types.Message:
31403141
"""
31413142
Use this method to send paid media to channel chats. On success, the sent Message is returned.
31423143
@@ -3175,6 +3176,9 @@ def send_paid_media(
31753176
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
31763177
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup` or :class:`telebot.types.ReplyKeyboardMarkup` or :class:`telebot.types.ReplyKeyboardRemove` or :class:`telebot.types.ForceReply`
31773178
3179+
:param business_connection_id: Identifier of a business connection, in which the message will be sent
3180+
:type business_connection_id: :obj:`str`
3181+
31783182
:return: On success, the sent Message is returned.
31793183
:rtype: :class:`telebot.types.Message`
31803184
"""
@@ -3183,7 +3187,7 @@ def send_paid_media(
31833187
self.token, chat_id, star_count, media, caption=caption, parse_mode=parse_mode,
31843188
caption_entities=caption_entities, show_caption_above_media=show_caption_above_media,
31853189
disable_notification=disable_notification, protect_content=protect_content,
3186-
reply_parameters=reply_parameters, reply_markup=reply_markup)
3190+
reply_parameters=reply_parameters, reply_markup=reply_markup, business_connection_id=business_connection_id)
31873191
)
31883192

31893193

@@ -4195,6 +4199,62 @@ def edit_chat_invite_link(
41954199
apihelper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
41964200
)
41974201

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=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=name)
4257+
)
41984258

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

telebot/apihelper.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ def send_photo(
529529
def send_paid_media(
530530
token, chat_id, star_count, media,
531531
caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None,
532-
disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None):
532+
disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None,
533+
business_connection_id=None):
533534
method_url = r'sendPaidMedia'
534535
media_json, files = convert_input_media_array(media)
535536
payload = {'chat_id': chat_id, 'star_count': star_count, 'media': media_json}
@@ -549,6 +550,8 @@ def send_paid_media(
549550
payload['reply_parameters'] = reply_parameters.to_json()
550551
if reply_markup:
551552
payload['reply_markup'] = _convert_markup(reply_markup)
553+
if business_connection_id:
554+
payload['business_connection_id'] = business_connection_id
552555
return _make_request(
553556
token, method_url, params=payload,
554557
method='post' if files else 'get',
@@ -1202,6 +1205,26 @@ def edit_chat_invite_link(token, chat_id, invite_link, name, expire_date, member
12021205

12031206
return _make_request(token, method_url, params=payload, method='post')
12041207

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(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')
12051228

12061229
def revoke_chat_invite_link(token, chat_id, invite_link):
12071230
method_url = 'revokeChatInviteLink'

telebot/async_telebot.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,7 @@ async def send_paid_media(
45644564
caption: Optional[str]=None, parse_mode: Optional[str]=None, caption_entities: Optional[List[types.MessageEntity]]=None,
45654565
show_caption_above_media: Optional[bool]=None, disable_notification: Optional[bool]=None,
45664566
protect_content: Optional[bool]=None, reply_parameters: Optional[types.ReplyParameters]=None,
4567-
reply_markup: Optional[REPLY_MARKUP_TYPES]=None) -> types.Message:
4567+
reply_markup: Optional[REPLY_MARKUP_TYPES]=None, business_connection_id: Optional[str]=None) -> types.Message:
45684568
"""
45694569
Use this method to send paid media to channel chats. On success, the sent Message is returned.
45704570
@@ -4603,6 +4603,9 @@ async def send_paid_media(
46034603
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
46044604
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup` or :class:`telebot.types.ReplyKeyboardMarkup` or :class:`telebot.types.ReplyKeyboardRemove` or :class:`telebot.types.ForceReply`
46054605
4606+
:param business_connection_id: Identifier of a business connection, in which the message will be sent
4607+
:type business_connection_id: :obj:`str`
4608+
46064609
:return: On success, the sent Message is returned.
46074610
:rtype: :class:`telebot.types.Message`
46084611
"""
@@ -4611,8 +4614,7 @@ async def send_paid_media(
46114614
self.token, chat_id, star_count, media, caption=caption, parse_mode=parse_mode,
46124615
caption_entities=caption_entities, show_caption_above_media=show_caption_above_media,
46134616
disable_notification=disable_notification, protect_content=protect_content,
4614-
reply_parameters=reply_parameters, reply_markup=reply_markup)
4615-
)
4617+
reply_parameters=reply_parameters, reply_markup=reply_markup, business_connection_id=business_connection_id))
46164618

46174619
async def send_media_group(
46184620
self, chat_id: Union[int, str],
@@ -5603,6 +5605,63 @@ async def edit_chat_invite_link(
56035605
return types.ChatInviteLink.de_json(
56045606
await asyncio_helper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
56055607
)
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=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=name)
5664+
)
56065665

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

telebot/asyncio_helper.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ async def send_message(
309309
if message_effect_id:
310310
params['message_effect_id'] = message_effect_id
311311

312-
return await _process_request(token, method_name, params=params)
312+
return await _process_request(token, method_name, params=params, method='post')
313313

314314
# methods
315315

@@ -519,7 +519,8 @@ async def send_photo(
519519
async def send_paid_media(
520520
token, chat_id, star_count, media,
521521
caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None,
522-
disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None):
522+
disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None,
523+
business_connection_id=None):
523524
method_url = r'sendPaidMedia'
524525
media_json, files = convert_input_media_array(media)
525526
payload = {'chat_id': chat_id, 'star_count': star_count, 'media': media_json}
@@ -539,6 +540,8 @@ async def send_paid_media(
539540
payload['reply_parameters'] = reply_parameters.to_json()
540541
if reply_markup:
541542
payload['reply_markup'] = _convert_markup(reply_markup)
543+
if business_connection_id:
544+
payload['business_connection_id'] = business_connection_id
542545
return await _process_request(
543546
token, method_url, params=payload,
544547
method='post' if files else 'get',
@@ -1182,6 +1185,28 @@ async def edit_chat_invite_link(token, chat_id, invite_link, name, expire_date,
11821185

11831186
return await _process_request(token, method_url, params=payload, method='post')
11841187

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+
11851210
async def revoke_chat_invite_link(token, chat_id, invite_link):
11861211
method_url = 'revokeChatInviteLink'
11871212
payload = {

telebot/types.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8478,6 +8478,27 @@ def to_dict(self) -> dict:
84788478
return json_dict
84798479

84808480

8481+
class ReactionTypePaid(ReactionType):
8482+
"""
8483+
This object represents a paid reaction type.
8484+
8485+
Telegram documentation: https://core.telegram.org/bots/api#reactiontypepaid
8486+
8487+
:param type: Type of the reaction, must be paid
8488+
:type type: :obj:`str`
8489+
8490+
:return: Instance of the class
8491+
:rtype: :class:`ReactionTypePaid`
8492+
"""
8493+
8494+
def __init__(self, **kwargs) -> None:
8495+
super().__init__('paid')
8496+
8497+
def to_dict(self) -> dict:
8498+
return super().to_dict()
8499+
8500+
8501+
84818502
class MessageReactionUpdated(JsonDeserializable):
84828503
"""
84838504
This object represents a service message about a change in the list of the current user's reactions to a message.
@@ -10390,20 +10411,26 @@ class TransactionPartnerUser(TransactionPartner):
1039010411
:param invoice_payload: Optional, Bot-specified invoice payload
1039110412
:type invoice_payload: :obj:`str`
1039210413
10414+
:param paid_media: Optional. Information about the paid media bought by the user
10415+
:type paid_media: :obj:`list` of :class:`PaidMedia`
10416+
1039310417
:return: Instance of the class
1039410418
:rtype: :class:`TransactionPartnerUser`
1039510419
"""
1039610420

10397-
def __init__(self, type, user, invoice_payload=None, **kwargs):
10421+
def __init__(self, type, user, invoice_payload=None, paid_media: Optional[List[PaidMedia]] = None, **kwargs):
1039810422
self.type: str = type
1039910423
self.user: User = user
1040010424
self.invoice_payload: Optional[str] = invoice_payload
10425+
self.paid_media: Optional[List[PaidMedia]] = paid_media
1040110426

1040210427
@classmethod
1040310428
def de_json(cls, json_string):
1040410429
if json_string is None: return None
1040510430
obj = cls.check_json(json_string)
1040610431
obj['user'] = User.de_json(obj['user'])
10432+
if 'paid_media' in obj:
10433+
obj['paid_media'] = [PaidMedia.de_json(media) for media in obj['paid_media']]
1040710434
return cls(**obj)
1040810435

1040910436

0 commit comments

Comments
 (0)