mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Added docs to types, added new methods
Added the methods createForumTopic, editForumTopic, closeForumTopic, reopenForumTopic, deleteForumTopic, unpinAllForumTopicMessages, and getForumTopicIconStickers for forum topic management.
This commit is contained in:
parent
876d679765
commit
4825624d48
@ -4530,6 +4530,150 @@ class TeleBot:
|
||||
"""
|
||||
return apihelper.delete_sticker_from_set(self.token, sticker)
|
||||
|
||||
def create_forum_topic(self,
|
||||
chat_id: int, name: str, icon_color: Optional[int]=None,
|
||||
icon_custom_emoji_id: Optional[str]=None) -> types.ForumTopic:
|
||||
"""
|
||||
Use this method to create a topic in a forum supergroup chat. The bot must be an administrator
|
||||
in the chat for this to work and must have the can_manage_topics administrator rights.
|
||||
Returns information about the created topic as a ForumTopic object.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#createforumtopic
|
||||
|
||||
: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: Name of the topic, 1-128 characters
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param icon_color: Color of the topic icon in RGB format. Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F
|
||||
:type icon_color: :obj:`int`
|
||||
|
||||
:param icon_custom_emoji_id: Custom emoji for the topic icon. Must be an emoji of type “tgs” and must be exactly 1 character long
|
||||
:type icon_custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: On success, information about the created topic is returned as a ForumTopic object.
|
||||
:rtype: :class:`telebot.types.ForumTopic`
|
||||
"""
|
||||
return apihelper.create_forum_topic(self.token, chat_id, name, icon_color, icon_custom_emoji_id)
|
||||
|
||||
def edit_forum_topic(
|
||||
self, chat_id: Union[int, str],
|
||||
message_thread_id: int, name: str,
|
||||
icon_custom_emoji_id: str,
|
||||
) -> bool:
|
||||
"""
|
||||
Use this method to edit name and icon of a 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,
|
||||
unless it is the creator of the topic. Returns True on success.
|
||||
|
||||
Telegram Documentation: https://core.telegram.org/bots/api#editforumtopic
|
||||
|
||||
: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 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
|
||||
: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
|
||||
:type icon_custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.edit_forum_topic(self.token, chat_id, message_thread_id, name, icon_custom_emoji_id)
|
||||
|
||||
def close_forum_topic(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator
|
||||
in the chat for this to work and must have the can_manage_topics administrator rights, unless it is
|
||||
the creator of the topic. Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#closeforumtopic
|
||||
|
||||
: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 message_thread_id: Identifier of the topic to close
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.close_forum_topic(self.token, chat_id, message_thread_id)
|
||||
|
||||
def reopen_forum_topic(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat
|
||||
for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#reopenforumtopic
|
||||
|
||||
: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 message_thread_id: Identifier of the topic to reopen
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.reopen_forum_topic(self.token, chat_id, message_thread_id)
|
||||
|
||||
def delete_forum_topic(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to delete a topic in a forum supergroup chat. The bot must be an administrator in the chat for this
|
||||
to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True
|
||||
on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#deleteforumtopic
|
||||
|
||||
: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 message_thread_id: Identifier of the topic to delete
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.delete_forum_topic(self.token, chat_id, message_thread_id)
|
||||
|
||||
def unpin_all_forum_topic_messages(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the
|
||||
chat for this to work and must have the can_pin_messages administrator right in the supergroup.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#unpinallforumtopicmessages
|
||||
|
||||
: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 message_thread_id: Identifier of the topic
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.unpin_all_forum_topic_messages(self.token, chat_id, message_thread_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.
|
||||
Requires no parameters. Returns an Array of Sticker objects.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#getforumtopiciconstickers
|
||||
|
||||
:return: On success, a list of StickerSet objects is returned.
|
||||
:rtype: List[:class:`telebot.types.StickerSet`]
|
||||
"""
|
||||
return apihelper.get_forum_topic_icon_stickers(self.token)
|
||||
|
||||
def answer_web_app_query(self, web_app_query_id: str, result: types.InlineQueryResultBase) -> types.SentWebAppMessage:
|
||||
"""
|
||||
Use this method to set the result of an interaction with a Web App and
|
||||
@ -6009,7 +6153,7 @@ class TeleBot:
|
||||
class TextMatchFilter(AdvancedCustomFilter):
|
||||
key = 'text'
|
||||
|
||||
async def check(self, message, text):
|
||||
def check(self, message, text):
|
||||
return text == message.text
|
||||
|
||||
:param custom_filter: Class with check(message) method.
|
||||
|
@ -1732,6 +1732,43 @@ def send_poll(
|
||||
payload['protect_content'] = protect_content
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def create_forum_topic(token, chat_id, name, icon_color=None, icon_custom_emoji_id=None):
|
||||
method_url = r'createForumTopic'
|
||||
payload = {'chat_id': chat_id, 'name': name}
|
||||
if icon_color:
|
||||
payload['icon_color'] = icon_color
|
||||
if icon_custom_emoji_id:
|
||||
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):
|
||||
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}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def close_forum_topic(token, chat_id, message_thread_id):
|
||||
method_url = r'closeForumTopic'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def reopen_forum_topic(token, chat_id, message_thread_id):
|
||||
method_url = r'reopenForumTopic'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def delete_forum_topic(token, chat_id, message_thread_id):
|
||||
method_url = r'deleteForumTopic'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def unpin_all_forum_topic_messages(token, chat_id, message_thread_id):
|
||||
method_url = r'unpinAllForumTopicMessages'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def get_forum_topic_icon_stickers(token):
|
||||
method_url = r'getForumTopicIconStickers'
|
||||
return _make_request(token, method_url)
|
||||
|
||||
def stop_poll(token, chat_id, message_id, reply_markup=None):
|
||||
method_url = r'stopPoll'
|
||||
|
@ -5378,6 +5378,149 @@ class AsyncTeleBot:
|
||||
"""
|
||||
return await asyncio_helper.delete_sticker_from_set(self.token, sticker)
|
||||
|
||||
async def create_forum_topic(self,
|
||||
chat_id: int, name: str, icon_color: Optional[int]=None,
|
||||
icon_custom_emoji_id: Optional[str]=None) -> types.ForumTopic:
|
||||
"""
|
||||
Use this method to create a topic in a forum supergroup chat. The bot must be an administrator
|
||||
in the chat for this to work and must have the can_manage_topics administrator rights.
|
||||
Returns information about the created topic as a ForumTopic object.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#createforumtopic
|
||||
|
||||
: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: Name of the topic, 1-128 characters
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param icon_color: Color of the topic icon in RGB format. Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F
|
||||
:type icon_color: :obj:`int`
|
||||
|
||||
:param icon_custom_emoji_id: Custom emoji for the topic icon. Must be an emoji of type “tgs” and must be exactly 1 character long
|
||||
:type icon_custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: On success, information about the created topic is returned as a ForumTopic object.
|
||||
:rtype: :class:`telebot.types.ForumTopic`
|
||||
"""
|
||||
return await asyncio_helper.create_forum_topic(self.token, chat_id, name, icon_color, icon_custom_emoji_id)
|
||||
|
||||
async def edit_forum_topic(
|
||||
self, chat_id: Union[int, str],
|
||||
message_thread_id: int, name: str,
|
||||
icon_custom_emoji_id: str,
|
||||
) -> bool:
|
||||
"""
|
||||
Use this method to edit name and icon of a 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,
|
||||
unless it is the creator of the topic. Returns True on success.
|
||||
|
||||
Telegram Documentation: https://core.telegram.org/bots/api#editforumtopic
|
||||
|
||||
: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 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
|
||||
: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
|
||||
:type icon_custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.edit_forum_topic(self.token, chat_id, message_thread_id, name, icon_custom_emoji_id)
|
||||
|
||||
async def close_forum_topic(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator
|
||||
in the chat for this to work and must have the can_manage_topics administrator rights, unless it is
|
||||
the creator of the topic. Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#closeforumtopic
|
||||
|
||||
: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 message_thread_id: Identifier of the topic to close
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.close_forum_topic(self.token, chat_id, message_thread_id)
|
||||
|
||||
async def reopen_forum_topic(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat
|
||||
for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#reopenforumtopic
|
||||
|
||||
: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 message_thread_id: Identifier of the topic to reopen
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.reopen_forum_topic(self.token, chat_id, message_thread_id)
|
||||
|
||||
async def delete_forum_topic(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to delete a topic in a forum supergroup chat. The bot must be an administrator in the chat for this
|
||||
to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True
|
||||
on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#deleteforumtopic
|
||||
|
||||
: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 message_thread_id: Identifier of the topic to delete
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.delete_forum_topic(self.token, chat_id, message_thread_id)
|
||||
|
||||
async def unpin_all_forum_topic_messages(self, chat_id: Union[str, int], message_thread_id: int) -> bool:
|
||||
"""
|
||||
Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the
|
||||
chat for this to work and must have the can_pin_messages administrator right in the supergroup.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#unpinallforumtopicmessages
|
||||
|
||||
: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 message_thread_id: Identifier of the topic
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.unpin_all_forum_topic_messages(self.token, chat_id, message_thread_id)
|
||||
|
||||
async 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.
|
||||
Requires no parameters. Returns an Array of Sticker objects.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#getforumtopiciconstickers
|
||||
|
||||
:return: On success, a list of StickerSet objects is returned.
|
||||
:rtype: List[:class:`telebot.types.StickerSet`]
|
||||
"""
|
||||
return await asyncio_helper.get_forum_topic_icon_stickers(self.token)
|
||||
|
||||
async def set_state(self, user_id: int, state: Union[State, int, str], chat_id: Optional[int]=None):
|
||||
"""
|
||||
|
@ -1720,6 +1720,45 @@ async def send_poll(
|
||||
payload['protect_content'] = protect_content
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
async def create_forum_topic(token, chat_id, name, icon_color=None, icon_custom_emoji_id=None):
|
||||
method_url = r'createForumTopic'
|
||||
payload = {'chat_id': chat_id, 'name': name}
|
||||
if icon_color:
|
||||
payload['icon_color'] = icon_color
|
||||
if icon_custom_emoji_id:
|
||||
payload['icon_custom_emoji_id'] = icon_custom_emoji_id
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def edit_forum_topic(token, chat_id, message_thread_id, name, icon_custom_emoji_id):
|
||||
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}
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def close_forum_topic(token, chat_id, message_thread_id):
|
||||
method_url = r'closeForumTopic'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def reopen_forum_topic(token, chat_id, message_thread_id):
|
||||
method_url = r'reopenForumTopic'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def delete_forum_topic(token, chat_id, message_thread_id):
|
||||
method_url = r'deleteForumTopic'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def unpin_all_forum_topic_messages(token, chat_id, message_thread_id):
|
||||
method_url = r'unpinAllForumTopicMessages'
|
||||
payload = {'chat_id': chat_id, 'message_thread_id': message_thread_id}
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def get_forum_topic_icon_stickers(token):
|
||||
method_url = r'getForumTopicIconStickers'
|
||||
return await _process_request(token, method_url)
|
||||
|
||||
async def _convert_list_json_serializable(results):
|
||||
ret = ''
|
||||
for r in results:
|
||||
|
@ -6766,6 +6766,7 @@ class ForumTopicCreated(JsonDeserializable):
|
||||
"""
|
||||
This object represents a service message about a new forum topic created in the chat.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#forumtopiccreated
|
||||
|
||||
:param name: Name of the topic
|
||||
:type name: :obj:`str`
|
||||
@ -6792,7 +6793,11 @@ class ForumTopicCreated(JsonDeserializable):
|
||||
|
||||
|
||||
class ForumTopicClosed(JsonDeserializable):
|
||||
"""This object represents a service message about a forum topic closed in the chat. Currently holds no information."""
|
||||
"""
|
||||
This object represents a service message about a forum topic closed in the chat. Currently holds no information.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#forumtopicclosed
|
||||
"""
|
||||
# for future use
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
@ -6803,7 +6808,11 @@ class ForumTopicClosed(JsonDeserializable):
|
||||
|
||||
|
||||
class ForumTopicReopened(JsonDeserializable):
|
||||
"""This object represents a service message about a forum topic reopened in the chat. Currently holds no information."""
|
||||
"""
|
||||
This object represents a service message about a forum topic reopened in the chat. Currently holds no information.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#forumtopicreopened
|
||||
"""
|
||||
# for future use
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
@ -6817,6 +6826,8 @@ class ForumTopic(JsonDeserializable):
|
||||
"""
|
||||
This object represents a forum topic.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#forumtopic
|
||||
|
||||
:param message_thread_id: Unique identifier of the forum topic
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
@ -6828,6 +6839,9 @@ class ForumTopic(JsonDeserializable):
|
||||
|
||||
:param icon_custom_emoji_id: Optional. Unique identifier of the custom emoji shown as the topic icon
|
||||
:type icon_custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: Instance of the class
|
||||
:rtype: :class:`telebot.types.ForumTopic`
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user