From a339514fb968c9ba6a9fdfe390889a32811887ae Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 16 Nov 2020 03:59:35 +0200 Subject: [PATCH] Initial update. Update types and methods --- aiogram/api/client/bot.py | 1072 +++++++++++------ aiogram/api/methods/__init__.py | 8 + aiogram/api/methods/base.py | 16 +- aiogram/api/methods/close.py | 26 + aiogram/api/methods/copy_message.py | 67 ++ aiogram/api/methods/delete_webhook.py | 7 +- aiogram/api/methods/edit_message_caption.py | 16 +- .../api/methods/edit_message_live_location.py | 9 +- aiogram/api/methods/edit_message_media.py | 14 +- .../api/methods/edit_message_reply_markup.py | 4 +- aiogram/api/methods/edit_message_text.py | 17 +- aiogram/api/methods/log_out.py | 27 + aiogram/api/methods/pin_chat_message.py | 9 +- aiogram/api/methods/promote_chat_member.py | 2 + aiogram/api/methods/restrict_chat_member.py | 2 +- aiogram/api/methods/send_animation.py | 13 +- aiogram/api/methods/send_audio.py | 15 +- aiogram/api/methods/send_contact.py | 3 + aiogram/api/methods/send_dice.py | 8 +- aiogram/api/methods/send_document.py | 18 +- aiogram/api/methods/send_game.py | 3 + aiogram/api/methods/send_invoice.py | 5 +- aiogram/api/methods/send_location.py | 11 + aiogram/api/methods/send_media_group.py | 18 +- aiogram/api/methods/send_message.py | 14 +- aiogram/api/methods/send_photo.py | 15 +- aiogram/api/methods/send_poll.py | 17 +- aiogram/api/methods/send_sticker.py | 3 + aiogram/api/methods/send_venue.py | 7 + aiogram/api/methods/send_video.py | 15 +- aiogram/api/methods/send_video_note.py | 3 + aiogram/api/methods/send_voice.py | 15 +- aiogram/api/methods/set_webhook.py | 5 + aiogram/api/methods/unban_chat_member.py | 9 +- .../api/methods/unpin_all_chat_messages.py | 30 + aiogram/api/methods/unpin_chat_message.py | 12 +- aiogram/api/types/__init__.py | 19 +- aiogram/api/types/audio.py | 2 + aiogram/api/types/chat.py | 14 +- aiogram/api/types/chat_location.py | 21 + aiogram/api/types/chat_member.py | 6 +- aiogram/api/types/dice.py | 3 +- .../api/types/inline_query_result_audio.py | 6 +- .../types/inline_query_result_cached_audio.py | 6 +- .../inline_query_result_cached_document.py | 6 +- .../types/inline_query_result_cached_gif.py | 6 +- .../inline_query_result_cached_mpeg4_gif.py | 6 +- .../types/inline_query_result_cached_photo.py | 6 +- .../types/inline_query_result_cached_video.py | 6 +- .../types/inline_query_result_cached_voice.py | 6 +- .../api/types/inline_query_result_document.py | 6 +- aiogram/api/types/inline_query_result_gif.py | 6 +- .../api/types/inline_query_result_location.py | 8 + .../types/inline_query_result_mpeg4_gif.py | 6 +- .../api/types/inline_query_result_photo.py | 6 +- .../api/types/inline_query_result_venue.py | 4 + .../api/types/inline_query_result_video.py | 3 +- .../api/types/inline_query_result_voice.py | 6 +- .../types/input_location_message_content.py | 8 + aiogram/api/types/input_media_animation.py | 6 +- aiogram/api/types/input_media_audio.py | 6 +- aiogram/api/types/input_media_document.py | 9 +- aiogram/api/types/input_media_photo.py | 6 +- aiogram/api/types/input_media_video.py | 6 +- aiogram/api/types/input_message_content.py | 4 +- .../api/types/input_text_message_content.py | 8 +- .../api/types/input_venue_message_content.py | 4 + aiogram/api/types/location.py | 12 + aiogram/api/types/message.py | 14 +- aiogram/api/types/message_id.py | 14 + .../api/types/proximity_alert_triggered.py | 24 + aiogram/api/types/venue.py | 6 +- aiogram/api/types/video.py | 2 + aiogram/api/types/webhook_info.py | 2 + aiogram/dispatcher/dispatcher.py | 2 +- 75 files changed, 1334 insertions(+), 492 deletions(-) create mode 100644 aiogram/api/methods/close.py create mode 100644 aiogram/api/methods/copy_message.py create mode 100644 aiogram/api/methods/log_out.py create mode 100644 aiogram/api/methods/unpin_all_chat_messages.py create mode 100644 aiogram/api/types/chat_location.py create mode 100644 aiogram/api/types/message_id.py create mode 100644 aiogram/api/types/proximity_alert_triggered.py diff --git a/aiogram/api/client/bot.py b/aiogram/api/client/bot.py index ce12de07..aa0666c0 100644 --- a/aiogram/api/client/bot.py +++ b/aiogram/api/client/bot.py @@ -27,6 +27,8 @@ from ..methods import ( AnswerInlineQuery, AnswerPreCheckoutQuery, AnswerShippingQuery, + Close, + CopyMessage, CreateNewStickerSet, DeleteChatPhoto, DeleteChatStickerSet, @@ -54,6 +56,7 @@ from ..methods import ( GetWebhookInfo, KickChatMember, LeaveChat, + LogOut, PinChatMessage, PromoteChatMember, RestrictChatMember, @@ -91,6 +94,7 @@ from ..methods import ( StopPoll, TelegramMethod, UnbanChatMember, + UnpinAllChatMessages, UnpinChatMessage, UploadStickerFile, ) @@ -100,7 +104,6 @@ from ..types import ( Chat, ChatMember, ChatPermissions, - Downloadable, File, ForceReply, GameHighScore, @@ -108,11 +111,15 @@ from ..types import ( InlineQueryResult, InputFile, InputMedia, + InputMediaAudio, + InputMediaDocument, InputMediaPhoto, InputMediaVideo, LabeledPrice, MaskPosition, Message, + MessageEntity, + MessageId, PassportElementError, Poll, ReplyKeyboardMarkup, @@ -173,19 +180,13 @@ class Bot(ContextInstanceMixin["Bot"]): yield self finally: if auto_close: - await self.close() + await self.session.close() self.reset_current(token) @alru_cache() # type: ignore async def me(self) -> User: return await self.get_me() - async def close(self) -> None: - """ - Close bot session - """ - await self.session.close() - @classmethod async def __download_file_binary_io( cls, destination: BinaryIO, seek: bool, stream: AsyncGenerator[bytes, None] @@ -327,23 +328,23 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#getupdates :param offset: Identifier of the first update to be returned. Must be greater by one than - the highest among the identifiers of previously received updates. By - default, updates starting with the earliest unconfirmed update are - returned. An update is considered confirmed as soon as getUpdates is called - with an offset higher than its update_id. The negative offset can be - specified to retrieve updates starting from -offset update from the end of - the updates queue. All previous updates will forgotten. + the highest among the identifiers of previously received updates. By + default, updates starting with the earliest unconfirmed update are + returned. An update is considered confirmed as soon as getUpdates is called + with an offset higher than its update_id. The negative offset can be + specified to retrieve updates starting from -offset update from the end of + the updates queue. All previous updates will forgotten. :param limit: Limits the number of updates to be retrieved. Values between 1-100 are - accepted. Defaults to 100. + accepted. Defaults to 100. :param timeout: Timeout in seconds for long polling. Defaults to 0, i.e. usual short - polling. Should be positive, short polling should be used for testing - purposes only. + polling. Should be positive, short polling should be used for testing + purposes only. :param allowed_updates: A JSON-serialized list of the update types you want your bot to - receive. For example, specify ['message', 'edited_channel_post', - 'callback_query'] to only receive updates of these types. See - Update for a complete list of available update types. Specify an - empty list to receive all updates regardless of type (default). If - not specified, the previous setting will be used. + receive. For example, specify ['message', 'edited_channel_post', + 'callback_query'] to only receive updates of these types. See + Update for a complete list of available update types. Specify an + empty list to receive all updates regardless of type (default). If + not specified, the previous setting will be used. :param request_timeout: Request timeout :return: An Array of Update objects is returned. """ @@ -356,8 +357,10 @@ class Bot(ContextInstanceMixin["Bot"]): self, url: str, certificate: Optional[InputFile] = None, + ip_address: Optional[str] = None, max_connections: Optional[int] = None, allowed_updates: Optional[List[str]] = None, + drop_pending_updates: Optional[bool] = None, request_timeout: Optional[int] = None, ) -> bool: """ @@ -380,41 +383,49 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setwebhook :param url: HTTPS url to send updates to. Use an empty string to remove webhook - integration + integration :param certificate: Upload your public key certificate so that the root certificate in use - can be checked. See our self-signed guide for details. + can be checked. See our self-signed guide for details. + :param ip_address: The fixed IP address which will be used to send webhook requests + instead of the IP address resolved through DNS :param max_connections: Maximum allowed number of simultaneous HTTPS connections to the - webhook for update delivery, 1-100. Defaults to 40. Use lower - values to limit the load on your bot's server, and higher values - to increase your bot's throughput. + webhook for update delivery, 1-100. Defaults to 40. Use lower + values to limit the load on your bot's server, and higher values + to increase your bot's throughput. :param allowed_updates: A JSON-serialized list of the update types you want your bot to - receive. For example, specify ['message', 'edited_channel_post', - 'callback_query'] to only receive updates of these types. See - Update for a complete list of available update types. Specify an - empty list to receive all updates regardless of type (default). If - not specified, the previous setting will be used. + receive. For example, specify ['message', 'edited_channel_post', + 'callback_query'] to only receive updates of these types. See + Update for a complete list of available update types. Specify an + empty list to receive all updates regardless of type (default). If + not specified, the previous setting will be used. + :param drop_pending_updates: Pass True to drop all pending updates :param request_timeout: Request timeout :return: Returns True on success. """ call = SetWebhook( url=url, certificate=certificate, + ip_address=ip_address, max_connections=max_connections, allowed_updates=allowed_updates, + drop_pending_updates=drop_pending_updates, ) return await self(call, request_timeout=request_timeout) - async def delete_webhook(self, request_timeout: Optional[int] = None,) -> bool: + async def delete_webhook( + self, drop_pending_updates: Optional[bool] = None, request_timeout: Optional[int] = None, + ) -> bool: """ Use this method to remove webhook integration if you decide to switch back to getUpdates. - Returns True on success. Requires no parameters. + Returns True on success. Source: https://core.telegram.org/bots/api#deletewebhook + :param drop_pending_updates: Pass True to drop all pending updates :param request_timeout: Request timeout :return: Returns True on success. """ - call = DeleteWebhook() + call = DeleteWebhook(drop_pending_updates=drop_pending_updates,) return await self(call, request_timeout=request_timeout) async def get_webhook_info(self, request_timeout: Optional[int] = None,) -> WebhookInfo: @@ -427,7 +438,7 @@ class Bot(ContextInstanceMixin["Bot"]): :param request_timeout: Request timeout :return: On success, returns a WebhookInfo object. If the bot is using getUpdates, will - return an object with the url field empty. + return an object with the url field empty. """ call = GetWebhookInfo() return await self(call, request_timeout=request_timeout) @@ -450,14 +461,48 @@ class Bot(ContextInstanceMixin["Bot"]): call = GetMe() return await self(call, request_timeout=request_timeout) + async def log_out(self, request_timeout: Optional[int] = None,) -> bool: + """ + Use this method to log out from the cloud Bot API server before launching the bot locally. + You must log out the bot before running it locally, otherwise there is no guarantee that + the bot will receive updates. After a successful call, you can immediately log in on a + local server, but will not be able to log in back to the cloud Bot API server for 10 + minutes. Returns True on success. Requires no parameters. + + Source: https://core.telegram.org/bots/api#logout + + :param request_timeout: Request timeout + :return: Returns True on success. + """ + call = LogOut() + return await self(call, request_timeout=request_timeout) + + async def close(self, request_timeout: Optional[int] = None,) -> bool: + """ + Use this method to close the bot instance before moving it from one local server to + another. You need to delete the webhook before calling this method to ensure that the bot + isn't launched again after server restart. The method will return error 429 in the first + 10 minutes after the bot is launched. Returns True on success. Requires no parameters. + + Source: https://core.telegram.org/bots/api#close + + :param request_timeout: Request timeout + :return: The method will return error 429 in the first 10 minutes after the bot is + launched. Returns True on success. + """ + call = Close() + return await self(call, request_timeout=request_timeout) + async def send_message( self, chat_id: Union[int, str], text: str, parse_mode: Optional[str] = UNSET, + entities: Optional[List[MessageEntity]] = None, disable_web_page_preview: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -469,17 +514,21 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendmessage :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param text: Text of the message to be sent, 1-4096 characters after entities parsing :param parse_mode: Mode for parsing entities in the message text. See formatting options - for more details. + for more details. + :param entities: List of special entities that appear in message text, which can be + specified instead of parse_mode :param disable_web_page_preview: Disables link previews for links in this message :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -487,9 +536,11 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id=chat_id, text=text, parse_mode=parse_mode, + entities=entities, disable_web_page_preview=disable_web_page_preview, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -508,12 +559,12 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#forwardmessage :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param from_chat_id: Unique identifier for the chat where the original message was sent - (or channel username in the format @channelusername) + (or channel username in the format @channelusername) :param message_id: Message identifier in the chat specified in from_chat_id :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -525,14 +576,75 @@ class Bot(ContextInstanceMixin["Bot"]): ) return await self(call, request_timeout=request_timeout) + async def copy_message( + self, + chat_id: Union[int, str], + from_chat_id: Union[int, str], + message_id: int, + caption: Optional[str] = None, + parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + request_timeout: Optional[int] = None, + ) -> MessageId: + """ + Use this method to copy messages of any kind. The method is analogous to the method + forwardMessages, but the copied message doesn't have a link to the original message. + Returns the MessageId of the sent message on success. + + Source: https://core.telegram.org/bots/api#copymessage + + :param chat_id: Unique identifier for the target chat or username of the target channel + (in the format @channelusername) + :param from_chat_id: Unique identifier for the chat where the original message was sent + (or channel username in the format @channelusername) + :param message_id: Message identifier in the chat specified in from_chat_id + :param caption: New caption for media, 0-1024 characters after entities parsing. If not + specified, the original caption is kept + :param parse_mode: Mode for parsing entities in the new caption. See formatting options + for more details. + :param caption_entities: List of special entities that appear in the new caption, which + can be specified instead of parse_mode + :param disable_notification: Sends the message silently. Users will receive a notification + with no sound. + :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found + :param reply_markup: Additional interface options. A JSON-serialized object for an inline + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. + :param request_timeout: Request timeout + :return: Returns the MessageId of the sent message on success. + """ + call = CopyMessage( + chat_id=chat_id, + from_chat_id=from_chat_id, + message_id=message_id, + caption=caption, + parse_mode=parse_mode, + caption_entities=caption_entities, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, + reply_markup=reply_markup, + ) + return await self(call, request_timeout=request_timeout) + async def send_photo( self, chat_id: Union[int, str], photo: Union[InputFile, str], caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -544,21 +656,25 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendphoto :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param photo: Photo to send. Pass a file_id as String to send a photo that exists on the - Telegram servers (recommended), pass an HTTP URL as a String for Telegram to - get a photo from the Internet, or upload a new photo using - multipart/form-data. + Telegram servers (recommended), pass an HTTP URL as a String for Telegram to + get a photo from the Internet, or upload a new photo using + multipart/form-data. :param caption: Photo caption (may also be used when resending photos by file_id), 0-1024 - characters after entities parsing + characters after entities parsing :param parse_mode: Mode for parsing entities in the photo caption. See formatting options - for more details. + for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -567,8 +683,10 @@ class Bot(ContextInstanceMixin["Bot"]): photo=photo, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -579,12 +697,14 @@ class Bot(ContextInstanceMixin["Bot"]): audio: Union[InputFile, str], caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, performer: Optional[str] = None, title: Optional[str] = None, thumb: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -600,30 +720,34 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendaudio :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param audio: Audio file to send. Pass a file_id as String to send an audio file that - exists on the Telegram servers (recommended), pass an HTTP URL as a String - for Telegram to get an audio file from the Internet, or upload a new one - using multipart/form-data. + exists on the Telegram servers (recommended), pass an HTTP URL as a String + for Telegram to get an audio file from the Internet, or upload a new one + using multipart/form-data. :param caption: Audio caption, 0-1024 characters after entities parsing :param parse_mode: Mode for parsing entities in the audio caption. See formatting options - for more details. + for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode :param duration: Duration of the audio in seconds :param performer: Performer :param title: Track name :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://' if the thumbnail was uploaded using - multipart/form-data under . + 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://' if the thumbnail was uploaded using + multipart/form-data under . :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -632,12 +756,14 @@ class Bot(ContextInstanceMixin["Bot"]): audio=audio, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, duration=duration, performer=performer, title=title, thumb=thumb, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -649,8 +775,11 @@ class Bot(ContextInstanceMixin["Bot"]): thumb: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, + disable_content_type_detection: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -664,28 +793,35 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#senddocument :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param document: File to send. Pass a file_id as String to send a file that exists on the - Telegram servers (recommended), pass an HTTP URL as a String for Telegram - to get a file from the Internet, or upload a new one using - multipart/form-data. + Telegram servers (recommended), pass an HTTP URL as a String for Telegram + to get a file from the Internet, or upload a new one using + multipart/form-data. :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://' if the thumbnail was uploaded using - multipart/form-data under . + 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://' if the thumbnail was uploaded using + multipart/form-data under . :param caption: Document caption (may also be used when resending documents by file_id), - 0-1024 characters after entities parsing + 0-1024 characters after entities parsing :param parse_mode: Mode for parsing entities in the document caption. See formatting - options for more details. + options for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode + :param disable_content_type_detection: Disables automatic server-side content type + detection for files uploaded using + multipart/form-data :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -695,8 +831,11 @@ class Bot(ContextInstanceMixin["Bot"]): thumb=thumb, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, + disable_content_type_detection=disable_content_type_detection, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -711,9 +850,11 @@ class Bot(ContextInstanceMixin["Bot"]): thumb: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, supports_streaming: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -727,32 +868,36 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendvideo :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param video: Video to send. Pass a file_id as String to send a video that exists on the - Telegram servers (recommended), pass an HTTP URL as a String for Telegram to - get a video from the Internet, or upload a new video using - multipart/form-data. + Telegram servers (recommended), pass an HTTP URL as a String for Telegram to + get a video from the Internet, or upload a new video using + multipart/form-data. :param duration: Duration of sent video in seconds :param width: Video width :param height: Video height :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://' if the thumbnail was uploaded using - multipart/form-data under . + 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://' if the thumbnail was uploaded using + multipart/form-data under . :param caption: Video caption (may also be used when resending videos by file_id), 0-1024 - characters after entities parsing + characters after entities parsing :param parse_mode: Mode for parsing entities in the video caption. See formatting options - for more details. + for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode :param supports_streaming: Pass True, if the uploaded video is suitable for streaming :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -765,9 +910,11 @@ class Bot(ContextInstanceMixin["Bot"]): thumb=thumb, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, supports_streaming=supports_streaming, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -782,8 +929,10 @@ class Bot(ContextInstanceMixin["Bot"]): thumb: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -797,31 +946,35 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendanimation :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param animation: Animation to send. Pass a file_id as String to send an animation that - exists on the Telegram servers (recommended), pass an HTTP URL as a - String for Telegram to get an animation from the Internet, or upload a - new animation using multipart/form-data. + exists on the Telegram servers (recommended), pass an HTTP URL as a + String for Telegram to get an animation from the Internet, or upload a + new animation using multipart/form-data. :param duration: Duration of sent animation in seconds :param width: Animation width :param height: Animation height :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://' if the thumbnail was uploaded using - multipart/form-data under . + 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://' if the thumbnail was uploaded using + multipart/form-data under . :param caption: Animation caption (may also be used when resending animation by file_id), - 0-1024 characters after entities parsing + 0-1024 characters after entities parsing :param parse_mode: Mode for parsing entities in the animation caption. See formatting - options for more details. + options for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -834,8 +987,10 @@ class Bot(ContextInstanceMixin["Bot"]): thumb=thumb, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -846,9 +1001,11 @@ class Bot(ContextInstanceMixin["Bot"]): voice: Union[InputFile, str], caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -864,21 +1021,25 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendvoice :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param voice: Audio file to send. Pass a file_id as String to send a file that exists on - the Telegram servers (recommended), pass an HTTP URL as a String for - Telegram to get a file from the Internet, or upload a new one using - multipart/form-data. + the Telegram servers (recommended), pass an HTTP URL as a String for + Telegram to get a file from the Internet, or upload a new one using + multipart/form-data. :param caption: Voice message caption, 0-1024 characters after entities parsing :param parse_mode: Mode for parsing entities in the voice message caption. See formatting - options for more details. + options for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode :param duration: Duration of the voice message in seconds :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -887,9 +1048,11 @@ class Bot(ContextInstanceMixin["Bot"]): voice=voice, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, duration=duration, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -903,6 +1066,7 @@ class Bot(ContextInstanceMixin["Bot"]): thumb: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -915,26 +1079,28 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendvideonote :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param video_note: Video note to send. Pass a file_id as String to send a video note that - exists on the Telegram servers (recommended) or upload a new video - using multipart/form-data.. Sending video notes by a URL is currently - unsupported + exists on the Telegram servers (recommended) or upload a new video + using multipart/form-data.. Sending video notes by a URL is currently + unsupported :param duration: Duration of sent video in seconds :param length: Video width and height, i.e. diameter of the video message :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://' if the thumbnail was uploaded using - multipart/form-data under . + 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://' if the thumbnail was uploaded using + multipart/form-data under . :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -946,6 +1112,7 @@ class Bot(ContextInstanceMixin["Bot"]): thumb=thumb, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -953,32 +1120,37 @@ class Bot(ContextInstanceMixin["Bot"]): async def send_media_group( self, chat_id: Union[int, str], - media: List[Union[InputMediaPhoto, InputMediaVideo]], + media: List[Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]], disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, request_timeout: Optional[int] = None, ) -> List[Message]: """ - Use this method to send a group of photos or videos as an album. On success, an array of - the sent Messages is returned. + Use this method to send a group of photos, videos, documents or audios as an album. + Documents and audio files can be only grouped in an album with messages of the same type. + On success, an array of Messages that were sent is returned. Source: https://core.telegram.org/bots/api#sendmediagroup :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) - :param media: A JSON-serialized array describing photos and videos to be sent, must - include 2-10 items - :param disable_notification: Sends the messages silently. Users will receive a - notification with no sound. + (in the format @channelusername) + :param media: A JSON-serialized array describing messages to be sent, must include 2-10 + items + :param disable_notification: Sends messages silently. Users will receive a notification + with no sound. :param reply_to_message_id: If the messages are a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param request_timeout: Request timeout - :return: On success, an array of the sent Messages is returned. + :return: On success, an array of Messages that were sent is returned. """ call = SendMediaGroup( chat_id=chat_id, media=media, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, ) return await self(call, request_timeout=request_timeout) @@ -987,9 +1159,13 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Union[int, str], latitude: float, longitude: float, + horizontal_accuracy: Optional[float] = None, live_period: Optional[int] = None, + heading: Optional[int] = None, + proximity_alert_radius: Optional[int] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -1001,17 +1177,26 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendlocation :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param latitude: Latitude of the location :param longitude: Longitude of the location + :param horizontal_accuracy: The radius of uncertainty for the location, measured in + meters; 0-1500 :param live_period: Period in seconds for which the location will be updated (see Live - Locations, should be between 60 and 86400. + Locations, should be between 60 and 86400. + :param heading: For live locations, a direction in which the user is moving, in degrees. + Must be between 1 and 360 if specified. + :param proximity_alert_radius: For live locations, a maximum distance for proximity alerts + about approaching another chat member, in meters. Must be + between 1 and 100000 if specified. :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -1019,9 +1204,13 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id=chat_id, latitude=latitude, longitude=longitude, + horizontal_accuracy=horizontal_accuracy, live_period=live_period, + heading=heading, + proximity_alert_radius=proximity_alert_radius, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -1033,30 +1222,40 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, + horizontal_accuracy: Optional[float] = None, + heading: Optional[int] = None, + proximity_alert_radius: Optional[int] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, ) -> Union[Message, bool]: """ Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to - stopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited - Message is returned, otherwise True is returned. + stopMessageLiveLocation. On success, if the edited message is not an inline message, the + edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagelivelocation :param latitude: Latitude of new location :param longitude: Longitude of new location :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat or username of the target channel (in the format - @channelusername) + target chat or username of the target channel (in the format + @channelusername) :param message_id: Required if inline_message_id is not specified. Identifier of the - message to edit + message to edit :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message + :param horizontal_accuracy: The radius of uncertainty for the location, measured in + meters; 0-1500 + :param heading: Direction in which the user is moving, in degrees. Must be between 1 and + 360 if specified. + :param proximity_alert_radius: Maximum distance for proximity alerts about approaching + another chat member, in meters. Must be between 1 and + 100000 if specified. :param reply_markup: A JSON-serialized object for a new inline keyboard. :param request_timeout: Request timeout - :return: On success, if the edited message was sent by the bot, the edited Message is - returned, otherwise True is returned. + :return: On success, if the edited message is not an inline message, the edited Message is + returned, otherwise True is returned. """ call = EditMessageLiveLocation( latitude=latitude, @@ -1064,6 +1263,9 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id, + horizontal_accuracy=horizontal_accuracy, + heading=heading, + proximity_alert_radius=proximity_alert_radius, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -1084,16 +1286,16 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#stopmessagelivelocation :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat or username of the target channel (in the format - @channelusername) + target chat or username of the target channel (in the format + @channelusername) :param message_id: Required if inline_message_id is not specified. Identifier of the - message with live location to stop + message with live location to stop :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param reply_markup: A JSON-serialized object for a new inline keyboard. :param request_timeout: Request timeout :return: On success, if the message was sent by the bot, the sent Message is returned, - otherwise True is returned. + otherwise True is returned. """ call = StopMessageLiveLocation( chat_id=chat_id, @@ -1112,8 +1314,11 @@ class Bot(ContextInstanceMixin["Bot"]): address: str, foursquare_id: Optional[str] = None, foursquare_type: Optional[str] = None, + google_place_id: Optional[str] = None, + google_place_type: Optional[str] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -1126,21 +1331,25 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendvenue :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param latitude: Latitude of the venue :param longitude: Longitude of the venue :param title: Name of the venue :param address: Address of the venue :param foursquare_id: Foursquare identifier of the venue :param foursquare_type: Foursquare type of the venue, if known. (For example, - 'arts_entertainment/default', 'arts_entertainment/aquarium' or - 'food/icecream'.) + 'arts_entertainment/default', 'arts_entertainment/aquarium' or + 'food/icecream'.) + :param google_place_id: Google Places identifier of the venue + :param google_place_type: Google Places type of the venue. (See supported types.) :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -1152,8 +1361,11 @@ class Bot(ContextInstanceMixin["Bot"]): address=address, foursquare_id=foursquare_id, foursquare_type=foursquare_type, + google_place_id=google_place_id, + google_place_type=google_place_type, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -1167,6 +1379,7 @@ class Bot(ContextInstanceMixin["Bot"]): vcard: Optional[str] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -1178,17 +1391,19 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendcontact :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param phone_number: Contact's phone number :param first_name: Contact's first name :param last_name: Contact's last name :param vcard: Additional data about the contact in the form of a vCard, 0-2048 bytes :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove keyboard or - to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove keyboard or + to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -1200,6 +1415,7 @@ class Bot(ContextInstanceMixin["Bot"]): vcard=vcard, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -1215,11 +1431,13 @@ class Bot(ContextInstanceMixin["Bot"]): correct_option_id: Optional[int] = None, explanation: Optional[str] = None, explanation_parse_mode: Optional[str] = UNSET, + explanation_entities: Optional[List[MessageEntity]] = None, open_period: Optional[int] = None, close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None, is_closed: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -1231,34 +1449,38 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendpoll :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) - :param question: Poll question, 1-255 characters + (in the format @channelusername) + :param question: Poll question, 1-300 characters :param options: A JSON-serialized list of answer options, 2-10 strings 1-100 characters - each + each :param is_anonymous: True, if the poll needs to be anonymous, defaults to True :param type: Poll type, 'quiz' or 'regular', defaults to 'regular' :param allows_multiple_answers: True, if the poll allows multiple answers, ignored for - polls in quiz mode, defaults to False + polls in quiz mode, defaults to False :param correct_option_id: 0-based identifier of the correct answer option, required for - polls in quiz mode + polls in quiz mode :param explanation: Text that is shown when a user chooses an incorrect answer or taps on - the lamp icon in a quiz-style poll, 0-200 characters with at most 2 - line feeds after entities parsing + the lamp icon in a quiz-style poll, 0-200 characters with at most 2 + line feeds after entities parsing :param explanation_parse_mode: Mode for parsing entities in the explanation. See - formatting options for more details. + formatting options for more details. + :param explanation_entities: List of special entities that appear in the poll explanation, + which can be specified instead of parse_mode :param open_period: Amount of time in seconds the poll will be active after creation, - 5-600. Can't be used together with close_date. + 5-600. Can't be used together with close_date. :param close_date: Point in time (Unix timestamp) when the poll will be automatically - closed. Must be at least 5 and no more than 600 seconds in the future. - Can't be used together with open_period. + closed. Must be at least 5 and no more than 600 seconds in the future. + Can't be used together with open_period. :param is_closed: Pass True, if the poll needs to be immediately closed. This can be - useful for poll preview. + useful for poll preview. :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -1272,11 +1494,13 @@ class Bot(ContextInstanceMixin["Bot"]): correct_option_id=correct_option_id, explanation=explanation, explanation_parse_mode=explanation_parse_mode, + explanation_entities=explanation_entities, open_period=open_period, close_date=close_date, is_closed=is_closed, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -1287,6 +1511,7 @@ class Bot(ContextInstanceMixin["Bot"]): emoji: Optional[str] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -1299,16 +1524,18 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#senddice :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param emoji: Emoji on which the dice throw animation is based. Currently, must be one of - '', '', or ''. Dice can have values 1-6 for '' and '', and values 1-5 for - ''. Defaults to '' + '', '', '', '', or ''. Dice can have values 1-6 for '' and '', values 1-5 + for '' and '', and values 1-64 for ''. Defaults to '' :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -1317,6 +1544,7 @@ class Bot(ContextInstanceMixin["Bot"]): emoji=emoji, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -1338,12 +1566,12 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendchataction :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param action: Type of action to broadcast. Choose one, depending on what the user is - about to receive: typing for text messages, upload_photo for photos, - record_video or upload_video for videos, record_audio or upload_audio for - audio files, upload_document for general files, find_location for location - data, record_video_note or upload_video_note for video notes. + about to receive: typing for text messages, upload_photo for photos, + record_video or upload_video for videos, record_audio or upload_audio for + audio files, upload_document for general files, find_location for location + data, record_video_note or upload_video_note for video notes. :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1365,9 +1593,9 @@ class Bot(ContextInstanceMixin["Bot"]): :param user_id: Unique identifier of the target user :param offset: Sequential number of the first photo to be returned. By default, all photos - are returned. + are returned. :param limit: Limits the number of photos to be retrieved. Values between 1-100 are - accepted. Defaults to 100. + accepted. Defaults to 100. :param request_timeout: Request timeout :return: Returns a UserProfilePhotos object. """ @@ -1410,36 +1638,44 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#kickchatmember :param chat_id: Unique identifier for the target group or username of the target - supergroup or channel (in the format @channelusername) + supergroup or channel (in the format @channelusername) :param user_id: Unique identifier of the target user :param until_date: Date when the user will be unbanned, unix time. If user is banned for - more than 366 days or less than 30 seconds from the current time they - are considered to be banned forever + more than 366 days or less than 30 seconds from the current time they + are considered to be banned forever :param request_timeout: Request timeout :return: In the case of supergroups and channels, the user will not be able to return to - the group on their own using invite links, etc. Returns True on success. + the group on their own using invite links, etc. Returns True on success. """ call = KickChatMember(chat_id=chat_id, user_id=user_id, until_date=until_date,) return await self(call, request_timeout=request_timeout) async def unban_chat_member( - self, chat_id: Union[int, str], user_id: int, request_timeout: Optional[int] = None, + self, + chat_id: Union[int, str], + user_id: int, + only_if_banned: Optional[bool] = None, + request_timeout: Optional[int] = None, ) -> bool: """ Use this method to unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, - etc. The bot must be an administrator for this to work. Returns True on success. + etc. The bot must be an administrator for this to work. By default, this method guarantees + that after the call the user is not a member of the chat, but will be able to join it. So + if the user is a member of the chat they will also be removed from the chat. If you don't + want this, use the parameter only_if_banned. Returns True on success. Source: https://core.telegram.org/bots/api#unbanchatmember :param chat_id: Unique identifier for the target group or username of the target - supergroup or channel (in the format @username) + supergroup or channel (in the format @username) :param user_id: Unique identifier of the target user + :param only_if_banned: Do nothing if the user is not banned :param request_timeout: Request timeout :return: The user will not return to the group or channel automatically, but will be able - to join via link, etc. Returns True on success. + to join via link, etc. Returns True on success. """ - call = UnbanChatMember(chat_id=chat_id, user_id=user_id,) + call = UnbanChatMember(chat_id=chat_id, user_id=user_id, only_if_banned=only_if_banned,) return await self(call, request_timeout=request_timeout) async def restrict_chat_member( @@ -1458,12 +1694,12 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#restrictchatmember :param chat_id: Unique identifier for the target chat or username of the target supergroup - (in the format @supergroupusername) + (in the format @supergroupusername) :param user_id: Unique identifier of the target user - :param permissions: New user permissions + :param permissions: A JSON-serialized object for new user permissions :param until_date: Date when restrictions will be lifted for the user, unix time. If user - is restricted for more than 366 days or less than 30 seconds from the - current time, they are considered to be restricted forever + is restricted for more than 366 days or less than 30 seconds from the + current time, they are considered to be restricted forever :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1476,6 +1712,7 @@ class Bot(ContextInstanceMixin["Bot"]): self, chat_id: Union[int, str], user_id: int, + is_anonymous: Optional[bool] = None, can_change_info: Optional[bool] = None, can_post_messages: Optional[bool] = None, can_edit_messages: Optional[bool] = None, @@ -1494,31 +1731,33 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#promotechatmember :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param user_id: Unique identifier of the target user + :param is_anonymous: Pass True, if the administrator's presence in the chat is hidden :param can_change_info: Pass True, if the administrator can change chat title, photo and - other settings + other settings :param can_post_messages: Pass True, if the administrator can create channel posts, - channels only + channels only :param can_edit_messages: Pass True, if the administrator can edit messages of other users - and can pin messages, channels only + and can pin messages, channels only :param can_delete_messages: Pass True, if the administrator can delete messages of other - users + users :param can_invite_users: Pass True, if the administrator can invite new users to the chat :param can_restrict_members: Pass True, if the administrator can restrict, ban or unban - chat members + chat members :param can_pin_messages: Pass True, if the administrator can pin messages, supergroups - only + only :param can_promote_members: Pass True, if the administrator can add new administrators - with a subset of their own privileges or demote administrators - that he has promoted, directly or indirectly (promoted by - administrators that were appointed by him) + with a subset of their own privileges or demote administrators + that he has promoted, directly or indirectly (promoted by + administrators that were appointed by him) :param request_timeout: Request timeout :return: Returns True on success. """ call = PromoteChatMember( chat_id=chat_id, user_id=user_id, + is_anonymous=is_anonymous, can_change_info=can_change_info, can_post_messages=can_post_messages, can_edit_messages=can_edit_messages, @@ -1544,10 +1783,10 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setchatadministratorcustomtitle :param chat_id: Unique identifier for the target chat or username of the target supergroup - (in the format @supergroupusername) + (in the format @supergroupusername) :param user_id: Unique identifier of the target user :param custom_title: New custom title for the administrator; 0-16 characters, emoji are - not allowed + not allowed :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1570,7 +1809,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setchatpermissions :param chat_id: Unique identifier for the target chat or username of the target supergroup - (in the format @supergroupusername) + (in the format @supergroupusername) :param permissions: New default chat permissions :param request_timeout: Request timeout :return: Returns True on success. @@ -1594,7 +1833,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#exportchatinvitelink :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param request_timeout: Request timeout :return: Returns the new invite link as String on success. """ @@ -1612,7 +1851,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setchatphoto :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param photo: New chat photo, uploaded using multipart/form-data :param request_timeout: Request timeout :return: Returns True on success. @@ -1631,7 +1870,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#deletechatphoto :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1649,7 +1888,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setchattitle :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param title: New chat title, 1-255 characters :param request_timeout: Request timeout :return: Returns True on success. @@ -1671,7 +1910,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setchatdescription :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param description: New chat description, 0-255 characters :param request_timeout: Request timeout :return: Returns True on success. @@ -1687,19 +1926,19 @@ class Bot(ContextInstanceMixin["Bot"]): request_timeout: Optional[int] = None, ) -> bool: """ - Use this method to pin a message in a group, a supergroup, or a channel. The bot must be - an administrator in the chat for this to work and must have the 'can_pin_messages' admin - right in the supergroup or 'can_edit_messages' admin right in the channel. Returns True on - success. + Use this method to add a message to the list of pinned messages in a chat. If the chat is + not a private chat, the bot must be an administrator in the chat for this to work and must + have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right + in a channel. Returns True on success. Source: https://core.telegram.org/bots/api#pinchatmessage :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param message_id: Identifier of a message to pin :param disable_notification: Pass True, if it is not necessary to send a notification to - all chat members about the new pinned message. Notifications - are always disabled in channels. + all chat members about the new pinned message. Notifications + are always disabled in channels and private chats. :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1709,22 +1948,46 @@ class Bot(ContextInstanceMixin["Bot"]): return await self(call, request_timeout=request_timeout) async def unpin_chat_message( - self, chat_id: Union[int, str], request_timeout: Optional[int] = None, + self, + chat_id: Union[int, str], + message_id: Optional[int] = None, + request_timeout: Optional[int] = None, ) -> bool: """ - Use this method to unpin a message in a group, a supergroup, or a channel. The bot must be - an administrator in the chat for this to work and must have the 'can_pin_messages' admin - right in the supergroup or 'can_edit_messages' admin right in the channel. Returns True on - success. + Use this method to remove a message from the list of pinned messages in a chat. If the + chat is not a private chat, the bot must be an administrator in the chat for this to work + and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' + admin right in a channel. Returns True on success. Source: https://core.telegram.org/bots/api#unpinchatmessage :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) + :param message_id: Identifier of a message to unpin. If not specified, the most recent + pinned message (by sending date) will be unpinned. :param request_timeout: Request timeout :return: Returns True on success. """ - call = UnpinChatMessage(chat_id=chat_id,) + call = UnpinChatMessage(chat_id=chat_id, message_id=message_id,) + return await self(call, request_timeout=request_timeout) + + async def unpin_all_chat_messages( + self, chat_id: Union[int, str], request_timeout: Optional[int] = None, + ) -> bool: + """ + Use this method to clear the list of pinned messages in a chat. If the chat is not a + private chat, the bot must be an administrator in the chat for this to work and must have + the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a + channel. Returns True on success. + + Source: https://core.telegram.org/bots/api#unpinallchatmessages + + :param chat_id: Unique identifier for the target chat or username of the target channel + (in the format @channelusername) + :param request_timeout: Request timeout + :return: Returns True on success. + """ + call = UnpinAllChatMessages(chat_id=chat_id,) return await self(call, request_timeout=request_timeout) async def leave_chat( @@ -1737,7 +2000,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#leavechat :param chat_id: Unique identifier for the target chat or username of the target supergroup - or channel (in the format @channelusername) + or channel (in the format @channelusername) :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1755,7 +2018,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#getchat :param chat_id: Unique identifier for the target chat or username of the target supergroup - or channel (in the format @channelusername) + or channel (in the format @channelusername) :param request_timeout: Request timeout :return: Returns a Chat object on success. """ @@ -1774,12 +2037,12 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#getchatadministrators :param chat_id: Unique identifier for the target chat or username of the target supergroup - or channel (in the format @channelusername) + or channel (in the format @channelusername) :param request_timeout: Request timeout :return: On success, returns an Array of ChatMember objects that contains information - about all chat administrators except other bots. If the chat is a group or a - supergroup and no administrators were appointed, only the creator will be - returned. + about all chat administrators except other bots. If the chat is a group or a + supergroup and no administrators were appointed, only the creator will be + returned. """ call = GetChatAdministrators(chat_id=chat_id,) return await self(call, request_timeout=request_timeout) @@ -1793,7 +2056,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#getchatmemberscount :param chat_id: Unique identifier for the target chat or username of the target supergroup - or channel (in the format @channelusername) + or channel (in the format @channelusername) :param request_timeout: Request timeout :return: Returns Int on success. """ @@ -1810,7 +2073,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#getchatmember :param chat_id: Unique identifier for the target chat or username of the target supergroup - or channel (in the format @channelusername) + or channel (in the format @channelusername) :param user_id: Unique identifier of the target user :param request_timeout: Request timeout :return: Returns a ChatMember object on success. @@ -1833,11 +2096,11 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setchatstickerset :param chat_id: Unique identifier for the target chat or username of the target supergroup - (in the format @supergroupusername) + (in the format @supergroupusername) :param sticker_set_name: Name of the sticker set to be set as the group sticker set :param request_timeout: Request timeout :return: Use the field can_set_sticker_set optionally returned in getChat requests to - check if the bot can use this method. Returns True on success. + check if the bot can use this method. Returns True on success. """ call = SetChatStickerSet(chat_id=chat_id, sticker_set_name=sticker_set_name,) return await self(call, request_timeout=request_timeout) @@ -1854,10 +2117,10 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#deletechatstickerset :param chat_id: Unique identifier for the target chat or username of the target supergroup - (in the format @supergroupusername) + (in the format @supergroupusername) :param request_timeout: Request timeout :return: Use the field can_set_sticker_set optionally returned in getChat requests to - check if the bot can use this method. Returns True on success. + check if the bot can use this method. Returns True on success. """ call = DeleteChatStickerSet(chat_id=chat_id,) return await self(call, request_timeout=request_timeout) @@ -1884,15 +2147,15 @@ class Bot(ContextInstanceMixin["Bot"]): :param callback_query_id: Unique identifier for the query to be answered :param text: Text of the notification. If not specified, nothing will be shown to the - user, 0-200 characters + user, 0-200 characters :param show_alert: If true, an alert will be shown by the client instead of a notification - at the top of the chat screen. Defaults to false. + at the top of the chat screen. Defaults to false. :param url: URL that will be opened by the user's client. If you have created a Game and - accepted the conditions via @Botfather, specify the URL that opens your game — - note that this will only work if the query comes from a callback_game button. + accepted the conditions via @Botfather, specify the URL that opens your game — + note that this will only work if the query comes from a callback_game button. :param cache_time: The maximum amount of time in seconds that the result of the callback - query may be cached client-side. Telegram apps will support caching - starting in version 3.14. Defaults to 0. + query may be cached client-side. Telegram apps will support caching + starting in version 3.14. Defaults to 0. :param request_timeout: Request timeout :return: On success, True is returned. """ @@ -1914,7 +2177,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#setmycommands :param commands: A JSON-serialized list of bot commands to be set as the list of the bot's - commands. At most 100 commands can be specified. + commands. At most 100 commands can be specified. :param request_timeout: Request timeout :return: Returns True on success. """ @@ -1946,31 +2209,34 @@ class Bot(ContextInstanceMixin["Bot"]): message_id: Optional[int] = None, inline_message_id: Optional[str] = None, parse_mode: Optional[str] = UNSET, + entities: Optional[List[MessageEntity]] = None, disable_web_page_preview: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, ) -> Union[Message, bool]: """ - Use this method to edit text and game messages. On success, if edited message is sent by - the bot, the edited Message is returned, otherwise True is returned. + Use this method to edit text and game messages. On success, if the edited message is not + an inline message, the edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagetext :param text: New text of the message, 1-4096 characters after entities parsing :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat or username of the target channel (in the format - @channelusername) + target chat or username of the target channel (in the format + @channelusername) :param message_id: Required if inline_message_id is not specified. Identifier of the - message to edit + message to edit :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param parse_mode: Mode for parsing entities in the message text. See formatting options - for more details. + for more details. + :param entities: List of special entities that appear in message text, which can be + specified instead of parse_mode :param disable_web_page_preview: Disables link previews for links in this message :param reply_markup: A JSON-serialized object for an inline keyboard. :param request_timeout: Request timeout - :return: On success, if edited message is sent by the bot, the edited Message is returned, - otherwise True is returned. + :return: On success, if the edited message is not an inline message, the edited Message is + returned, otherwise True is returned. """ call = EditMessageText( text=text, @@ -1978,6 +2244,7 @@ class Bot(ContextInstanceMixin["Bot"]): message_id=message_id, inline_message_id=inline_message_id, parse_mode=parse_mode, + entities=entities, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup, ) @@ -1990,29 +2257,32 @@ class Bot(ContextInstanceMixin["Bot"]): inline_message_id: Optional[str] = None, caption: Optional[str] = None, parse_mode: Optional[str] = UNSET, + caption_entities: Optional[List[MessageEntity]] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, ) -> Union[Message, bool]: """ - Use this method to edit captions of messages. On success, if edited message is sent by the - bot, the edited Message is returned, otherwise True is returned. + Use this method to edit captions of messages. On success, if the edited message is not an + inline message, the edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagecaption :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat or username of the target channel (in the format - @channelusername) + target chat or username of the target channel (in the format + @channelusername) :param message_id: Required if inline_message_id is not specified. Identifier of the - message to edit + message to edit :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param caption: New caption of the message, 0-1024 characters after entities parsing :param parse_mode: Mode for parsing entities in the message caption. See formatting - options for more details. + options for more details. + :param caption_entities: List of special entities that appear in the caption, which can be + specified instead of parse_mode :param reply_markup: A JSON-serialized object for an inline keyboard. :param request_timeout: Request timeout - :return: On success, if edited message is sent by the bot, the edited Message is returned, - otherwise True is returned. + :return: On success, if the edited message is not an inline message, the edited Message is + returned, otherwise True is returned. """ call = EditMessageCaption( chat_id=chat_id, @@ -2020,6 +2290,7 @@ class Bot(ContextInstanceMixin["Bot"]): inline_message_id=inline_message_id, caption=caption, parse_mode=parse_mode, + caption_entities=caption_entities, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -2035,26 +2306,26 @@ class Bot(ContextInstanceMixin["Bot"]): ) -> Union[Message, bool]: """ Use this method to edit animation, audio, document, photo, or video messages. If a message - is a part of a message album, then it can be edited only to a photo or a video. Otherwise, - message type can be changed arbitrarily. When inline message is edited, new file can't be - uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if - the edited message was sent by the bot, the edited Message is returned, otherwise True is - returned. + is part of a message album, then it can be edited only to an audio for audio albums, only + to a document for document albums and to a photo or a video otherwise. When an inline + message is edited, a new file can't be uploaded. Use a previously uploaded file via its + file_id or specify a URL. On success, if the edited message was sent by the bot, the + edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagemedia :param media: A JSON-serialized object for a new media content of the message :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat or username of the target channel (in the format - @channelusername) + target chat or username of the target channel (in the format + @channelusername) :param message_id: Required if inline_message_id is not specified. Identifier of the - message to edit + message to edit :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param reply_markup: A JSON-serialized object for a new inline keyboard. :param request_timeout: Request timeout :return: On success, if the edited message was sent by the bot, the edited Message is - returned, otherwise True is returned. + returned, otherwise True is returned. """ call = EditMessageMedia( media=media, @@ -2074,22 +2345,23 @@ class Bot(ContextInstanceMixin["Bot"]): request_timeout: Optional[int] = None, ) -> Union[Message, bool]: """ - Use this method to edit only the reply markup of messages. On success, if edited message - is sent by the bot, the edited Message is returned, otherwise True is returned. + Use this method to edit only the reply markup of messages. On success, if the edited + message is not an inline message, the edited Message is returned, otherwise True is + returned. Source: https://core.telegram.org/bots/api#editmessagereplymarkup :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat or username of the target channel (in the format - @channelusername) + target chat or username of the target channel (in the format + @channelusername) :param message_id: Required if inline_message_id is not specified. Identifier of the - message to edit + message to edit :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param reply_markup: A JSON-serialized object for an inline keyboard. :param request_timeout: Request timeout - :return: On success, if edited message is sent by the bot, the edited Message is returned, - otherwise True is returned. + :return: On success, if the edited message is not an inline message, the edited Message is + returned, otherwise True is returned. """ call = EditMessageReplyMarkup( chat_id=chat_id, @@ -2113,7 +2385,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#stoppoll :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param message_id: Identifier of the original message with the poll :param reply_markup: A JSON-serialized object for a new message inline keyboard. :param request_timeout: Request timeout @@ -2142,7 +2414,7 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#deletemessage :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param message_id: Identifier of the message to delete :param request_timeout: Request timeout :return: Returns True on success. @@ -2161,6 +2433,7 @@ class Bot(ContextInstanceMixin["Bot"]): sticker: Union[InputFile, str], disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None, @@ -2173,17 +2446,19 @@ class Bot(ContextInstanceMixin["Bot"]): Source: https://core.telegram.org/bots/api#sendsticker :param chat_id: Unique identifier for the target chat or username of the target channel - (in the format @channelusername) + (in the format @channelusername) :param sticker: Sticker to send. Pass a file_id as String to send a file that exists on - the Telegram servers (recommended), pass an HTTP URL as a String for - Telegram to get a .WEBP file from the Internet, or upload a new one using - multipart/form-data. + the Telegram servers (recommended), pass an HTTP URL as a String for + Telegram to get a .WEBP file from the Internet, or upload a new one using + multipart/form-data. :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: Additional interface options. A JSON-serialized object for an inline - keyboard, custom reply keyboard, instructions to remove reply - keyboard or to force a reply from the user. + keyboard, custom reply keyboard, instructions to remove reply + keyboard or to force a reply from the user. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -2192,6 +2467,7 @@ class Bot(ContextInstanceMixin["Bot"]): sticker=sticker, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -2223,8 +2499,8 @@ class Bot(ContextInstanceMixin["Bot"]): :param user_id: User identifier of sticker file owner :param png_sticker: 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. + dimensions must not exceed 512px, and either width or height must be + exactly 512px. :param request_timeout: Request timeout :return: Returns the uploaded File on success. """ @@ -2252,23 +2528,23 @@ class Bot(ContextInstanceMixin["Bot"]): :param user_id: User identifier of created sticker set owner :param name: Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., - animals). Can contain only english letters, digits and underscores. Must - begin with a letter, can't contain consecutive underscores and must end in - '_by_'. is case insensitive. 1-64 characters. + animals). Can contain only english letters, digits and underscores. Must + begin with a letter, can't contain consecutive underscores and must end in + '_by_'. is case insensitive. 1-64 characters. :param title: Sticker set title, 1-64 characters :param emojis: One or more emoji corresponding to the sticker :param png_sticker: 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. Pass a file_id as a String to send a file that already - exists on the Telegram servers, pass an HTTP URL as a String for - Telegram to get a file from the Internet, or upload a new one using - multipart/form-data. + dimensions must not exceed 512px, and either width or height must be + exactly 512px. Pass a file_id as a String to send a file that already + exists on the Telegram servers, pass an HTTP URL as a String for + Telegram to get a file from the Internet, or upload a new one using + multipart/form-data. :param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data. - See https://core.telegram.org/animated_stickers#technical-requirements - for technical requirements + See https://core.telegram.org/animated_stickers#technical-requirements + for technical requirements :param contains_masks: Pass True, if a set of mask stickers should be created :param mask_position: A JSON-serialized object for position where the mask should be - placed on faces + placed on faces :param request_timeout: Request timeout :return: Returns True on success. """ @@ -2306,16 +2582,16 @@ class Bot(ContextInstanceMixin["Bot"]): :param name: Sticker set name :param emojis: One or more emoji corresponding to the sticker :param png_sticker: 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. Pass a file_id as a String to send a file that already - exists on the Telegram servers, pass an HTTP URL as a String for - Telegram to get a file from the Internet, or upload a new one using - multipart/form-data. + dimensions must not exceed 512px, and either width or height must be + exactly 512px. Pass a file_id as a String to send a file that already + exists on the Telegram servers, pass an HTTP URL as a String for + Telegram to get a file from the Internet, or upload a new one using + multipart/form-data. :param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data. - See https://core.telegram.org/animated_stickers#technical-requirements - for technical requirements + See https://core.telegram.org/animated_stickers#technical-requirements + for technical requirements :param mask_position: A JSON-serialized object for position where the mask should be - placed on faces + placed on faces :param request_timeout: Request timeout :return: Returns True on success. """ @@ -2378,14 +2654,14 @@ class Bot(ContextInstanceMixin["Bot"]): :param name: Sticker set name :param user_id: User identifier of the sticker set owner :param thumb: A PNG image with the thumbnail, must be up to 128 kilobytes in size and have - width and height exactly 100px, or a TGS animation with the thumbnail up to - 32 kilobytes in size; see - https://core.telegram.org/animated_stickers#technical-requirements for - animated sticker technical requirements. Pass a file_id as a String to send - a file that already exists on the Telegram servers, pass an HTTP URL as a - String for Telegram to get a file from the Internet, or upload a new one - using multipart/form-data.. Animated sticker set thumbnail can't be uploaded - via HTTP URL. + width and height exactly 100px, or a TGS animation with the thumbnail up to + 32 kilobytes in size; see + https://core.telegram.org/animated_stickers#technical-requirements for + animated sticker technical requirements. Pass a file_id as a String to send + a file that already exists on the Telegram servers, pass an HTTP URL as a + String for Telegram to get a file from the Internet, or upload a new one + using multipart/form-data.. Animated sticker set thumbnail can't be uploaded + via HTTP URL. :param request_timeout: Request timeout :return: Returns True on success. """ @@ -2417,20 +2693,20 @@ class Bot(ContextInstanceMixin["Bot"]): :param inline_query_id: Unique identifier for the answered query :param results: A JSON-serialized array of results for the inline query :param cache_time: The maximum amount of time in seconds that the result of the inline - query may be cached on the server. Defaults to 300. + query may be cached on the server. Defaults to 300. :param is_personal: Pass True, if results may be cached on the server side only for the - user that sent the query. By default, results may be returned to any - user who sends the same query + user that sent the query. By default, results may be returned to any + user who sends the same query :param next_offset: Pass the offset that a client should send in the next query with the - same text to receive more results. Pass an empty string if there are - no more results or if you don't support pagination. Offset length - can't exceed 64 bytes. + same text to receive more results. Pass an empty string if there are + no more results or if you don't support pagination. Offset length + can't exceed 64 bytes. :param switch_pm_text: If passed, clients will display a button with specified text that - switches the user to a private chat with the bot and sends the bot - a start message with the parameter switch_pm_parameter + switches the user to a private chat with the bot and sends the bot + a start message with the parameter switch_pm_parameter :param switch_pm_parameter: Deep-linking parameter for the /start message sent to the bot - when user presses the switch button. 1-64 characters, only - A-Z, a-z, 0-9, _ and - are allowed. + when user presses the switch button. 1-64 characters, only + A-Z, a-z, 0-9, _ and - are allowed. :param request_timeout: Request timeout :return: On success, True is returned. """ @@ -2474,6 +2750,7 @@ class Bot(ContextInstanceMixin["Bot"]): is_flexible: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, ) -> Message: @@ -2486,40 +2763,42 @@ class Bot(ContextInstanceMixin["Bot"]): :param title: Product name, 1-32 characters :param description: Product description, 1-255 characters :param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to - the user, use for your internal processes. + the user, use for your internal processes. :param provider_token: Payments provider token, obtained via Botfather :param start_parameter: Unique deep-linking parameter that can be used to generate this - invoice when used as a start parameter + invoice when used as a start parameter :param currency: Three-letter ISO 4217 currency code, see more on currencies :param prices: Price breakdown, a JSON-serialized list of components (e.g. product price, - tax, discount, delivery cost, delivery tax, bonus, etc.) - :param provider_data: JSON-encoded data about the invoice, which will be shared with the - payment provider. A detailed description of required fields should - be provided by the payment provider. + tax, discount, delivery cost, delivery tax, bonus, etc.) + :param provider_data: A JSON-serialized data about the invoice, which will be shared with + the payment provider. A detailed description of required fields + should be provided by the payment provider. :param photo_url: URL of the product photo for the invoice. Can be a photo of the goods or - a marketing image for a service. People like it better when they see - what they are paying for. + a marketing image for a service. People like it better when they see + what they are paying for. :param photo_size: Photo size :param photo_width: Photo width :param photo_height: Photo height :param need_name: Pass True, if you require the user's full name to complete the order :param need_phone_number: Pass True, if you require the user's phone number to complete - the order + the order :param need_email: Pass True, if you require the user's email address to complete the - order + order :param need_shipping_address: Pass True, if you require the user's shipping address to - complete the order + complete the order :param send_phone_number_to_provider: Pass True, if user's phone number should be sent to - provider + provider :param send_email_to_provider: Pass True, if user's email address should be sent to - provider + provider :param is_flexible: Pass True, if the final price depends on the shipping method :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay - total price' button will be shown. If not empty, the first button - must be a Pay button. + total price' button will be shown. If not empty, the first button + must be a Pay button. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -2546,6 +2825,7 @@ class Bot(ContextInstanceMixin["Bot"]): is_flexible=is_flexible, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -2567,14 +2847,14 @@ class Bot(ContextInstanceMixin["Bot"]): :param shipping_query_id: Unique identifier for the query to be answered :param ok: Specify True if delivery to the specified address is possible and False if - there are any problems (for example, if delivery to the specified address is - not possible) + there are any problems (for example, if delivery to the specified address is + not possible) :param shipping_options: Required if ok is True. A JSON-serialized array of available - shipping options. + shipping options. :param error_message: Required if ok is False. Error message in human readable form that - explains why it is impossible to complete the order (e.g. "Sorry, - delivery to your desired address is unavailable'). Telegram will - display this message to the user. + explains why it is impossible to complete the order (e.g. "Sorry, + delivery to your desired address is unavailable'). Telegram will + display this message to the user. :param request_timeout: Request timeout :return: On success, True is returned. """ @@ -2603,13 +2883,13 @@ class Bot(ContextInstanceMixin["Bot"]): :param pre_checkout_query_id: Unique identifier for the query to be answered :param ok: Specify True if everything is alright (goods are available, etc.) and the bot - is ready to proceed with the order. Use False if there are any problems. + is ready to proceed with the order. Use False if there are any problems. :param error_message: Required if ok is False. Error message in human readable form that - explains the reason for failure to proceed with the checkout (e.g. - "Sorry, somebody just bought the last of our amazing black T-shirts - while you were busy filling out your payment details. Please choose - a different color or garment!"). Telegram will display this message - to the user. + explains the reason for failure to proceed with the checkout (e.g. + "Sorry, somebody just bought the last of our amazing black T-shirts + while you were busy filling out your payment details. Please choose + a different color or garment!"). Telegram will display this message + to the user. :param request_timeout: Request timeout :return: On success, True is returned. """ @@ -2645,8 +2925,8 @@ class Bot(ContextInstanceMixin["Bot"]): :param errors: A JSON-serialized array describing the errors :param request_timeout: Request timeout :return: The user will not be able to re-submit their Passport to you until the errors are - fixed (the contents of the field for which you returned the error must change). - Returns True on success. + fixed (the contents of the field for which you returned the error must change). + Returns True on success. """ call = SetPassportDataErrors(user_id=user_id, errors=errors,) return await self(call, request_timeout=request_timeout) @@ -2662,6 +2942,7 @@ class Bot(ContextInstanceMixin["Bot"]): game_short_name: str, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, + allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, ) -> Message: @@ -2672,13 +2953,15 @@ class Bot(ContextInstanceMixin["Bot"]): :param chat_id: Unique identifier for the target chat :param game_short_name: Short name of the game, serves as the unique identifier for the - game. Set up your games via Botfather. + game. Set up your games via Botfather. :param disable_notification: Sends the message silently. Users will receive a notification - with no sound. + with no sound. :param reply_to_message_id: If the message is a reply, ID of the original message + :param allow_sending_without_reply: Pass True, if the message should be sent even if the + specified replied-to message is not found :param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Play - game_title' button will be shown. If not empty, the first button must - launch the game. + game_title' button will be shown. If not empty, the first button must + launch the game. :param request_timeout: Request timeout :return: On success, the sent Message is returned. """ @@ -2687,6 +2970,7 @@ class Bot(ContextInstanceMixin["Bot"]): game_short_name=game_short_name, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + allow_sending_without_reply=allow_sending_without_reply, reply_markup=reply_markup, ) return await self(call, request_timeout=request_timeout) @@ -2713,19 +2997,19 @@ class Bot(ContextInstanceMixin["Bot"]): :param user_id: User identifier :param score: New score, must be non-negative :param force: Pass True, if the high score is allowed to decrease. This can be useful when - fixing mistakes or banning cheaters + fixing mistakes or banning cheaters :param disable_edit_message: Pass True, if the game message should not be automatically - edited to include the current scoreboard + edited to include the current scoreboard :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat + target chat :param message_id: Required if inline_message_id is not specified. Identifier of the sent - message + message :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param request_timeout: Request timeout :return: On success, if the message was sent by the bot, returns the edited Message, - otherwise returns True. Returns an error, if the new score is not greater than - the user's current score in the chat and force is False. + otherwise returns True. Returns an error, if the new score is not greater than + the user's current score in the chat and force is False. """ call = SetGameScore( user_id=user_id, @@ -2758,17 +3042,17 @@ class Bot(ContextInstanceMixin["Bot"]): :param user_id: Target user id :param chat_id: Required if inline_message_id is not specified. Unique identifier for the - target chat + target chat :param message_id: Required if inline_message_id is not specified. Identifier of the sent - message + message :param inline_message_id: Required if chat_id and message_id are not specified. Identifier - of the inline message + of the inline message :param request_timeout: Request timeout :return: Will return the score of the specified user and several of their neighbors in a - game. On success, returns an Array of GameHighScore objects. This method will - currently return scores for the target user, plus two of their closest neighbors - on each side. Will also return the top three users if the user and his neighbors - are not among them. + game. On success, returns an Array of GameHighScore objects. This method will + currently return scores for the target user, plus two of their closest neighbors + on each side. Will also return the top three users if the user and his neighbors + are not among them. """ call = GetGameHighScores( user_id=user_id, diff --git a/aiogram/api/methods/__init__.py b/aiogram/api/methods/__init__.py index 52785ed0..9d498162 100644 --- a/aiogram/api/methods/__init__.py +++ b/aiogram/api/methods/__init__.py @@ -4,6 +4,8 @@ from .answer_inline_query import AnswerInlineQuery from .answer_pre_checkout_query import AnswerPreCheckoutQuery from .answer_shipping_query import AnswerShippingQuery from .base import Request, Response, TelegramMethod +from .close import Close +from .copy_message import CopyMessage from .create_new_sticker_set import CreateNewStickerSet from .delete_chat_photo import DeleteChatPhoto from .delete_chat_sticker_set import DeleteChatStickerSet @@ -31,6 +33,7 @@ from .get_user_profile_photos import GetUserProfilePhotos from .get_webhook_info import GetWebhookInfo from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat +from .log_out import LogOut from .pin_chat_message import PinChatMessage from .promote_chat_member import PromoteChatMember from .restrict_chat_member import RestrictChatMember @@ -67,6 +70,7 @@ from .set_webhook import SetWebhook from .stop_message_live_location import StopMessageLiveLocation from .stop_poll import StopPoll from .unban_chat_member import UnbanChatMember +from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .upload_sticker_file import UploadStickerFile @@ -79,8 +83,11 @@ __all__ = ( "DeleteWebhook", "GetWebhookInfo", "GetMe", + "LogOut", + "Close", "SendMessage", "ForwardMessage", + "CopyMessage", "SendPhoto", "SendAudio", "SendDocument", @@ -112,6 +119,7 @@ __all__ = ( "SetChatDescription", "PinChatMessage", "UnpinChatMessage", + "UnpinAllChatMessages", "LeaveChat", "GetChat", "GetChatAdministrators", diff --git a/aiogram/api/methods/base.py b/aiogram/api/methods/base.py index dfdfda34..19632b37 100644 --- a/aiogram/api/methods/base.py +++ b/aiogram/api/methods/base.py @@ -126,7 +126,12 @@ def prepare_media_file(data: Dict[str, Any], files: Dict[str, InputFile]) -> Non data["media"]["media"] = f"attach://{tag}" -def prepare_parse_mode(bot: Bot, root: Any, parse_mode_property: str = "parse_mode") -> None: +def prepare_parse_mode( + bot: Bot, + root: Any, + parse_mode_property: str = "parse_mode", + entities_property: str = "entities", +) -> None: """ Find and set parse_mode with highest priority. @@ -137,9 +142,14 @@ def prepare_parse_mode(bot: Bot, root: Any, parse_mode_property: str = "parse_mo """ if isinstance(root, list): for item in root: - prepare_parse_mode(bot=bot, root=item, parse_mode_property=parse_mode_property) + prepare_parse_mode( + bot=bot, + root=item, + parse_mode_property=parse_mode_property, + entities_property=entities_property, + ) elif root.get(parse_mode_property, UNSET) is UNSET: - if bot.parse_mode: + if bot.parse_mode and not root.get(entities_property, None): root[parse_mode_property] = bot.parse_mode else: root[parse_mode_property] = None diff --git a/aiogram/api/methods/close.py b/aiogram/api/methods/close.py new file mode 100644 index 00000000..04999a22 --- /dev/null +++ b/aiogram/api/methods/close.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class Close(TelegramMethod[bool]): + """ + Use this method to close the bot instance before moving it from one local server to another. + You need to delete the webhook before calling this method to ensure that the bot isn't + launched again after server restart. The method will return error 429 in the first 10 minutes + after the bot is launched. Returns True on success. Requires no parameters. + + Source: https://core.telegram.org/bots/api#close + """ + + __returning__ = bool + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="close", data=data) diff --git a/aiogram/api/methods/copy_message.py b/aiogram/api/methods/copy_message.py new file mode 100644 index 00000000..0f3e0e91 --- /dev/null +++ b/aiogram/api/methods/copy_message.py @@ -0,0 +1,67 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union + +from ..types import ( + UNSET, + ForceReply, + InlineKeyboardMarkup, + MessageEntity, + MessageId, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod, prepare_parse_mode + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class CopyMessage(TelegramMethod[MessageId]): + """ + Use this method to copy messages of any kind. The method is analogous to the method + forwardMessages, but the copied message doesn't have a link to the original message. Returns + the MessageId of the sent message on success. + + Source: https://core.telegram.org/bots/api#copymessage + """ + + __returning__ = MessageId + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format + @channelusername)""" + from_chat_id: Union[int, str] + """Unique identifier for the chat where the original message was sent (or channel username in + the format @channelusername)""" + message_id: int + """Message identifier in the chat specified in from_chat_id""" + caption: Optional[str] = None + """New caption for media, 0-1024 characters after entities parsing. If not specified, the + original caption is kept""" + parse_mode: Optional[str] = UNSET + """Mode for parsing entities in the new caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the new caption, which can be specified instead of + parse_mode""" + disable_notification: Optional[bool] = None + """Sends the message silently. Users will receive a notification with no sound.""" + reply_to_message_id: Optional[int] = None + """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None + """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply + keyboard, instructions to remove reply keyboard or to force a reply from the user.""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + + return Request(method="copyMessage", data=data) diff --git a/aiogram/api/methods/delete_webhook.py b/aiogram/api/methods/delete_webhook.py index 9242a634..71b3f167 100644 --- a/aiogram/api/methods/delete_webhook.py +++ b/aiogram/api/methods/delete_webhook.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING, Any, Dict, Optional from .base import Request, TelegramMethod @@ -11,13 +11,16 @@ if TYPE_CHECKING: # pragma: no cover class DeleteWebhook(TelegramMethod[bool]): """ Use this method to remove webhook integration if you decide to switch back to getUpdates. - Returns True on success. Requires no parameters. + Returns True on success. Source: https://core.telegram.org/bots/api#deletewebhook """ __returning__ = bool + drop_pending_updates: Optional[bool] = None + """Pass True to drop all pending updates""" + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/api/methods/edit_message_caption.py b/aiogram/api/methods/edit_message_caption.py index 3359c45f..be8efc0f 100644 --- a/aiogram/api/methods/edit_message_caption.py +++ b/aiogram/api/methods/edit_message_caption.py @@ -1,8 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union -from ..types import UNSET, InlineKeyboardMarkup, Message +from ..types import UNSET, InlineKeyboardMarkup, Message, MessageEntity from .base import Request, TelegramMethod, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover @@ -11,8 +11,8 @@ if TYPE_CHECKING: # pragma: no cover class EditMessageCaption(TelegramMethod[Union[Message, bool]]): """ - Use this method to edit captions of messages. On success, if edited message is sent by the - bot, the edited Message is returned, otherwise True is returned. + Use this method to edit captions of messages. On success, if the edited message is not an + inline message, the edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagecaption """ @@ -30,11 +30,17 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]): """New caption of the message, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the message caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard.""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(bot, data) + + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) return Request(method="editMessageCaption", data=data) diff --git a/aiogram/api/methods/edit_message_live_location.py b/aiogram/api/methods/edit_message_live_location.py index ddd95d74..c5366d98 100644 --- a/aiogram/api/methods/edit_message_live_location.py +++ b/aiogram/api/methods/edit_message_live_location.py @@ -13,7 +13,7 @@ class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """ Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if - the edited message was sent by the bot, the edited Message is returned, otherwise True is + the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagelivelocation @@ -32,6 +32,13 @@ class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """Required if inline_message_id is not specified. Identifier of the message to edit""" inline_message_id: Optional[str] = None """Required if chat_id and message_id are not specified. Identifier of the inline message""" + horizontal_accuracy: Optional[float] = None + """The radius of uncertainty for the location, measured in meters; 0-1500""" + heading: Optional[int] = None + """Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.""" + proximity_alert_radius: Optional[int] = None + """Maximum distance for proximity alerts about approaching another chat member, in meters. + Must be between 1 and 100000 if specified.""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new inline keyboard.""" diff --git a/aiogram/api/methods/edit_message_media.py b/aiogram/api/methods/edit_message_media.py index db8e344f..1c9f9f9c 100644 --- a/aiogram/api/methods/edit_message_media.py +++ b/aiogram/api/methods/edit_message_media.py @@ -2,8 +2,8 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, InputFile, InputMedia, Message -from .base import Request, TelegramMethod, prepare_media_file, prepare_parse_mode +from ..types import InlineKeyboardMarkup, InputMedia, Message, InputFile +from .base import Request, TelegramMethod, prepare_parse_mode, prepare_media_file if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -12,11 +12,11 @@ if TYPE_CHECKING: # pragma: no cover class EditMessageMedia(TelegramMethod[Union[Message, bool]]): """ Use this method to edit animation, audio, document, photo, or video messages. If a message is - a part of a message album, then it can be edited only to a photo or a video. Otherwise, - message type can be changed arbitrarily. When inline message is edited, new file can't be - uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the - edited message was sent by the bot, the edited Message is returned, otherwise True is - returned. + part of a message album, then it can be edited only to an audio for audio albums, only to a + document for document albums and to a photo or a video otherwise. When an inline message is + edited, a new file can't be uploaded. Use a previously uploaded file via its file_id or + specify a URL. On success, if the edited message was sent by the bot, the edited Message is + returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagemedia """ diff --git a/aiogram/api/methods/edit_message_reply_markup.py b/aiogram/api/methods/edit_message_reply_markup.py index b9973e40..5887dbed 100644 --- a/aiogram/api/methods/edit_message_reply_markup.py +++ b/aiogram/api/methods/edit_message_reply_markup.py @@ -11,8 +11,8 @@ if TYPE_CHECKING: # pragma: no cover class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): """ - Use this method to edit only the reply markup of messages. On success, if edited message is - sent by the bot, the edited Message is returned, otherwise True is returned. + Use this method to edit only the reply markup of messages. On success, if the edited message + is not an inline message, the edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagereplymarkup """ diff --git a/aiogram/api/methods/edit_message_text.py b/aiogram/api/methods/edit_message_text.py index d30fc82e..a8f661d0 100644 --- a/aiogram/api/methods/edit_message_text.py +++ b/aiogram/api/methods/edit_message_text.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union -from ..types import UNSET, InlineKeyboardMarkup, Message -from .base import Request, TelegramMethod +from ..types import UNSET, InlineKeyboardMarkup, Message, MessageEntity +from .base import Request, TelegramMethod, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -11,8 +11,8 @@ if TYPE_CHECKING: # pragma: no cover class EditMessageText(TelegramMethod[Union[Message, bool]]): """ - Use this method to edit text and game messages. On success, if edited message is sent by the - bot, the edited Message is returned, otherwise True is returned. + Use this method to edit text and game messages. On success, if the edited message is not an + inline message, the edited Message is returned, otherwise True is returned. Source: https://core.telegram.org/bots/api#editmessagetext """ @@ -30,6 +30,9 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): """Required if chat_id and message_id are not specified. Identifier of the inline message""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the message text. See formatting options for more details.""" + entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in message text, which can be specified instead of + parse_mode""" disable_web_page_preview: Optional[bool] = None """Disables link previews for links in this message""" reply_markup: Optional[InlineKeyboardMarkup] = None @@ -38,4 +41,8 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="entities" + ) + return Request(method="editMessageText", data=data) diff --git a/aiogram/api/methods/log_out.py b/aiogram/api/methods/log_out.py new file mode 100644 index 00000000..bba9f7ea --- /dev/null +++ b/aiogram/api/methods/log_out.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class LogOut(TelegramMethod[bool]): + """ + Use this method to log out from the cloud Bot API server before launching the bot locally. You + must log out the bot before running it locally, otherwise there is no guarantee that the bot + will receive updates. After a successful call, you can immediately log in on a local server, + but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True + on success. Requires no parameters. + + Source: https://core.telegram.org/bots/api#logout + """ + + __returning__ = bool + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="logOut", data=data) diff --git a/aiogram/api/methods/pin_chat_message.py b/aiogram/api/methods/pin_chat_message.py index dbf0d013..e372178a 100644 --- a/aiogram/api/methods/pin_chat_message.py +++ b/aiogram/api/methods/pin_chat_message.py @@ -10,9 +10,10 @@ if TYPE_CHECKING: # pragma: no cover class PinChatMessage(TelegramMethod[bool]): """ - Use this method to pin a message in a group, a supergroup, or a channel. The bot must be an - administrator in the chat for this to work and must have the 'can_pin_messages' admin right in - the supergroup or 'can_edit_messages' admin right in the channel. Returns True on success. + Use this method to add a message to the list of pinned messages in a chat. If the chat is not + a private chat, the bot must be an administrator in the chat for this to work and must have + the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a + channel. Returns True on success. Source: https://core.telegram.org/bots/api#pinchatmessage """ @@ -26,7 +27,7 @@ class PinChatMessage(TelegramMethod[bool]): """Identifier of a message to pin""" disable_notification: Optional[bool] = None """Pass True, if it is not necessary to send a notification to all chat members about the new - pinned message. Notifications are always disabled in channels.""" + pinned message. Notifications are always disabled in channels and private chats.""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/api/methods/promote_chat_member.py b/aiogram/api/methods/promote_chat_member.py index 1b4ca625..23572897 100644 --- a/aiogram/api/methods/promote_chat_member.py +++ b/aiogram/api/methods/promote_chat_member.py @@ -24,6 +24,8 @@ class PromoteChatMember(TelegramMethod[bool]): @channelusername)""" user_id: int """Unique identifier of the target user""" + is_anonymous: Optional[bool] = None + """Pass True, if the administrator's presence in the chat is hidden""" can_change_info: Optional[bool] = None """Pass True, if the administrator can change chat title, photo and other settings""" can_post_messages: Optional[bool] = None diff --git a/aiogram/api/methods/restrict_chat_member.py b/aiogram/api/methods/restrict_chat_member.py index 9626e05a..8bad26c7 100644 --- a/aiogram/api/methods/restrict_chat_member.py +++ b/aiogram/api/methods/restrict_chat_member.py @@ -27,7 +27,7 @@ class RestrictChatMember(TelegramMethod[bool]): user_id: int """Unique identifier of the target user""" permissions: ChatPermissions - """New user permissions""" + """A JSON-serialized object for new user permissions""" until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None """Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be diff --git a/aiogram/api/methods/send_animation.py b/aiogram/api/methods/send_animation.py index dcb8e91c..deb36526 100644 --- a/aiogram/api/methods/send_animation.py +++ b/aiogram/api/methods/send_animation.py @@ -8,10 +8,11 @@ from ..types import ( InlineKeyboardMarkup, InputFile, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file +from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -54,10 +55,16 @@ class SendAnimation(TelegramMethod[Message]): parse_mode: Optional[str] = UNSET """Mode for parsing entities in the animation caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -67,6 +74,10 @@ class SendAnimation(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"animation", "thumb"}) + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + files: Dict[str, InputFile] = {} prepare_file(data=data, files=files, name="animation", value=self.animation) prepare_file(data=data, files=files, name="thumb", value=self.thumb) diff --git a/aiogram/api/methods/send_audio.py b/aiogram/api/methods/send_audio.py index 739fadcb..b09e7d92 100644 --- a/aiogram/api/methods/send_audio.py +++ b/aiogram/api/methods/send_audio.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( UNSET, @@ -8,10 +8,11 @@ from ..types import ( InlineKeyboardMarkup, InputFile, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file +from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -41,6 +42,9 @@ class SendAudio(TelegramMethod[Message]): """Audio caption, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the audio caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" duration: Optional[int] = None """Duration of the audio in seconds""" performer: Optional[str] = None @@ -58,6 +62,9 @@ class SendAudio(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -67,6 +74,10 @@ class SendAudio(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"audio", "thumb"}) + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + files: Dict[str, InputFile] = {} prepare_file(data=data, files=files, name="audio", value=self.audio) prepare_file(data=data, files=files, name="thumb", value=self.thumb) diff --git a/aiogram/api/methods/send_contact.py b/aiogram/api/methods/send_contact.py index 90c1fd7d..b92a4d05 100644 --- a/aiogram/api/methods/send_contact.py +++ b/aiogram/api/methods/send_contact.py @@ -39,6 +39,9 @@ class SendContact(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None diff --git a/aiogram/api/methods/send_dice.py b/aiogram/api/methods/send_dice.py index 1b69fed4..b648c134 100644 --- a/aiogram/api/methods/send_dice.py +++ b/aiogram/api/methods/send_dice.py @@ -29,12 +29,16 @@ class SendDice(TelegramMethod[Message]): """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" emoji: Optional[str] = None - """Emoji on which the dice throw animation is based. Currently, must be one of '', '', or ''. - Dice can have values 1-6 for '' and '', and values 1-5 for ''. Defaults to ''""" + """Emoji on which the dice throw animation is based. Currently, must be one of '', '', '', '', + or ''. Dice can have values 1-6 for '' and '', values 1-5 for '' and '', and values 1-64 + for ''. Defaults to ''""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None diff --git a/aiogram/api/methods/send_document.py b/aiogram/api/methods/send_document.py index 9ee44b54..2fc7dab7 100644 --- a/aiogram/api/methods/send_document.py +++ b/aiogram/api/methods/send_document.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( UNSET, @@ -8,10 +8,11 @@ from ..types import ( InlineKeyboardMarkup, InputFile, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file +from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -47,10 +48,19 @@ class SendDocument(TelegramMethod[Message]): after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the document caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" + disable_content_type_detection: Optional[bool] = None + """Disables automatic server-side content type detection for files uploaded using + multipart/form-data""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -60,6 +70,10 @@ class SendDocument(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"document", "thumb"}) + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + files: Dict[str, InputFile] = {} prepare_file(data=data, files=files, name="document", value=self.document) prepare_file(data=data, files=files, name="thumb", value=self.thumb) diff --git a/aiogram/api/methods/send_game.py b/aiogram/api/methods/send_game.py index 15257073..1f6fd05f 100644 --- a/aiogram/api/methods/send_game.py +++ b/aiogram/api/methods/send_game.py @@ -27,6 +27,9 @@ class SendGame(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game.""" diff --git a/aiogram/api/methods/send_invoice.py b/aiogram/api/methods/send_invoice.py index fa9f0615..6277fc82 100644 --- a/aiogram/api/methods/send_invoice.py +++ b/aiogram/api/methods/send_invoice.py @@ -38,7 +38,7 @@ class SendInvoice(TelegramMethod[Message]): """Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)""" provider_data: Optional[str] = None - """JSON-encoded data about the invoice, which will be shared with the payment provider. A + """A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.""" photo_url: Optional[str] = None """URL of the product photo for the invoice. Can be a photo of the goods or a marketing image @@ -67,6 +67,9 @@ class SendInvoice(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.""" diff --git a/aiogram/api/methods/send_location.py b/aiogram/api/methods/send_location.py index 76cdda91..d1225c69 100644 --- a/aiogram/api/methods/send_location.py +++ b/aiogram/api/methods/send_location.py @@ -31,13 +31,24 @@ class SendLocation(TelegramMethod[Message]): """Latitude of the location""" longitude: float """Longitude of the location""" + horizontal_accuracy: Optional[float] = None + """The radius of uncertainty for the location, measured in meters; 0-1500""" live_period: Optional[int] = None """Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.""" + heading: Optional[int] = None + """For live locations, a direction in which the user is moving, in degrees. Must be between 1 + and 360 if specified.""" + proximity_alert_radius: Optional[int] = None + """For live locations, a maximum distance for proximity alerts about approaching another chat + member, in meters. Must be between 1 and 100000 if specified.""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None diff --git a/aiogram/api/methods/send_media_group.py b/aiogram/api/methods/send_media_group.py index 70c804e1..6f60f7ed 100644 --- a/aiogram/api/methods/send_media_group.py +++ b/aiogram/api/methods/send_media_group.py @@ -2,8 +2,8 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union -from ..types import InputFile, InputMediaPhoto, InputMediaVideo, Message -from .base import Request, TelegramMethod, prepare_input_media, prepare_parse_mode +from ..types import InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo +from .base import Request, TelegramMethod if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -11,8 +11,9 @@ if TYPE_CHECKING: # pragma: no cover class SendMediaGroup(TelegramMethod[List[Message]]): """ - Use this method to send a group of photos or videos as an album. On success, an array of the - sent Messages is returned. + Use this method to send a group of photos, videos, documents or audios as an album. Documents + and audio files can be only grouped in an album with messages of the same type. On success, an + array of Messages that were sent is returned. Source: https://core.telegram.org/bots/api#sendmediagroup """ @@ -22,12 +23,15 @@ class SendMediaGroup(TelegramMethod[List[Message]]): chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" - media: List[Union[InputMediaPhoto, InputMediaVideo]] - """A JSON-serialized array describing photos and videos to be sent, must include 2-10 items""" + media: List[Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]] + """A JSON-serialized array describing messages to be sent, must include 2-10 items""" disable_notification: Optional[bool] = None - """Sends the messages silently. Users will receive a notification with no sound.""" + """Sends messages silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the messages are a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/api/methods/send_message.py b/aiogram/api/methods/send_message.py index 9dbeaa16..1e1720c3 100644 --- a/aiogram/api/methods/send_message.py +++ b/aiogram/api/methods/send_message.py @@ -1,12 +1,13 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( UNSET, ForceReply, InlineKeyboardMarkup, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) @@ -32,12 +33,18 @@ class SendMessage(TelegramMethod[Message]): """Text of the message to be sent, 1-4096 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the message text. See formatting options for more details.""" + entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in message text, which can be specified instead of + parse_mode""" disable_web_page_preview: Optional[bool] = None """Disables link previews for links in this message""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -46,6 +53,9 @@ class SendMessage(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(bot, data) + + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="entities" + ) return Request(method="sendMessage", data=data) diff --git a/aiogram/api/methods/send_photo.py b/aiogram/api/methods/send_photo.py index b35cc165..a3b0377f 100644 --- a/aiogram/api/methods/send_photo.py +++ b/aiogram/api/methods/send_photo.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( UNSET, @@ -8,10 +8,11 @@ from ..types import ( InlineKeyboardMarkup, InputFile, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file +from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -38,10 +39,16 @@ class SendPhoto(TelegramMethod[Message]): entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the photo caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -51,6 +58,10 @@ class SendPhoto(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"photo"}) + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + files: Dict[str, InputFile] = {} prepare_file(data=data, files=files, name="photo", value=self.photo) diff --git a/aiogram/api/methods/send_poll.py b/aiogram/api/methods/send_poll.py index 35fa45be..49bfe76e 100644 --- a/aiogram/api/methods/send_poll.py +++ b/aiogram/api/methods/send_poll.py @@ -8,6 +8,7 @@ from ..types import ( ForceReply, InlineKeyboardMarkup, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) @@ -30,7 +31,7 @@ class SendPoll(TelegramMethod[Message]): """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" question: str - """Poll question, 1-255 characters""" + """Poll question, 1-300 characters""" options: List[str] """A JSON-serialized list of answer options, 2-10 strings 1-100 characters each""" is_anonymous: Optional[bool] = None @@ -47,6 +48,9 @@ class SendPoll(TelegramMethod[Message]): quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing""" explanation_parse_mode: Optional[str] = UNSET """Mode for parsing entities in the explanation. See formatting options for more details.""" + explanation_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the poll explanation, which can be specified + instead of parse_mode""" open_period: Optional[int] = None """Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.""" @@ -59,6 +63,9 @@ class SendPoll(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -67,6 +74,12 @@ class SendPoll(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(bot, data, parse_mode_property="explanation_parse_mode") + + prepare_parse_mode( + bot, + data, + parse_mode_property="explanation_parse_mode", + entities_property="explanation_entities", + ) return Request(method="sendPoll", data=data) diff --git a/aiogram/api/methods/send_sticker.py b/aiogram/api/methods/send_sticker.py index a2adbffa..2d6c982a 100644 --- a/aiogram/api/methods/send_sticker.py +++ b/aiogram/api/methods/send_sticker.py @@ -37,6 +37,9 @@ class SendSticker(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None diff --git a/aiogram/api/methods/send_venue.py b/aiogram/api/methods/send_venue.py index e81455e4..ef902217 100644 --- a/aiogram/api/methods/send_venue.py +++ b/aiogram/api/methods/send_venue.py @@ -40,10 +40,17 @@ class SendVenue(TelegramMethod[Message]): foursquare_type: Optional[str] = None """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" + google_place_id: Optional[str] = None + """Google Places identifier of the venue""" + google_place_type: Optional[str] = None + """Google Places type of the venue. (See supported types.)""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None diff --git a/aiogram/api/methods/send_video.py b/aiogram/api/methods/send_video.py index c9c5acb2..bee4bc94 100644 --- a/aiogram/api/methods/send_video.py +++ b/aiogram/api/methods/send_video.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( UNSET, @@ -8,10 +8,11 @@ from ..types import ( InlineKeyboardMarkup, InputFile, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file +from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -53,12 +54,18 @@ class SendVideo(TelegramMethod[Message]): entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the video caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" supports_streaming: Optional[bool] = None """Pass True, if the uploaded video is suitable for streaming""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -68,6 +75,10 @@ class SendVideo(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"video", "thumb"}) + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + files: Dict[str, InputFile] = {} prepare_file(data=data, files=files, name="video", value=self.video) prepare_file(data=data, files=files, name="thumb", value=self.thumb) diff --git a/aiogram/api/methods/send_video_note.py b/aiogram/api/methods/send_video_note.py index f3b75574..6d7eb177 100644 --- a/aiogram/api/methods/send_video_note.py +++ b/aiogram/api/methods/send_video_note.py @@ -48,6 +48,9 @@ class SendVideoNote(TelegramMethod[Message]): """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None diff --git a/aiogram/api/methods/send_voice.py b/aiogram/api/methods/send_voice.py index 2a464439..f146e7e2 100644 --- a/aiogram/api/methods/send_voice.py +++ b/aiogram/api/methods/send_voice.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( UNSET, @@ -8,10 +8,11 @@ from ..types import ( InlineKeyboardMarkup, InputFile, Message, + MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file +from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -42,12 +43,18 @@ class SendVoice(TelegramMethod[Message]): parse_mode: Optional[str] = UNSET """Mode for parsing entities in the voice message caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" duration: Optional[int] = None """Duration of the voice message in seconds""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" + allow_sending_without_reply: Optional[bool] = None + """Pass True, if the message should be sent even if the specified replied-to message is not + found""" reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None @@ -57,6 +64,10 @@ class SendVoice(TelegramMethod[Message]): def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"voice"}) + prepare_parse_mode( + bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" + ) + files: Dict[str, InputFile] = {} prepare_file(data=data, files=files, name="voice", value=self.voice) diff --git a/aiogram/api/methods/set_webhook.py b/aiogram/api/methods/set_webhook.py index 49c7617d..e3d3a240 100644 --- a/aiogram/api/methods/set_webhook.py +++ b/aiogram/api/methods/set_webhook.py @@ -37,6 +37,9 @@ class SetWebhook(TelegramMethod[bool]): certificate: Optional[InputFile] = None """Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details.""" + ip_address: Optional[str] = None + """The fixed IP address which will be used to send webhook requests instead of the IP address + resolved through DNS""" max_connections: Optional[int] = None """Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, @@ -47,6 +50,8 @@ class SetWebhook(TelegramMethod[bool]): these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.""" + drop_pending_updates: Optional[bool] = None + """Pass True to drop all pending updates""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"certificate"}) diff --git a/aiogram/api/methods/unban_chat_member.py b/aiogram/api/methods/unban_chat_member.py index 56a30bd6..f50e430c 100644 --- a/aiogram/api/methods/unban_chat_member.py +++ b/aiogram/api/methods/unban_chat_member.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from .base import Request, TelegramMethod @@ -12,7 +12,10 @@ class UnbanChatMember(TelegramMethod[bool]): """ Use this method to unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The - bot must be an administrator for this to work. Returns True on success. + bot must be an administrator for this to work. By default, this method guarantees that after + the call the user is not a member of the chat, but will be able to join it. So if the user is + a member of the chat they will also be removed from the chat. If you don't want this, use the + parameter only_if_banned. Returns True on success. Source: https://core.telegram.org/bots/api#unbanchatmember """ @@ -24,6 +27,8 @@ class UnbanChatMember(TelegramMethod[bool]): the format @username)""" user_id: int """Unique identifier of the target user""" + only_if_banned: Optional[bool] = None + """Do nothing if the user is not banned""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/api/methods/unpin_all_chat_messages.py b/aiogram/api/methods/unpin_all_chat_messages.py new file mode 100644 index 00000000..c26d6874 --- /dev/null +++ b/aiogram/api/methods/unpin_all_chat_messages.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class UnpinAllChatMessages(TelegramMethod[bool]): + """ + Use this method to clear the list of pinned messages in a chat. If the chat is not a private + chat, the bot must be an administrator in the chat for this to work and must have the + 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a + channel. Returns True on success. + + Source: https://core.telegram.org/bots/api#unpinallchatmessages + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format + @channelusername)""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="unpinAllChatMessages", data=data) diff --git a/aiogram/api/methods/unpin_chat_message.py b/aiogram/api/methods/unpin_chat_message.py index 419a7edd..86eaf325 100644 --- a/aiogram/api/methods/unpin_chat_message.py +++ b/aiogram/api/methods/unpin_chat_message.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from .base import Request, TelegramMethod @@ -10,9 +10,10 @@ if TYPE_CHECKING: # pragma: no cover class UnpinChatMessage(TelegramMethod[bool]): """ - Use this method to unpin a message in a group, a supergroup, or a channel. The bot must be an - administrator in the chat for this to work and must have the 'can_pin_messages' admin right in - the supergroup or 'can_edit_messages' admin right in the channel. Returns True on success. + Use this method to remove a message from the list of pinned messages in a chat. If the chat is + not a private chat, the bot must be an administrator in the chat for this to work and must + have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in + a channel. Returns True on success. Source: https://core.telegram.org/bots/api#unpinchatmessage """ @@ -22,6 +23,9 @@ class UnpinChatMessage(TelegramMethod[bool]): chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + message_id: Optional[int] = None + """Identifier of a message to unpin. If not specified, the most recent pinned message (by + sending date) will be unpinned.""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/api/types/__init__.py b/aiogram/api/types/__init__.py index 3dbb0439..3a6141d9 100644 --- a/aiogram/api/types/__init__.py +++ b/aiogram/api/types/__init__.py @@ -5,12 +5,13 @@ from .bot_command import BotCommand from .callback_game import CallbackGame from .callback_query import CallbackQuery from .chat import Chat +from .chat_location import ChatLocation from .chat_member import ChatMember from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .chosen_inline_result import ChosenInlineResult from .contact import Contact -from .dice import Dice, DiceEmoji +from .dice import Dice from .document import Document from .downloadable import Downloadable from .encrypted_credentials import EncryptedCredentials @@ -64,6 +65,7 @@ from .login_url import LoginUrl from .mask_position import MaskPosition from .message import ContentType, Message from .message_entity import MessageEntity +from .message_id import MessageId from .order_info import OrderInfo from .passport_data import PassportData from .passport_element_error import PassportElementError @@ -82,6 +84,7 @@ from .poll import Poll from .poll_answer import PollAnswer from .poll_option import PollOption from .pre_checkout_query import PreCheckoutQuery +from .proximity_alert_triggered import ProximityAlertTriggered from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove from .response_parameters import ResponseParameters @@ -113,22 +116,23 @@ __all__ = ( "Chat", "Message", "ContentType", + "MessageId", "MessageEntity", "PhotoSize", + "Animation", "Audio", "Document", "Video", - "Animation", - "Voice", "VideoNote", + "Voice", "Contact", - "Location", - "Venue", + "Dice", "PollOption", "PollAnswer", "Poll", - "Dice", - "DiceEmoji", + "Location", + "Venue", + "ProximityAlertTriggered", "UserProfilePhotos", "File", "ReplyKeyboardMarkup", @@ -143,6 +147,7 @@ __all__ = ( "ChatPhoto", "ChatMember", "ChatPermissions", + "ChatLocation", "BotCommand", "ResponseParameters", "InputMedia", diff --git a/aiogram/api/types/audio.py b/aiogram/api/types/audio.py index 4b496d06..e1ecd36f 100644 --- a/aiogram/api/types/audio.py +++ b/aiogram/api/types/audio.py @@ -26,6 +26,8 @@ class Audio(TelegramObject): """Performer of the audio as defined by sender or by audio tags""" title: Optional[str] = None """Title of the audio as defined by sender or by audio tags""" + file_name: Optional[str] = None + """Original filename as defined by sender""" mime_type: Optional[str] = None """MIME type of the file as defined by sender""" file_size: Optional[int] = None diff --git a/aiogram/api/types/chat.py b/aiogram/api/types/chat.py index 2e3163b2..c2125a02 100644 --- a/aiogram/api/types/chat.py +++ b/aiogram/api/types/chat.py @@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, Optional from .base import TelegramObject if TYPE_CHECKING: # pragma: no cover + from .chat_location import ChatLocation from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .message import Message @@ -34,6 +35,8 @@ class Chat(TelegramObject): """Last name of the other party in a private chat""" photo: Optional[ChatPhoto] = None """Chat photo. Returned only in getChat.""" + bio: Optional[str] = None + """Bio of the other party in a private chat. Returned only in getChat.""" description: Optional[str] = None """Description, for groups, supergroups and channel chats. Returned only in getChat.""" invite_link: Optional[str] = None @@ -41,7 +44,7 @@ class Chat(TelegramObject): generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat.""" pinned_message: Optional[Message] = None - """Pinned message, for groups, supergroups and channels. Returned only in getChat.""" + """The most recent pinned message (by sending date). Returned only in getChat.""" permissions: Optional[ChatPermissions] = None """Default chat member permissions, for groups and supergroups. Returned only in getChat.""" slow_mode_delay: Optional[int] = None @@ -51,3 +54,12 @@ class Chat(TelegramObject): """For supergroups, name of group sticker set. Returned only in getChat.""" can_set_sticker_set: Optional[bool] = None """True, if the bot can change the group sticker set. Returned only in getChat.""" + linked_chat_id: Optional[int] = None + """Unique identifier for the linked chat, i.e. the discussion group identifier for a channel + and vice versa; for supergroups and channel chats. This identifier may be greater than 32 + bits and some programming languages may have difficulty/silent defects in interpreting it. + But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type + are safe for storing this identifier. Returned only in getChat.""" + location: Optional[ChatLocation] = None + """For supergroups, the location to which the supergroup is connected. Returned only in + getChat.""" diff --git a/aiogram/api/types/chat_location.py b/aiogram/api/types/chat_location.py new file mode 100644 index 00000000..77c5a45b --- /dev/null +++ b/aiogram/api/types/chat_location.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from .base import TelegramObject + +if TYPE_CHECKING: # pragma: no cover + from .location import Location + + +class ChatLocation(TelegramObject): + """ + Represents a location to which a chat is connected. + + Source: https://core.telegram.org/bots/api#chatlocation + """ + + location: Location + """The location to which the supergroup is connected. Can't be a live location.""" + address: str + """Location address; 1-64 characters, as defined by the chat owner""" diff --git a/aiogram/api/types/chat_member.py b/aiogram/api/types/chat_member.py index dca3029e..35f0a542 100644 --- a/aiogram/api/types/chat_member.py +++ b/aiogram/api/types/chat_member.py @@ -24,8 +24,8 @@ class ChatMember(TelegramObject): 'left' or 'kicked'""" custom_title: Optional[str] = None """Owner and administrators only. Custom title for this user""" - until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None - """Restricted and kicked only. Date when restrictions will be lifted for this user; unix time""" + is_anonymous: Optional[bool] = None + """Owner and administrators only. True, if the user's presence in the chat is hidden""" can_be_edited: Optional[bool] = None """Administrators only. True, if the bot is allowed to edit administrator privileges of that user""" @@ -66,6 +66,8 @@ class ChatMember(TelegramObject): inline bots""" can_add_web_page_previews: Optional[bool] = None """Restricted only. True, if the user is allowed to add web page previews to their messages""" + until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None + """Restricted and kicked only. Date when restrictions will be lifted for this user; unix time""" @property def is_chat_admin(self) -> bool: diff --git a/aiogram/api/types/dice.py b/aiogram/api/types/dice.py index d9b1da10..54a36afd 100644 --- a/aiogram/api/types/dice.py +++ b/aiogram/api/types/dice.py @@ -13,7 +13,8 @@ class Dice(TelegramObject): emoji: str """Emoji on which the dice throw animation is based""" value: int - """Value of the dice, 1-6 for '' and '' base emoji, 1-5 for '' base emoji""" + """Value of the dice, 1-6 for '' and '' base emoji, 1-5 for '' and '' base emoji, 1-64 for '' + base emoji""" class DiceEmoji: diff --git a/aiogram/api/types/inline_query_result_audio.py b/aiogram/api/types/inline_query_result_audio.py index b236f26d..f959b7e6 100644 --- a/aiogram/api/types/inline_query_result_audio.py +++ b/aiogram/api/types/inline_query_result_audio.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultAudio(InlineQueryResult): @@ -35,6 +36,9 @@ class InlineQueryResultAudio(InlineQueryResult): """Caption, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the audio caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" performer: Optional[str] = None """Performer""" audio_duration: Optional[int] = None diff --git a/aiogram/api/types/inline_query_result_cached_audio.py b/aiogram/api/types/inline_query_result_cached_audio.py index b26edfed..ff666f26 100644 --- a/aiogram/api/types/inline_query_result_cached_audio.py +++ b/aiogram/api/types/inline_query_result_cached_audio.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedAudio(InlineQueryResult): @@ -33,6 +34,9 @@ class InlineQueryResultCachedAudio(InlineQueryResult): """Caption, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the audio caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_document.py b/aiogram/api/types/inline_query_result_cached_document.py index 74fa2ecf..145527f3 100644 --- a/aiogram/api/types/inline_query_result_cached_document.py +++ b/aiogram/api/types/inline_query_result_cached_document.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedDocument(InlineQueryResult): @@ -37,6 +38,9 @@ class InlineQueryResultCachedDocument(InlineQueryResult): """Caption of the document to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the document caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_gif.py b/aiogram/api/types/inline_query_result_cached_gif.py index cb66af96..80c5c916 100644 --- a/aiogram/api/types/inline_query_result_cached_gif.py +++ b/aiogram/api/types/inline_query_result_cached_gif.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedGif(InlineQueryResult): @@ -33,6 +34,9 @@ class InlineQueryResultCachedGif(InlineQueryResult): """Caption of the GIF file to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py b/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py index a43de25f..d459cd8e 100644 --- a/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py +++ b/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): @@ -34,6 +35,9 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): """Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_photo.py b/aiogram/api/types/inline_query_result_cached_photo.py index b3a9f8a1..779415a3 100644 --- a/aiogram/api/types/inline_query_result_cached_photo.py +++ b/aiogram/api/types/inline_query_result_cached_photo.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedPhoto(InlineQueryResult): @@ -35,6 +36,9 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): """Caption of the photo to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the photo caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_video.py b/aiogram/api/types/inline_query_result_cached_video.py index ef561bb4..c75a288f 100644 --- a/aiogram/api/types/inline_query_result_cached_video.py +++ b/aiogram/api/types/inline_query_result_cached_video.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedVideo(InlineQueryResult): @@ -35,6 +36,9 @@ class InlineQueryResultCachedVideo(InlineQueryResult): """Caption of the video to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the video caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_voice.py b/aiogram/api/types/inline_query_result_cached_voice.py index aec92d44..98c7825c 100644 --- a/aiogram/api/types/inline_query_result_cached_voice.py +++ b/aiogram/api/types/inline_query_result_cached_voice.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultCachedVoice(InlineQueryResult): @@ -36,6 +37,9 @@ class InlineQueryResultCachedVoice(InlineQueryResult): parse_mode: Optional[str] = UNSET """Mode for parsing entities in the voice message caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_document.py b/aiogram/api/types/inline_query_result_document.py index 01e389ff..1a9e964d 100644 --- a/aiogram/api/types/inline_query_result_document.py +++ b/aiogram/api/types/inline_query_result_document.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultDocument(InlineQueryResult): @@ -38,6 +39,9 @@ class InlineQueryResultDocument(InlineQueryResult): """Caption of the document to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the document caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" description: Optional[str] = None """Short description of the result""" reply_markup: Optional[InlineKeyboardMarkup] = None diff --git a/aiogram/api/types/inline_query_result_gif.py b/aiogram/api/types/inline_query_result_gif.py index 8812c43a..e449b00f 100644 --- a/aiogram/api/types/inline_query_result_gif.py +++ b/aiogram/api/types/inline_query_result_gif.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultGif(InlineQueryResult): @@ -44,6 +45,9 @@ class InlineQueryResultGif(InlineQueryResult): """Caption of the GIF file to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_location.py b/aiogram/api/types/inline_query_result_location.py index 22498ebb..404ecb6b 100644 --- a/aiogram/api/types/inline_query_result_location.py +++ b/aiogram/api/types/inline_query_result_location.py @@ -32,8 +32,16 @@ class InlineQueryResultLocation(InlineQueryResult): """Location longitude in degrees""" title: str """Location title""" + horizontal_accuracy: Optional[float] = None + """The radius of uncertainty for the location, measured in meters; 0-1500""" live_period: Optional[int] = None """Period in seconds for which the location can be updated, should be between 60 and 86400.""" + heading: Optional[int] = None + """For live locations, a direction in which the user is moving, in degrees. Must be between 1 + and 360 if specified.""" + proximity_alert_radius: Optional[int] = None + """For live locations, a maximum distance for proximity alerts about approaching another chat + member, in meters. Must be between 1 and 100000 if specified.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_mpeg4_gif.py b/aiogram/api/types/inline_query_result_mpeg4_gif.py index 76f97e0a..d50d413e 100644 --- a/aiogram/api/types/inline_query_result_mpeg4_gif.py +++ b/aiogram/api/types/inline_query_result_mpeg4_gif.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultMpeg4Gif(InlineQueryResult): @@ -45,6 +46,9 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): """Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_photo.py b/aiogram/api/types/inline_query_result_photo.py index 31cddee2..aadbded6 100644 --- a/aiogram/api/types/inline_query_result_photo.py +++ b/aiogram/api/types/inline_query_result_photo.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultPhoto(InlineQueryResult): @@ -41,6 +42,9 @@ class InlineQueryResultPhoto(InlineQueryResult): """Caption of the photo to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the photo caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_venue.py b/aiogram/api/types/inline_query_result_venue.py index 902db9a2..05aa9919 100644 --- a/aiogram/api/types/inline_query_result_venue.py +++ b/aiogram/api/types/inline_query_result_venue.py @@ -38,6 +38,10 @@ class InlineQueryResultVenue(InlineQueryResult): foursquare_type: Optional[str] = None """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" + google_place_id: Optional[str] = None + """Google Places identifier of the venue""" + google_place_type: Optional[str] = None + """Google Places type of the venue. (See supported types.)""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_video.py b/aiogram/api/types/inline_query_result_video.py index 3002b8be..68239fd0 100644 --- a/aiogram/api/types/inline_query_result_video.py +++ b/aiogram/api/types/inline_query_result_video.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultVideo(InlineQueryResult): diff --git a/aiogram/api/types/inline_query_result_voice.py b/aiogram/api/types/inline_query_result_voice.py index 724d46bc..e51484cb 100644 --- a/aiogram/api/types/inline_query_result_voice.py +++ b/aiogram/api/types/inline_query_result_voice.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from pydantic import Field @@ -10,6 +10,7 @@ from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_markup import InlineKeyboardMarkup from .input_message_content import InputMessageContent + from .message_entity import MessageEntity class InlineQueryResultVoice(InlineQueryResult): @@ -37,6 +38,9 @@ class InlineQueryResultVoice(InlineQueryResult): parse_mode: Optional[str] = UNSET """Mode for parsing entities in the voice message caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" voice_duration: Optional[int] = None """Recording duration in seconds""" reply_markup: Optional[InlineKeyboardMarkup] = None diff --git a/aiogram/api/types/input_location_message_content.py b/aiogram/api/types/input_location_message_content.py index c1ee650f..8f3224e6 100644 --- a/aiogram/api/types/input_location_message_content.py +++ b/aiogram/api/types/input_location_message_content.py @@ -16,5 +16,13 @@ class InputLocationMessageContent(InputMessageContent): """Latitude of the location in degrees""" longitude: float """Longitude of the location in degrees""" + horizontal_accuracy: Optional[float] = None + """The radius of uncertainty for the location, measured in meters; 0-1500""" live_period: Optional[int] = None """Period in seconds for which the location can be updated, should be between 60 and 86400.""" + heading: Optional[int] = None + """For live locations, a direction in which the user is moving, in degrees. Must be between 1 + and 360 if specified.""" + proximity_alert_radius: Optional[int] = None + """For live locations, a maximum distance for proximity alerts about approaching another chat + member, in meters. Must be between 1 and 100000 if specified.""" diff --git a/aiogram/api/types/input_media_animation.py b/aiogram/api/types/input_media_animation.py index d30084a2..73685672 100644 --- a/aiogram/api/types/input_media_animation.py +++ b/aiogram/api/types/input_media_animation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field @@ -9,6 +9,7 @@ from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover from .input_file import InputFile + from .message_entity import MessageEntity class InputMediaAnimation(InputMedia): @@ -37,6 +38,9 @@ class InputMediaAnimation(InputMedia): parse_mode: Optional[str] = UNSET """Mode for parsing entities in the animation caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" width: Optional[int] = None """Animation width""" height: Optional[int] = None diff --git a/aiogram/api/types/input_media_audio.py b/aiogram/api/types/input_media_audio.py index 098087d1..7418954c 100644 --- a/aiogram/api/types/input_media_audio.py +++ b/aiogram/api/types/input_media_audio.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field @@ -9,6 +9,7 @@ from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover from .input_file import InputFile + from .message_entity import MessageEntity class InputMediaAudio(InputMedia): @@ -36,6 +37,9 @@ class InputMediaAudio(InputMedia): """Caption of the audio to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the audio caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" duration: Optional[int] = None """Duration of the audio in seconds""" performer: Optional[str] = None diff --git a/aiogram/api/types/input_media_document.py b/aiogram/api/types/input_media_document.py index e29a5014..a75a657a 100644 --- a/aiogram/api/types/input_media_document.py +++ b/aiogram/api/types/input_media_document.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field @@ -9,6 +9,7 @@ from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover from .input_file import InputFile + from .message_entity import MessageEntity class InputMediaDocument(InputMedia): @@ -36,3 +37,9 @@ class InputMediaDocument(InputMedia): """Caption of the document to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the document caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" + disable_content_type_detection: Optional[bool] = None + """Disables automatic server-side content type detection for files uploaded using + multipart/form-data. Always true, if the document is sent as part of an album.""" diff --git a/aiogram/api/types/input_media_photo.py b/aiogram/api/types/input_media_photo.py index 6ef61006..7e53754b 100644 --- a/aiogram/api/types/input_media_photo.py +++ b/aiogram/api/types/input_media_photo.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field @@ -9,6 +9,7 @@ from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover from .input_file import InputFile + from .message_entity import MessageEntity class InputMediaPhoto(InputMedia): @@ -29,3 +30,6 @@ class InputMediaPhoto(InputMedia): """Caption of the photo to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the photo caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" diff --git a/aiogram/api/types/input_media_video.py b/aiogram/api/types/input_media_video.py index d8dc0adf..a0868954 100644 --- a/aiogram/api/types/input_media_video.py +++ b/aiogram/api/types/input_media_video.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field @@ -9,6 +9,7 @@ from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover from .input_file import InputFile + from .message_entity import MessageEntity class InputMediaVideo(InputMedia): @@ -36,6 +37,9 @@ class InputMediaVideo(InputMedia): """Caption of the video to be sent, 0-1024 characters after entities parsing""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the video caption. See formatting options for more details.""" + caption_entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in the caption, which can be specified instead of + parse_mode""" width: Optional[int] = None """Video width""" height: Optional[int] = None diff --git a/aiogram/api/types/input_message_content.py b/aiogram/api/types/input_message_content.py index fd002b02..38da01f8 100644 --- a/aiogram/api/types/input_message_content.py +++ b/aiogram/api/types/input_message_content.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .base import MutableTelegramObject +from .base import TelegramObject -class InputMessageContent(MutableTelegramObject): +class InputMessageContent(TelegramObject): """ This object represents the content of a message to be sent as a result of an inline query. Telegram clients currently support the following 4 types: diff --git a/aiogram/api/types/input_text_message_content.py b/aiogram/api/types/input_text_message_content.py index 389cb48e..07a47b61 100644 --- a/aiogram/api/types/input_text_message_content.py +++ b/aiogram/api/types/input_text_message_content.py @@ -1,10 +1,13 @@ from __future__ import annotations -from typing import Optional +from typing import TYPE_CHECKING, List, Optional from .base import UNSET from .input_message_content import InputMessageContent +if TYPE_CHECKING: # pragma: no cover + from .message_entity import MessageEntity + class InputTextMessageContent(InputMessageContent): """ @@ -17,5 +20,8 @@ class InputTextMessageContent(InputMessageContent): """Text of the message to be sent, 1-4096 characters""" parse_mode: Optional[str] = UNSET """Mode for parsing entities in the message text. See formatting options for more details.""" + entities: Optional[List[MessageEntity]] = None + """List of special entities that appear in message text, which can be specified instead of + parse_mode""" disable_web_page_preview: Optional[bool] = None """Disables link previews for links in the sent message""" diff --git a/aiogram/api/types/input_venue_message_content.py b/aiogram/api/types/input_venue_message_content.py index 2e8c1796..354f4f85 100644 --- a/aiogram/api/types/input_venue_message_content.py +++ b/aiogram/api/types/input_venue_message_content.py @@ -25,3 +25,7 @@ class InputVenueMessageContent(InputMessageContent): foursquare_type: Optional[str] = None """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" + google_place_id: Optional[str] = None + """Google Places identifier of the venue""" + google_place_type: Optional[str] = None + """Google Places type of the venue. (See supported types.)""" diff --git a/aiogram/api/types/location.py b/aiogram/api/types/location.py index 99c7ffc4..4d8a4fab 100644 --- a/aiogram/api/types/location.py +++ b/aiogram/api/types/location.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import Optional + from .base import TelegramObject @@ -14,3 +16,13 @@ class Location(TelegramObject): """Longitude as defined by sender""" latitude: float """Latitude as defined by sender""" + horizontal_accuracy: Optional[float] = None + """The radius of uncertainty for the location, measured in meters; 0-1500""" + live_period: Optional[int] = None + """Time relative to the message sending date, during which the location can be updated, in + seconds. For active live locations only.""" + heading: Optional[int] = None + """The direction in which user is moving, in degrees; 1-360. For active live locations only.""" + proximity_alert_radius: Optional[int] = None + """Maximum distance for proximity alerts about approaching another chat member, in meters. For + sent live locations only.""" diff --git a/aiogram/api/types/message.py b/aiogram/api/types/message.py index 67470b66..590b3a04 100644 --- a/aiogram/api/types/message.py +++ b/aiogram/api/types/message.py @@ -30,6 +30,7 @@ if TYPE_CHECKING: # pragma: no cover from .poll import Poll from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove + from .proximity_alert_triggered import ProximityAlertTriggered from .sticker import Sticker from .successful_payment import SuccessfulPayment from .user import User @@ -74,10 +75,15 @@ class Message(TelegramObject): """Conversation the message belongs to""" from_user: Optional[User] = Field(None, alias="from") """Sender, empty for messages sent to channels""" + sender_chat: Optional[Chat] = None + """Sender of the message, sent on behalf of a chat. The channel itself for channel messages. + The supergroup itself for messages from anonymous group administrators. The linked channel + for messages automatically forwarded to the discussion group""" forward_from: Optional[User] = None """For forwarded messages, sender of the original message""" forward_from_chat: Optional[Chat] = None - """For messages forwarded from channels, information about the original channel""" + """For messages forwarded from channels or from anonymous administrators, information about + the original sender chat""" forward_from_message_id: Optional[int] = None """For messages forwarded from channels, identifier of the original message in the channel""" forward_signature: Optional[str] = None @@ -97,7 +103,8 @@ class Message(TelegramObject): media_group_id: Optional[str] = None """The unique identifier of a media message group this message belongs to""" author_signature: Optional[str] = None - """Signature of the post author for messages in channels""" + """Signature of the post author for messages in channels, or the custom title of an anonymous + group administrator""" text: Optional[str] = None """For text messages, the actual UTF-8 text of the message, 0-4096 characters""" entities: Optional[List[MessageEntity]] = None @@ -183,6 +190,9 @@ class Message(TelegramObject): """The domain name of the website on which the user has logged in.""" passport_data: Optional[PassportData] = None """Telegram Passport data""" + proximity_alert_triggered: Optional[ProximityAlertTriggered] = None + """Service message. A user in the chat triggered another user's proximity alert while sharing + Live Location.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons.""" diff --git a/aiogram/api/types/message_id.py b/aiogram/api/types/message_id.py new file mode 100644 index 00000000..edd4784c --- /dev/null +++ b/aiogram/api/types/message_id.py @@ -0,0 +1,14 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class MessageId(TelegramObject): + """ + This object represents a unique message identifier. + + Source: https://core.telegram.org/bots/api#messageid + """ + + message_id: int + """Unique message identifier""" diff --git a/aiogram/api/types/proximity_alert_triggered.py b/aiogram/api/types/proximity_alert_triggered.py new file mode 100644 index 00000000..7ff1ae9d --- /dev/null +++ b/aiogram/api/types/proximity_alert_triggered.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from .base import TelegramObject + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ProximityAlertTriggered(TelegramObject): + """ + This object represents the content of a service message, sent whenever a user in the chat + triggers a proximity alert set by another user. + + Source: https://core.telegram.org/bots/api#proximityalerttriggered + """ + + traveler: User + """User that triggered the alert""" + watcher: User + """User that set the alert""" + distance: int + """The distance between the users""" diff --git a/aiogram/api/types/venue.py b/aiogram/api/types/venue.py index 4e8769ab..08ff1c34 100644 --- a/aiogram/api/types/venue.py +++ b/aiogram/api/types/venue.py @@ -16,7 +16,7 @@ class Venue(TelegramObject): """ location: Location - """Venue location""" + """Venue location. Can't be a live location""" title: str """Name of the venue""" address: str @@ -26,3 +26,7 @@ class Venue(TelegramObject): foursquare_type: Optional[str] = None """Foursquare type of the venue. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" + google_place_id: Optional[str] = None + """Google Places identifier of the venue""" + google_place_type: Optional[str] = None + """Google Places type of the venue. (See supported types.)""" diff --git a/aiogram/api/types/video.py b/aiogram/api/types/video.py index 647333b5..5c731ab1 100644 --- a/aiogram/api/types/video.py +++ b/aiogram/api/types/video.py @@ -28,6 +28,8 @@ class Video(TelegramObject): """Duration of the video in seconds as defined by sender""" thumb: Optional[PhotoSize] = None """Video thumbnail""" + file_name: Optional[str] = None + """Original filename as defined by sender""" mime_type: Optional[str] = None """Mime type of a file as defined by sender""" file_size: Optional[int] = None diff --git a/aiogram/api/types/webhook_info.py b/aiogram/api/types/webhook_info.py index febcb465..a1ee8847 100644 --- a/aiogram/api/types/webhook_info.py +++ b/aiogram/api/types/webhook_info.py @@ -18,6 +18,8 @@ class WebhookInfo(TelegramObject): """True, if a custom certificate was provided for webhook certificate checks""" pending_update_count: int """Number of updates awaiting delivery""" + ip_address: Optional[str] = None + """Currently used webhook IP address""" last_error_date: Optional[int] = None """Unix time for the most recent error that happened when trying to deliver an update via webhook""" diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 699f746d..bee4af18 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -255,7 +255,7 @@ class Dispatcher(Router): await asyncio.gather(*coro_list) finally: for bot in bots: # Close sessions - await bot.close() + await bot.session.close() loggers.dispatcher.info("Polling stopped") await self.emit_shutdown(**workflow_data)