Skip to content

Commit a9d4e8b

Browse files
authored
Merge pull request eternnoir#2440 from coder2020official/botapi-82
Bot API 8.2 full support
2 parents c56f9de + ebb291a commit a9d4e8b

6 files changed

Lines changed: 210 additions & 10 deletions

File tree

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#november-17-2024"><img src="https://img.shields.io/badge/Bot%20API-8.1-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#january-1-2025"><img src="https://img.shields.io/badge/Bot%20API-8.2-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: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6250,7 +6250,8 @@ def delete_sticker_set(self, name:str) -> bool:
62506250
"""
62516251
return apihelper.delete_sticker_set(self.token, name)
62526252

6253-
def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_parse_mode: Optional[str]=None, text_entities: Optional[List[types.MessageEntity]]=None) -> bool:
6253+
def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_parse_mode: Optional[str]=None,
6254+
text_entities: Optional[List[types.MessageEntity]]=None, pay_for_upgrade: Optional[bool]=None) -> bool:
62546255
"""
62556256
Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success.
62566257
@@ -6262,6 +6263,9 @@ def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_p
62626263
:param gift_id: Identifier of the gift
62636264
:type gift_id: :obj:`str`
62646265
6266+
:param pay_for_upgrade: Pass True to pay for the gift upgrade from the bot's balance, thereby making the upgrade free for the receiver
6267+
:type pay_for_upgrade: :obj:`bool`
6268+
62656269
:param text: Text that will be shown along with the gift; 0-255 characters
62666270
:type text: :obj:`str`
62676271
@@ -6274,7 +6278,71 @@ def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_p
62746278
:return: Returns True on success.
62756279
:rtype: :obj:`bool`
62766280
"""
6277-
return apihelper.send_gift(self.token, user_id, gift_id, text=text, text_parse_mode=text_parse_mode, text_entities=text_entities)
6281+
return apihelper.send_gift(self.token, user_id, gift_id, text=text, text_parse_mode=text_parse_mode, text_entities=text_entities,
6282+
pay_for_upgrade=pay_for_upgrade)
6283+
6284+
def verify_user(self, user_id: int, custom_description: Optional[str]=None) -> bool:
6285+
"""
6286+
Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.
6287+
6288+
Telegram documentation: https://core.telegram.org/bots/api#verifyuser
6289+
6290+
:param user_id: Unique identifier of the target user
6291+
:type user_id: :obj:`int`
6292+
6293+
:param custom_description: Custom description for the verification; 0-70 characters. Must be empty if the organization isn't allowed to provide a custom verification description.
6294+
:type custom_description: :obj:`str`
6295+
6296+
:return: Returns True on success.
6297+
:rtype: :obj:`bool`
6298+
"""
6299+
return apihelper.verify_user(self.token, user_id, custom_description=custom_description)
6300+
6301+
def verify_chat(self, chat_id: Union[int, str], custom_description: Optional[str]=None) -> bool:
6302+
"""
6303+
Verifies a chat on behalf of the organization which is represented by the bot. Returns True on success.
6304+
6305+
Telegram documentation: https://core.telegram.org/bots/api#verifychat
6306+
6307+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
6308+
:type chat_id: :obj:`int` | :obj:`str`
6309+
6310+
:param custom_description: Custom description for the verification; 0-70 characters. Must be empty if the organization isn't allowed to provide a custom verification description.
6311+
:type custom_description: :obj:`str`
6312+
6313+
:return: Returns True on success.
6314+
:rtype: :obj:`bool`
6315+
"""
6316+
return apihelper.verify_chat(self.token, chat_id, custom_description=custom_description)
6317+
6318+
def remove_user_verification(self, user_id: int) -> bool:
6319+
"""
6320+
Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.
6321+
6322+
Telegram documentation: https://core.telegram.org/bots/api#removeuserverification
6323+
6324+
:param user_id: Unique identifier of the target user
6325+
:type user_id: :obj:`int`
6326+
6327+
:return: Returns True on success.
6328+
:rtype: :obj:`bool`
6329+
"""
6330+
6331+
return apihelper.remove_user_verification(self.token, user_id)
6332+
6333+
def remove_chat_verification(self, chat_id: Union[int, str]) -> bool:
6334+
"""
6335+
Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.
6336+
6337+
Telegram documentation: https://core.telegram.org/bots/api#removechatverification
6338+
6339+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
6340+
:type chat_id: :obj:`int` | :obj:`str`
6341+
6342+
:return: Returns True on success.
6343+
:rtype: :obj:`bool`
6344+
"""
6345+
return apihelper.remove_chat_verification(self.token, chat_id)
62786346

62796347
def get_available_gifts(self) -> types.Gifts:
62806348
"""

telebot/apihelper.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ def get_available_gifts(token):
19291929
return _make_request(token, method_url)
19301930

19311931

1932-
def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None):
1932+
def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None):
19331933
method_url = 'sendGift'
19341934
payload = {'user_id': user_id, 'gift_id': gift_id}
19351935
if text:
@@ -1938,6 +1938,36 @@ def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_ent
19381938
payload['text_parse_mode'] = text_parse_mode
19391939
if text_entities:
19401940
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
1941+
if pay_for_upgrade is not None:
1942+
payload['pay_for_upgrade'] = pay_for_upgrade
1943+
return _make_request(token, method_url, params=payload, method='post')
1944+
1945+
1946+
def verify_user(token, user_id, custom_description=None):
1947+
method_url = 'verifyUser'
1948+
payload = {'user_id': user_id}
1949+
if custom_description:
1950+
payload['custom_description'] = custom_description
1951+
return _make_request(token, method_url, params=payload, method='post')
1952+
1953+
1954+
def verify_chat(token, chat_id, custom_description=None):
1955+
method_url = 'verifyChat'
1956+
payload = {'chat_id': chat_id}
1957+
if custom_description:
1958+
payload['custom_description'] = custom_description
1959+
return _make_request(token, method_url, params=payload, method='post')
1960+
1961+
1962+
def remove_user_verification(token, user_id):
1963+
method_url = 'removeUserVerification'
1964+
payload = {'user_id': user_id}
1965+
return _make_request(token, method_url, params=payload, method='post')
1966+
1967+
1968+
def remove_chat_verification(token, chat_id):
1969+
method_url = 'removeChatVerification'
1970+
payload = {'chat_id': chat_id}
19411971
return _make_request(token, method_url, params=payload, method='post')
19421972

19431973
def set_sticker_emoji_list(token, sticker, emoji_list):
@@ -2276,7 +2306,7 @@ def convert_input_media_array(array):
22762306
if isinstance(thumbnail, types.InputFile):
22772307
thumbnail_key = 'thumbnail_' + key
22782308
files[thumbnail_key] = thumbnail
2279-
media_dict['thumbnail'] = 'attach://' + thumbnail_key
2309+
media_dict['thumbnail'] = 'attach://' + thumbnail_key
22802310
media.append(media_dict)
22812311
return json.dumps(media), files
22822312

telebot/async_telebot.py

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7707,7 +7707,8 @@ async def delete_sticker_set(self, name:str) -> bool:
77077707

77087708
return await asyncio_helper.delete_sticker_set(self.token, name)
77097709

7710-
async def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_parse_mode: Optional[str]=None, text_entities: Optional[List[types.MessageEntity]]=None) -> bool:
7710+
async def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_parse_mode: Optional[str]=None,
7711+
text_entities: Optional[List[types.MessageEntity]]=None, pay_for_upgrade: Optional[bool]=None) -> bool:
77117712
"""
77127713
Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success.
77137714
@@ -7719,6 +7720,9 @@ async def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None,
77197720
:param gift_id: Identifier of the gift
77207721
:type gift_id: :obj:`str`
77217722
7723+
:param pay_for_upgrade: Pass True to pay for the gift upgrade from the bot's balance, thereby making the upgrade free for the receiver
7724+
:type pay_for_upgrade: :obj:`bool`
7725+
77227726
:param text: Text that will be shown along with the gift; 0-255 characters
77237727
:type text: :obj:`str`
77247728
@@ -7731,7 +7735,71 @@ async def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None,
77317735
:return: Returns True on success.
77327736
:rtype: :obj:`bool`
77337737
"""
7734-
return await asyncio_helper.send_gift(self.token, user_id, gift_id, text, text_parse_mode, text_entities)
7738+
return await asyncio_helper.send_gift(self.token, user_id, gift_id, text, text_parse_mode, text_entities, pay_for_upgrade=pay_for_upgrade)
7739+
7740+
async def verify_user(self, user_id: int, custom_description: Optional[str]=None) -> bool:
7741+
"""
7742+
Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.
7743+
7744+
Telegram documentation: https://core.telegram.org/bots/api#verifyuser
7745+
7746+
:param user_id: Unique identifier of the target user
7747+
:type user_id: :obj:`int`
7748+
7749+
:param custom_description: Custom description for the verification; 0-70 characters. Must be empty if the organization isn't allowed to provide a custom verification description.
7750+
:type custom_description: :obj:`str`
7751+
7752+
:return: Returns True on success.
7753+
:rtype: :obj:`bool`
7754+
"""
7755+
return await asyncio_helper.verify_user(self.token, user_id, custom_description=custom_description)
7756+
7757+
async def verify_chat(self, chat_id: Union[int, str], custom_description: Optional[str]=None) -> bool:
7758+
"""
7759+
Verifies a chat on behalf of the organization which is represented by the bot. Returns True on success.
7760+
7761+
Telegram documentation: https://core.telegram.org/bots/api#verifychat
7762+
7763+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
7764+
:type chat_id: :obj:`int` | :obj:`str`
7765+
7766+
:param custom_description: Custom description for the verification; 0-70 characters. Must be empty if the organization isn't allowed to provide a custom verification description.
7767+
:type custom_description: :obj:`str`
7768+
7769+
:return: Returns True on success.
7770+
:rtype: :obj:`bool`
7771+
"""
7772+
7773+
return await asyncio_helper.verify_chat(self.token, chat_id, custom_description=custom_description)
7774+
7775+
async def remove_user_verification(self, user_id: int) -> bool:
7776+
"""
7777+
Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.
7778+
7779+
Telegram documentation: https://core.telegram.org/bots/api#removeuserverification
7780+
7781+
:param user_id: Unique identifier of the target user
7782+
:type user_id: :obj:`int`
7783+
7784+
:return: Returns True on success.
7785+
:rtype: :obj:`bool`
7786+
7787+
"""
7788+
return await asyncio_helper.remove_user_verification(self.token, user_id)
7789+
7790+
async def remove_chat_verification(self, chat_id: Union[int, str]) -> bool:
7791+
"""
7792+
Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.
7793+
7794+
Telegram documentation: https://core.telegram.org/bots/api#removechatverification
7795+
7796+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
7797+
:type chat_id: :obj:`int` | :obj:`str`
7798+
7799+
:return: Returns True on success.
7800+
:rtype: :obj:`bool`
7801+
"""
7802+
return await asyncio_helper.remove_chat_verification(self.token, chat_id)
77357803

77367804
async def get_available_gifts(self) -> types.Gifts:
77377805
"""

telebot/asyncio_helper.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ async def delete_sticker_set(token, name):
19161916
payload = {'name': name}
19171917
return await _process_request(token, method_url, params=payload, method='post')
19181918

1919-
async def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None):
1919+
async def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None):
19201920
method_url = 'sendGift'
19211921
payload = {'user_id': user_id, 'gift_id': gift_id}
19221922
if text:
@@ -1925,6 +1925,32 @@ async def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, te
19251925
payload['text_parse_mode'] = text_parse_mode
19261926
if text_entities:
19271927
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
1928+
if pay_for_upgrade is not None:
1929+
payload['pay_for_upgrade'] = pay_for_upgrade
1930+
return await _process_request(token, method_url, params=payload, method='post')
1931+
1932+
async def verify_user(token, user_id, custom_description=None):
1933+
method_url = 'verifyUser'
1934+
payload = {'user_id': user_id}
1935+
if custom_description:
1936+
payload['custom_description'] = custom_description
1937+
return await _process_request(token, method_url, params=payload, method='post')
1938+
1939+
async def verify_chat(token, chat_id, custom_description=None):
1940+
method_url = 'verifyChat'
1941+
payload = {'chat_id': chat_id}
1942+
if custom_description:
1943+
payload['custom_description'] = custom_description
1944+
return await _process_request(token, method_url, params=payload, method='post')
1945+
1946+
async def remove_user_verification(token, user_id):
1947+
method_url = 'removeUserVerification'
1948+
payload = {'user_id': user_id}
1949+
return await _process_request(token, method_url, params=payload, method='post')
1950+
1951+
async def remove_chat_verification(token, chat_id):
1952+
method_url = 'removeChatVerification'
1953+
payload = {'chat_id': chat_id}
19281954
return await _process_request(token, method_url, params=payload, method='post')
19291955

19301956
async def get_available_gifts(token):
@@ -2248,7 +2274,7 @@ async def convert_input_media_array(array):
22482274
if isinstance(thumbnail, types.InputFile):
22492275
thumbnail_key = 'thumbnail_' + key
22502276
files[thumbnail_key] = thumbnail
2251-
media_dict['thumbnail'] = 'attach://' + thumbnail_key
2277+
media_dict['thumbnail'] = 'attach://' + thumbnail_key
22522278
media.append(media_dict)
22532279
return json.dumps(media), files
22542280

telebot/types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4449,6 +4449,10 @@ def __init__(self, id: str, title: str, input_message_content: InputMessageConte
44494449
self.thumbnail_width: Optional[int] = thumbnail_width
44504450
self.thumbnail_height: Optional[int] = thumbnail_height
44514451

4452+
if hide_url:
4453+
log_deprecation_warning('The parameter "hide_url" is deprecated. Pass an empty string as url instead.')
4454+
self.url = ''
4455+
44524456

44534457
@property
44544458
def thumb_url(self) -> str:
@@ -11059,6 +11063,9 @@ class Gift(JsonDeserializable):
1105911063
:param star_count: The number of Telegram Stars that must be paid to send the sticker
1106011064
:type star_count: :obj:`int`
1106111065
11066+
:param upgrade_star_count: Optional. The number of Telegram Stars that must be paid to upgrade the gift to a unique one
11067+
:type upgrade_star_count: :obj:`int`
11068+
1106211069
:param total_count: Optional. The total number of the gifts of this type that can be sent; for limited gifts only
1106311070
:type total_count: :obj:`int`
1106411071
@@ -11069,12 +11076,13 @@ class Gift(JsonDeserializable):
1106911076
:rtype: :class:`Gift`
1107011077
"""
1107111078

11072-
def __init__(self, id, sticker, star_count, total_count=None, remaining_count=None, **kwargs):
11079+
def __init__(self, id, sticker, star_count, total_count=None, remaining_count=None, upgrade_star_count=None, **kwargs):
1107311080
self.id: str = id
1107411081
self.sticker: Sticker = sticker
1107511082
self.star_count: int = star_count
1107611083
self.total_count: Optional[int] = total_count
1107711084
self.remaining_count: Optional[int] = remaining_count
11085+
self.upgrade_star_count: Optional[int] = upgrade_star_count
1107811086

1107911087
@classmethod
1108011088
def de_json(cls, json_string):

0 commit comments

Comments
 (0)