diff --git a/aiogram/dispatcher/webhook.py b/aiogram/dispatcher/webhook.py index dd6b3ffe..21f32954 100644 --- a/aiogram/dispatcher/webhook.py +++ b/aiogram/dispatcher/webhook.py @@ -529,7 +529,7 @@ class SendVideoNote(BaseResponse): """ :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username of the target channel (in the format @channelusername) - :param video_note: Union[io.BytesIO, io.FileIO, String] - Video note to send. Pass a file_id + :param video_note: String - 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 :param duration: Integer (Optional) - Duration of sent video in seconds @@ -1094,19 +1094,608 @@ class AnswerCallbackQuery(BaseResponse): } -class Empty(BaseResponse): +class EditMessageText(BaseResponse): """ """ - __slots__ = () + __slots__ = ('chat_id', 'message_id', 'inline_message_id', 'text', 'parse_mode', + 'disable_web_page_preview', 'reply_markup') + + method = api.Methods.EDIT_MESSAGE_TEXT + + def __init__(self, text: String, + chat_id: Optional[Union[Integer, String]] = None, + message_id: Optional[Integer] = None, + inline_message_id: Optional[String] = None, + parse_mode: Optional[String] = None, + disable_web_page_preview: Optional[Boolean] = None, + reply_markup: Optional[types.InlineKeyboardMarkup] = None): + """ + :param chat_id: Union[Integer, String] (Optional) - Required if inline_message_id + is not specified. Unique identifier for the target chat or username of the target channel + (in the format @channelusername) + :param message_id: Integer (Optional) - Required if inline_message_id is not specified. + Identifier of the sent message + :param inline_message_id: String (Optional) - Required if chat_id and message_id are not specified. + Identifier of the inline message + :param text: String - New text of the message + :param parse_mode: String (Optional) - Send Markdown or HTML, if you want Telegram apps to show bold, + italic, fixed-width text or inline URLs in your bot's message. + :param disable_web_page_preview: Boolean (Optional) - Disables link previews for links in this message + :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for + an inline keyboard. + """ + self.chat_id = chat_id + self.message_id = message_id + self.inline_message_id = inline_message_id + self.text = text + self.parse_mode = parse_mode + self.disable_web_page_preview = disable_web_page_preview + self.reply_markup = reply_markup + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'message_id': self.message_id, + 'inline_message_id': self.inline_message_id, + 'text': self.text, + 'parse_mode': self.parse_mode, + 'disable_web_page_preview': self.disable_web_page_preview, + 'reply_markup': prepare_arg(self.reply_markup) + } + + +class EditMessageCaption(BaseResponse): + """ + + """ + __slots__ = ('chat_id', 'message_id', 'inline_message_id', 'caption', 'reply_markup') + + method = api.Methods.EDIT_MESSAGE_CAPTION + + def __init__(self, chat_id: Optional[Union[Integer, String]] = None, + message_id: Optional[Integer] = None, + inline_message_id: Optional[String] = None, + caption: Optional[String] = None, + reply_markup: Optional[types.InlineKeyboardMarkup] = None): + """ + :param chat_id: Union[Integer, String] (Optional) - Required if inline_message_id + is not specified. Unique identifier for the target chat or username of the target channel + (in the format @channelusername) + :param message_id: Integer (Optional) - Required if inline_message_id is not specified. + Identifier of the sent message + :param inline_message_id: String (Optional) - Required if chat_id and message_id are not specified. + Identifier of the inline message + :param caption: String (Optional) - New caption of the message + :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for an inline keyboard. + """ + self.chat_id = chat_id + self.message_id = message_id + self.inline_message_id = inline_message_id + self.caption = caption + self.reply_markup = reply_markup + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'message_id': self.message_id, + 'inline_message_id': self.inline_message_id, + 'caption': self.caption, + 'reply_markup': prepare_arg(self.reply_markup) + } + + +class EditMessageReplyMarkup(BaseResponse): + """ + + """ + __slots__ = ('chat_id', 'message_id', 'inline_message_id', 'reply_markup') + + method = api.Methods.EDIT_MESSAGE_REPLY_MARKUP + + def __init__(self, chat_id: Optional[Union[Integer, String]] = None, + message_id: Optional[Integer] = None, + inline_message_id: Optional[String] = None, + reply_markup: Optional[types.InlineKeyboardMarkup] = None): + """ + :param chat_id: Union[Integer, String] (Optional) - Required if inline_message_id is not specified. + Unique identifier for the target chat or username of the target channel (in the format @channelusername) + :param message_id: Integer (Optional) - Required if inline_message_id is not specified. + Identifier of the sent message + :param inline_message_id: String (Optional) - Required if chat_id and message_id are not specified. + Identifier of the inline message + :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for an inline keyboard. + """ + self.chat_id = chat_id + self.message_id = message_id + self.inline_message_id = inline_message_id + self.reply_markup = reply_markup + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'message_id': self.message_id, + 'inline_message_id': self.inline_message_id, + 'reply_markup': prepare_arg(self.reply_markup) + } + + +class DeleteMessage(BaseResponse): + """ + + """ + __slots__ = ('chat_id', 'message_id') + + method = api.Methods.DELETE_MESSAGE + + def __init__(self, chat_id: Union[Integer, String], message_id: Integer): + """ + :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username + of the target channel (in the format @channelusername) + :param message_id: Integer - Identifier of the message to delete + """ + self.chat_id = chat_id + self.message_id = message_id + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'message_id': self.message_id + } + + +class SendSticker(BaseResponse): + """ + + """ + __slots__ = ('chat_id', 'sticker', 'disable_notification', 'reply_to_message_id', 'reply_markup') + + method = api.Methods.SEND_STICKER + + def __init__(self, chat_id: Union[Integer, String], + sticker: String, + disable_notification: Optional[Boolean] = None, + reply_to_message_id: Optional[Integer] = None, + reply_markup: Optional[ + Union[types.InlineKeyboardMarkup, + types.ReplyKeyboardMarkup, Dict, String]] = None): + """ + :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username + of the target channel (in the format @channelusername) + :param sticker: String - 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. More info on Sending Files » + :param disable_notification: Boolean (Optional) - Sends the message silently. + Users will receive a notification with no sound. + :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message + :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional) - + 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. + """ + self.chat_id = chat_id + self.sticker = sticker + self.disable_notification = disable_notification + self.reply_to_message_id = reply_to_message_id + self.reply_markup = reply_markup + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'sticker': self.sticker, + 'disable_notification': self.disable_notification, + 'reply_to_message_id': self.reply_to_message_id, + 'reply_markup': prepare_arg(self.reply_markup) + } + + +class CreateNewStickerSet(BaseResponse): + """ + + """ + __slots__ = ('user_id', 'name', 'title', 'png_sticker', 'emojis', 'contains_masks', 'mask_position') method = api.Methods - def __init__(self): + def __init__(self, user_id: Integer, + name: String, title: String, + png_sticker: String, + emojis: String, + contains_masks: Optional[Boolean] = None, + mask_position: Optional[types.MaskPosition] = None): """ - + :param user_id: Integer - User identifier of created sticker set owner + :param name: String - 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. + :param title: String - Sticker set title, 1-64 characters + :param png_sticker: String - 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. + :param emojis: String - One or more emoji corresponding to the sticker + :param contains_masks: Boolean (Optional) - Pass True, if a set of mask stickers should be created + :param mask_position: types.MaskPosition (Optional) - Position where the mask should be placed on faces """ - pass + self.user_id = user_id + self.name = name + self.title = title + self.png_sticker = png_sticker + self.emojis = emojis + self.contains_masks = contains_masks + self.mask_position = mask_position def prepare(self): - return {} + return { + 'user_id': self.user_id, + 'name': self.name, + 'title': self.title, + 'png_sticker': self.png_sticker, + 'emojis': self.emojis, + 'contains_masks': self.contains_masks, + 'mask_position': self.mask_position + } + + +class AddStickerToSet(BaseResponse): + """ + + """ + __slots__ = ('user_id', 'name', 'png_sticker', 'emojis', 'mask_position') + + method = api.Methods.ADD_STICKER_TO_SET + + def __init__(self, user_id: Integer, + name: String, + png_sticker: String, + emojis: String, + mask_position: Optional[types.MaskPosition] = None): + """ + :param user_id: Integer - User identifier of sticker set owner + :param name: String - Sticker set name + :param png_sticker: String - 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. + :param emojis: String - One or more emoji corresponding to the sticker + :param mask_position: types.MaskPosition (Optional) - Position where the mask should be placed on faces + """ + self.user_id = user_id + self.name = name + self.png_sticker = png_sticker + self.emojis = emojis + self.mask_position = mask_position + + def prepare(self): + return { + 'user_id': self.user_id, + 'name': self.name, + 'png_sticker': self.png_sticker, + 'emojis': self.emojis, + 'mask_position': prepare_arg(self.mask_position) + } + + +class SetStickerPositionInSet(BaseResponse): + """ + + """ + __slots__ = ('sticker', 'position') + + method = api.Methods.SET_STICKER_POSITION_IN_SET + + def __init__(self, sticker: String, position: Integer): + """ + :param sticker: String - File identifier of the sticker + :param position: Integer - New sticker position in the set, zero-based + """ + self.sticker = sticker + self.position = position + + def prepare(self): + return { + 'sticker': self.sticker, + 'position': self.position + } + + +class DeleteStickerFromSet(BaseResponse): + """ + + """ + __slots__ = ('sticker',) + + method = api.Methods.DELETE_STICKER_FROM_SET + + def __init__(self, sticker: String): + """ + :param sticker: String - File identifier of the sticker + """ + self.sticker = sticker + + def prepare(self): + return { + 'sticker': self.sticker + } + + +class AnswerInlineQuery(BaseResponse): + """ + + """ + __slots__ = ('inline_query_id', 'results', 'cache_time', 'is_personal', 'next_offset', + 'switch_pm_text', 'switch_pm_parameter') + + method = api.Methods.ANSWER_INLINE_QUERY + + def __init__(self, inline_query_id: String, + results: [types.InlineQueryResult], + cache_time: Optional[Integer] = None, + is_personal: Optional[Boolean] = None, + next_offset: Optional[String] = None, + switch_pm_text: Optional[String] = None, + switch_pm_parameter: Optional[String] = None): + """ + :param inline_query_id: String - Unique identifier for the answered query + :param results: [types.InlineQueryResult] - A JSON-serialized array of results for the inline query + :param cache_time: Integer (Optional) - The maximum amount of time in seconds that the result + of the inline query may be cached on the server. Defaults to 300. + :param is_personal: Boolean (Optional) - 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 + :param next_offset: String (Optional) - 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. + :param switch_pm_text: String (Optional) - 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 + :param switch_pm_parameter: String (Optional) - 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. + Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their + YouTube account to adapt search results accordingly. To do this, + it displays a ‘Connect your YouTube account’ button above the results, or even before showing any. + The user presses the button, switches to a private chat with the bot and, + in doing so, passes a start parameter that instructs the bot to return an oauth link. + Once done, the bot can offer a switch_inline button so that the user can easily return + to the chat where they wanted to use the bot's inline capabilities. + """ + self.inline_query_id = inline_query_id + self.results = results + self.cache_time = cache_time + self.is_personal = is_personal + self.next_offset = next_offset + self.switch_pm_text = switch_pm_text + self.switch_pm_parameter = switch_pm_parameter + + def prepare(self): + return { + 'inline_query_id': self.inline_query_id, + 'results': prepare_arg(self.results), + 'cache_time': self.cache_time, + 'is_personal': self.is_personal, + 'next_offset': self.next_offset, + 'switch_pm_text': self.switch_pm_text, + 'switch_pm_parameter': self.switch_pm_parameter, + } + + +class SendInvoice(BaseResponse): + """ + + """ + __slots__ = ('chat_id', 'title', 'description', 'payload', 'provider_token', 'start_parameter', + 'currency', 'prices', 'photo_url', 'photo_size', 'photo_width', 'photo_height', + 'need_name', 'need_phone_number', 'need_email', 'need_shipping_address', 'is_flexible', + 'disable_notification', 'reply_to_message_id', 'reply_markup') + + method = api.Methods.SEND_INVOICE + + def __init__(self, chat_id: Integer, + title: String, + description: String, + payload: String, + provider_token: String, + start_parameter: String, + currency: String, + prices: [types.LabeledPrice], + photo_url: Optional[String] = None, + photo_size: Optional[Integer] = None, + photo_width: Optional[Integer] = None, + photo_height: Optional[Integer] = None, + need_name: Optional[Boolean] = None, + need_phone_number: Optional[Boolean] = None, + need_email: Optional[Boolean] = None, + need_shipping_address: Optional[Boolean] = None, + is_flexible: Optional[Boolean] = None, + disable_notification: Optional[Boolean] = None, + reply_to_message_id: Optional[Integer] = None, + reply_markup: Optional[types.InlineKeyboardMarkup] = None): + """ + :param chat_id: Integer - Unique identifier for the target private chat + :param title: String - Product name, 1-32 characters + :param description: String - Product description, 1-255 characters + :param payload: String - Bot-defined invoice payload, 1-128 bytes. + This will not be displayed to the user, use for your internal processes. + :param provider_token: String - Payments provider token, obtained via Botfather + :param start_parameter: String - Unique deep-linking parameter that can be used to + generate this invoice when used as a start parameter + :param currency: String - Three-letter ISO 4217 currency code, see more on currencies + :param prices: [types.LabeledPrice] - Price breakdown, a list of components + (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + :param photo_url: String (Optional) - 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. + :param photo_size: Integer (Optional) - Photo size + :param photo_width: Integer (Optional) - Photo width + :param photo_height: Integer (Optional) - Photo height + :param need_name: Boolean (Optional) - Pass True, if you require the user's full name to complete the order + :param need_phone_number: Boolean (Optional) - Pass True, if you require + the user's phone number to complete the order + :param need_email: Boolean (Optional) - Pass True, if you require the user's email to complete the order + :param need_shipping_address: Boolean (Optional) - Pass True, if you require the user's + shipping address to complete the order + :param is_flexible: Boolean (Optional) - Pass True, if the final price depends on the shipping method + :param disable_notification: Boolean (Optional) - Sends the message silently. + Users will receive a notification with no sound. + :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message + :param reply_markup: types.InlineKeyboardMarkup (Optional) - 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. + """ + self.chat_id = chat_id + self.title = title + self.description = description + self.payload = payload + self.provider_token = provider_token + self.start_parameter = start_parameter + self.currency = currency + self.prices = prices + self.photo_url = photo_url + self.photo_size = photo_size + self.photo_width = photo_width + self.photo_height = photo_height + self.need_name = need_name + self.need_phone_number = need_phone_number + self.need_email = need_email + self.need_shipping_address = need_shipping_address + self.is_flexible = is_flexible + self.disable_notification = disable_notification + self.reply_to_message_id = reply_to_message_id + self.reply_markup = reply_markup + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'title': self.title, + 'description': self.description, + 'payload': self.payload, + 'provider_token': self.provider_token, + 'start_parameter': self.start_parameter, + 'currency': self.currency, + 'prices': prepare_arg(self.prices), + 'photo_url': self.photo_url, + 'photo_size': self.photo_size, + 'photo_width': self.photo_width, + 'photo_height': self.photo_height, + 'need_name': self.need_name, + 'need_phone_number': self.need_phone_number, + 'need_email': self.need_email, + 'need_shipping_address': self.need_shipping_address, + 'is_flexible': self.is_flexible, + 'disable_notification': self.disable_notification, + 'reply_to_message_id': self.reply_to_message_id, + 'reply_markup': prepare_arg(self.reply_markup), + } + + +class AnswerShippingQuery(BaseResponse): + """ + + """ + __slots__ = ('shipping_query_id', 'ok', 'shipping_options', 'error_message') + + method = api.Methods.ANSWER_SHIPPING_QUERY + + def __init__(self, shipping_query_id: String, + ok: Boolean, + shipping_options: Optional[typing.List[types.ShippingOption]] = None, + error_message: Optional[String] = None): + """ + :param shipping_query_id: String - Unique identifier for the query to be answered + :param ok: Boolean - 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) + :param shipping_options: [types.ShippingOption] (Optional) - Required if ok is True. + A JSON-serialized array of available shipping options. + :param error_message: String (Optional) - 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. + """ + self.shipping_query_id = shipping_query_id + self.ok = ok + self.shipping_options = shipping_options + self.error_message = error_message + + def prepare(self): + return { + 'shipping_query_id': self.shipping_query_id, + 'ok': self.ok, + 'shipping_options': prepare_arg(self.shipping_options), + 'error_message': self.error_message + } + + +class AnswerPreCheckoutQuery(BaseResponse): + """ + + """ + __slots__ = ('pre_checkout_query_id', 'ok', 'error_message') + + method = api.Methods.ANSWER_PRE_CHECKOUT_QUERY + + def __init__(self, pre_checkout_query_id: String, + ok: Boolean, + error_message: Optional[String] = None): + """ + :param pre_checkout_query_id: String - Unique identifier for the query to be answered + :param ok: Boolean - 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. + :param error_message: String (Optional) - 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. + """ + self.pre_checkout_query_id = pre_checkout_query_id + self.ok = ok + self.error_message = error_message + + def prepare(self): + return { + 'pre_checkout_query_id': self.pre_checkout_query_id, + 'ok': self.ok, + 'error_message': self.error_message + } + + +class SendGame(BaseResponse): + """ + + """ + __slots__ = ('chat_id', 'game_short_name', 'disable_notification', 'reply_to_message_id', 'reply_markup') + + method = api.Methods.SEND_GAME + + def __init__(self, chat_id: Integer, + game_short_name: String, + disable_notification: Optional[Boolean] = None, + reply_to_message_id: Optional[Integer] = None, + reply_markup: Optional[types.InlineKeyboardMarkup] = None): + """ + :param chat_id: Integer - Unique identifier for the target chat + :param game_short_name: String - Short name of the game, serves as the unique identifier for the game. + Set up your games via Botfather. + :param disable_notification: Boolean (Optional) - Sends the message silently. + Users will receive a notification with no sound. + :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message + :param reply_markup: types.InlineKeyboardMarkup (Optional) - 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. + """ + self.chat_id = chat_id + self.game_short_name = game_short_name + self.disable_notification = disable_notification + self.reply_to_message_id = reply_to_message_id + self.reply_markup = reply_markup + + def prepare(self): + return { + 'chat_id': self.chat_id, + 'game_short_name': self.game_short_name, + 'disable_notification': self.disable_notification, + 'reply_to_message_id': self.reply_to_message_id, + 'reply_markup': prepare_arg(self.reply_markup) + }