Skip to content

Commit 1baa9cf

Browse files
authored
Merge pull request #2453 from coder2020official/botapi-83
Bot API 8.3 Update
2 parents 198d92f + 7d82d8f commit 1baa9cf

File tree

6 files changed

+236
-47
lines changed

6 files changed

+236
-47
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#january-1-2025"><img src="https://img.shields.io/badge/Bot%20API-8.2-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#february-12-2025"><img src="https://img.shields.io/badge/Bot%20API-8.3-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: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,8 @@ def forward_message(
18101810
message_id: int, disable_notification: Optional[bool]=None,
18111811
protect_content: Optional[bool]=None,
18121812
timeout: Optional[int]=None,
1813-
message_thread_id: Optional[int]=None) -> types.Message:
1813+
message_thread_id: Optional[int]=None,
1814+
video_start_timestamp: Optional[int]=None) -> types.Message:
18141815
"""
18151816
Use this method to forward messages of any kind.
18161817
@@ -1825,6 +1826,9 @@ def forward_message(
18251826
:param from_chat_id: Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
18261827
:type from_chat_id: :obj:`int` or :obj:`str`
18271828
1829+
:param video_start_timestamp: New start timestamp for the forwarded video in the message
1830+
:type video_start_timestamp: :obj:`int`
1831+
18281832
:param message_id: Message identifier in the chat specified in from_chat_id
18291833
:type message_id: :obj:`int`
18301834
@@ -1846,7 +1850,8 @@ def forward_message(
18461850
return types.Message.de_json(
18471851
apihelper.forward_message(
18481852
self.token, chat_id, from_chat_id, message_id, disable_notification=disable_notification,
1849-
timeout=timeout, protect_content=protect_content, message_thread_id=message_thread_id))
1853+
timeout=timeout, protect_content=protect_content, message_thread_id=message_thread_id,
1854+
video_start_timestamp=video_start_timestamp))
18501855

18511856

18521857
def copy_message(
@@ -1865,7 +1870,8 @@ def copy_message(
18651870
message_thread_id: Optional[int]=None,
18661871
reply_parameters: Optional[types.ReplyParameters]=None,
18671872
show_caption_above_media: Optional[bool]=None,
1868-
allow_paid_broadcast: Optional[bool]=None) -> types.MessageID:
1873+
allow_paid_broadcast: Optional[bool]=None,
1874+
video_start_timestamp: Optional[int]=None) -> types.MessageID:
18691875
"""
18701876
Use this method to copy messages of any kind.
18711877
Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
@@ -1883,6 +1889,9 @@ def copy_message(
18831889
:param message_id: Message identifier in the chat specified in from_chat_id
18841890
:type message_id: :obj:`int`
18851891
1892+
:param video_start_timestamp: New start timestamp for the copied video in the message
1893+
:type video_start_timestamp: :obj:`int`
1894+
18861895
:param caption: New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
18871896
:type caption: :obj:`str`
18881897
@@ -1956,7 +1965,8 @@ def copy_message(
19561965
parse_mode=parse_mode, caption_entities=caption_entities, disable_notification=disable_notification,
19571966
reply_markup=reply_markup, timeout=timeout, protect_content=protect_content,
19581967
message_thread_id=message_thread_id, reply_parameters=reply_parameters,
1959-
show_caption_above_media=show_caption_above_media, allow_paid_broadcast=allow_paid_broadcast))
1968+
show_caption_above_media=show_caption_above_media, allow_paid_broadcast=allow_paid_broadcast,
1969+
video_start_timestamp=video_start_timestamp))
19601970

19611971

19621972
def delete_message(self, chat_id: Union[int, str], message_id: int,
@@ -2824,7 +2834,9 @@ def send_video(
28242834
business_connection_id: Optional[str]=None,
28252835
message_effect_id: Optional[str]=None,
28262836
show_caption_above_media: Optional[bool]=None,
2827-
allow_paid_broadcast: Optional[bool]=None) -> types.Message:
2837+
allow_paid_broadcast: Optional[bool]=None,
2838+
cover: Optional[Union[Any, str]]=None,
2839+
start_timestamp: Optional[int]=None) -> types.Message:
28282840
"""
28292841
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
28302842
@@ -2845,8 +2857,18 @@ def send_video(
28452857
:param height: Video height
28462858
:type height: :obj:`int`
28472859
2848-
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
2860+
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size.
2861+
A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
2862+
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
28492863
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
2864+
2865+
:param cover: Cover for the video in the message. Pass a file_id to send a file that exists on the Telegram servers (recommended),
2866+
pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://<file_attach_name>” to upload a new one using multipart/form-data under
2867+
<file_attach_name> name. More information on Sending Files »
2868+
:type cover: :obj:`str` or :class:`telebot.types.InputFile`
2869+
2870+
:param start_timestamp: Start timestamp for the video in the message
2871+
:type start_timestamp: :obj:`int`
28502872
28512873
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
28522874
:type caption: :obj:`str`
@@ -2949,7 +2971,8 @@ def send_video(
29492971
thumbnail=thumbnail, height=height, width=width, caption_entities=caption_entities,
29502972
protect_content=protect_content, message_thread_id=message_thread_id, has_spoiler=has_spoiler,
29512973
reply_parameters=reply_parameters, business_connection_id=business_connection_id, message_effect_id=message_effect_id,
2952-
show_caption_above_media=show_caption_above_media, allow_paid_broadcast=allow_paid_broadcast)
2974+
show_caption_above_media=show_caption_above_media, allow_paid_broadcast=allow_paid_broadcast,
2975+
cover=cover, start_timestamp=start_timestamp)
29532976
)
29542977

29552978

@@ -6250,19 +6273,24 @@ def delete_sticker_set(self, name:str) -> bool:
62506273
"""
62516274
return apihelper.delete_sticker_set(self.token, name)
62526275

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:
6276+
def send_gift(self, user_id: Optional[Union[str, int]] = None, gift_id: str=None, text: Optional[str]=None, text_parse_mode: Optional[str]=None,
6277+
text_entities: Optional[List[types.MessageEntity]]=None, pay_for_upgrade: Optional[bool]=None,
6278+
chat_id: Optional[Union[str, int]] = None) -> bool:
62556279
"""
62566280
Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success.
62576281
62586282
Telegram documentation: https://core.telegram.org/bots/api#sendgift
62596283
6260-
:param user_id: Unique identifier of the target user that will receive the gift
6261-
:type user_id: :obj:`int`
6262-
62636284
:param gift_id: Identifier of the gift
62646285
:type gift_id: :obj:`str`
62656286
6287+
:param user_id: Required if chat_id is not specified. Unique identifier of the target user who will receive the gift.
6288+
:type user_id::obj:`int` | :obj:`str`
6289+
6290+
:param chat_id: Required if user_id is not specified. Unique identifier for the chat or username of the channel
6291+
(in the format @channelusername) that will receive the gift.
6292+
:type chat_id: :obj:`int` | :obj:`str`
6293+
62666294
: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
62676295
:type pay_for_upgrade: :obj:`bool`
62686296
@@ -6278,8 +6306,14 @@ def send_gift(self, user_id: int, gift_id: str, text: Optional[str]=None, text_p
62786306
:return: Returns True on success.
62796307
:rtype: :obj:`bool`
62806308
"""
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)
6309+
if user_id is None and chat_id is None:
6310+
raise ValueError("Either user_id or chat_id must be specified.")
6311+
6312+
if gift_id is None:
6313+
raise ValueError("gift_id must be specified.")
6314+
6315+
return apihelper.send_gift(self.token, gift_id, text=text, text_parse_mode=text_parse_mode, text_entities=text_entities,
6316+
pay_for_upgrade=pay_for_upgrade, chat_id=chat_id, user_id=user_id)
62836317

62846318
def verify_user(self, user_id: int, custom_description: Optional[str]=None) -> bool:
62856319
"""

telebot/apihelper.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ def get_chat_member(token, chat_id, user_id):
424424

425425
def forward_message(
426426
token, chat_id, from_chat_id, message_id,
427-
disable_notification=None, timeout=None, protect_content=None, message_thread_id=None):
427+
disable_notification=None, timeout=None, protect_content=None, message_thread_id=None,
428+
video_start_timestamp=None):
428429
method_url = r'forwardMessage'
429430
payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id}
430431
if disable_notification is not None:
@@ -435,12 +436,15 @@ def forward_message(
435436
payload['protect_content'] = protect_content
436437
if message_thread_id:
437438
payload['message_thread_id'] = message_thread_id
439+
if video_start_timestamp:
440+
payload['video_start_timestamp'] = video_start_timestamp
438441
return _make_request(token, method_url, params=payload)
439442

440443

441444
def copy_message(token, chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None,
442445
disable_notification=None, reply_markup=None, timeout=None, protect_content=None, message_thread_id=None,
443-
reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None):
446+
reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None,
447+
video_start_timestamp=None):
444448
method_url = r'copyMessage'
445449
payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id}
446450
if caption is not None:
@@ -465,6 +469,8 @@ def copy_message(token, chat_id, from_chat_id, message_id, caption=None, parse_m
465469
payload['show_caption_above_media'] = show_caption_above_media
466470
if allow_paid_broadcast is not None:
467471
payload['allow_paid_broadcast'] = allow_paid_broadcast
472+
if video_start_timestamp:
473+
payload['video_start_timestamp'] = video_start_timestamp
468474
return _make_request(token, method_url, params=payload)
469475

470476

@@ -783,7 +789,8 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_markup=N
783789
parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None,
784790
thumbnail=None, width=None, height=None, caption_entities=None, protect_content=None,
785791
message_thread_id=None, has_spoiler=None, reply_parameters=None, business_connection_id=None,
786-
message_effect_id=None, show_caption_above_media=None, allow_paid_broadcast=None):
792+
message_effect_id=None, show_caption_above_media=None, allow_paid_broadcast=None,
793+
cover=None, start_timestamp=None):
787794
method_url = r'sendVideo'
788795
payload = {'chat_id': chat_id}
789796
files = None
@@ -835,6 +842,16 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_markup=N
835842
payload['show_caption_above_media'] = show_caption_above_media
836843
if allow_paid_broadcast is not None:
837844
payload['allow_paid_broadcast'] = allow_paid_broadcast
845+
if cover:
846+
if not util.is_string(cover):
847+
if files:
848+
files['cover'] = cover
849+
else:
850+
files = {'cover': cover}
851+
else:
852+
payload['cover'] = cover
853+
if start_timestamp:
854+
payload['start_timestamp'] = start_timestamp
838855

839856
return _make_request(token, method_url, params=payload, files=files, method='post')
840857

@@ -1929,7 +1946,8 @@ def get_available_gifts(token):
19291946
return _make_request(token, method_url)
19301947

19311948

1932-
def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None):
1949+
def send_gift(token, gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None,
1950+
chat_id=None, user_id=None):
19331951
method_url = 'sendGift'
19341952
payload = {'user_id': user_id, 'gift_id': gift_id}
19351953
if text:
@@ -1940,6 +1958,10 @@ def send_gift(token, user_id, gift_id, text=None, text_parse_mode=None, text_ent
19401958
payload['text_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(text_entities))
19411959
if pay_for_upgrade is not None:
19421960
payload['pay_for_upgrade'] = pay_for_upgrade
1961+
if chat_id:
1962+
payload['chat_id'] = chat_id
1963+
if user_id:
1964+
payload['user_id'] = user_id
19431965
return _make_request(token, method_url, params=payload, method='post')
19441966

19451967

0 commit comments

Comments
 (0)