Skip to content

Commit

Permalink
Merge pull request #1855 from coder2020official/botapi6.4
Browse files Browse the repository at this point in the history
Bot API 6.4
  • Loading branch information
Badiboy authored Jan 2, 2023
2 parents 79bc869 + 3be5015 commit 3b62ad4
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
<p align="center">Both synchronous and asynchronous.</p>

## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#november-5-2022">6.3</a>!
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#december-30-2022">6.4</a>!

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

Expand Down
111 changes: 99 additions & 12 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,8 @@ def send_photo(
allow_sending_without_reply: Optional[bool]=None,
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
timeout: Optional[int]=None,
message_thread_id: Optional[int]=None) -> types.Message:
message_thread_id: Optional[int]=None,
has_spoiler: Optional[bool]=None) -> types.Message:
"""
Use this method to send photos. On success, the sent Message is returned.
Expand Down Expand Up @@ -1808,6 +1809,9 @@ def send_photo(
:param message_thread_id: Identifier of a message thread, in which the message will be sent
:type message_thread_id: :obj:`int`
:param has_spoiler: Pass True, if the photo should be sent as a spoiler
:type has_spoiler: :obj:`bool`
:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
Expand All @@ -1821,7 +1825,7 @@ def send_photo(
apihelper.send_photo(
self.token, chat_id, photo, caption, reply_to_message_id, reply_markup,
parse_mode, disable_notification, timeout, caption_entities,
allow_sending_without_reply, protect_content, message_thread_id))
allow_sending_without_reply, protect_content, message_thread_id, has_spoiler))

# TODO: Rewrite this method like in API.
def send_audio(
Expand Down Expand Up @@ -2171,7 +2175,8 @@ def send_video(
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
timeout: Optional[int]=None,
data: Optional[Union[Any, str]]=None,
message_thread_id: Optional[int]=None) -> types.Message:
message_thread_id: Optional[int]=None,
has_spoiler: Optional[bool]=None) -> types.Message:
"""
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
Expand Down Expand Up @@ -2233,6 +2238,9 @@ def send_video(
:param message_thread_id: Identifier of a message thread, in which the video will be sent
:type message_thread_id: :obj:`int`
:param has_spoiler: Pass True, if the video should be sent as a spoiler
:type has_spoiler: :obj:`bool`
:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
Expand All @@ -2249,7 +2257,7 @@ def send_video(
apihelper.send_video(
self.token, chat_id, video, duration, caption, reply_to_message_id, reply_markup,
parse_mode, supports_streaming, disable_notification, timeout, thumb, width, height,
caption_entities, allow_sending_without_reply, protect_content, message_thread_id))
caption_entities, allow_sending_without_reply, protect_content, message_thread_id, has_spoiler))

def send_animation(
self, chat_id: Union[int, str], animation: Union[Any, str],
Expand All @@ -2266,7 +2274,8 @@ def send_animation(
allow_sending_without_reply: Optional[bool]=None,
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
timeout: Optional[int]=None,
message_thread_id: Optional[int]=None) -> types.Message:
message_thread_id: Optional[int]=None,
has_spoiler: Optional[bool]=None) -> types.Message:
"""
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
Expand Down Expand Up @@ -2327,6 +2336,9 @@ def send_animation(
:param message_thread_id: Identifier of a message thread, in which the video will be sent
:type message_thread_id: :obj:`int`
:param has_spoiler: Pass True, if the animation should be sent as a spoiler
:type has_spoiler: :obj:`bool`
:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
Expand All @@ -2339,7 +2351,7 @@ def send_animation(
apihelper.send_animation(
self.token, chat_id, animation, duration, caption, reply_to_message_id,
reply_markup, parse_mode, disable_notification, timeout, thumb,
caption_entities, allow_sending_without_reply, protect_content, width, height, message_thread_id))
caption_entities, allow_sending_without_reply, protect_content, width, height, message_thread_id, has_spoiler))

# TODO: Rewrite this method like in API.
def send_video_note(
Expand Down Expand Up @@ -2794,7 +2806,7 @@ def send_contact(
allow_sending_without_reply, protect_content, message_thread_id))

def send_chat_action(
self, chat_id: Union[int, str], action: str, timeout: Optional[int]=None) -> bool:
self, chat_id: Union[int, str], action: str, timeout: Optional[int]=None, message_thread_id: Optional[int]=None) -> bool:
"""
Use this method when you need to tell the user that something is happening on the bot's side.
The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
Expand All @@ -2817,10 +2829,13 @@ def send_chat_action(
:param timeout: Timeout in seconds for the request.
:type timeout: :obj:`int`
:param message_thread_id: The thread identifier of a message from which the reply will be sent(supergroups only)
:type message_thread_id: :obj:`int`
:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.send_chat_action(self.token, chat_id, action, timeout)
return apihelper.send_chat_action(self.token, chat_id, action, timeout, message_thread_id)

@util.deprecated(deprecation_text="Use ban_chat_member instead")
def kick_chat_member(
Expand Down Expand Up @@ -4636,8 +4651,8 @@ def create_forum_topic(self,

def edit_forum_topic(
self, chat_id: Union[int, str],
message_thread_id: int, name: str,
icon_custom_emoji_id: str,
message_thread_id: int, name: Optional[str]=None,
icon_custom_emoji_id: Optional[str]=None
) -> bool:
"""
Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an
Expand All @@ -4652,10 +4667,13 @@ def edit_forum_topic(
:param message_thread_id: Identifier of the topic to edit
:type message_thread_id: :obj:`int`
:param name: New name of the topic, 1-128 characters
:param name: Optional, New name of the topic, 1-128 characters. If not specififed or empty,
the current name of the topic will be kept
:type name: :obj:`str`
:param icon_custom_emoji_id: New custom emoji for the topic icon. Must be an emoji of type “tgs” and must be exactly 1 character long
:param icon_custom_emoji_id: Optional, New unique identifier of the custom emoji shown as the topic icon.
Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the
icon. If not specified, the current icon will be kept
:type icon_custom_emoji_id: :obj:`str`
:return: On success, True is returned.
Expand Down Expand Up @@ -4739,6 +4757,75 @@ def unpin_all_forum_topic_messages(self, chat_id: Union[str, int], message_threa
"""
return apihelper.unpin_all_forum_topic_messages(self.token, chat_id, message_thread_id)

def edit_general_forum_topic(self, chat_id: Union[int, str], name: str) -> bool:
"""
Use this method to edit the name of the 'General' topic in a forum supergroup chat.
The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#editgeneralforumtopic
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`
:param name: New topic name, 1-128 characters
:type name: :obj:`str`
"""

return apihelper.edit_general_forum_topic(self.token, chat_id, name)

def close_general_forum_topic(self, chat_id: Union[int, str]) -> bool:
"""
Use this method to close the 'General' topic in a forum supergroup chat.
The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#closegeneralforumtopic
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`
"""
return apihelper.close_general_forum_topic(self.token, chat_id)

def reopen_general_forum_topic(self, chat_id: Union[int, str]) -> bool:
"""
Use this method to reopen the 'General' topic in a forum supergroup chat.
The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#reopengeneralforumtopic
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`
"""
return apihelper.reopen_general_forum_topic(self.token, chat_id)

def hide_general_forum_topic(self, chat_id: Union[int, str]) -> bool:
"""
Use this method to hide the 'General' topic in a forum supergroup chat.
The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#hidegeneralforumtopic
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`
"""
return apihelper.hide_general_forum_topic(self.token, chat_id)

def unhide_general_forum_topic(self, chat_id: Union[int, str]) -> bool:
"""
Use this method to unhide the 'General' topic in a forum supergroup chat.
The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#unhidegeneralforumtopic
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`
"""
return apihelper.unhide_general_forum_topic(self.token, chat_id)

def get_forum_topic_icon_stickers(self) -> List[types.Sticker]:
"""
Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user.
Expand Down
50 changes: 44 additions & 6 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def send_photo(
caption=None, reply_to_message_id=None, reply_markup=None,
parse_mode=None, disable_notification=None, timeout=None,
caption_entities=None, allow_sending_without_reply=None, protect_content=None,
message_thread_id=None):
message_thread_id=None, has_spoiler=None):
method_url = r'sendPhoto'
payload = {'chat_id': chat_id}
files = None
Expand Down Expand Up @@ -489,6 +489,8 @@ def send_photo(
payload['protect_content'] = protect_content
if message_thread_id is not None:
payload['message_thread_id'] = message_thread_id
if has_spoiler is not None:
payload['has_spoiler'] = has_spoiler
return _make_request(token, method_url, params=payload, files=files, method='post')


Expand Down Expand Up @@ -655,18 +657,20 @@ def send_contact(
return _make_request(token, method_url, params=payload)


def send_chat_action(token, chat_id, action, timeout=None):
def send_chat_action(token, chat_id, action, timeout=None, message_thread_id=None):
method_url = r'sendChatAction'
payload = {'chat_id': chat_id, 'action': action}
if timeout:
payload['timeout'] = timeout
if message_thread_id is not None:
payload['message_thread_id'] = message_thread_id
return _make_request(token, method_url, params=payload)


def send_video(token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None,
parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None,
thumb=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None,
message_thread_id=None):
message_thread_id=None, has_spoiler=None):
method_url = r'sendVideo'
payload = {'chat_id': chat_id}
files = None
Expand Down Expand Up @@ -710,13 +714,16 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_to_messa
payload['protect_content'] = protect_content
if message_thread_id:
payload['message_thread_id'] = message_thread_id
if has_spoiler is not None:
payload['has_spoiler'] = has_spoiler
return _make_request(token, method_url, params=payload, files=files, method='post')


def send_animation(
token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None,
parse_mode=None, disable_notification=None, timeout=None, thumb=None, caption_entities=None,
allow_sending_without_reply=None, protect_content=None, width=None, height=None, message_thread_id=None):
allow_sending_without_reply=None, protect_content=None, width=None, height=None, message_thread_id=None,
has_spoiler=None):
method_url = r'sendAnimation'
payload = {'chat_id': chat_id}
files = None
Expand Down Expand Up @@ -758,6 +765,8 @@ def send_animation(
payload['height'] = height
if message_thread_id:
payload['message_thread_id'] = message_thread_id
if has_spoiler is not None:
payload['has_spoiler'] = has_spoiler
return _make_request(token, method_url, params=payload, files=files, method='post')


Expand Down Expand Up @@ -1766,9 +1775,13 @@ def create_forum_topic(token, chat_id, name, icon_color=None, icon_custom_emoji_
payload['icon_custom_emoji_id'] = icon_custom_emoji_id
return _make_request(token, method_url, params=payload)

def edit_forum_topic(token, chat_id, message_thread_id, name, icon_custom_emoji_id):
def edit_forum_topic(token, chat_id, message_thread_id, name=None, icon_custom_emoji_id=None):
method_url = r'editForumTopic'
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id, 'name': name, 'icon_custom_emoji_id': icon_custom_emoji_id}
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
if name is not None:
payload['name'] = name
if icon_custom_emoji_id is not None:
payload['icon_custom_emoji_id'] = icon_custom_emoji_id
return _make_request(token, method_url, params=payload)

def close_forum_topic(token, chat_id, message_thread_id):
Expand Down Expand Up @@ -1802,6 +1815,31 @@ def stop_poll(token, chat_id, message_id, reply_markup=None):
payload['reply_markup'] = _convert_markup(reply_markup)
return _make_request(token, method_url, params=payload)

def edit_general_forum_topic(token, chat_id, name):
method_url = r'editGeneralForumTopic'
payload = {'chat_id': chat_id, 'name': name}
return _make_request(token, method_url, params=payload)

def close_general_forum_topic(token, chat_id):
method_url = r'closeGeneralForumTopic'
payload = {'chat_id': chat_id}
return _make_request(token, method_url, params=payload)

def reopen_general_forum_topic(token, chat_id):
method_url = r'reopenGeneralForumTopic'
payload = {'chat_id': chat_id}
return _make_request(token, method_url, params=payload)

def hide_general_forum_topic(token, chat_id):
method_url = r'hideGeneralForumTopic'
payload = {'chat_id': chat_id}
return _make_request(token, method_url, params=payload)

def unhide_general_forum_topic(token, chat_id):
method_url = r'unhideGeneralForumTopic'
payload = {'chat_id': chat_id}
return _make_request(token, method_url, params=payload)


def _convert_list_json_serializable(results):
ret = ''
Expand Down
Loading

0 comments on commit 3b62ad4

Please sign in to comment.