mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1937 from coder2020official/botapi6.6
I'm back: Bot API 6.6 Update
This commit is contained in:
commit
41521f5618
@ -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#february-3-2023">6.5</a>!
|
||||
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#march-9-2023">6.6</a>!
|
||||
|
||||
<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
|
||||
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>
|
||||
|
@ -1837,11 +1837,12 @@ class TeleBot:
|
||||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send audio files, if you want Telegram clients to display them in the music player.
|
||||
Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size,
|
||||
@ -1887,11 +1888,11 @@ class TeleBot:
|
||||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
: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>
|
||||
:type thumb: :obj:`str`
|
||||
:type thumbnail: :obj:`str`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
@ -1913,10 +1914,14 @@ class TeleBot:
|
||||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('thumb is deprecated, use thumbnail instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_audio(
|
||||
self.token, chat_id, audio, caption, duration, performer, title, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
# TODO: Rewrite this method like in API.
|
||||
@ -2003,13 +2008,14 @@ class TeleBot:
|
||||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
visible_file_name: Optional[str]=None,
|
||||
disable_content_type_detection: Optional[bool]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
protect_content: Optional[bool]=None, message_thread_id: Optional[int]=None) -> types.Message:
|
||||
protect_content: Optional[bool]=None, message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send general files.
|
||||
|
||||
@ -2042,8 +2048,8 @@ class TeleBot:
|
||||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: InputFile or String : 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>
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:param thumbnail: InputFile or String : 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>
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
@ -2078,11 +2084,15 @@ class TeleBot:
|
||||
# function typo miss compatibility
|
||||
document = data
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('thumb is deprecated, use thumbnail instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_data(
|
||||
self.token, chat_id, document, 'document',
|
||||
reply_to_message_id = reply_to_message_id, reply_markup = reply_markup, parse_mode = parse_mode,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumb,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumbnail,
|
||||
caption_entities = caption_entities, allow_sending_without_reply = allow_sending_without_reply,
|
||||
disable_content_type_detection = disable_content_type_detection, visible_file_name = visible_file_name,
|
||||
protect_content = protect_content, message_thread_id = message_thread_id))
|
||||
@ -2099,7 +2109,8 @@ class TeleBot:
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content:Optional[bool]=None,
|
||||
data: Union[Any, str]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
emoji: Optional[str]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.
|
||||
On success, the sent Message is returned.
|
||||
@ -2139,6 +2150,9 @@ class TeleBot:
|
||||
:param message_thread_id: The thread to which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param emoji: Emoji associated with the sticker; only for just uploaded stickers
|
||||
:type emoji: :obj:`str`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
@ -2156,14 +2170,14 @@ class TeleBot:
|
||||
reply_to_message_id=reply_to_message_id, reply_markup=reply_markup,
|
||||
disable_notification=disable_notification, timeout=timeout,
|
||||
allow_sending_without_reply=allow_sending_without_reply,
|
||||
protect_content=protect_content, message_thread_id=message_thread_id))
|
||||
protect_content=protect_content, message_thread_id=message_thread_id, emoji=emoji))
|
||||
|
||||
def send_video(
|
||||
self, chat_id: Union[int, str], video: Union[Any, str],
|
||||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
@ -2176,7 +2190,8 @@ class TeleBot:
|
||||
timeout: Optional[int]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
|
||||
|
||||
@ -2197,8 +2212,8 @@ class TeleBot:
|
||||
:param height: Video height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: 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>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
: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>.
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
@ -2253,10 +2268,14 @@ class TeleBot:
|
||||
# function typo miss compatibility
|
||||
video = data
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('thumb is deprecated, use thumbnail instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
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,
|
||||
parse_mode, supports_streaming, disable_notification, timeout, thumbnail, width, height,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id, has_spoiler))
|
||||
|
||||
def send_animation(
|
||||
@ -2264,7 +2283,7 @@ class TeleBot:
|
||||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
@ -2275,7 +2294,8 @@ class TeleBot:
|
||||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
timeout: Optional[int]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=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.
|
||||
@ -2298,11 +2318,11 @@ class TeleBot:
|
||||
:param height: Animation height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
: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>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
@ -2347,10 +2367,13 @@ class TeleBot:
|
||||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumbnail is None and thumb is not None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
return types.Message.de_json(
|
||||
apihelper.send_animation(
|
||||
self.token, chat_id, animation, duration, caption, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, protect_content, width, height, message_thread_id, has_spoiler))
|
||||
|
||||
# TODO: Rewrite this method like in API.
|
||||
@ -2362,10 +2385,11 @@ class TeleBot:
|
||||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long.
|
||||
Use this method to send video messages. On success, the sent Message is returned.
|
||||
@ -2399,11 +2423,11 @@ class TeleBot:
|
||||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
: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>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param allow_sending_without_reply: Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
:type allow_sending_without_reply: :obj:`bool`
|
||||
@ -2421,10 +2445,14 @@ class TeleBot:
|
||||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumbnail is None and thumb is not None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_video_note(
|
||||
self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
|
||||
disable_notification, timeout, thumb, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
disable_notification, timeout, thumbnail, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
|
||||
def send_media_group(
|
||||
@ -3400,6 +3428,68 @@ class TeleBot:
|
||||
"""
|
||||
result = apihelper.get_my_commands(self.token, scope, language_code)
|
||||
return [types.BotCommand.de_json(cmd) for cmd in result]
|
||||
|
||||
def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's description, which is shown in
|
||||
the chat with the bot if the chat is empty.
|
||||
Returns True on success.
|
||||
|
||||
:param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
:type description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for
|
||||
whose language there is no dedicated description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return apihelper.set_my_description(self.token, description, language_code)
|
||||
|
||||
def get_my_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot description for the given user language.
|
||||
Returns BotDescription on success.
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotDescription`
|
||||
"""
|
||||
|
||||
return types.BotDescription.de_json(apihelper.get_my_description(self.token, language_code))
|
||||
|
||||
def set_my_short_description(self, short_description:Optional[str]=None, language_code:Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's short description, which is shown on the bot's profile page and
|
||||
is sent together with the link when users share the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param short_description: New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
|
||||
:type short_description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code.
|
||||
If empty, the short description will be applied to all users for whose language there is no dedicated short description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return apihelper.set_my_short_description(self.token, short_description, language_code)
|
||||
|
||||
def get_my_short_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot short description for the given user language.
|
||||
Returns BotShortDescription on success.
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotShortDescription`
|
||||
"""
|
||||
|
||||
return types.BotShortDescription.de_json(apihelper.get_my_short_description(self.token, language_code))
|
||||
|
||||
def set_chat_menu_button(self, chat_id: Union[int, str]=None,
|
||||
menu_button: types.MenuButton=None) -> bool:
|
||||
@ -4447,7 +4537,7 @@ class TeleBot:
|
||||
"""
|
||||
return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
|
||||
|
||||
def set_sticker_set_thumb(
|
||||
def set_sticker_set_thumbnail(
|
||||
self, name: str, user_id: int, thumb: Union[Any, str]=None):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set.
|
||||
@ -4468,6 +4558,8 @@ class TeleBot:
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_sticker_set_thumb(self.token, name, user_id, thumb)
|
||||
|
||||
set_sticker_set_thumb = set_sticker_set_thumbnail
|
||||
|
||||
def get_sticker_set(self, name: str) -> types.StickerSet:
|
||||
"""
|
||||
@ -4497,8 +4589,107 @@ class TeleBot:
|
||||
"""
|
||||
result = apihelper.get_custom_emoji_stickers(self.token, custom_emoji_ids)
|
||||
return [types.Sticker.de_json(sticker) for sticker in result]
|
||||
|
||||
def set_sticker_keywords(self, sticker: str, keywords: List[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to change search keywords assigned to a regular or custom emoji sticker.
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File:
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param keywords: A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters
|
||||
:type keywords: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_sticker_keywords(self.token, sticker, keywords)
|
||||
|
||||
def set_sticker_mask_position(self, sticker: str, mask_position: types.MaskPosition=None) -> bool:
|
||||
"""
|
||||
Use this method to change the mask position of a mask sticker.
|
||||
The sticker must belong to a sticker set that was created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces.
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_sticker_mask_position(self.token, sticker, mask_position)
|
||||
|
||||
|
||||
def set_custom_emoji_sticker_set_thumbnail(self, name: str, custom_emoji_id: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to set the thumbnail of a custom emoji sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param custom_emoji_id: Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.
|
||||
:type custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_custom_emoji_sticker_set_thumbnail(self.token, name, custom_emoji_id)
|
||||
|
||||
def set_sticker_set_title(self, name: str, title: str) -> bool:
|
||||
"""
|
||||
Use this method to set the title of a created sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param title: New sticker set title
|
||||
:type title: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.set_sticker_set_title(self.token, name, title)
|
||||
|
||||
def delete_sticker_set(self, name:str) -> bool:
|
||||
"""
|
||||
Use this method to delete a sticker set. Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.delete_sticker_set(self.token, name)
|
||||
|
||||
def set_sticker_emoji_list(self, sticker: str, emoji_list: List[str]) -> bool:
|
||||
"""
|
||||
Use this method to set the emoji list of a custom emoji sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: Sticker identifier
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param emoji_list: List of emoji
|
||||
:type emoji_list: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.set_sticker_emoji_list(self.token, sticker, emoji_list)
|
||||
|
||||
|
||||
def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File:
|
||||
"""
|
||||
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
|
||||
methods (can be used multiple times). Returns the uploaded File on success.
|
||||
@ -4508,25 +4699,40 @@ class TeleBot:
|
||||
:param user_id: User identifier of sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
:param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
and either width or height must be exactly 512px.
|
||||
:type png_sticker: :obj:`filelike object`
|
||||
|
||||
:param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
|
||||
See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
|
||||
:type sticker: :class:`telebot.types.InputFile`
|
||||
|
||||
:param sticker_format: One of "static", "animated", "video".
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, the sent file is returned.
|
||||
:rtype: :class:`telebot.types.File`
|
||||
"""
|
||||
result = apihelper.upload_sticker_file(self.token, user_id, png_sticker)
|
||||
if png_sticker:
|
||||
logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning)
|
||||
sticker = png_sticker
|
||||
sticker_format = "static"
|
||||
|
||||
result = apihelper.upload_sticker_file(self.token, user_id, sticker, sticker_format)
|
||||
return types.File.de_json(result)
|
||||
|
||||
def create_new_sticker_set(
|
||||
self, user_id: int, name: str, title: str,
|
||||
emojis: str,
|
||||
emojis: Optional[List[str]]=None,
|
||||
png_sticker: Union[Any, str]=None,
|
||||
tgs_sticker: Union[Any, str]=None,
|
||||
webm_sticker: Union[Any, str]=None,
|
||||
contains_masks: Optional[bool]=None,
|
||||
sticker_type: Optional[str]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
needs_repainting: Optional[bool]=None,
|
||||
stickers: List[types.InputSticker]=None,
|
||||
sticker_format: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to create new sticker set owned by a user.
|
||||
The bot will be able to edit the created sticker set.
|
||||
@ -4534,6 +4740,9 @@ class TeleBot:
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
|
||||
|
||||
.. note::
|
||||
Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
@ -4563,38 +4772,69 @@ class TeleBot:
|
||||
use sticker_type instead.
|
||||
:type contains_masks: :obj:`bool`
|
||||
|
||||
:param sticker_type: Optional, Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created
|
||||
via the Bot API at the moment. By default, a regular sticker set is created.
|
||||
:param sticker_type: Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.
|
||||
:type sticker_type: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param needs_repainting: Pass True if stickers in the sticker set must be repainted to the color of text when used in messages,
|
||||
the accent color if used as emoji status, white on chat photos, or another appropriate color based on context;
|
||||
for custom emoji sticker sets only
|
||||
:type needs_repainting: :obj:`bool`
|
||||
|
||||
:param stickers: List of stickers to be added to the set
|
||||
:type stickers: :obj:`list` of :class:`telebot.types.InputSticker`
|
||||
|
||||
:param sticker_format: Format of stickers in the set, must be one of “static”, “animated”, “video”
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if tgs_sticker:
|
||||
sticker_format = 'animated'
|
||||
elif webm_sticker:
|
||||
sticker_format = 'video'
|
||||
elif png_sticker:
|
||||
sticker_format = 'static'
|
||||
|
||||
if contains_masks is not None:
|
||||
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
||||
if sticker_type is None:
|
||||
sticker_type = 'mask' if contains_masks else 'regular'
|
||||
|
||||
if stickers is None:
|
||||
stickers = png_sticker or tgs_sticker or webm_sticker
|
||||
if stickers is None:
|
||||
raise ValueError('You must pass at least one sticker')
|
||||
stickers = [types.InputSticker(sticker=stickers, emoji_list=emojis, mask_position=mask_position)]
|
||||
|
||||
|
||||
|
||||
return apihelper.create_new_sticker_set(
|
||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position, webm_sticker, sticker_type)
|
||||
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
|
||||
|
||||
|
||||
def add_sticker_to_set(
|
||||
self, user_id: int, name: str, emojis: str,
|
||||
self, user_id: int, name: str, emojis: List[str]=None,
|
||||
png_sticker: Optional[Union[Any, str]]=None,
|
||||
tgs_sticker: Optional[Union[Any, str]]=None,
|
||||
webm_sticker: Optional[Union[Any, str]]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
sticker: Optional[List[types.InputSticker]]=None) -> bool:
|
||||
"""
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
It's required to pass `png_sticker` or `tgs_sticker`.
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
The format of the added sticker must match the format of the other stickers in the set.
|
||||
Emoji sticker sets can have up to 200 stickers. Animated and video sticker sets can have up to 50 stickers.
|
||||
Static sticker sets can have up to 120 stickers.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
|
||||
|
||||
.. note::
|
||||
**_sticker parameters are deprecated, use stickers instead
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
@ -4618,11 +4858,19 @@ class TeleBot:
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param sticker: A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
|
||||
:type sticker: :class:`telebot.types.InputSticker`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
# Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position
|
||||
if sticker is None:
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
sticker = types.InputSticker(sticker, emojis, mask_position)
|
||||
|
||||
return apihelper.add_sticker_to_set(
|
||||
self.token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker)
|
||||
self.token, user_id, name, sticker)
|
||||
|
||||
def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
||||
"""
|
||||
|
@ -356,7 +356,7 @@ def get_chat_member_count(token, chat_id):
|
||||
|
||||
|
||||
def set_sticker_set_thumb(token, name, user_id, thumb):
|
||||
method_url = r'setStickerSetThumb'
|
||||
method_url = r'setStickerSetThumbnail'
|
||||
payload = {'name': name, 'user_id': user_id}
|
||||
files = {}
|
||||
if thumb:
|
||||
@ -697,11 +697,11 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_to_messa
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if width:
|
||||
payload['width'] = width
|
||||
if height:
|
||||
@ -748,11 +748,11 @@ def send_animation(
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
@ -832,11 +832,11 @@ def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_m
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if allow_sending_without_reply is not None:
|
||||
payload['allow_sending_without_reply'] = allow_sending_without_reply
|
||||
if protect_content is not None:
|
||||
@ -877,11 +877,11 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
@ -896,7 +896,7 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non
|
||||
def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None,
|
||||
disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None,
|
||||
protect_content = None, message_thread_id=None):
|
||||
protect_content = None, message_thread_id=None, emoji=None):
|
||||
method_url = get_method_by_type(data_type)
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
@ -922,11 +922,11 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
@ -937,6 +937,8 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m
|
||||
payload['disable_content_type_detection'] = disable_content_type_detection
|
||||
if message_thread_id:
|
||||
payload['message_thread_id'] = message_thread_id
|
||||
if emoji:
|
||||
payload['emoji'] = emoji
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
@ -1152,6 +1154,39 @@ def set_chat_title(token, chat_id, title):
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def set_my_description(token, description=None, language_code=None):
|
||||
method_url = r'setMyDescription'
|
||||
payload = {}
|
||||
if description is not None:
|
||||
payload['description'] = description
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def get_my_description(token, language_code=None):
|
||||
method_url = r'getMyDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def set_my_short_description(token, short_description=None, language_code=None):
|
||||
method_url = r'setMyShortDescription'
|
||||
payload = {}
|
||||
if short_description:
|
||||
payload['short_description'] = short_description
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def get_my_short_description(token, language_code=None):
|
||||
method_url = r'getMyShortDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def get_my_commands(token, scope=None, language_code=None):
|
||||
method_url = r'getMyCommands'
|
||||
payload = {}
|
||||
@ -1584,56 +1619,88 @@ def get_sticker_set(token, name):
|
||||
|
||||
def get_custom_emoji_stickers(token, custom_emoji_ids):
|
||||
method_url = r'getCustomEmojiStickers'
|
||||
return _make_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids})
|
||||
return _make_request(token, method_url, params={'custom_emoji_ids': json.dumps(custom_emoji_ids)})
|
||||
|
||||
def set_sticker_keywords(token, sticker, keywords=None):
|
||||
method_url = 'setStickerKeywords'
|
||||
payload = {'sticker': sticker}
|
||||
if keywords:
|
||||
payload['keywords'] = json.dumps(keywords)
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def set_sticker_mask_position(token, sticker, mask_position=None):
|
||||
method_url = 'setStickerMaskPosition'
|
||||
payload = {'sticker': sticker}
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def upload_sticker_file(token, user_id, png_sticker):
|
||||
def upload_sticker_file(token, user_id, sticker, sticker_format):
|
||||
method_url = 'uploadStickerFile'
|
||||
payload = {'user_id': user_id}
|
||||
files = {'png_sticker': png_sticker}
|
||||
payload = {'user_id': user_id, 'sticker_format': sticker_format}
|
||||
files = {'sticker': sticker}
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
def set_custom_emoji_sticker_set_thumbnail(token, name, custom_emoji_id=None):
|
||||
method_url = 'setCustomEmojiStickerSetThumbnail'
|
||||
payload = {'name': name}
|
||||
if custom_emoji_id:
|
||||
payload['custom_emoji_id'] = custom_emoji_id
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def set_sticker_set_title(token, name, title):
|
||||
method_url = 'setStickerSetTitle'
|
||||
payload = {'name': name, 'title': title}
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def delete_sticker_set(token, name):
|
||||
method_url = 'deleteStickerSet'
|
||||
payload = {'name': name}
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def set_sticker_emoji_list(token, sticker, emoji_list):
|
||||
method_url = 'setStickerEmojiList'
|
||||
payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)}
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def create_new_sticker_set(
|
||||
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position=None, webm_sticker=None, sticker_type=None):
|
||||
token, user_id, name, title, stickers, sticker_format=None, sticker_type=None, needs_repainting=None):
|
||||
method_url = 'createNewStickerSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
files = None
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title}
|
||||
if sticker_type:
|
||||
payload['sticker_type'] = sticker_type
|
||||
if needs_repainting:
|
||||
payload['needs_repainting'] = needs_repainting
|
||||
if sticker_format:
|
||||
payload['sticker_format'] = sticker_format
|
||||
|
||||
files = {}
|
||||
lst = []
|
||||
|
||||
for sticker in stickers:
|
||||
json_dict, file = sticker.convert_input_sticker()
|
||||
json_dict = sticker.to_dict()
|
||||
|
||||
if file:
|
||||
list_keys = list(file.keys())
|
||||
files[list_keys[0]] = file[list_keys[0]]
|
||||
lst.append(json_dict)
|
||||
|
||||
payload['stickers'] = json.dumps(lst)
|
||||
|
||||
|
||||
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
def add_sticker_to_set(token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker):
|
||||
def add_sticker_to_set(token, user_id, name, sticker):
|
||||
method_url = 'addStickerToSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
files = None
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
json_dict, files = sticker.convert_input_sticker()
|
||||
payload = {'user_id': user_id, 'name': name, 'sticker': json_dict}
|
||||
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
|
@ -2700,11 +2700,12 @@ class AsyncTeleBot:
|
||||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send audio files, if you want Telegram clients to display them in the music player.
|
||||
Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size,
|
||||
@ -2750,11 +2751,11 @@ class AsyncTeleBot:
|
||||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
: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>
|
||||
:type thumb: :obj:`str`
|
||||
:type thumbnail: :obj:`str`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
@ -2776,10 +2777,14 @@ class AsyncTeleBot:
|
||||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_audio(
|
||||
self.token, chat_id, audio, caption, duration, performer, title, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
async def send_voice(
|
||||
@ -2864,14 +2869,15 @@ class AsyncTeleBot:
|
||||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
visible_file_name: Optional[str]=None,
|
||||
disable_content_type_detection: Optional[bool]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send general files.
|
||||
|
||||
@ -2904,8 +2910,8 @@ class AsyncTeleBot:
|
||||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: InputFile or String : 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>
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:param thumbnail: InputFile or String : 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>
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
@ -2940,11 +2946,15 @@ class AsyncTeleBot:
|
||||
# function typo miss compatibility
|
||||
document = data
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('thumb is deprecated, use thumbnail instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_data(
|
||||
self.token, chat_id, document, 'document',
|
||||
reply_to_message_id = reply_to_message_id, reply_markup = reply_markup, parse_mode = parse_mode,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumb,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumbnail,
|
||||
caption_entities = caption_entities, allow_sending_without_reply = allow_sending_without_reply,
|
||||
disable_content_type_detection = disable_content_type_detection, visible_file_name = visible_file_name, protect_content = protect_content,
|
||||
message_thread_id = message_thread_id))
|
||||
@ -2958,7 +2968,8 @@ class AsyncTeleBot:
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
data: Union[Any, str]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
emoji: Optional[str]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.
|
||||
On success, the sent Message is returned.
|
||||
@ -2998,6 +3009,9 @@ class AsyncTeleBot:
|
||||
:param message_thread_id: Identifier of a message thread, in which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param emoji: Emoji associated with the sticker; only for just uploaded stickers
|
||||
:type emoji: :obj:`str`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
@ -3016,14 +3030,14 @@ class AsyncTeleBot:
|
||||
reply_to_message_id=reply_to_message_id, reply_markup=reply_markup,
|
||||
disable_notification=disable_notification, timeout=timeout,
|
||||
allow_sending_without_reply=allow_sending_without_reply, protect_content=protect_content,
|
||||
message_thread_id=message_thread_id))
|
||||
message_thread_id=message_thread_id, emoji=emoji))
|
||||
|
||||
async def send_video(
|
||||
self, chat_id: Union[int, str], video: Union[Any, str],
|
||||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
@ -3036,7 +3050,8 @@ class AsyncTeleBot:
|
||||
timeout: Optional[int]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
|
||||
|
||||
@ -3057,8 +3072,8 @@ class AsyncTeleBot:
|
||||
:param height: Video height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: 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>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
: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>.
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
@ -3114,10 +3129,14 @@ class AsyncTeleBot:
|
||||
logger.warning("send_sticker: data parameter is deprecated. Use video instead.")
|
||||
video = data
|
||||
|
||||
if thumb and not(thumbnail):
|
||||
logger.warning("send_sticker: thumb parameter is deprecated. Use thumbnail instead.")
|
||||
thumbnail = thumb
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.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,
|
||||
parse_mode, supports_streaming, disable_notification, timeout, thumbnail, width, height,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id, has_spoiler))
|
||||
|
||||
async def send_animation(
|
||||
@ -3125,7 +3144,7 @@ class AsyncTeleBot:
|
||||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
@ -3136,7 +3155,8 @@ class AsyncTeleBot:
|
||||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
timeout: Optional[int]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=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.
|
||||
@ -3159,11 +3179,11 @@ class AsyncTeleBot:
|
||||
:param height: Animation height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
: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>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
@ -3208,10 +3228,14 @@ class AsyncTeleBot:
|
||||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('thumb is deprecated, use thumbnail instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_animation(
|
||||
self.token, chat_id, animation, duration, caption, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, width, height, protect_content, message_thread_id, has_spoiler))
|
||||
|
||||
async def send_video_note(
|
||||
@ -3222,10 +3246,11 @@ class AsyncTeleBot:
|
||||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long.
|
||||
Use this method to send video messages. On success, the sent Message is returned.
|
||||
@ -3259,11 +3284,11 @@ class AsyncTeleBot:
|
||||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
: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>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param allow_sending_without_reply: Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
:type allow_sending_without_reply: :obj:`bool`
|
||||
@ -3281,10 +3306,14 @@ class AsyncTeleBot:
|
||||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('thumb is deprecated, use thumbnail instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_video_note(
|
||||
self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
|
||||
disable_notification, timeout, thumb, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
disable_notification, timeout, thumbnail, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
async def send_media_group(
|
||||
self, chat_id: Union[int, str],
|
||||
@ -4238,6 +4267,68 @@ class AsyncTeleBot:
|
||||
"""
|
||||
return await asyncio_helper.delete_chat_photo(self.token, chat_id)
|
||||
|
||||
async def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's description, which is shown in
|
||||
the chat with the bot if the chat is empty.
|
||||
Returns True on success.
|
||||
|
||||
:param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
:type description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for
|
||||
whose language there is no dedicated description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_my_description(self.token, description, language_code)
|
||||
|
||||
async def get_my_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot description for the given user language.
|
||||
Returns BotDescription on success.
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotDescription`
|
||||
"""
|
||||
result = await asyncio_helper.get_my_description(self.token, language_code)
|
||||
return types.BotDescription.de_json(result)
|
||||
|
||||
async def set_my_short_description(self, short_description:Optional[str]=None, language_code:Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's short description, which is shown on the bot's profile page and
|
||||
is sent together with the link when users share the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param short_description: New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
|
||||
:type short_description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code.
|
||||
If empty, the short description will be applied to all users for whose language there is no dedicated short description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_my_short_description(self.token, short_description, language_code)
|
||||
|
||||
async def get_my_short_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot short description for the given user language.
|
||||
Returns BotShortDescription on success.
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotShortDescription`
|
||||
"""
|
||||
result = await asyncio_helper.get_my_short_description(self.token, language_code)
|
||||
return types.BotShortDescription.de_json(result)
|
||||
|
||||
async def get_my_commands(self, scope: Optional[types.BotCommandScope],
|
||||
language_code: Optional[str]) -> List[types.BotCommand]:
|
||||
"""
|
||||
@ -5310,7 +5401,7 @@ class AsyncTeleBot:
|
||||
"""
|
||||
return await asyncio_helper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
|
||||
|
||||
async def set_sticker_set_thumb(
|
||||
async def set_sticker_set_thumbnail(
|
||||
self, name: str, user_id: int, thumb: Union[Any, str]=None):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set.
|
||||
@ -5331,6 +5422,8 @@ class AsyncTeleBot:
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_set_thumb(self.token, name, user_id, thumb)
|
||||
|
||||
set_sticker_set_thumb = set_sticker_set_thumbnail
|
||||
|
||||
async def get_sticker_set(self, name: str) -> types.StickerSet:
|
||||
"""
|
||||
@ -5346,6 +5439,40 @@ class AsyncTeleBot:
|
||||
"""
|
||||
result = await asyncio_helper.get_sticker_set(self.token, name)
|
||||
return types.StickerSet.de_json(result)
|
||||
|
||||
async def set_sticker_keywords(self, sticker: str, keywords: List[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to change search keywords assigned to a regular or custom emoji sticker.
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param keywords: A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters
|
||||
:type keywords: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_keywords(self.token, sticker, keywords)
|
||||
|
||||
async def set_sticker_mask_position(self, sticker: str, mask_position: types.MaskPosition=None) -> bool:
|
||||
"""
|
||||
Use this method to change the mask position of a mask sticker.
|
||||
The sticker must belong to a sticker set that was created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces.
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_mask_position(self.token, sticker, mask_position)
|
||||
|
||||
async def get_custom_emoji_stickers(self, custom_emoji_ids: List[str]) -> List[types.Sticker]:
|
||||
"""
|
||||
@ -5361,7 +5488,7 @@ class AsyncTeleBot:
|
||||
result = await asyncio_helper.get_custom_emoji_stickers(self.token, custom_emoji_ids)
|
||||
return [types.Sticker.de_json(sticker) for sticker in result]
|
||||
|
||||
async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File:
|
||||
async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File:
|
||||
"""
|
||||
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
|
||||
methods (can be used multiple times). Returns the uploaded File on success.
|
||||
@ -5371,25 +5498,105 @@ class AsyncTeleBot:
|
||||
:param user_id: User identifier of sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
:param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
and either width or height must be exactly 512px.
|
||||
:type png_sticker: :obj:`filelike object`
|
||||
|
||||
:param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
|
||||
See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
|
||||
:type sticker: :class:`telebot.types.InputFile`
|
||||
|
||||
:param sticker_format: One of "static", "animated", "video".
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, the sent file is returned.
|
||||
:rtype: :class:`telebot.types.File`
|
||||
"""
|
||||
result = await asyncio_helper.upload_sticker_file(self.token, user_id, png_sticker)
|
||||
if png_sticker:
|
||||
logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning)
|
||||
sticker = png_sticker
|
||||
sticker_format = "static"
|
||||
|
||||
result = await asyncio_helper.upload_sticker_file(self.token, user_id, sticker, sticker_format)
|
||||
return types.File.de_json(result)
|
||||
|
||||
async def set_custom_emoji_sticker_set_thumbnail(self, name: str, custom_emoji_id: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to set the thumbnail of a custom emoji sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param custom_emoji_id: Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.
|
||||
:type custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_custom_emoji_sticker_set_thumbnail(self.token, name, custom_emoji_id)
|
||||
|
||||
async def set_sticker_set_title(self, name: str, title: str) -> bool:
|
||||
"""
|
||||
Use this method to set the title of a created sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param title: New sticker set title
|
||||
:type title: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_sticker_set_title(self.token, name, title)
|
||||
|
||||
async def delete_sticker_set(self, name:str) -> bool:
|
||||
"""
|
||||
Use this method to delete a sticker set. Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return await asyncio_helper.delete_sticker_set(self.token, name)
|
||||
|
||||
|
||||
async def set_sticker_emoji_list(self, name: str, emoji_list: List[str]) -> bool:
|
||||
"""
|
||||
Use this method to set the emoji list of a sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param emoji_list: List of emojis
|
||||
:type emoji_list: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_sticker_emoji_list(self.token, name, emoji_list)
|
||||
|
||||
|
||||
async def create_new_sticker_set(
|
||||
self, user_id: int, name: str, title: str,
|
||||
emojis: str,
|
||||
emojis: Optional[str]=None,
|
||||
png_sticker: Union[Any, str]=None,
|
||||
tgs_sticker: Union[Any, str]=None,
|
||||
webm_sticker: Union[Any, str]=None,
|
||||
contains_masks: Optional[bool]=None,
|
||||
sticker_type: Optional[str]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
needs_repainting: Optional[bool]=None,
|
||||
stickers: List[types.InputSticker]=None,
|
||||
sticker_format: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to create new sticker set owned by a user.
|
||||
The bot will be able to edit the created sticker set.
|
||||
@ -5397,6 +5604,9 @@ class AsyncTeleBot:
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
|
||||
|
||||
.. note::
|
||||
Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
@ -5426,35 +5636,62 @@ class AsyncTeleBot:
|
||||
use sticker_type instead.
|
||||
:type contains_masks: :obj:`bool`
|
||||
|
||||
:param sticker_type: Optional, Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created
|
||||
via the Bot API at the moment. By default, a regular sticker set is created.
|
||||
:param sticker_type: Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.
|
||||
:type sticker_type: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param needs_repainting: Pass True if stickers in the sticker set must be repainted to the color of text when used in messages,
|
||||
the accent color if used as emoji status, white on chat photos, or another appropriate color based on context;
|
||||
for custom emoji sticker sets only
|
||||
:type needs_repainting: :obj:`bool`
|
||||
|
||||
:param stickers: List of stickers to be added to the set
|
||||
:type stickers: :obj:`list` of :class:`telebot.types.InputSticker`
|
||||
|
||||
:param sticker_format: Format of stickers in the set, must be one of “static”, “animated”, “video”
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if tgs_sticker:
|
||||
sticker_format = 'animated'
|
||||
elif webm_sticker:
|
||||
sticker_format = 'video'
|
||||
elif png_sticker:
|
||||
sticker_format = 'static'
|
||||
|
||||
if contains_masks is not None:
|
||||
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
||||
if sticker_type is None:
|
||||
sticker_type = 'mask' if contains_masks else 'regular'
|
||||
|
||||
if stickers is None:
|
||||
stickers = png_sticker or tgs_sticker or webm_sticker
|
||||
if stickers is None:
|
||||
raise ValueError('You must pass at least one sticker')
|
||||
stickers = [types.InputSticker(sticker=stickers, emoji_list=emojis, mask_position=mask_position)]
|
||||
|
||||
|
||||
|
||||
return await asyncio_helper.create_new_sticker_set(
|
||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position, webm_sticker, sticker_type)
|
||||
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
|
||||
|
||||
|
||||
async def add_sticker_to_set(
|
||||
self, user_id: int, name: str, emojis: str,
|
||||
self, user_id: int, name: str, emojis: List[str]=None,
|
||||
png_sticker: Optional[Union[Any, str]]=None,
|
||||
tgs_sticker: Optional[Union[Any, str]]=None,
|
||||
webm_sticker: Optional[Union[Any, str]]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
sticker: Optional[List[types.InputSticker]]=None) -> bool:
|
||||
"""
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
It's required to pass `png_sticker` or `tgs_sticker`.
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
The format of the added sticker must match the format of the other stickers in the set.
|
||||
Emoji sticker sets can have up to 200 stickers. Animated and video sticker sets can have up to 50 stickers.
|
||||
Static sticker sets can have up to 120 stickers.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
|
||||
@ -5482,11 +5719,21 @@ class AsyncTeleBot:
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param sticker: A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
|
||||
:type sticker: :class:`telebot.types.InputSticker`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
# Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position
|
||||
if sticker is None:
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
if sticker is None:
|
||||
raise ValueError('You must pass at least one sticker')
|
||||
sticker = types.InputSticker(sticker, emojis, mask_position)
|
||||
|
||||
return await asyncio_helper.add_sticker_to_set(
|
||||
self.token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker)
|
||||
self.token, user_id, name, sticker)
|
||||
|
||||
|
||||
async def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
||||
|
@ -342,7 +342,7 @@ async def get_chat_member_count(token, chat_id):
|
||||
|
||||
|
||||
async def set_sticker_set_thumb(token, name, user_id, thumb):
|
||||
method_url = r'setStickerSetThumb'
|
||||
method_url = r'setStickerSetThumbnail'
|
||||
payload = {'name': name, 'user_id': user_id}
|
||||
files = {}
|
||||
if thumb:
|
||||
@ -689,11 +689,11 @@ async def send_video(token, chat_id, data, duration=None, caption=None, reply_to
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if width:
|
||||
payload['width'] = width
|
||||
if height:
|
||||
@ -740,11 +740,11 @@ async def send_animation(
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
@ -824,11 +824,11 @@ async def send_video_note(token, chat_id, data, duration=None, length=None, repl
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if allow_sending_without_reply is not None:
|
||||
payload['allow_sending_without_reply'] = allow_sending_without_reply
|
||||
if protect_content is not None:
|
||||
@ -869,11 +869,11 @@ async def send_audio(token, chat_id, audio, caption=None, duration=None, perform
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
@ -888,7 +888,7 @@ async def send_audio(token, chat_id, audio, caption=None, duration=None, perform
|
||||
async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None,
|
||||
disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None, protect_content=None,
|
||||
message_thread_id=None):
|
||||
message_thread_id=None, emoji=None):
|
||||
method_url = await get_method_by_type(data_type)
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
@ -914,11 +914,11 @@ async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, r
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumb
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumb}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumb
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
@ -929,6 +929,8 @@ async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, r
|
||||
payload['disable_content_type_detection'] = disable_content_type_detection
|
||||
if message_thread_id:
|
||||
payload['message_thread_id'] = message_thread_id
|
||||
if emoji:
|
||||
payload['emoji'] = emoji
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
@ -1138,6 +1140,37 @@ async def set_chat_title(token, chat_id, title):
|
||||
payload = {'chat_id': chat_id, 'title': title}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_my_description(token, description=None, language_code=None):
|
||||
method_url = r'setMyDescription'
|
||||
payload = {}
|
||||
if description:
|
||||
payload['description'] = description
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def get_my_description(token, language_code=None):
|
||||
method_url = r'getMyDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def set_my_short_description(token, short_description=None, language_code=None):
|
||||
method_url = r'setMyShortDescription'
|
||||
payload = {}
|
||||
if short_description:
|
||||
payload['short_description'] = short_description
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def get_my_short_description(token, language_code=None):
|
||||
method_url = r'getMyShortDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def get_my_commands(token, scope=None, language_code=None):
|
||||
method_url = r'getMyCommands'
|
||||
@ -1573,60 +1606,87 @@ async def get_sticker_set(token, name):
|
||||
|
||||
async def get_custom_emoji_stickers(token, custom_emoji_ids):
|
||||
method_url = r'getCustomEmojiStickers'
|
||||
return await _process_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids})
|
||||
return await _process_request(token, method_url, params={'custom_emoji_ids': json.dumps(custom_emoji_ids)})
|
||||
|
||||
async def upload_sticker_file(token, user_id, png_sticker):
|
||||
async def set_sticker_keywords(token, sticker, keywords=None):
|
||||
method_url = 'setStickerKeywords'
|
||||
payload = {'sticker': sticker}
|
||||
if keywords:
|
||||
payload['keywords'] = json.dumps(keywords)
|
||||
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_sticker_mask_position(token, sticker, mask_position=None):
|
||||
method_url = 'setStickerMaskPosition'
|
||||
payload = {'sticker': sticker}
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def upload_sticker_file(token, user_id, sticker, sticker_format):
|
||||
method_url = 'uploadStickerFile'
|
||||
payload = {'user_id': user_id}
|
||||
files = {'png_sticker': png_sticker}
|
||||
payload = {'user_id': user_id, 'sticker_format': sticker_format}
|
||||
files = {'sticker': sticker}
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
async def set_sticker_emoji_list(token, sticker, emoji_list):
|
||||
method_url = 'setStickerEmojiList'
|
||||
payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def delete_sticker_set(token, name):
|
||||
method_url = 'deleteStickerSet'
|
||||
payload = {'name': name}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_custom_emoji_sticker_set_thumbnail(token, name, custom_emoji_id=None):
|
||||
method_url = 'setCustomEmojiStickerSetThumbnail'
|
||||
payload = {'name': name}
|
||||
if custom_emoji_id:
|
||||
payload['custom_emoji_id'] = custom_emoji_id
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
async def set_sticker_set_title(token, name, title):
|
||||
method_url = 'setStickerSetTitle'
|
||||
payload = {'name': name, 'title': title}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def create_new_sticker_set(
|
||||
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position=None, webm_sticker=None, sticker_type=None):
|
||||
token, user_id, name, title, stickers, sticker_format=None, sticker_type=None, needs_repainting=None):
|
||||
method_url = 'createNewStickerSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
files = None
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title}
|
||||
if sticker_type:
|
||||
payload['sticker_type'] = sticker_type
|
||||
if needs_repainting:
|
||||
payload['needs_repainting'] = needs_repainting
|
||||
if sticker_format:
|
||||
payload['sticker_format'] = sticker_format
|
||||
|
||||
files = {}
|
||||
lst = []
|
||||
|
||||
for sticker in stickers:
|
||||
json_dict, file = sticker.convert_input_sticker()
|
||||
json_dict = sticker.to_dict()
|
||||
|
||||
if file:
|
||||
list_keys = list(file.keys())
|
||||
files[list_keys[0]] = file[list_keys[0]]
|
||||
lst.append(json_dict)
|
||||
|
||||
payload['stickers'] = json.dumps(lst)
|
||||
|
||||
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
async def add_sticker_to_set(token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker):
|
||||
async def add_sticker_to_set(token, user_id, name, sticker):
|
||||
method_url = 'addStickerToSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
files = None
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
json_dict, files = sticker.convert_input_sticker()
|
||||
payload = {'user_id': user_id, 'name': name, 'sticker': json_dict}
|
||||
|
||||
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
|
||||
if webm_sticker:
|
||||
payload['webm_sticker'] = webm_sticker
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
|
529
telebot/types.py
529
telebot/types.py
File diff suppressed because it is too large
Load Diff
@ -67,9 +67,9 @@ def test_json_GroupChat():
|
||||
|
||||
|
||||
def test_json_Document():
|
||||
json_string = r'{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AgADJQEAAqfhOEY","file_size":446}'
|
||||
json_string = r'{"file_name":"Text File","thumbnail":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AgADJQEAAqfhOEY","file_size":446}'
|
||||
doc = types.Document.de_json(json_string)
|
||||
assert doc.thumb is None
|
||||
assert doc.thumbnail is None
|
||||
assert doc.file_name == 'Text File'
|
||||
|
||||
|
||||
@ -83,23 +83,23 @@ def test_json_Message_Audio():
|
||||
|
||||
|
||||
def test_json_Message_Sticker():
|
||||
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "thumb": {"file_id": "AAMCBAADHQJOFL7mAAJUMF8Dj62hpmDhpRAYvkc8CtIqipolAAJ8AAPA-8cF9yxjgjkLS97A0D4iXQARtQAHbQADHy4AAhoE", "file_unique_id": "AQADwNA-Il0AAx8uAAI", "file_size": 7776, "width": 60, "height": 60}, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
|
||||
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "thumbnail": {"file_id": "AAMCBAADHQJOFL7mAAJUMF8Dj62hpmDhpRAYvkc8CtIqipolAAJ8AAPA-8cF9yxjgjkLS97A0D4iXQARtQAHbQADHy4AAhoE", "file_unique_id": "AQADwNA-Il0AAx8uAAI", "file_size": 7776, "width": 60, "height": 60}, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.sticker.height == 368
|
||||
assert msg.sticker.thumb.height == 60
|
||||
assert msg.sticker.thumbnail.height == 60
|
||||
assert msg.content_type == 'sticker'
|
||||
|
||||
|
||||
def test_json_Message_Sticker_without_thumb():
|
||||
def test_json_Message_Sticker_without_thumbnail():
|
||||
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.sticker.height == 368
|
||||
assert msg.sticker.thumb is None
|
||||
assert msg.sticker.thumbnail is None
|
||||
assert msg.content_type == 'sticker'
|
||||
|
||||
|
||||
def test_json_Message_Document():
|
||||
json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":446}}'
|
||||
json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumbnail":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":446}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.document.file_name == 'Text File'
|
||||
assert msg.content_type == 'document'
|
||||
@ -113,11 +113,11 @@ def test_json_Message_Photo():
|
||||
|
||||
|
||||
def test_json_Message_Video():
|
||||
json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumb":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_unique_id": "AQADTeisa3QAAz1nAAI","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_unique_id": "AgADbgEAAn8VSFY","file_size":260699}}'
|
||||
json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumbnail":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_unique_id": "AQADTeisa3QAAz1nAAI","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_unique_id": "AgADbgEAAn8VSFY","file_size":260699}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.video
|
||||
assert msg.video.duration == 3
|
||||
assert msg.video.thumb.width == 50
|
||||
assert msg.video.thumbnail.width == 50
|
||||
assert msg.content_type == 'video'
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user