From 278999761c778d7033075ada7b44a3facb51c1a3 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 3 Nov 2019 22:14:41 +0200 Subject: [PATCH] Add new autogenerated methods and types and add prototype of sessions. --- aiogram/_telegram/types.py | 2793 ----------------- aiogram/{_telegram => api}/__init__.py | 0 aiogram/api/client/__init__.py | 0 aiogram/api/client/base.py | 18 + aiogram/api/client/bot.py | 2144 +++++++++++++ aiogram/api/methods/__init__.py | 137 + aiogram/api/methods/add_sticker_to_set.py | 34 + aiogram/api/methods/answer_callback_query.py | 36 + aiogram/api/methods/answer_inline_query.py | 43 + .../api/methods/answer_pre_checkout_query.py | 27 + aiogram/api/methods/answer_shipping_query.py | 31 + aiogram/api/methods/base.py | 49 + aiogram/api/methods/create_new_sticker_set.py | 40 + aiogram/api/methods/delete_chat_photo.py | 21 + .../api/methods/delete_chat_sticker_set.py | 21 + aiogram/api/methods/delete_message.py | 31 + .../api/methods/delete_sticker_from_set.py | 21 + aiogram/api/methods/delete_webhook.py | 18 + aiogram/api/methods/edit_message_caption.py | 37 + .../api/methods/edit_message_live_location.py | 37 + aiogram/api/methods/edit_message_media.py | 34 + .../api/methods/edit_message_reply_markup.py | 31 + aiogram/api/methods/edit_message_text.py | 40 + .../api/methods/export_chat_invite_link.py | 22 + aiogram/api/methods/forward_message.py | 31 + aiogram/api/methods/get_chat.py | 22 + .../api/methods/get_chat_administrators.py | 22 + aiogram/api/methods/get_chat_member.py | 25 + aiogram/api/methods/get_chat_members_count.py | 21 + aiogram/api/methods/get_file.py | 23 + aiogram/api/methods/get_game_high_scores.py | 32 + aiogram/api/methods/get_me.py | 19 + aiogram/api/methods/get_sticker_set.py | 22 + aiogram/api/methods/get_updates.py | 36 + .../api/methods/get_user_profile_photos.py | 28 + aiogram/api/methods/get_webhook_info.py | 19 + aiogram/api/methods/kick_chat_member.py | 27 + aiogram/api/methods/leave_chat.py | 21 + aiogram/api/methods/pin_chat_message.py | 27 + aiogram/api/methods/promote_chat_member.py | 48 + aiogram/api/methods/restrict_chat_member.py | 31 + aiogram/api/methods/send_animation.py | 61 + aiogram/api/methods/send_audio.py | 62 + aiogram/api/methods/send_chat_action.py | 26 + aiogram/api/methods/send_contact.py | 51 + aiogram/api/methods/send_document.py | 52 + aiogram/api/methods/send_game.py | 34 + aiogram/api/methods/send_invoice.py | 88 + aiogram/api/methods/send_location.py | 48 + aiogram/api/methods/send_media_group.py | 31 + aiogram/api/methods/send_message.py | 48 + aiogram/api/methods/send_photo.py | 49 + aiogram/api/methods/send_poll.py | 45 + aiogram/api/methods/send_sticker.py | 43 + aiogram/api/methods/send_venue.py | 57 + aiogram/api/methods/send_video.py | 64 + aiogram/api/methods/send_video_note.py | 52 + aiogram/api/methods/send_voice.py | 52 + aiogram/api/methods/set_chat_description.py | 24 + aiogram/api/methods/set_chat_permissions.py | 25 + aiogram/api/methods/set_chat_photo.py | 25 + aiogram/api/methods/set_chat_sticker_set.py | 24 + aiogram/api/methods/set_chat_title.py | 24 + aiogram/api/methods/set_game_score.py | 40 + .../api/methods/set_passport_data_errors.py | 26 + .../methods/set_sticker_position_in_set.py | 24 + aiogram/api/methods/set_webhook.py | 39 + .../api/methods/stop_message_live_location.py | 31 + aiogram/api/methods/stop_poll.py | 28 + aiogram/api/methods/unban_chat_member.py | 24 + aiogram/api/methods/unpin_chat_message.py | 21 + aiogram/api/methods/upload_sticker_file.py | 25 + aiogram/api/session/__init__.py | 0 aiogram/api/session/aiohttp.py | 51 + aiogram/api/session/api.py | 0 aiogram/api/session/base.py | 54 + aiogram/api/types/__init__.py | 199 ++ aiogram/api/types/animation.py | 33 + aiogram/api/types/audio.py | 31 + aiogram/api/types/base.py | 10 + aiogram/api/types/callback_game.py | 11 + aiogram/api/types/callback_query.py | 35 + aiogram/api/types/chat.py | 45 + aiogram/api/types/chat_member.py | 53 + aiogram/api/types/chat_permissions.py | 30 + aiogram/api/types/chat_photo.py | 16 + aiogram/api/types/chosen_inline_result.py | 31 + aiogram/api/types/contact.py | 24 + aiogram/api/types/document.py | 27 + aiogram/api/types/encrypted_credentials.py | 18 + .../api/types/encrypted_passport_element.py | 37 + aiogram/api/types/file.py | 21 + aiogram/api/types/force_reply.py | 23 + aiogram/api/types/game.py | 31 + aiogram/api/types/game_high_score.py | 25 + aiogram/api/types/inline_keyboard_button.py | 42 + aiogram/api/types/inline_keyboard_markup.py | 20 + aiogram/api/types/inline_query.py | 30 + aiogram/api/types/inline_query_result.py | 31 + .../api/types/inline_query_result_article.py | 42 + .../api/types/inline_query_result_audio.py | 41 + .../types/inline_query_result_cached_audio.py | 35 + .../inline_query_result_cached_document.py | 39 + .../types/inline_query_result_cached_gif.py | 36 + .../inline_query_result_cached_mpeg4_gif.py | 36 + .../types/inline_query_result_cached_photo.py | 38 + .../inline_query_result_cached_sticker.py | 31 + .../types/inline_query_result_cached_video.py | 38 + .../types/inline_query_result_cached_voice.py | 37 + .../api/types/inline_query_result_contact.py | 43 + .../api/types/inline_query_result_document.py | 47 + aiogram/api/types/inline_query_result_game.py | 28 + aiogram/api/types/inline_query_result_gif.py | 44 + .../api/types/inline_query_result_location.py | 43 + .../types/inline_query_result_mpeg4_gif.py | 44 + .../api/types/inline_query_result_photo.py | 44 + .../api/types/inline_query_result_venue.py | 47 + .../api/types/inline_query_result_video.py | 49 + .../api/types/inline_query_result_voice.py | 39 + .../types/input_contact_message_content.py | 22 + aiogram/api/types/input_file.py | 11 + .../types/input_location_message_content.py | 20 + aiogram/api/types/input_media.py | 16 + aiogram/api/types/input_media_animation.py | 35 + aiogram/api/types/input_media_audio.py | 35 + aiogram/api/types/input_media_document.py | 29 + aiogram/api/types/input_media_photo.py | 24 + aiogram/api/types/input_media_video.py | 37 + aiogram/api/types/input_message_content.py | 15 + .../api/types/input_text_message_content.py | 20 + .../api/types/input_venue_message_content.py | 26 + aiogram/api/types/invoice.py | 22 + aiogram/api/types/keyboard_button.py | 21 + aiogram/api/types/labeled_price.py | 16 + aiogram/api/types/location.py | 16 + aiogram/api/types/login_url.py | 26 + aiogram/api/types/mask_position.py | 20 + aiogram/api/types/message.py | 133 + aiogram/api/types/message_entity.py | 27 + aiogram/api/types/order_info.py | 25 + aiogram/api/types/passport_data.py | 22 + aiogram/api/types/passport_element_error.py | 20 + .../passport_element_error_data_field.py | 24 + .../api/types/passport_element_error_file.py | 22 + .../api/types/passport_element_error_files.py | 24 + .../passport_element_error_front_side.py | 22 + .../passport_element_error_reverse_side.py | 22 + .../types/passport_element_error_selfie.py | 22 + ...passport_element_error_translation_file.py | 22 + ...assport_element_error_translation_files.py | 24 + .../passport_element_error_unspecified.py | 22 + aiogram/api/types/passport_file.py | 18 + aiogram/api/types/photo_size.py | 22 + aiogram/api/types/poll.py | 25 + aiogram/api/types/poll_option.py | 16 + aiogram/api/types/pre_checkout_query.py | 34 + aiogram/api/types/reply_keyboard_markup.py | 27 + aiogram/api/types/reply_keyboard_remove.py | 20 + aiogram/api/types/response_parameters.py | 18 + aiogram/api/types/shipping_address.py | 24 + aiogram/api/types/shipping_option.py | 23 + aiogram/api/types/shipping_query.py | 28 + aiogram/api/types/sticker.py | 36 + aiogram/api/types/sticker_set.py | 27 + aiogram/api/types/successful_payment.py | 31 + aiogram/api/types/update.py | 46 + aiogram/api/types/user.py | 26 + aiogram/api/types/user_profile_photos.py | 21 + aiogram/api/types/venue.py | 27 + aiogram/api/types/video.py | 31 + aiogram/api/types/video_note.py | 27 + aiogram/api/types/voice.py | 22 + aiogram/api/types/webhook_info.py | 28 + 173 files changed, 7717 insertions(+), 2793 deletions(-) delete mode 100644 aiogram/_telegram/types.py rename aiogram/{_telegram => api}/__init__.py (100%) create mode 100644 aiogram/api/client/__init__.py create mode 100644 aiogram/api/client/base.py create mode 100644 aiogram/api/client/bot.py create mode 100644 aiogram/api/methods/__init__.py create mode 100644 aiogram/api/methods/add_sticker_to_set.py create mode 100644 aiogram/api/methods/answer_callback_query.py create mode 100644 aiogram/api/methods/answer_inline_query.py create mode 100644 aiogram/api/methods/answer_pre_checkout_query.py create mode 100644 aiogram/api/methods/answer_shipping_query.py create mode 100644 aiogram/api/methods/base.py create mode 100644 aiogram/api/methods/create_new_sticker_set.py create mode 100644 aiogram/api/methods/delete_chat_photo.py create mode 100644 aiogram/api/methods/delete_chat_sticker_set.py create mode 100644 aiogram/api/methods/delete_message.py create mode 100644 aiogram/api/methods/delete_sticker_from_set.py create mode 100644 aiogram/api/methods/delete_webhook.py create mode 100644 aiogram/api/methods/edit_message_caption.py create mode 100644 aiogram/api/methods/edit_message_live_location.py create mode 100644 aiogram/api/methods/edit_message_media.py create mode 100644 aiogram/api/methods/edit_message_reply_markup.py create mode 100644 aiogram/api/methods/edit_message_text.py create mode 100644 aiogram/api/methods/export_chat_invite_link.py create mode 100644 aiogram/api/methods/forward_message.py create mode 100644 aiogram/api/methods/get_chat.py create mode 100644 aiogram/api/methods/get_chat_administrators.py create mode 100644 aiogram/api/methods/get_chat_member.py create mode 100644 aiogram/api/methods/get_chat_members_count.py create mode 100644 aiogram/api/methods/get_file.py create mode 100644 aiogram/api/methods/get_game_high_scores.py create mode 100644 aiogram/api/methods/get_me.py create mode 100644 aiogram/api/methods/get_sticker_set.py create mode 100644 aiogram/api/methods/get_updates.py create mode 100644 aiogram/api/methods/get_user_profile_photos.py create mode 100644 aiogram/api/methods/get_webhook_info.py create mode 100644 aiogram/api/methods/kick_chat_member.py create mode 100644 aiogram/api/methods/leave_chat.py create mode 100644 aiogram/api/methods/pin_chat_message.py create mode 100644 aiogram/api/methods/promote_chat_member.py create mode 100644 aiogram/api/methods/restrict_chat_member.py create mode 100644 aiogram/api/methods/send_animation.py create mode 100644 aiogram/api/methods/send_audio.py create mode 100644 aiogram/api/methods/send_chat_action.py create mode 100644 aiogram/api/methods/send_contact.py create mode 100644 aiogram/api/methods/send_document.py create mode 100644 aiogram/api/methods/send_game.py create mode 100644 aiogram/api/methods/send_invoice.py create mode 100644 aiogram/api/methods/send_location.py create mode 100644 aiogram/api/methods/send_media_group.py create mode 100644 aiogram/api/methods/send_message.py create mode 100644 aiogram/api/methods/send_photo.py create mode 100644 aiogram/api/methods/send_poll.py create mode 100644 aiogram/api/methods/send_sticker.py create mode 100644 aiogram/api/methods/send_venue.py create mode 100644 aiogram/api/methods/send_video.py create mode 100644 aiogram/api/methods/send_video_note.py create mode 100644 aiogram/api/methods/send_voice.py create mode 100644 aiogram/api/methods/set_chat_description.py create mode 100644 aiogram/api/methods/set_chat_permissions.py create mode 100644 aiogram/api/methods/set_chat_photo.py create mode 100644 aiogram/api/methods/set_chat_sticker_set.py create mode 100644 aiogram/api/methods/set_chat_title.py create mode 100644 aiogram/api/methods/set_game_score.py create mode 100644 aiogram/api/methods/set_passport_data_errors.py create mode 100644 aiogram/api/methods/set_sticker_position_in_set.py create mode 100644 aiogram/api/methods/set_webhook.py create mode 100644 aiogram/api/methods/stop_message_live_location.py create mode 100644 aiogram/api/methods/stop_poll.py create mode 100644 aiogram/api/methods/unban_chat_member.py create mode 100644 aiogram/api/methods/unpin_chat_message.py create mode 100644 aiogram/api/methods/upload_sticker_file.py create mode 100644 aiogram/api/session/__init__.py create mode 100644 aiogram/api/session/aiohttp.py create mode 100644 aiogram/api/session/api.py create mode 100644 aiogram/api/session/base.py create mode 100644 aiogram/api/types/__init__.py create mode 100644 aiogram/api/types/animation.py create mode 100644 aiogram/api/types/audio.py create mode 100644 aiogram/api/types/base.py create mode 100644 aiogram/api/types/callback_game.py create mode 100644 aiogram/api/types/callback_query.py create mode 100644 aiogram/api/types/chat.py create mode 100644 aiogram/api/types/chat_member.py create mode 100644 aiogram/api/types/chat_permissions.py create mode 100644 aiogram/api/types/chat_photo.py create mode 100644 aiogram/api/types/chosen_inline_result.py create mode 100644 aiogram/api/types/contact.py create mode 100644 aiogram/api/types/document.py create mode 100644 aiogram/api/types/encrypted_credentials.py create mode 100644 aiogram/api/types/encrypted_passport_element.py create mode 100644 aiogram/api/types/file.py create mode 100644 aiogram/api/types/force_reply.py create mode 100644 aiogram/api/types/game.py create mode 100644 aiogram/api/types/game_high_score.py create mode 100644 aiogram/api/types/inline_keyboard_button.py create mode 100644 aiogram/api/types/inline_keyboard_markup.py create mode 100644 aiogram/api/types/inline_query.py create mode 100644 aiogram/api/types/inline_query_result.py create mode 100644 aiogram/api/types/inline_query_result_article.py create mode 100644 aiogram/api/types/inline_query_result_audio.py create mode 100644 aiogram/api/types/inline_query_result_cached_audio.py create mode 100644 aiogram/api/types/inline_query_result_cached_document.py create mode 100644 aiogram/api/types/inline_query_result_cached_gif.py create mode 100644 aiogram/api/types/inline_query_result_cached_mpeg4_gif.py create mode 100644 aiogram/api/types/inline_query_result_cached_photo.py create mode 100644 aiogram/api/types/inline_query_result_cached_sticker.py create mode 100644 aiogram/api/types/inline_query_result_cached_video.py create mode 100644 aiogram/api/types/inline_query_result_cached_voice.py create mode 100644 aiogram/api/types/inline_query_result_contact.py create mode 100644 aiogram/api/types/inline_query_result_document.py create mode 100644 aiogram/api/types/inline_query_result_game.py create mode 100644 aiogram/api/types/inline_query_result_gif.py create mode 100644 aiogram/api/types/inline_query_result_location.py create mode 100644 aiogram/api/types/inline_query_result_mpeg4_gif.py create mode 100644 aiogram/api/types/inline_query_result_photo.py create mode 100644 aiogram/api/types/inline_query_result_venue.py create mode 100644 aiogram/api/types/inline_query_result_video.py create mode 100644 aiogram/api/types/inline_query_result_voice.py create mode 100644 aiogram/api/types/input_contact_message_content.py create mode 100644 aiogram/api/types/input_file.py create mode 100644 aiogram/api/types/input_location_message_content.py create mode 100644 aiogram/api/types/input_media.py create mode 100644 aiogram/api/types/input_media_animation.py create mode 100644 aiogram/api/types/input_media_audio.py create mode 100644 aiogram/api/types/input_media_document.py create mode 100644 aiogram/api/types/input_media_photo.py create mode 100644 aiogram/api/types/input_media_video.py create mode 100644 aiogram/api/types/input_message_content.py create mode 100644 aiogram/api/types/input_text_message_content.py create mode 100644 aiogram/api/types/input_venue_message_content.py create mode 100644 aiogram/api/types/invoice.py create mode 100644 aiogram/api/types/keyboard_button.py create mode 100644 aiogram/api/types/labeled_price.py create mode 100644 aiogram/api/types/location.py create mode 100644 aiogram/api/types/login_url.py create mode 100644 aiogram/api/types/mask_position.py create mode 100644 aiogram/api/types/message.py create mode 100644 aiogram/api/types/message_entity.py create mode 100644 aiogram/api/types/order_info.py create mode 100644 aiogram/api/types/passport_data.py create mode 100644 aiogram/api/types/passport_element_error.py create mode 100644 aiogram/api/types/passport_element_error_data_field.py create mode 100644 aiogram/api/types/passport_element_error_file.py create mode 100644 aiogram/api/types/passport_element_error_files.py create mode 100644 aiogram/api/types/passport_element_error_front_side.py create mode 100644 aiogram/api/types/passport_element_error_reverse_side.py create mode 100644 aiogram/api/types/passport_element_error_selfie.py create mode 100644 aiogram/api/types/passport_element_error_translation_file.py create mode 100644 aiogram/api/types/passport_element_error_translation_files.py create mode 100644 aiogram/api/types/passport_element_error_unspecified.py create mode 100644 aiogram/api/types/passport_file.py create mode 100644 aiogram/api/types/photo_size.py create mode 100644 aiogram/api/types/poll.py create mode 100644 aiogram/api/types/poll_option.py create mode 100644 aiogram/api/types/pre_checkout_query.py create mode 100644 aiogram/api/types/reply_keyboard_markup.py create mode 100644 aiogram/api/types/reply_keyboard_remove.py create mode 100644 aiogram/api/types/response_parameters.py create mode 100644 aiogram/api/types/shipping_address.py create mode 100644 aiogram/api/types/shipping_option.py create mode 100644 aiogram/api/types/shipping_query.py create mode 100644 aiogram/api/types/sticker.py create mode 100644 aiogram/api/types/sticker_set.py create mode 100644 aiogram/api/types/successful_payment.py create mode 100644 aiogram/api/types/update.py create mode 100644 aiogram/api/types/user.py create mode 100644 aiogram/api/types/user_profile_photos.py create mode 100644 aiogram/api/types/venue.py create mode 100644 aiogram/api/types/video.py create mode 100644 aiogram/api/types/video_note.py create mode 100644 aiogram/api/types/voice.py create mode 100644 aiogram/api/types/webhook_info.py diff --git a/aiogram/_telegram/types.py b/aiogram/_telegram/types.py deleted file mode 100644 index da37d1c7..00000000 --- a/aiogram/_telegram/types.py +++ /dev/null @@ -1,2793 +0,0 @@ -""" -!!! DO NOT EDIT THIS FILE !!! -This file is autogenerated from Docs of Telegram Bot API at 2019-06-30 20:10:58 UTC -""" -import typing - -import pydantic - -from aiogram import types - -__all__ = [ - "Update", - "WebhookInfo", - "User", - "Chat", - "Message", - "MessageEntity", - "PhotoSize", - "Audio", - "Document", - "Video", - "Animation", - "Voice", - "VideoNote", - "Contact", - "Location", - "Venue", - "PollOption", - "Poll", - "UserProfilePhotos", - "File", - "ReplyKeyboardMarkup", - "KeyboardButton", - "ReplyKeyboardRemove", - "InlineKeyboardMarkup", - "InlineKeyboardButton", - "LoginUrl", - "CallbackQuery", - "ForceReply", - "ChatPhoto", - "ChatMember", - "ResponseParameters", - "InputMedia", - "InputMediaPhoto", - "InputMediaVideo", - "InputMediaAnimation", - "InputMediaAudio", - "InputMediaDocument", - "InputFile", - "Sticker", - "StickerSet", - "MaskPosition", - "InlineQuery", - "InlineQueryResult", - "InlineQueryResultArticle", - "InlineQueryResultPhoto", - "InlineQueryResultGif", - "InlineQueryResultMpeg4Gif", - "InlineQueryResultVideo", - "InlineQueryResultAudio", - "InlineQueryResultVoice", - "InlineQueryResultDocument", - "InlineQueryResultLocation", - "InlineQueryResultVenue", - "InlineQueryResultContact", - "InlineQueryResultGame", - "InlineQueryResultCachedPhoto", - "InlineQueryResultCachedGif", - "InlineQueryResultCachedMpeg4Gif", - "InlineQueryResultCachedSticker", - "InlineQueryResultCachedDocument", - "InlineQueryResultCachedVideo", - "InlineQueryResultCachedVoice", - "InlineQueryResultCachedAudio", - "InputMessageContent", - "InputTextMessageContent", - "InputLocationMessageContent", - "InputVenueMessageContent", - "InputContactMessageContent", - "ChosenInlineResult", - "LabeledPrice", - "Invoice", - "ShippingAddress", - "OrderInfo", - "ShippingOption", - "SuccessfulPayment", - "ShippingQuery", - "PreCheckoutQuery", - "PassportData", - "PassportFile", - "EncryptedPassportElement", - "EncryptedCredentials", - "PassportElementError", - "PassportElementErrorDataField", - "PassportElementErrorFrontSide", - "PassportElementErrorReverseSide", - "PassportElementErrorSelfie", - "PassportElementErrorFile", - "PassportElementErrorFiles", - "PassportElementErrorTranslationFile", - "PassportElementErrorTranslationFiles", - "PassportElementErrorUnspecified", - "Games", - "Game", - "CallbackGame", - "GameHighScore", -] - - -# %% Region: 'Getting updates' -""" -There are two mutually exclusive ways of receiving updates for your bot — the getUpdates method on one hand and Webhooks on the other. Incoming updates are stored on the server until the bot receives them either way, but they will not be kept longer than 24 hours. -Regardless of which option you choose, you will receive JSON-serialized Update objects as a result. - -link: https://core.telegram.org/bots/api#getting-updates -""" - - -class Update(pydantic.BaseModel): - """ - This object represents an incoming update. - At most one of the optional parameters can be present in any given update. - - Source: https://core.telegram.org/bots/api#update - """ - - update_id: int - """The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.""" - - message: typing.Optional[types.Message] = None - """New incoming message of any kind — text, photo, sticker, etc.""" - - edited_message: typing.Optional[types.Message] = None - """New version of a message that is known to the bot and was edited""" - - channel_post: typing.Optional[types.Message] = None - """New incoming channel post of any kind — text, photo, sticker, etc.""" - - edited_channel_post: typing.Optional[types.Message] = None - """New version of a channel post that is known to the bot and was edited""" - - inline_query: typing.Optional[types.InlineQuery] = None - """New incoming inline query""" - - chosen_inline_result: typing.Optional[types.ChosenInlineResult] = None - """The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.""" - - callback_query: typing.Optional[types.CallbackQuery] = None - """New incoming callback query""" - - shipping_query: typing.Optional[types.ShippingQuery] = None - """New incoming shipping query. Only for invoices with flexible price""" - - pre_checkout_query: typing.Optional[types.PreCheckoutQuery] = None - """New incoming pre-checkout query. Contains full information about checkout""" - - poll: typing.Optional[types.Poll] = None - """New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot""" - - -class WebhookInfo(pydantic.BaseModel): - """ - Contains information about the current status of a webhook. - - Source: https://core.telegram.org/bots/api#webhookinfo - """ - - url: str - """Webhook URL, may be empty if webhook is not set up""" - - has_custom_certificate: bool - """True, if a custom certificate was provided for webhook certificate checks""" - - pending_update_count: int - """Number of updates awaiting delivery""" - - last_error_date: typing.Optional[int] = None - """Unix time for the most recent error that happened when trying to deliver an update via webhook""" - - last_error_message: typing.Optional[str] = None - """Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook""" - - max_connections: typing.Optional[int] = None - """Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery""" - - allowed_updates: typing.Optional[typing.List[str]] = None - """A list of update types the bot is subscribed to. Defaults to all update types""" - - -# %% End of region 'Getting updates' - -# %% Region: 'Available types' -""" -All types used in the Bot API responses are represented as JSON-objects. -It is safe to use 32-bit signed integers for storing all Integer fields unless otherwise noted. -Optional fields may be not returned when irrelevant. - -link: https://core.telegram.org/bots/api#available-types -""" - - -class User(pydantic.BaseModel): - """ - This object represents a Telegram user or bot. - - Source: https://core.telegram.org/bots/api#user - """ - - id: int - """Unique identifier for this user or bot""" - - is_bot: bool - """True, if this user is a bot""" - - first_name: str - """User‘s or bot’s first name""" - - last_name: typing.Optional[str] = None - """User‘s or bot’s last name""" - - username: typing.Optional[str] = None - """User‘s or bot’s username""" - - language_code: typing.Optional[str] = None - """IETF language tag of the user's language""" - - -class Chat(pydantic.BaseModel): - """ - This object represents a chat. - - Source: https://core.telegram.org/bots/api#chat - """ - - id: int - """Unique identifier for this chat. This number 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.""" - - type: str - """Type of chat, can be either 'private', 'group', 'supergroup' or 'channel'""" - - title: typing.Optional[str] = None - """Title, for supergroups, channels and group chats""" - - username: typing.Optional[str] = None - """Username, for private chats, supergroups and channels if available""" - - first_name: typing.Optional[str] = None - """First name of the other party in a private chat""" - - last_name: typing.Optional[str] = None - """Last name of the other party in a private chat""" - - all_members_are_administrators: typing.Optional[bool] = None - """True if a group has ‘All Members Are Admins’ enabled.""" - - photo: typing.Optional[types.ChatPhoto] = None - """Chat photo. Returned only in getChat.""" - - description: typing.Optional[str] = None - """Description, for supergroups and channel chats. Returned only in getChat.""" - - invite_link: typing.Optional[str] = None - """Chat invite link, for supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat.""" - - pinned_message: typing.Optional[types.Message] = None - """Pinned message, for groups, supergroups and channels. Returned only in getChat.""" - - sticker_set_name: typing.Optional[str] = None - """For supergroups, name of group sticker set. Returned only in getChat.""" - - can_set_sticker_set: typing.Optional[bool] = None - """True, if the bot can change the group sticker set. Returned only in getChat.""" - - -class Message(pydantic.BaseModel): - """ - This object represents a message. - - Source: https://core.telegram.org/bots/api#message - """ - - message_id: int - """Unique message identifier inside this chat""" - - from_user: typing.Optional[types.User] = pydantic.Schema(None, alias="from") - """Sender, empty for messages sent to channels""" - - date: int - """Date the message was sent in Unix time""" - - chat: types.Chat - """Conversation the message belongs to""" - - forward_from: typing.Optional[types.User] = None - """For forwarded messages, sender of the original message""" - - forward_from_chat: typing.Optional[types.Chat] = None - """For messages forwarded from channels, information about the original channel""" - - forward_from_message_id: typing.Optional[int] = None - """For messages forwarded from channels, identifier of the original message in the channel""" - - forward_signature: typing.Optional[str] = None - """For messages forwarded from channels, signature of the post author if present""" - - forward_sender_name: typing.Optional[str] = None - """Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages""" - - forward_date: typing.Optional[int] = None - """For forwarded messages, date the original message was sent in Unix time""" - - reply_to_message: typing.Optional[types.Message] = None - """For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.""" - - edit_date: typing.Optional[int] = None - """Date the message was last edited in Unix time""" - - media_group_id: typing.Optional[str] = None - """The unique identifier of a media message group this message belongs to""" - - author_signature: typing.Optional[str] = None - """Signature of the post author for messages in channels""" - - text: typing.Optional[str] = None - """For text messages, the actual UTF-8 text of the message, 0-4096 characters.""" - - entities: typing.Optional[typing.List[types.MessageEntity]] = None - """For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text""" - - caption_entities: typing.Optional[typing.List[types.MessageEntity]] = None - """For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption""" - - audio: typing.Optional[types.Audio] = None - """Message is an audio file, information about the file""" - - document: typing.Optional[types.Document] = None - """Message is a general file, information about the file""" - - animation: typing.Optional[types.Animation] = None - """Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set""" - - game: typing.Optional[types.Game] = None - """Message is a game, information about the game.""" - - photo: typing.Optional[typing.List[types.PhotoSize]] = None - """Message is a photo, available sizes of the photo""" - - sticker: typing.Optional[types.Sticker] = None - """Message is a sticker, information about the sticker""" - - video: typing.Optional[types.Video] = None - """Message is a video, information about the video""" - - voice: typing.Optional[types.Voice] = None - """Message is a voice message, information about the file""" - - video_note: typing.Optional[types.VideoNote] = None - """Message is a video note, information about the video message""" - - caption: typing.Optional[str] = None - """Caption for the animation, audio, document, photo, video or voice, 0-1024 characters""" - - contact: typing.Optional[types.Contact] = None - """Message is a shared contact, information about the contact""" - - location: typing.Optional[types.Location] = None - """Message is a shared location, information about the location""" - - venue: typing.Optional[types.Venue] = None - """Message is a venue, information about the venue""" - - poll: typing.Optional[types.Poll] = None - """Message is a native poll, information about the poll""" - - new_chat_members: typing.Optional[typing.List[types.User]] = None - """New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)""" - - left_chat_member: typing.Optional[types.User] = None - """A member was removed from the group, information about them (this member may be the bot itself)""" - - new_chat_title: typing.Optional[str] = None - """A chat title was changed to this value""" - - new_chat_photo: typing.Optional[typing.List[types.PhotoSize]] = None - """A chat photo was change to this value""" - - delete_chat_photo: typing.Optional[bool] = None - """Service message: the chat photo was deleted""" - - group_chat_created: typing.Optional[bool] = None - """Service message: the group has been created""" - - supergroup_chat_created: typing.Optional[bool] = None - """Service message: the supergroup has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.""" - - channel_chat_created: typing.Optional[bool] = None - """Service message: the channel has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.""" - - migrate_to_chat_id: typing.Optional[int] = None - """The group has been migrated to a supergroup with the specified identifier. This number 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.""" - - migrate_from_chat_id: typing.Optional[int] = None - """The supergroup has been migrated from a group with the specified identifier. This number 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.""" - - pinned_message: typing.Optional[types.Message] = None - """Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.""" - - invoice: typing.Optional[types.Invoice] = None - """Message is an invoice for a payment, information about the invoice.""" - - successful_payment: typing.Optional[types.SuccessfulPayment] = None - """Message is a service message about a successful payment, information about the payment.""" - - connected_website: typing.Optional[str] = None - """The domain name of the website on which the user has logged in.""" - - passport_data: typing.Optional[types.PassportData] = None - """Telegram Passport data""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons.""" - - -class MessageEntity(pydantic.BaseModel): - """ - This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. - - Source: https://core.telegram.org/bots/api#messageentity - """ - - type: str - """Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)""" - - offset: int - """Offset in UTF-16 code units to the start of the entity""" - - length: int - """Length of the entity in UTF-16 code units""" - - url: typing.Optional[str] = None - """For 'text_link' only, url that will be opened after user taps on the text""" - - user: typing.Optional[types.User] = None - """For 'text_mention' only, the mentioned user""" - - -class PhotoSize(pydantic.BaseModel): - """ - This object represents one size of a photo or a file / sticker thumbnail. - - Source: https://core.telegram.org/bots/api#photosize - """ - - file_id: str - """Unique identifier for this file""" - - width: int - """Photo width""" - - height: int - """Photo height""" - - file_size: typing.Optional[int] = None - """File size""" - - -class Audio(pydantic.BaseModel): - """ - This object represents an audio file to be treated as music by the Telegram clients. - - Source: https://core.telegram.org/bots/api#audio - """ - - file_id: str - """Unique identifier for this file""" - - duration: int - """Duration of the audio in seconds as defined by sender""" - - performer: typing.Optional[str] = None - """Performer of the audio as defined by sender or by audio tags""" - - title: typing.Optional[str] = None - """Title of the audio as defined by sender or by audio tags""" - - mime_type: typing.Optional[str] = None - """MIME type of the file as defined by sender""" - - file_size: typing.Optional[int] = None - """File size""" - - thumb: typing.Optional[types.PhotoSize] = None - """Thumbnail of the album cover to which the music file belongs""" - - -class Document(pydantic.BaseModel): - """ - This object represents a general file (as opposed to photos, voice messages and audio files). - - Source: https://core.telegram.org/bots/api#document - """ - - file_id: str - """Unique file identifier""" - - thumb: typing.Optional[types.PhotoSize] = None - """Document thumbnail as defined by sender""" - - file_name: typing.Optional[str] = None - """Original filename as defined by sender""" - - mime_type: typing.Optional[str] = None - """MIME type of the file as defined by sender""" - - file_size: typing.Optional[int] = None - """File size""" - - -class Video(pydantic.BaseModel): - """ - This object represents a video file. - - Source: https://core.telegram.org/bots/api#video - """ - - file_id: str - """Unique identifier for this file""" - - width: int - """Video width as defined by sender""" - - height: int - """Video height as defined by sender""" - - duration: int - """Duration of the video in seconds as defined by sender""" - - thumb: typing.Optional[types.PhotoSize] = None - """Video thumbnail""" - - mime_type: typing.Optional[str] = None - """Mime type of a file as defined by sender""" - - file_size: typing.Optional[int] = None - """File size""" - - -class Animation(pydantic.BaseModel): - """ - This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). - - Source: https://core.telegram.org/bots/api#animation - """ - - file_id: str - """Unique file identifier""" - - width: int - """Video width as defined by sender""" - - height: int - """Video height as defined by sender""" - - duration: int - """Duration of the video in seconds as defined by sender""" - - thumb: typing.Optional[types.PhotoSize] = None - """Animation thumbnail as defined by sender""" - - file_name: typing.Optional[str] = None - """Original animation filename as defined by sender""" - - mime_type: typing.Optional[str] = None - """MIME type of the file as defined by sender""" - - file_size: typing.Optional[int] = None - """File size""" - - -class Voice(pydantic.BaseModel): - """ - This object represents a voice note. - - Source: https://core.telegram.org/bots/api#voice - """ - - file_id: str - """Unique identifier for this file""" - - duration: int - """Duration of the audio in seconds as defined by sender""" - - mime_type: typing.Optional[str] = None - """MIME type of the file as defined by sender""" - - file_size: typing.Optional[int] = None - """File size""" - - -class VideoNote(pydantic.BaseModel): - """ - This object represents a video message (available in Telegram apps as of v.4.0). - - Source: https://core.telegram.org/bots/api#videonote - """ - - file_id: str - """Unique identifier for this file""" - - length: int - """Video width and height (diameter of the video message) as defined by sender""" - - duration: int - """Duration of the video in seconds as defined by sender""" - - thumb: typing.Optional[types.PhotoSize] = None - """Video thumbnail""" - - file_size: typing.Optional[int] = None - """File size""" - - -class Contact(pydantic.BaseModel): - """ - This object represents a phone contact. - - Source: https://core.telegram.org/bots/api#contact - """ - - phone_number: str - """Contact's phone number""" - - first_name: str - """Contact's first name""" - - last_name: typing.Optional[str] = None - """Contact's last name""" - - user_id: typing.Optional[int] = None - """Contact's user identifier in Telegram""" - - vcard: typing.Optional[str] = None - """Additional data about the contact in the form of a vCard""" - - -class Location(pydantic.BaseModel): - """ - This object represents a point on the map. - - Source: https://core.telegram.org/bots/api#location - """ - - longitude: float - """Longitude as defined by sender""" - - latitude: float - """Latitude as defined by sender""" - - -class Venue(pydantic.BaseModel): - """ - This object represents a venue. - - Source: https://core.telegram.org/bots/api#venue - """ - - location: types.Location - """Venue location""" - - title: str - """Name of the venue""" - - address: str - """Address of the venue""" - - foursquare_id: typing.Optional[str] = None - """Foursquare identifier of the venue""" - - foursquare_type: typing.Optional[str] = None - """Foursquare type of the venue. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" - - -class PollOption(pydantic.BaseModel): - """ - This object contains information about one answer option in a poll. - - Source: https://core.telegram.org/bots/api#polloption - """ - - text: str - """Option text, 1-100 characters""" - - voter_count: int - """Number of users that voted for this option""" - - -class Poll(pydantic.BaseModel): - """ - This object contains information about a poll. - - Source: https://core.telegram.org/bots/api#poll - """ - - id: str - """Unique poll identifier""" - - question: str - """Poll question, 1-255 characters""" - - options: typing.List[types.PollOption] - """List of poll options""" - - is_closed: bool - """True, if the poll is closed""" - - -class UserProfilePhotos(pydantic.BaseModel): - """ - This object represent a user's profile pictures. - - Source: https://core.telegram.org/bots/api#userprofilephotos - """ - - total_count: int - """Total number of profile pictures the target user has""" - - photos: typing.List[typing.List[types.PhotoSize]] - """Requested profile pictures (in up to 4 sizes each)""" - - -class File(pydantic.BaseModel): - """ - This object represents a file ready to be downloaded. The file can be downloaded via the link https://api.telegram.org/file/bot/. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile. - Maximum file size to download is 20 MB - - Source: https://core.telegram.org/bots/api#file - """ - - file_id: str - """Unique identifier for this file""" - - file_size: typing.Optional[int] = None - """File size, if known""" - - file_path: typing.Optional[str] = None - """File path. Use https://api.telegram.org/file/bot/ to get the file.""" - - -class ReplyKeyboardMarkup(pydantic.BaseModel): - """ - This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). - - Source: https://core.telegram.org/bots/api#replykeyboardmarkup - """ - - keyboard: typing.List[typing.List[types.KeyboardButton]] - """Array of button rows, each represented by an Array of KeyboardButton objects""" - - resize_keyboard: typing.Optional[bool] = None - """Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.""" - - one_time_keyboard: typing.Optional[bool] = None - """Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat – the user can press a special button in the input field to see the custom keyboard again. Defaults to false.""" - - selective: typing.Optional[bool] = None - """Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. - - Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.""" - - -class KeyboardButton(pydantic.BaseModel): - """ - This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive. - Note: request_contact and request_location options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#keyboardbutton - """ - - text: str - """Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed""" - - request_contact: typing.Optional[bool] = None - """If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only""" - - request_location: typing.Optional[bool] = None - """If True, the user's current location will be sent when the button is pressed. Available in private chats only""" - - -class ReplyKeyboardRemove(pydantic.BaseModel): - """ - Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup). - - Source: https://core.telegram.org/bots/api#replykeyboardremove - """ - - remove_keyboard: bool - """Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)""" - - selective: typing.Optional[bool] = None - """Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. - - Example: A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.""" - - -class InlineKeyboardMarkup(pydantic.BaseModel): - """ - This object represents an inline keyboard that appears right next to the message it belongs to. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will display unsupported message. - - Source: https://core.telegram.org/bots/api#inlinekeyboardmarkup - """ - - inline_keyboard: typing.List[typing.List[types.InlineKeyboardButton]] - """Array of button rows, each represented by an Array of InlineKeyboardButton objects""" - - -class InlineKeyboardButton(pydantic.BaseModel): - """ - This object represents one button of an inline keyboard. You must use exactly one of the optional fields. - - Source: https://core.telegram.org/bots/api#inlinekeyboardbutton - """ - - text: str - """Label text on the button""" - - url: typing.Optional[str] = None - """HTTP or tg:// url to be opened when button is pressed""" - - login_url: typing.Optional[types.LoginUrl] = None - """An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.""" - - callback_data: typing.Optional[str] = None - """Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes""" - - switch_inline_query: typing.Optional[str] = None - """If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. - - Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm… actions – in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.""" - - switch_inline_query_current_chat: typing.Optional[str] = None - """If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. - - This offers a quick way for the user to open your bot in inline mode in the same chat – good for selecting something from multiple options.""" - - callback_game: typing.Optional[types.CallbackGame] = None - """Description of the game that will be launched when the user presses the button. - - NOTE: This type of button must always be the first button in the first row.""" - - pay: typing.Optional[bool] = None - """Specify True, to send a Pay button. - - NOTE: This type of button must always be the first button in the first row.""" - - -class LoginUrl(pydantic.BaseModel): - """ - This object represents a parameter of the inline keyboard button used to automatically authorize a user. Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram. All the user needs to do is tap/click a button and confirm that they want to log in: - Telegram apps support these buttons as of version 5.7. - Sample bot: @discussbot - - Source: https://core.telegram.org/bots/api#loginurl - """ - - url: str - """An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in Receiving authorization data. - - NOTE: You must always check the hash of the received data to verify the authentication and the integrity of the data as described in Checking authorization.""" - - forward_text: typing.Optional[str] = None - """New text of the button in forwarded messages.""" - - bot_username: typing.Optional[str] = None - """Username of a bot, which will be used for user authorization. See Setting up a bot for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the bot. See Linking your domain to the bot for more details.""" - - request_write_access: typing.Optional[bool] = None - """Pass True to request the permission for your bot to send messages to the user.""" - - -class CallbackQuery(pydantic.BaseModel): - """ - This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present. - NOTE: After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery. It is, therefore, necessary to react by calling answerCallbackQuery even if no notification to the user is needed (e.g., without specifying any of the optional parameters). - - Source: https://core.telegram.org/bots/api#callbackquery - """ - - id: str - """Unique identifier for this query""" - - from_user: types.User = pydantic.Schema(..., alias="from") - """Sender""" - - message: typing.Optional[types.Message] = None - """Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old""" - - inline_message_id: typing.Optional[str] = None - """Identifier of the message sent via the bot in inline mode, that originated the query.""" - - chat_instance: str - """Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.""" - - data: typing.Optional[str] = None - """Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.""" - - game_short_name: typing.Optional[str] = None - """Short name of a Game to be returned, serves as the unique identifier for the game""" - - -class ForceReply(pydantic.BaseModel): - """ - Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. - Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). There could be two ways to create a new poll: - - Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). May be appealing for hardcore users but lacks modern day polish. - - Guide the user through a step-by-step process. ‘Please send me your question’, ‘Cool, now let’s add the first answer option‘, ’Great. Keep adding answer options, then send /done when you‘re ready’. - The last option is definitely more attractive. And if you use ForceReply in your bot‘s questions, it will receive the user’s answers even if it only receives replies, commands and mentions — without any extra work for the user. - - Source: https://core.telegram.org/bots/api#forcereply - """ - - force_reply: bool - """Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'""" - - selective: typing.Optional[bool] = None - """Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.""" - - -class ChatPhoto(pydantic.BaseModel): - """ - This object represents a chat photo. - - Source: https://core.telegram.org/bots/api#chatphoto - """ - - small_file_id: str - """Unique file identifier of small (160x160) chat photo. This file_id can be used only for photo download.""" - - big_file_id: str - """Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download.""" - - -class ChatMember(pydantic.BaseModel): - """ - This object contains information about one member of a chat. - - Source: https://core.telegram.org/bots/api#chatmember - """ - - user: types.User - """Information about the user""" - - status: str - """The member's status in the chat. Can be 'creator', 'administrator', 'member', 'restricted', 'left' or 'kicked'""" - - until_date: typing.Optional[int] = None - """Restricted and kicked only. Date when restrictions will be lifted for this user, unix time""" - - can_be_edited: typing.Optional[bool] = None - """Administrators only. True, if the bot is allowed to edit administrator privileges of that user""" - - can_change_info: typing.Optional[bool] = None - """Administrators only. True, if the administrator can change the chat title, photo and other settings""" - - can_post_messages: typing.Optional[bool] = None - """Administrators only. True, if the administrator can post in the channel, channels only""" - - can_edit_messages: typing.Optional[bool] = None - """Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only""" - - can_delete_messages: typing.Optional[bool] = None - """Administrators only. True, if the administrator can delete messages of other users""" - - can_invite_users: typing.Optional[bool] = None - """Administrators only. True, if the administrator can invite new users to the chat""" - - can_restrict_members: typing.Optional[bool] = None - """Administrators only. True, if the administrator can restrict, ban or unban chat members""" - - can_pin_messages: typing.Optional[bool] = None - """Administrators only. True, if the administrator can pin messages, groups and supergroups only""" - - can_promote_members: typing.Optional[bool] = None - """Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)""" - - is_member: typing.Optional[bool] = None - """Restricted only. True, if the user is a member of the chat at the moment of the request""" - - can_send_messages: typing.Optional[bool] = None - """Restricted only. True, if the user can send text messages, contacts, locations and venues""" - - can_send_media_messages: typing.Optional[bool] = None - """Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages""" - - can_send_other_messages: typing.Optional[bool] = None - """Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages""" - - can_add_web_page_previews: typing.Optional[bool] = None - """Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages""" - - -class ResponseParameters(pydantic.BaseModel): - """ - Contains information about why a request was unsuccessful. - - Source: https://core.telegram.org/bots/api#responseparameters - """ - - migrate_to_chat_id: typing.Optional[int] = None - """The group has been migrated to a supergroup with the specified identifier. This number 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.""" - - retry_after: typing.Optional[int] = None - """In case of exceeding flood control, the number of seconds left to wait before the request can be repeated""" - - -class InputMedia(pydantic.BaseModel): - """ - This object represents the content of a media message to be sent. It should be one of - - InputMediaAnimation - - InputMediaDocument - - InputMediaAudio - - InputMediaPhoto - - InputMediaVideo - - Source: https://core.telegram.org/bots/api#inputmedia - """ - - pass - - -class InputMediaPhoto(pydantic.BaseModel): - """ - Represents a photo to be sent. - - Source: https://core.telegram.org/bots/api#inputmediaphoto - """ - - type: str - """Type of the result, must be photo""" - - media: str - """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" - - caption: typing.Optional[str] = None - """Caption of the photo to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - -class InputMediaVideo(pydantic.BaseModel): - """ - Represents a video to be sent. - - Source: https://core.telegram.org/bots/api#inputmediavideo - """ - - type: str - """Type of the result, must be video""" - - media: str - """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" - - thumb: typing.Optional[types.InputFile, str] = None - """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 .""" - - caption: typing.Optional[str] = None - """Caption of the video to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - width: typing.Optional[int] = None - """Video width""" - - height: typing.Optional[int] = None - """Video height""" - - duration: typing.Optional[int] = None - """Video duration""" - - supports_streaming: typing.Optional[bool] = None - """Pass True, if the uploaded video is suitable for streaming""" - - -class InputMediaAnimation(pydantic.BaseModel): - """ - Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. - - Source: https://core.telegram.org/bots/api#inputmediaanimation - """ - - type: str - """Type of the result, must be animation""" - - media: str - """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" - - thumb: typing.Optional[types.InputFile, str] = None - """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 .""" - - caption: typing.Optional[str] = None - """Caption of the animation to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - width: typing.Optional[int] = None - """Animation width""" - - height: typing.Optional[int] = None - """Animation height""" - - duration: typing.Optional[int] = None - """Animation duration""" - - -class InputMediaAudio(pydantic.BaseModel): - """ - Represents an audio file to be treated as music to be sent. - - Source: https://core.telegram.org/bots/api#inputmediaaudio - """ - - type: str - """Type of the result, must be audio""" - - media: str - """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" - - thumb: typing.Optional[types.InputFile, str] = None - """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 .""" - - caption: typing.Optional[str] = None - """Caption of the audio to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - duration: typing.Optional[int] = None - """Duration of the audio in seconds""" - - performer: typing.Optional[str] = None - """Performer of the audio""" - - title: typing.Optional[str] = None - """Title of the audio""" - - -class InputMediaDocument(pydantic.BaseModel): - """ - Represents a general file to be sent. - - Source: https://core.telegram.org/bots/api#inputmediadocument - """ - - type: str - """Type of the result, must be document""" - - media: str - """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" - - thumb: typing.Optional[types.InputFile, str] = None - """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 .""" - - caption: typing.Optional[str] = None - """Caption of the document to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - -class InputFile(pydantic.BaseModel): - """ - This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser. - - Source: https://core.telegram.org/bots/api#inputfile - """ - - pass - - -# %% End of region 'Available types' - -# %% Region: 'Available methods' -""" -All methods in the Bot API are case-insensitive. We support GET and POST HTTP methods. Use either URL query string or application/json or application/x-www-form-urlencoded or multipart/form-data for passing parameters in Bot API requests. -On successful call, a JSON-object containing the result will be returned. - -link: https://core.telegram.org/bots/api#available-methods -""" - -# %% End of region 'Available methods' - -# %% Region: 'Updating messages' -""" -The following methods allow you to change an existing message in the message history instead of sending a new one with a result of an action. This is most useful for messages with inline keyboards using callback queries, but can also help reduce clutter in conversations with regular chat bots. -Please note, that it is currently only possible to edit messages without reply_markup or with inline keyboards. - -link: https://core.telegram.org/bots/api#updating-messages -""" - -# %% End of region 'Updating messages' - -# %% Region: 'Stickers' -""" -The following methods and objects allow your bot to handle stickers and sticker sets. - -link: https://core.telegram.org/bots/api#stickers -""" - - -class Sticker(pydantic.BaseModel): - """ - This object represents a sticker. - - Source: https://core.telegram.org/bots/api#sticker - """ - - file_id: str - """Unique identifier for this file""" - - width: int - """Sticker width""" - - height: int - """Sticker height""" - - thumb: typing.Optional[types.PhotoSize] = None - """Sticker thumbnail in the .webp or .jpg format""" - - emoji: typing.Optional[str] = None - """Emoji associated with the sticker""" - - set_name: typing.Optional[str] = None - """Name of the sticker set to which the sticker belongs""" - - mask_position: typing.Optional[types.MaskPosition] = None - """For mask stickers, the position where the mask should be placed""" - - file_size: typing.Optional[int] = None - """File size""" - - -class StickerSet(pydantic.BaseModel): - """ - This object represents a sticker set. - - Source: https://core.telegram.org/bots/api#stickerset - """ - - name: str - """Sticker set name""" - - title: str - """Sticker set title""" - - contains_masks: bool - """True, if the sticker set contains masks""" - - stickers: typing.List[types.Sticker] - """List of all set stickers""" - - -class MaskPosition(pydantic.BaseModel): - """ - This object describes the position on faces where a mask should be placed by default. - - Source: https://core.telegram.org/bots/api#maskposition - """ - - point: str - """The part of the face relative to which the mask should be placed. One of 'forehead', 'eyes', 'mouth', or 'chin'.""" - - x_shift: float - """Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position.""" - - y_shift: float - """Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position.""" - - scale: float - """Mask scaling coefficient. For example, 2.0 means double size.""" - - -# %% End of region 'Stickers' - -# %% Region: 'Inline mode' -""" -The following methods and objects allow your bot to work in inline mode. -Please see our Introduction to Inline bots for more details. -To enable this option, send the /setinline command to @BotFather and provide the placeholder text that the user will see in the input field after typing your bot’s name. - -link: https://core.telegram.org/bots/api#inline-mode -""" - - -class InlineQuery(pydantic.BaseModel): - """ - This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results. - - Source: https://core.telegram.org/bots/api#inlinequery - """ - - id: str - """Unique identifier for this query""" - - from_user: types.User = pydantic.Schema(..., alias="from") - """Sender""" - - location: typing.Optional[types.Location] = None - """Sender location, only for bots that request user location""" - - query: str - """Text of the query (up to 512 characters)""" - - offset: str - """Offset of the results to be returned, can be controlled by the bot""" - - -class InlineQueryResult(pydantic.BaseModel): - """ - This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: - - InlineQueryResultCachedAudio - - InlineQueryResultCachedDocument - - InlineQueryResultCachedGif - - InlineQueryResultCachedMpeg4Gif - - InlineQueryResultCachedPhoto - - InlineQueryResultCachedSticker - - InlineQueryResultCachedVideo - - InlineQueryResultCachedVoice - - InlineQueryResultArticle - - InlineQueryResultAudio - - InlineQueryResultContact - - InlineQueryResultGame - - InlineQueryResultDocument - - InlineQueryResultGif - - InlineQueryResultLocation - - InlineQueryResultMpeg4Gif - - InlineQueryResultPhoto - - InlineQueryResultVenue - - InlineQueryResultVideo - - InlineQueryResultVoice - - Source: https://core.telegram.org/bots/api#inlinequeryresult - """ - - pass - - -class InlineQueryResultArticle(pydantic.BaseModel): - """ - Represents a link to an article or web page. - - Source: https://core.telegram.org/bots/api#inlinequeryresultarticle - """ - - type: str - """Type of the result, must be article""" - - id: str - """Unique identifier for this result, 1-64 Bytes""" - - title: str - """Title of the result""" - - input_message_content: types.InputMessageContent - """Content of the message to be sent""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - url: typing.Optional[str] = None - """URL of the result""" - - hide_url: typing.Optional[bool] = None - """Pass True, if you don't want the URL to be shown in the message""" - - description: typing.Optional[str] = None - """Short description of the result""" - - thumb_url: typing.Optional[str] = None - """Url of the thumbnail for the result""" - - thumb_width: typing.Optional[int] = None - """Thumbnail width""" - - thumb_height: typing.Optional[int] = None - """Thumbnail height""" - - -class InlineQueryResultPhoto(pydantic.BaseModel): - """ - Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. - - Source: https://core.telegram.org/bots/api#inlinequeryresultphoto - """ - - type: str - """Type of the result, must be photo""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - photo_url: str - """A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB""" - - thumb_url: str - """URL of the thumbnail for the photo""" - - photo_width: typing.Optional[int] = None - """Width of the photo""" - - photo_height: typing.Optional[int] = None - """Height of the photo""" - - title: typing.Optional[str] = None - """Title for the result""" - - description: typing.Optional[str] = None - """Short description of the result""" - - caption: typing.Optional[str] = None - """Caption of the photo to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the photo""" - - -class InlineQueryResultGif(pydantic.BaseModel): - """ - Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. - - Source: https://core.telegram.org/bots/api#inlinequeryresultgif - """ - - type: str - """Type of the result, must be gif""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - gif_url: str - """A valid URL for the GIF file. File size must not exceed 1MB""" - - gif_width: typing.Optional[int] = None - """Width of the GIF""" - - gif_height: typing.Optional[int] = None - """Height of the GIF""" - - gif_duration: typing.Optional[int] = None - """Duration of the GIF""" - - thumb_url: str - """URL of the static thumbnail for the result (jpeg or gif)""" - - title: typing.Optional[str] = None - """Title for the result""" - - caption: typing.Optional[str] = None - """Caption of the GIF file to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the GIF animation""" - - -class InlineQueryResultMpeg4Gif(pydantic.BaseModel): - """ - Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. - - Source: https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif - """ - - type: str - """Type of the result, must be mpeg4_gif""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - mpeg4_url: str - """A valid URL for the MP4 file. File size must not exceed 1MB""" - - mpeg4_width: typing.Optional[int] = None - """Video width""" - - mpeg4_height: typing.Optional[int] = None - """Video height""" - - mpeg4_duration: typing.Optional[int] = None - """Video duration""" - - thumb_url: str - """URL of the static thumbnail (jpeg or gif) for the result""" - - title: typing.Optional[str] = None - """Title for the result""" - - caption: typing.Optional[str] = None - """Caption of the MPEG-4 file to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the video animation""" - - -class InlineQueryResultVideo(pydantic.BaseModel): - """ - Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. - If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must replace its content using input_message_content. - - Source: https://core.telegram.org/bots/api#inlinequeryresultvideo - """ - - type: str - """Type of the result, must be video""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - video_url: str - """A valid URL for the embedded video player or video file""" - - mime_type: str - """Mime type of the content of video url, 'text/html' or 'video/mp4'""" - - thumb_url: str - """URL of the thumbnail (jpeg only) for the video""" - - title: str - """Title for the result""" - - caption: typing.Optional[str] = None - """Caption of the video to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - video_width: typing.Optional[int] = None - """Video width""" - - video_height: typing.Optional[int] = None - """Video height""" - - video_duration: typing.Optional[int] = None - """Video duration in seconds""" - - description: typing.Optional[str] = None - """Short description of the result""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video).""" - - -class InlineQueryResultAudio(pydantic.BaseModel): - """ - Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultaudio - """ - - type: str - """Type of the result, must be audio""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - audio_url: str - """A valid URL for the audio file""" - - title: str - """Title""" - - caption: typing.Optional[str] = None - """Caption, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - performer: typing.Optional[str] = None - """Performer""" - - audio_duration: typing.Optional[int] = None - """Audio duration in seconds""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the audio""" - - -class InlineQueryResultVoice(pydantic.BaseModel): - """ - Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultvoice - """ - - type: str - """Type of the result, must be voice""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - voice_url: str - """A valid URL for the voice recording""" - - title: str - """Recording title""" - - caption: typing.Optional[str] = None - """Caption, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - voice_duration: typing.Optional[int] = None - """Recording duration in seconds""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the voice recording""" - - -class InlineQueryResultDocument(pydantic.BaseModel): - """ - Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultdocument - """ - - type: str - """Type of the result, must be document""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - title: str - """Title for the result""" - - caption: typing.Optional[str] = None - """Caption of the document to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - document_url: str - """A valid URL for the file""" - - mime_type: str - """Mime type of the content of the file, either 'application/pdf' or 'application/zip'""" - - description: typing.Optional[str] = None - """Short description of the result""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the file""" - - thumb_url: typing.Optional[str] = None - """URL of the thumbnail (jpeg only) for the file""" - - thumb_width: typing.Optional[int] = None - """Thumbnail width""" - - thumb_height: typing.Optional[int] = None - """Thumbnail height""" - - -class InlineQueryResultLocation(pydantic.BaseModel): - """ - Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultlocation - """ - - type: str - """Type of the result, must be location""" - - id: str - """Unique identifier for this result, 1-64 Bytes""" - - latitude: float - """Location latitude in degrees""" - - longitude: float - """Location longitude in degrees""" - - title: str - """Location title""" - - live_period: typing.Optional[int] = None - """Period in seconds for which the location can be updated, should be between 60 and 86400.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the location""" - - thumb_url: typing.Optional[str] = None - """Url of the thumbnail for the result""" - - thumb_width: typing.Optional[int] = None - """Thumbnail width""" - - thumb_height: typing.Optional[int] = None - """Thumbnail height""" - - -class InlineQueryResultVenue(pydantic.BaseModel): - """ - Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultvenue - """ - - type: str - """Type of the result, must be venue""" - - id: str - """Unique identifier for this result, 1-64 Bytes""" - - latitude: float - """Latitude of the venue location in degrees""" - - longitude: float - """Longitude of the venue location in degrees""" - - title: str - """Title of the venue""" - - address: str - """Address of the venue""" - - foursquare_id: typing.Optional[str] = None - """Foursquare identifier of the venue if known""" - - foursquare_type: typing.Optional[str] = None - """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the venue""" - - thumb_url: typing.Optional[str] = None - """Url of the thumbnail for the result""" - - thumb_width: typing.Optional[int] = None - """Thumbnail width""" - - thumb_height: typing.Optional[int] = None - """Thumbnail height""" - - -class InlineQueryResultContact(pydantic.BaseModel): - """ - Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcontact - """ - - type: str - """Type of the result, must be contact""" - - id: str - """Unique identifier for this result, 1-64 Bytes""" - - phone_number: str - """Contact's phone number""" - - first_name: str - """Contact's first name""" - - last_name: typing.Optional[str] = None - """Contact's last name""" - - vcard: typing.Optional[str] = None - """Additional data about the contact in the form of a vCard, 0-2048 bytes""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the contact""" - - thumb_url: typing.Optional[str] = None - """Url of the thumbnail for the result""" - - thumb_width: typing.Optional[int] = None - """Thumbnail width""" - - thumb_height: typing.Optional[int] = None - """Thumbnail height""" - - -class InlineQueryResultGame(pydantic.BaseModel): - """ - Represents a Game. - Note: This will only work in Telegram versions released after October 1, 2016. Older clients will not display any inline results if a game result is among them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultgame - """ - - type: str - """Type of the result, must be game""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - game_short_name: str - """Short name of the game""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - -class InlineQueryResultCachedPhoto(pydantic.BaseModel): - """ - Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedphoto - """ - - type: str - """Type of the result, must be photo""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - photo_file_id: str - """A valid file identifier of the photo""" - - title: typing.Optional[str] = None - """Title for the result""" - - description: typing.Optional[str] = None - """Short description of the result""" - - caption: typing.Optional[str] = None - """Caption of the photo to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the photo""" - - -class InlineQueryResultCachedGif(pydantic.BaseModel): - """ - Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedgif - """ - - type: str - """Type of the result, must be gif""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - gif_file_id: str - """A valid file identifier for the GIF file""" - - title: typing.Optional[str] = None - """Title for the result""" - - caption: typing.Optional[str] = None - """Caption of the GIF file to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the GIF animation""" - - -class InlineQueryResultCachedMpeg4Gif(pydantic.BaseModel): - """ - Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif - """ - - type: str - """Type of the result, must be mpeg4_gif""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - mpeg4_file_id: str - """A valid file identifier for the MP4 file""" - - title: typing.Optional[str] = None - """Title for the result""" - - caption: typing.Optional[str] = None - """Caption of the MPEG-4 file to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the video animation""" - - -class InlineQueryResultCachedSticker(pydantic.BaseModel): - """ - Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedsticker - """ - - type: str - """Type of the result, must be sticker""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - sticker_file_id: str - """A valid file identifier of the sticker""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the sticker""" - - -class InlineQueryResultCachedDocument(pydantic.BaseModel): - """ - Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcacheddocument - """ - - type: str - """Type of the result, must be document""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - title: str - """Title for the result""" - - document_file_id: str - """A valid file identifier for the file""" - - description: typing.Optional[str] = None - """Short description of the result""" - - caption: typing.Optional[str] = None - """Caption of the document to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the file""" - - -class InlineQueryResultCachedVideo(pydantic.BaseModel): - """ - Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvideo - """ - - type: str - """Type of the result, must be video""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - video_file_id: str - """A valid file identifier for the video file""" - - title: str - """Title for the result""" - - description: typing.Optional[str] = None - """Short description of the result""" - - caption: typing.Optional[str] = None - """Caption of the video to be sent, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the video""" - - -class InlineQueryResultCachedVoice(pydantic.BaseModel): - """ - Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvoice - """ - - type: str - """Type of the result, must be voice""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - voice_file_id: str - """A valid file identifier for the voice message""" - - title: str - """Voice message title""" - - caption: typing.Optional[str] = None - """Caption, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the voice message""" - - -class InlineQueryResultCachedAudio(pydantic.BaseModel): - """ - Represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. - Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. - - Source: https://core.telegram.org/bots/api#inlinequeryresultcachedaudio - """ - - type: str - """Type of the result, must be audio""" - - id: str - """Unique identifier for this result, 1-64 bytes""" - - audio_file_id: str - """A valid file identifier for the audio file""" - - caption: typing.Optional[str] = None - """Caption, 0-1024 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" - - reply_markup: typing.Optional[types.InlineKeyboardMarkup] = None - """Inline keyboard attached to the message""" - - input_message_content: typing.Optional[types.InputMessageContent] = None - """Content of the message to be sent instead of the audio""" - - -class InputMessageContent(pydantic.BaseModel): - """ - 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: - - InputTextMessageContent - - InputLocationMessageContent - - InputVenueMessageContent - - InputContactMessageContent - - Source: https://core.telegram.org/bots/api#inputmessagecontent - """ - - pass - - -class InputTextMessageContent(pydantic.BaseModel): - """ - Represents the content of a text message to be sent as the result of an inline query. - - Source: https://core.telegram.org/bots/api#inputtextmessagecontent - """ - - message_text: str - """Text of the message to be sent, 1-4096 characters""" - - parse_mode: typing.Optional[str] = None - """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.""" - - disable_web_page_preview: typing.Optional[bool] = None - """Disables link previews for links in the sent message""" - - -class InputLocationMessageContent(pydantic.BaseModel): - """ - Represents the content of a location message to be sent as the result of an inline query. - - Source: https://core.telegram.org/bots/api#inputlocationmessagecontent - """ - - latitude: float - """Latitude of the location in degrees""" - - longitude: float - """Longitude of the location in degrees""" - - live_period: typing.Optional[int] = None - """Period in seconds for which the location can be updated, should be between 60 and 86400.""" - - -class InputVenueMessageContent(pydantic.BaseModel): - """ - Represents the content of a venue message to be sent as the result of an inline query. - - Source: https://core.telegram.org/bots/api#inputvenuemessagecontent - """ - - latitude: float - """Latitude of the venue in degrees""" - - longitude: float - """Longitude of the venue in degrees""" - - title: str - """Name of the venue""" - - address: str - """Address of the venue""" - - foursquare_id: typing.Optional[str] = None - """Foursquare identifier of the venue, if known""" - - foursquare_type: typing.Optional[str] = None - """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" - - -class InputContactMessageContent(pydantic.BaseModel): - """ - Represents the content of a contact message to be sent as the result of an inline query. - - Source: https://core.telegram.org/bots/api#inputcontactmessagecontent - """ - - phone_number: str - """Contact's phone number""" - - first_name: str - """Contact's first name""" - - last_name: typing.Optional[str] = None - """Contact's last name""" - - vcard: typing.Optional[str] = None - """Additional data about the contact in the form of a vCard, 0-2048 bytes""" - - -class ChosenInlineResult(pydantic.BaseModel): - """ - Represents a result of an inline query that was chosen by the user and sent to their chat partner. - Note: It is necessary to enable inline feedback via @Botfather in order to receive these objects in updates. - - Source: https://core.telegram.org/bots/api#choseninlineresult - """ - - result_id: str - """The unique identifier for the result that was chosen""" - - from_user: types.User = pydantic.Schema(..., alias="from") - """The user that chose the result""" - - location: typing.Optional[types.Location] = None - """Sender location, only for bots that require user location""" - - inline_message_id: typing.Optional[str] = None - """Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.""" - - query: str - """The query that was used to obtain the result""" - - -# %% End of region 'Inline mode' - -# %% Region: 'Payments' -""" -Your bot can accept payments from Telegram users. Please see the introduction to payments for more details on the process and how to set up payments for your bot. Please note that users will need Telegram v.4.0 or higher to use payments (released on May 18, 2017). - -link: https://core.telegram.org/bots/api#payments -""" - - -class LabeledPrice(pydantic.BaseModel): - """ - This object represents a portion of the price for goods or services. - - Source: https://core.telegram.org/bots/api#labeledprice - """ - - label: str - """Portion label""" - - amount: int - """Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" - - -class Invoice(pydantic.BaseModel): - """ - This object contains basic information about an invoice. - - Source: https://core.telegram.org/bots/api#invoice - """ - - title: str - """Product name""" - - description: str - """Product description""" - - start_parameter: str - """Unique bot deep-linking parameter that can be used to generate this invoice""" - - currency: str - """Three-letter ISO 4217 currency code""" - - total_amount: int - """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" - - -class ShippingAddress(pydantic.BaseModel): - """ - This object represents a shipping address. - - Source: https://core.telegram.org/bots/api#shippingaddress - """ - - country_code: str - """ISO 3166-1 alpha-2 country code""" - - state: str - """State, if applicable""" - - city: str - """City""" - - street_line1: str - """First line for the address""" - - street_line2: str - """Second line for the address""" - - post_code: str - """Address post code""" - - -class OrderInfo(pydantic.BaseModel): - """ - This object represents information about an order. - - Source: https://core.telegram.org/bots/api#orderinfo - """ - - name: typing.Optional[str] = None - """User name""" - - phone_number: typing.Optional[str] = None - """User's phone number""" - - email: typing.Optional[str] = None - """User email""" - - shipping_address: typing.Optional[types.ShippingAddress] = None - """User shipping address""" - - -class ShippingOption(pydantic.BaseModel): - """ - This object represents one shipping option. - - Source: https://core.telegram.org/bots/api#shippingoption - """ - - id: str - """Shipping option identifier""" - - title: str - """Option title""" - - prices: typing.List[types.LabeledPrice] - """List of price portions""" - - -class SuccessfulPayment(pydantic.BaseModel): - """ - This object contains basic information about a successful payment. - - Source: https://core.telegram.org/bots/api#successfulpayment - """ - - currency: str - """Three-letter ISO 4217 currency code""" - - total_amount: int - """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" - - invoice_payload: str - """Bot specified invoice payload""" - - shipping_option_id: typing.Optional[str] = None - """Identifier of the shipping option chosen by the user""" - - order_info: typing.Optional[types.OrderInfo] = None - """Order info provided by the user""" - - telegram_payment_charge_id: str - """Telegram payment identifier""" - - provider_payment_charge_id: str - """Provider payment identifier""" - - -class ShippingQuery(pydantic.BaseModel): - """ - This object contains information about an incoming shipping query. - - Source: https://core.telegram.org/bots/api#shippingquery - """ - - id: str - """Unique query identifier""" - - from_user: types.User = pydantic.Schema(..., alias="from") - """User who sent the query""" - - invoice_payload: str - """Bot specified invoice payload""" - - shipping_address: types.ShippingAddress - """User specified shipping address""" - - -class PreCheckoutQuery(pydantic.BaseModel): - """ - This object contains information about an incoming pre-checkout query. - - Source: https://core.telegram.org/bots/api#precheckoutquery - """ - - id: str - """Unique query identifier""" - - from_user: types.User = pydantic.Schema(..., alias="from") - """User who sent the query""" - - currency: str - """Three-letter ISO 4217 currency code""" - - total_amount: int - """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" - - invoice_payload: str - """Bot specified invoice payload""" - - shipping_option_id: typing.Optional[str] = None - """Identifier of the shipping option chosen by the user""" - - order_info: typing.Optional[types.OrderInfo] = None - """Order info provided by the user""" - - -# %% End of region 'Payments' - -# %% Region: 'Telegram Passport' -""" -Telegram Passport is a unified authorization method for services that require personal identification. Users can upload their documents once, then instantly share their data with services that require real-world ID (finance, ICOs, etc.). Please see the manual for details. - -link: https://core.telegram.org/bots/api#telegram-passport -""" - - -class PassportData(pydantic.BaseModel): - """ - Contains information about Telegram Passport data shared with the bot by the user. - - Source: https://core.telegram.org/bots/api#passportdata - """ - - data: typing.List[types.EncryptedPassportElement] - """Array with information about documents and other Telegram Passport elements that was shared with the bot""" - - credentials: types.EncryptedCredentials - """Encrypted credentials required to decrypt the data""" - - -class PassportFile(pydantic.BaseModel): - """ - This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB. - - Source: https://core.telegram.org/bots/api#passportfile - """ - - file_id: str - """Unique identifier for this file""" - - file_size: int - """File size""" - - file_date: int - """Unix time when the file was uploaded""" - - -class EncryptedPassportElement(pydantic.BaseModel): - """ - Contains information about documents or other Telegram Passport elements shared with the bot by the user. - - Source: https://core.telegram.org/bots/api#encryptedpassportelement - """ - - type: str - """Element type. One of 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport', 'address', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration', 'phone_number', 'email'.""" - - data: typing.Optional[str] = None - """Base64-encoded encrypted Telegram Passport element data provided by the user, available for 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport' and 'address' types. Can be decrypted and verified using the accompanying EncryptedCredentials.""" - - phone_number: typing.Optional[str] = None - """User's verified phone number, available only for 'phone_number' type""" - - email: typing.Optional[str] = None - """User's verified email address, available only for 'email' type""" - - files: typing.Optional[typing.List[types.PassportFile]] = None - """Array of encrypted files with documents provided by the user, available for 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration' and 'temporary_registration' types. Files can be decrypted and verified using the accompanying EncryptedCredentials.""" - - front_side: typing.Optional[types.PassportFile] = None - """Encrypted file with the front side of the document, provided by the user. Available for 'passport', 'driver_license', 'identity_card' and 'internal_passport'. The file can be decrypted and verified using the accompanying EncryptedCredentials.""" - - reverse_side: typing.Optional[types.PassportFile] = None - """Encrypted file with the reverse side of the document, provided by the user. Available for 'driver_license' and 'identity_card'. The file can be decrypted and verified using the accompanying EncryptedCredentials.""" - - selfie: typing.Optional[types.PassportFile] = None - """Encrypted file with the selfie of the user holding a document, provided by the user; available for 'passport', 'driver_license', 'identity_card' and 'internal_passport'. The file can be decrypted and verified using the accompanying EncryptedCredentials.""" - - translation: typing.Optional[typing.List[types.PassportFile]] = None - """Array of encrypted files with translated versions of documents provided by the user. Available if requested for 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration' and 'temporary_registration' types. Files can be decrypted and verified using the accompanying EncryptedCredentials.""" - - hash: str - """Base64-encoded element hash for using in PassportElementErrorUnspecified""" - - -class EncryptedCredentials(pydantic.BaseModel): - """ - Contains data required for decrypting and authenticating EncryptedPassportElement. See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes. - - Source: https://core.telegram.org/bots/api#encryptedcredentials - """ - - data: str - """Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for EncryptedPassportElement decryption and authentication""" - - hash: str - """Base64-encoded data hash for data authentication""" - - secret: str - """Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption""" - - -class PassportElementError(pydantic.BaseModel): - """ - This object represents an error in the Telegram Passport element which was submitted that should be resolved by the user. It should be one of: - - PassportElementErrorDataField - - PassportElementErrorFrontSide - - PassportElementErrorReverseSide - - PassportElementErrorSelfie - - PassportElementErrorFile - - PassportElementErrorFiles - - PassportElementErrorTranslationFile - - PassportElementErrorTranslationFiles - - PassportElementErrorUnspecified - - Source: https://core.telegram.org/bots/api#passportelementerror - """ - - pass - - -class PassportElementErrorDataField(pydantic.BaseModel): - """ - Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes. - - Source: https://core.telegram.org/bots/api#passportelementerrordatafield - """ - - source: str - """Error source, must be data""" - - type: str - """The section of the user's Telegram Passport which has the error, one of 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport', 'address'""" - - field_name: str - """Name of the data field which has the error""" - - data_hash: str - """Base64-encoded data hash""" - - message: str - """Error message""" - - -class PassportElementErrorFrontSide(pydantic.BaseModel): - """ - Represents an issue with the front side of a document. The error is considered resolved when the file with the front side of the document changes. - - Source: https://core.telegram.org/bots/api#passportelementerrorfrontside - """ - - source: str - """Error source, must be front_side""" - - type: str - """The section of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport'""" - - file_hash: str - """Base64-encoded hash of the file with the front side of the document""" - - message: str - """Error message""" - - -class PassportElementErrorReverseSide(pydantic.BaseModel): - """ - Represents an issue with the reverse side of a document. The error is considered resolved when the file with reverse side of the document changes. - - Source: https://core.telegram.org/bots/api#passportelementerrorreverseside - """ - - source: str - """Error source, must be reverse_side""" - - type: str - """The section of the user's Telegram Passport which has the issue, one of 'driver_license', 'identity_card'""" - - file_hash: str - """Base64-encoded hash of the file with the reverse side of the document""" - - message: str - """Error message""" - - -class PassportElementErrorSelfie(pydantic.BaseModel): - """ - Represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes. - - Source: https://core.telegram.org/bots/api#passportelementerrorselfie - """ - - source: str - """Error source, must be selfie""" - - type: str - """The section of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport'""" - - file_hash: str - """Base64-encoded hash of the file with the selfie""" - - message: str - """Error message""" - - -class PassportElementErrorFile(pydantic.BaseModel): - """ - Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes. - - Source: https://core.telegram.org/bots/api#passportelementerrorfile - """ - - source: str - """Error source, must be file""" - - type: str - """The section of the user's Telegram Passport which has the issue, one of 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" - - file_hash: str - """Base64-encoded file hash""" - - message: str - """Error message""" - - -class PassportElementErrorFiles(pydantic.BaseModel): - """ - Represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes. - - Source: https://core.telegram.org/bots/api#passportelementerrorfiles - """ - - source: str - """Error source, must be files""" - - type: str - """The section of the user's Telegram Passport which has the issue, one of 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" - - file_hashes: typing.List[str] - """List of base64-encoded file hashes""" - - message: str - """Error message""" - - -class PassportElementErrorTranslationFile(pydantic.BaseModel): - """ - Represents an issue with one of the files that constitute the translation of a document. The error is considered resolved when the file changes. - - Source: https://core.telegram.org/bots/api#passportelementerrortranslationfile - """ - - source: str - """Error source, must be translation_file""" - - type: str - """Type of element of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" - - file_hash: str - """Base64-encoded file hash""" - - message: str - """Error message""" - - -class PassportElementErrorTranslationFiles(pydantic.BaseModel): - """ - Represents an issue with the translated version of a document. The error is considered resolved when a file with the document translation change. - - Source: https://core.telegram.org/bots/api#passportelementerrortranslationfiles - """ - - source: str - """Error source, must be translation_files""" - - type: str - """Type of element of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" - - file_hashes: typing.List[str] - """List of base64-encoded file hashes""" - - message: str - """Error message""" - - -class PassportElementErrorUnspecified(pydantic.BaseModel): - """ - Represents an issue in an unspecified place. The error is considered resolved when new data is added. - - Source: https://core.telegram.org/bots/api#passportelementerrorunspecified - """ - - source: str - """Error source, must be unspecified""" - - type: str - """Type of element of the user's Telegram Passport which has the issue""" - - element_hash: str - """Base64-encoded element hash""" - - message: str - """Error message""" - - -# %% End of region 'Telegram Passport' - -# %% Region: 'Games' -""" -link: https://core.telegram.org/bots/api#games -""" - - -class Games(pydantic.BaseModel): - """ - Your bot can offer users HTML5 games to play solo or to compete against each other in groups and one-on-one chats. Create games via @BotFather using the /newgame command. Please note that this kind of power requires responsibility: you will need to accept the terms for each game that your bots will be offering. - - Games are a new type of content on Telegram, represented by the Game and InlineQueryResultGame objects. - - Once you've created a game via BotFather, you can send games to chats as regular messages using the sendGame method, or use inline mode with InlineQueryResultGame. - - If you send the game message without any buttons, it will automatically have a 'Play GameName' button. When this button is pressed, your bot gets a CallbackQuery with the game_short_name of the requested game. You provide the correct URL for this particular user and the app opens the game in the in-app browser. - - You can manually add multiple buttons to your game message. Please note that the first button in the first row must always launch the game, using the field callback_game in InlineKeyboardButton. You can add extra buttons according to taste: e.g., for a description of the rules, or to open the game's official community. - - To make your game more attractive, you can upload a GIF animation that demostrates the game to the users via BotFather (see Lumberjack for example). - - A game message will also display high scores for the current chat. Use setGameScore to post high scores to the chat with the game, add the edit_message parameter to automatically update the message with the current scoreboard. - - Use getGameHighScores to get data for in-game high score tables. - - You can also add an extra sharing button for users to share their best score to different chats. - - For examples of what can be done using this new stuff, check the @gamebot and @gamee bots. - - Source: https://core.telegram.org/bots/api#games - """ - - pass - - -class Game(pydantic.BaseModel): - """ - This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. - - Source: https://core.telegram.org/bots/api#game - """ - - title: str - """Title of the game""" - - description: str - """Description of the game""" - - photo: typing.List[types.PhotoSize] - """Photo that will be displayed in the game message in chats.""" - - text: typing.Optional[str] = None - """Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.""" - - text_entities: typing.Optional[typing.List[types.MessageEntity]] = None - """Special entities that appear in text, such as usernames, URLs, bot commands, etc.""" - - animation: typing.Optional[types.Animation] = None - """Animation that will be displayed in the game message in chats. Upload via BotFather""" - - -class CallbackGame(pydantic.BaseModel): - """ - A placeholder, currently holds no information. Use BotFather to set up your game. - - Source: https://core.telegram.org/bots/api#callbackgame - """ - - pass - - -class GameHighScore(pydantic.BaseModel): - """ - This object represents one row of the high scores table for a game. - And that‘s about all we’ve got for now. - If you've got any questions, please check out our Bot FAQ - - Source: https://core.telegram.org/bots/api#gamehighscore - """ - - position: int - """Position in high score table for the game""" - - user: types.User - """User""" - - score: int - """Score""" - - -# %% End of region 'Games' diff --git a/aiogram/_telegram/__init__.py b/aiogram/api/__init__.py similarity index 100% rename from aiogram/_telegram/__init__.py rename to aiogram/api/__init__.py diff --git a/aiogram/api/client/__init__.py b/aiogram/api/client/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/aiogram/api/client/base.py b/aiogram/api/client/base.py new file mode 100644 index 00000000..05bfc4a9 --- /dev/null +++ b/aiogram/api/client/base.py @@ -0,0 +1,18 @@ +from typing import TypeVar + +from ..methods import TelegramMethod +from ..session.aiohttp import AiohttpSession +from ..session.base import BaseSession + +T = TypeVar("T") + + +class BaseBot: + def __init__(self, token: str, session: BaseSession = None): + if session is None: + session = AiohttpSession() + self.session = session + self.token = token + + async def emit(self, method: TelegramMethod[T]) -> T: + return await self.session.make_request(self.token, method) diff --git a/aiogram/api/client/bot.py b/aiogram/api/client/bot.py new file mode 100644 index 00000000..723c615e --- /dev/null +++ b/aiogram/api/client/bot.py @@ -0,0 +1,2144 @@ +from typing import List, Optional, Union + +from ..methods import ( + AddStickerToSet, + AnswerCallbackQuery, + AnswerInlineQuery, + AnswerPreCheckoutQuery, + AnswerShippingQuery, + CreateNewStickerSet, + DeleteChatPhoto, + DeleteChatStickerSet, + DeleteMessage, + DeleteStickerFromSet, + DeleteWebhook, + EditMessageCaption, + EditMessageLiveLocation, + EditMessageMedia, + EditMessageReplyMarkup, + EditMessageText, + ExportChatInviteLink, + ForwardMessage, + GetChat, + GetChatAdministrators, + GetChatMember, + GetChatMembersCount, + GetFile, + GetGameHighScores, + GetMe, + GetStickerSet, + GetUpdates, + GetUserProfilePhotos, + GetWebhookInfo, + KickChatMember, + LeaveChat, + PinChatMessage, + PromoteChatMember, + RestrictChatMember, + SendAnimation, + SendAudio, + SendChatAction, + SendContact, + SendDocument, + SendGame, + SendInvoice, + SendLocation, + SendMediaGroup, + SendMessage, + SendPhoto, + SendPoll, + SendSticker, + SendVenue, + SendVideo, + SendVideoNote, + SendVoice, + SetChatDescription, + SetChatPermissions, + SetChatPhoto, + SetChatStickerSet, + SetChatTitle, + SetGameScore, + SetPassportDataErrors, + SetStickerPositionInSet, + SetWebhook, + StopMessageLiveLocation, + StopPoll, + UnbanChatMember, + UnpinChatMessage, + UploadStickerFile, +) +from ..types import ( + Chat, + ChatMember, + ChatPermissions, + File, + ForceReply, + GameHighScore, + InlineKeyboardMarkup, + InlineQueryResult, + InputFile, + InputMedia, + InputMediaPhoto, + InputMediaVideo, + LabeledPrice, + MaskPosition, + Message, + PassportElementError, + Poll, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, + ShippingOption, + StickerSet, + Update, + User, + UserProfilePhotos, + WebhookInfo, +) +from .base import BaseBot + + +class Bot(BaseBot): + """ + Class where located all API methods + """ + + # ============================================================================================= + # Group: Getting updates + # Source: https://core.telegram.org/bots/api#getting-updates + # ============================================================================================= + + async def get_updates( + self, + offset: Optional[int] = None, + limit: Optional[int] = None, + timeout: Optional[int] = None, + allowed_updates: Optional[List[str]] = None, + ) -> List[Update]: + """ + Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. + Notes + 1. This method will not work if an outgoing webhook is set up. + 2. In order to avoid getting duplicate updates, recalculate offset after each server response. + + 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. + :type offset: :obj:`Optional[int]` + :param limit: Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100. + :type limit: :obj:`Optional[int]` + :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. + :type timeout: :obj:`Optional[int]` + :param allowed_updates: List the types of updates 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. + :type allowed_updates: :obj:`Optional[List[str]]` + :return: An Array of Update objects is returned. + :rtype: :obj:`List[Update]` + """ + call = GetUpdates( + offset=offset, limit=limit, timeout=timeout, allowed_updates=allowed_updates, + ) + return await self.emit(call) + + async def set_webhook( + self, + url: str, + certificate: Optional[InputFile] = None, + max_connections: Optional[int] = None, + allowed_updates: Optional[List[str]] = None, + ) -> bool: + """ + Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success. + If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. + Notes + 1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up. + 2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work. + 3. Ports currently supported for Webhooks: 443, 80, 88, 8443. + NEW! If you're having any trouble setting up webhooks, please check out this amazing guide to Webhooks. + + Source: https://core.telegram.org/bots/api#setwebhook + + :param url: HTTPS url to send updates to. Use an empty string to remove webhook integration + :type url: :obj:`str` + :param certificate: Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details. + :type certificate: :obj:`Optional[InputFile]` + :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. + :type max_connections: :obj:`Optional[int]` + :param allowed_updates: List the types of updates 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. + :type allowed_updates: :obj:`Optional[List[str]]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SetWebhook( + url=url, + certificate=certificate, + max_connections=max_connections, + allowed_updates=allowed_updates, + ) + return await self.emit(call) + + async def delete_webhook(self,) -> bool: + """ + Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters. + + Source: https://core.telegram.org/bots/api#deletewebhook + + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = DeleteWebhook() + return await self.emit(call) + + async def get_webhook_info(self,) -> WebhookInfo: + """ + Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty. + + Source: https://core.telegram.org/bots/api#getwebhookinfo + + :return: On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty. + :rtype: :obj:`WebhookInfo` + """ + call = GetWebhookInfo() + return await self.emit(call) + + # ============================================================================================= + # Group: Available methods + # Source: https://core.telegram.org/bots/api#available-methods + # ============================================================================================= + + async def get_me(self,) -> User: + """ + A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object. + + Source: https://core.telegram.org/bots/api#getme + + :return: Returns basic information about the bot in form of a User object. + :rtype: :obj:`User` + """ + call = GetMe() + return await self.emit(call) + + async def send_message( + self, + chat_id: Union[int, str], + text: str, + parse_mode: Optional[str] = None, + disable_web_page_preview: Optional[bool] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send text messages. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param text: Text of the message to be sent + :type text: :obj:`str` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + :type parse_mode: :obj:`Optional[str]` + :param disable_web_page_preview: Disables link previews for links in this message + :type disable_web_page_preview: :obj:`Optional[bool]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendMessage( + chat_id=chat_id, + text=text, + parse_mode=parse_mode, + disable_web_page_preview=disable_web_page_preview, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def forward_message( + self, + chat_id: Union[int, str], + from_chat_id: Union[int, str], + message_id: int, + disable_notification: Optional[bool] = None, + ) -> Message: + """ + Use this method to forward messages of any kind. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param from_chat_id: Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) + :type from_chat_id: :obj:`Union[int, str]` + :param message_id: Message identifier in the chat specified in from_chat_id + :type message_id: :obj:`int` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = ForwardMessage( + chat_id=chat_id, + from_chat_id=from_chat_id, + message_id=message_id, + disable_notification=disable_notification, + ) + return await self.emit(call) + + async def send_photo( + self, + chat_id: Union[int, str], + photo: Union[InputFile, str], + caption: Optional[str] = None, + parse_mode: Optional[str] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send photos. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type photo: :obj:`Union[InputFile, str]` + :param caption: Photo caption (may also be used when resending photos by file_id), 0-1024 characters + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendPhoto( + chat_id=chat_id, + photo=photo, + caption=caption, + parse_mode=parse_mode, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_audio( + self, + chat_id: Union[int, str], + audio: Union[InputFile, str], + caption: Optional[str] = None, + parse_mode: Optional[str] = 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, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. + For sending voice messages, use the sendVoice method instead. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type audio: :obj:`Union[InputFile, str]` + :param caption: Audio caption, 0-1024 characters + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param duration: Duration of the audio in seconds + :type duration: :obj:`Optional[int]` + :param performer: Performer + :type performer: :obj:`Optional[str]` + :param title: Track name + :type title: :obj:`Optional[str]` + :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 . + :type thumb: :obj:`Optional[Union[InputFile, str]]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendAudio( + chat_id=chat_id, + audio=audio, + caption=caption, + parse_mode=parse_mode, + duration=duration, + performer=performer, + title=title, + thumb=thumb, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_document( + self, + chat_id: Union[int, str], + document: Union[InputFile, str], + thumb: Optional[Union[InputFile, str]] = None, + caption: Optional[str] = None, + parse_mode: Optional[str] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type document: :obj:`Union[InputFile, str]` + :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 . + :type thumb: :obj:`Optional[Union[InputFile, str]]` + :param caption: Document caption (may also be used when resending documents by file_id), 0-1024 characters + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendDocument( + chat_id=chat_id, + document=document, + thumb=thumb, + caption=caption, + parse_mode=parse_mode, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_video( + self, + chat_id: Union[int, str], + video: Union[InputFile, str], + duration: Optional[int] = None, + width: Optional[int] = None, + height: Optional[int] = None, + thumb: Optional[Union[InputFile, str]] = None, + caption: Optional[str] = None, + parse_mode: Optional[str] = None, + supports_streaming: Optional[bool] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type video: :obj:`Union[InputFile, str]` + :param duration: Duration of sent video in seconds + :type duration: :obj:`Optional[int]` + :param width: Video width + :type width: :obj:`Optional[int]` + :param height: Video height + :type height: :obj:`Optional[int]` + :param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . + :type thumb: :obj:`Optional[Union[InputFile, str]]` + :param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param supports_streaming: Pass True, if the uploaded video is suitable for streaming + :type supports_streaming: :obj:`Optional[bool]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendVideo( + chat_id=chat_id, + video=video, + duration=duration, + width=width, + height=height, + thumb=thumb, + caption=caption, + parse_mode=parse_mode, + supports_streaming=supports_streaming, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_animation( + self, + chat_id: Union[int, str], + animation: Union[InputFile, str], + duration: Optional[int] = None, + width: Optional[int] = None, + height: Optional[int] = None, + thumb: Optional[Union[InputFile, str]] = None, + caption: Optional[str] = None, + parse_mode: Optional[str] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type animation: :obj:`Union[InputFile, str]` + :param duration: Duration of sent animation in seconds + :type duration: :obj:`Optional[int]` + :param width: Animation width + :type width: :obj:`Optional[int]` + :param height: Animation height + :type height: :obj:`Optional[int]` + :param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . + :type thumb: :obj:`Optional[Union[InputFile, str]]` + :param caption: Animation caption (may also be used when resending animation by file_id), 0-1024 characters + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendAnimation( + chat_id=chat_id, + animation=animation, + duration=duration, + width=width, + height=height, + thumb=thumb, + caption=caption, + parse_mode=parse_mode, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_voice( + self, + chat_id: Union[int, str], + voice: Union[InputFile, str], + caption: Optional[str] = None, + parse_mode: Optional[str] = None, + duration: Optional[int] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type voice: :obj:`Union[InputFile, str]` + :param caption: Voice message caption, 0-1024 characters + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param duration: Duration of the voice message in seconds + :type duration: :obj:`Optional[int]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendVoice( + chat_id=chat_id, + voice=voice, + caption=caption, + parse_mode=parse_mode, + duration=duration, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_video_note( + self, + chat_id: Union[int, str], + video_note: Union[InputFile, str], + duration: Optional[int] = None, + length: Optional[int] = None, + thumb: Optional[Union[InputFile, str]] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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 + :type video_note: :obj:`Union[InputFile, str]` + :param duration: Duration of sent video in seconds + :type duration: :obj:`Optional[int]` + :param length: Video width and height, i.e. diameter of the video message + :type length: :obj:`Optional[int]` + :param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . + :type thumb: :obj:`Optional[Union[InputFile, str]]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendVideoNote( + chat_id=chat_id, + video_note=video_note, + duration=duration, + length=length, + thumb=thumb, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_media_group( + self, + chat_id: Union[int, str], + media: List[Union[InputMediaPhoto, InputMediaVideo]], + disable_notification: Optional[bool] = None, + reply_to_message_id: 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param media: A JSON-serialized array describing photos and videos to be sent, must include 2–10 items + :type media: :obj:`List[Union[InputMediaPhoto, InputMediaVideo]]` + :param disable_notification: Sends the messages silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the messages are a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :return: On success, an array of the sent Messages is returned. + :rtype: :obj:`List[Message]` + """ + call = SendMediaGroup( + chat_id=chat_id, + media=media, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + ) + return await self.emit(call) + + async def send_location( + self, + chat_id: Union[int, str], + latitude: float, + longitude: float, + live_period: Optional[int] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send point on the map. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param latitude: Latitude of the location + :type latitude: :obj:`float` + :param longitude: Longitude of the location + :type longitude: :obj:`float` + :param live_period: Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400. + :type live_period: :obj:`Optional[int]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendLocation( + chat_id=chat_id, + latitude=latitude, + longitude=longitude, + live_period=live_period, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def edit_message_live_location( + self, + latitude: float, + longitude: float, + chat_id: Optional[Union[int, str]] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + reply_markup: Optional[InlineKeyboardMarkup] = 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. + + Source: https://core.telegram.org/bots/api#editmessagelivelocation + + :param latitude: Latitude of new location + :type latitude: :obj:`float` + :param longitude: Longitude of new location + :type longitude: :obj:`float` + :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) + :type chat_id: :obj:`Optional[Union[int, str]]` + :param message_id: Required if inline_message_id is not specified. Identifier of the message to edit + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :param reply_markup: A JSON-serialized object for a new inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. + :rtype: :obj:`Union[Message, bool]` + """ + call = EditMessageLiveLocation( + latitude=latitude, + longitude=longitude, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def stop_message_live_location( + self, + chat_id: Optional[Union[int, str]] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + reply_markup: Optional[InlineKeyboardMarkup] = None, + ) -> Union[Message, bool]: + """ + Use this method to stop updating a live location message before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned. + + 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) + :type chat_id: :obj:`Optional[Union[int, str]]` + :param message_id: Required if inline_message_id is not specified. Identifier of the message with live location to stop + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :param reply_markup: A JSON-serialized object for a new inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned. + :rtype: :obj:`Union[Message, bool]` + """ + call = StopMessageLiveLocation( + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_venue( + self, + chat_id: Union[int, str], + latitude: float, + longitude: float, + title: str, + address: str, + foursquare_id: Optional[str] = None, + foursquare_type: Optional[str] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send information about a venue. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param latitude: Latitude of the venue + :type latitude: :obj:`float` + :param longitude: Longitude of the venue + :type longitude: :obj:`float` + :param title: Name of the venue + :type title: :obj:`str` + :param address: Address of the venue + :type address: :obj:`str` + :param foursquare_id: Foursquare identifier of the venue + :type foursquare_id: :obj:`Optional[str]` + :param foursquare_type: Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.) + :type foursquare_type: :obj:`Optional[str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendVenue( + chat_id=chat_id, + latitude=latitude, + longitude=longitude, + title=title, + address=address, + foursquare_id=foursquare_id, + foursquare_type=foursquare_type, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_contact( + self, + chat_id: Union[int, str], + phone_number: str, + first_name: str, + last_name: Optional[str] = None, + vcard: Optional[str] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send phone contacts. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param phone_number: Contact's phone number + :type phone_number: :obj:`str` + :param first_name: Contact's first name + :type first_name: :obj:`str` + :param last_name: Contact's last name + :type last_name: :obj:`Optional[str]` + :param vcard: Additional data about the contact in the form of a vCard, 0-2048 bytes + :type vcard: :obj:`Optional[str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendContact( + chat_id=chat_id, + phone_number=phone_number, + first_name=first_name, + last_name=last_name, + vcard=vcard, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_poll( + self, + chat_id: Union[int, str], + question: str, + options: List[str], + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned. + + 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). A native poll can't be sent to a private chat. + :type chat_id: :obj:`Union[int, str]` + :param question: Poll question, 1-255 characters + :type question: :obj:`str` + :param options: List of answer options, 2-10 strings 1-100 characters each + :type options: :obj:`List[str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendPoll( + chat_id=chat_id, + question=question, + options=options, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def send_chat_action(self, chat_id: Union[int, str], action: str,) -> bool: + """ + Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. + Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of 'Retrieving image, please wait…', the bot may use sendChatAction with action = upload_photo. The user will see a 'sending photo' status for the bot. + We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type action: :obj:`str` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SendChatAction(chat_id=chat_id, action=action,) + return await self.emit(call) + + async def get_user_profile_photos( + self, user_id: int, offset: Optional[int] = None, limit: Optional[int] = None, + ) -> UserProfilePhotos: + """ + Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. + + Source: https://core.telegram.org/bots/api#getuserprofilephotos + + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + :param offset: Sequential number of the first photo to be returned. By default, all photos are returned. + :type offset: :obj:`Optional[int]` + :param limit: Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. + :type limit: :obj:`Optional[int]` + :return: Returns a UserProfilePhotos object. + :rtype: :obj:`UserProfilePhotos` + """ + call = GetUserProfilePhotos(user_id=user_id, offset=offset, limit=limit,) + return await self.emit(call) + + async def get_file(self, file_id: str,) -> File: + """ + Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. + Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received. + + Source: https://core.telegram.org/bots/api#getfile + + :param file_id: File identifier to get info about + :type file_id: :obj:`str` + :return: On success, a File object is returned. + :rtype: :obj:`File` + """ + call = GetFile(file_id=file_id,) + return await self.emit(call) + + async def kick_chat_member( + self, chat_id: Union[int, str], user_id: int, until_date: Optional[int] = None, + ) -> bool: + """ + Use this method to kick a user from a group, a supergroup or a channel. 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., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + :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 + :type until_date: :obj:`Optional[int]` + :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. + :rtype: :obj:`bool` + """ + call = KickChatMember(chat_id=chat_id, user_id=user_id, until_date=until_date,) + return await self.emit(call) + + async def unban_chat_member(self, chat_id: Union[int, str], user_id: int,) -> 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + :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. + :rtype: :obj:`bool` + """ + call = UnbanChatMember(chat_id=chat_id, user_id=user_id,) + return await self.emit(call) + + async def restrict_chat_member( + self, + chat_id: Union[int, str], + user_id: int, + permissions: ChatPermissions, + until_date: Optional[int] = None, + ) -> bool: + """ + Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + :param permissions: New user permissions + :type permissions: :obj:`ChatPermissions` + :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 + :type until_date: :obj:`Optional[int]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = RestrictChatMember( + chat_id=chat_id, user_id=user_id, permissions=permissions, until_date=until_date, + ) + return await self.emit(call) + + async def promote_chat_member( + self, + chat_id: Union[int, str], + user_id: int, + can_change_info: Optional[bool] = None, + can_post_messages: Optional[bool] = None, + can_edit_messages: Optional[bool] = None, + can_delete_messages: Optional[bool] = None, + can_invite_users: Optional[bool] = None, + can_restrict_members: Optional[bool] = None, + can_pin_messages: Optional[bool] = None, + can_promote_members: Optional[bool] = None, + ) -> bool: + """ + Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + :param can_change_info: Pass True, if the administrator can change chat title, photo and other settings + :type can_change_info: :obj:`Optional[bool]` + :param can_post_messages: Pass True, if the administrator can create channel posts, channels only + :type can_post_messages: :obj:`Optional[bool]` + :param can_edit_messages: Pass True, if the administrator can edit messages of other users and can pin messages, channels only + :type can_edit_messages: :obj:`Optional[bool]` + :param can_delete_messages: Pass True, if the administrator can delete messages of other users + :type can_delete_messages: :obj:`Optional[bool]` + :param can_invite_users: Pass True, if the administrator can invite new users to the chat + :type can_invite_users: :obj:`Optional[bool]` + :param can_restrict_members: Pass True, if the administrator can restrict, ban or unban chat members + :type can_restrict_members: :obj:`Optional[bool]` + :param can_pin_messages: Pass True, if the administrator can pin messages, supergroups only + :type can_pin_messages: :obj:`Optional[bool]` + :param can_promote_members: Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him) + :type can_promote_members: :obj:`Optional[bool]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = PromoteChatMember( + chat_id=chat_id, + user_id=user_id, + can_change_info=can_change_info, + can_post_messages=can_post_messages, + can_edit_messages=can_edit_messages, + can_delete_messages=can_delete_messages, + can_invite_users=can_invite_users, + can_restrict_members=can_restrict_members, + can_pin_messages=can_pin_messages, + can_promote_members=can_promote_members, + ) + return await self.emit(call) + + async def set_chat_permissions( + self, chat_id: Union[int, str], permissions: ChatPermissions, + ) -> bool: + """ + Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param permissions: New default chat permissions + :type permissions: :obj:`ChatPermissions` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SetChatPermissions(chat_id=chat_id, permissions=permissions,) + return await self.emit(call) + + async def export_chat_invite_link(self, chat_id: Union[int, str],) -> str: + """ + Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as String on success. + Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink – after this the link will become available to the bot via the getChat method. If your bot needs to generate a new invite link replacing its previous one, use exportChatInviteLink again. + + 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) + :type chat_id: :obj:`Union[int, str]` + :return: Returns the new invite link as String on success. + :rtype: :obj:`str` + """ + call = ExportChatInviteLink(chat_id=chat_id,) + return await self.emit(call) + + async def set_chat_photo(self, chat_id: Union[int, str], photo: InputFile,) -> bool: + """ + Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param photo: New chat photo, uploaded using multipart/form-data + :type photo: :obj:`InputFile` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SetChatPhoto(chat_id=chat_id, photo=photo,) + return await self.emit(call) + + async def delete_chat_photo(self, chat_id: Union[int, str],) -> bool: + """ + Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = DeleteChatPhoto(chat_id=chat_id,) + return await self.emit(call) + + async def set_chat_title(self, chat_id: Union[int, str], title: str,) -> bool: + """ + Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param title: New chat title, 1-255 characters + :type title: :obj:`str` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SetChatTitle(chat_id=chat_id, title=title,) + return await self.emit(call) + + async def set_chat_description( + self, chat_id: Union[int, str], description: Optional[str] = None, + ) -> bool: + """ + Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param description: New chat description, 0-255 characters + :type description: :obj:`Optional[str]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SetChatDescription(chat_id=chat_id, description=description,) + return await self.emit(call) + + async def pin_chat_message( + self, + chat_id: Union[int, str], + message_id: int, + disable_notification: Optional[bool] = 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param message_id: Identifier of a message to pin + :type message_id: :obj:`int` + :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. + :type disable_notification: :obj:`Optional[bool]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = PinChatMessage( + chat_id=chat_id, message_id=message_id, disable_notification=disable_notification, + ) + return await self.emit(call) + + async def unpin_chat_message(self, chat_id: Union[int, str],) -> 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = UnpinChatMessage(chat_id=chat_id,) + return await self.emit(call) + + async def leave_chat(self, chat_id: Union[int, str],) -> bool: + """ + Use this method for your bot to leave a group, supergroup or channel. Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = LeaveChat(chat_id=chat_id,) + return await self.emit(call) + + async def get_chat(self, chat_id: Union[int, str],) -> Chat: + """ + Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :return: Returns a Chat object on success. + :rtype: :obj:`Chat` + """ + call = GetChat(chat_id=chat_id,) + return await self.emit(call) + + async def get_chat_administrators(self, chat_id: Union[int, str],) -> List[ChatMember]: + """ + Use this method to get a list of administrators in a chat. 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :rtype: :obj:`List[ChatMember]` + """ + call = GetChatAdministrators(chat_id=chat_id,) + return await self.emit(call) + + async def get_chat_members_count(self, chat_id: Union[int, str],) -> int: + """ + Use this method to get the number of members in a chat. Returns Int on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :return: Returns Int on success. + :rtype: :obj:`int` + """ + call = GetChatMembersCount(chat_id=chat_id,) + return await self.emit(call) + + async def get_chat_member(self, chat_id: Union[int, str], user_id: int,) -> ChatMember: + """ + Use this method to get information about a member of a chat. Returns a ChatMember object on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param user_id: Unique identifier of the target user + :type user_id: :obj:`int` + :return: Returns a ChatMember object on success. + :rtype: :obj:`ChatMember` + """ + call = GetChatMember(chat_id=chat_id, user_id=user_id,) + return await self.emit(call) + + async def set_chat_sticker_set(self, chat_id: Union[int, str], sticker_set_name: str,) -> bool: + """ + Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param sticker_set_name: Name of the sticker set to be set as the group sticker set + :type sticker_set_name: :obj:`str` + :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. + :rtype: :obj:`bool` + """ + call = SetChatStickerSet(chat_id=chat_id, sticker_set_name=sticker_set_name,) + return await self.emit(call) + + async def delete_chat_sticker_set(self, chat_id: Union[int, str],) -> bool: + """ + Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 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. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :rtype: :obj:`bool` + """ + call = DeleteChatStickerSet(chat_id=chat_id,) + return await self.emit(call) + + async def answer_callback_query( + self, + callback_query_id: str, + text: Optional[str] = None, + show_alert: Optional[bool] = None, + url: Optional[str] = None, + cache_time: Optional[int] = None, + ) -> bool: + """ + Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned. + Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter. + + Source: https://core.telegram.org/bots/api#answercallbackquery + + :param callback_query_id: Unique identifier for the query to be answered + :type callback_query_id: :obj:`str` + :param text: Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + :type text: :obj:`Optional[str]` + :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. + :type show_alert: :obj:`Optional[bool]` + :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. + :type url: :obj:`Optional[str]` + :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. + :type cache_time: :obj:`Optional[int]` + :return: On success, True is returned. + :rtype: :obj:`bool` + """ + call = AnswerCallbackQuery( + callback_query_id=callback_query_id, + text=text, + show_alert=show_alert, + url=url, + cache_time=cache_time, + ) + return await self.emit(call) + + # ============================================================================================= + # Group: Updating messages + # Source: https://core.telegram.org/bots/api#updating-messages + # ============================================================================================= + + async def edit_message_text( + self, + text: str, + chat_id: Optional[Union[int, str]] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + parse_mode: Optional[str] = None, + disable_web_page_preview: Optional[bool] = None, + reply_markup: Optional[InlineKeyboardMarkup] = 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. + + Source: https://core.telegram.org/bots/api#editmessagetext + + :param text: New text of the message + :type text: :obj:`str` + :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) + :type chat_id: :obj:`Optional[Union[int, str]]` + :param message_id: Required if inline_message_id is not specified. Identifier of the message to edit + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + :type parse_mode: :obj:`Optional[str]` + :param disable_web_page_preview: Disables link previews for links in this message + :type disable_web_page_preview: :obj:`Optional[bool]` + :param reply_markup: A JSON-serialized object for an inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. + :rtype: :obj:`Union[Message, bool]` + """ + call = EditMessageText( + text=text, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + parse_mode=parse_mode, + disable_web_page_preview=disable_web_page_preview, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def edit_message_caption( + self, + chat_id: Optional[Union[int, str]] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + caption: Optional[str] = None, + parse_mode: Optional[str] = None, + reply_markup: Optional[InlineKeyboardMarkup] = 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. + + 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) + :type chat_id: :obj:`Optional[Union[int, str]]` + :param message_id: Required if inline_message_id is not specified. Identifier of the message to edit + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :param caption: New caption of the message + :type caption: :obj:`Optional[str]` + :param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + :type parse_mode: :obj:`Optional[str]` + :param reply_markup: A JSON-serialized object for an inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. + :rtype: :obj:`Union[Message, bool]` + """ + call = EditMessageCaption( + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + caption=caption, + parse_mode=parse_mode, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def edit_message_media( + self, + media: InputMedia, + chat_id: Optional[Union[int, str]] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + reply_markup: Optional[InlineKeyboardMarkup] = None, + ) -> 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. + + Source: https://core.telegram.org/bots/api#editmessagemedia + + :param media: A JSON-serialized object for a new media content of the message + :type media: :obj:`InputMedia` + :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) + :type chat_id: :obj:`Optional[Union[int, str]]` + :param message_id: Required if inline_message_id is not specified. Identifier of the message to edit + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :param reply_markup: A JSON-serialized object for a new inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. + :rtype: :obj:`Union[Message, bool]` + """ + call = EditMessageMedia( + media=media, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def edit_message_reply_markup( + self, + chat_id: Optional[Union[int, str]] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + reply_markup: Optional[InlineKeyboardMarkup] = 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. + + 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) + :type chat_id: :obj:`Optional[Union[int, str]]` + :param message_id: Required if inline_message_id is not specified. Identifier of the message to edit + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :param reply_markup: A JSON-serialized object for an inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. + :rtype: :obj:`Union[Message, bool]` + """ + call = EditMessageReplyMarkup( + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def stop_poll( + self, + chat_id: Union[int, str], + message_id: int, + reply_markup: Optional[InlineKeyboardMarkup] = None, + ) -> Poll: + """ + Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param message_id: Identifier of the original message with the poll + :type message_id: :obj:`int` + :param reply_markup: A JSON-serialized object for a new message inline keyboard. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, the stopped Poll with the final results is returned. + :rtype: :obj:`Poll` + """ + call = StopPoll(chat_id=chat_id, message_id=message_id, reply_markup=reply_markup,) + return await self.emit(call) + + async def delete_message(self, chat_id: Union[int, str], message_id: int,) -> bool: + """ + Use this method to delete a message, including service messages, with the following limitations: + - A message can only be deleted if it was sent less than 48 hours ago. + - Bots can delete outgoing messages in private chats, groups, and supergroups. + - Bots can delete incoming messages in private chats. + - Bots granted can_post_messages permissions can delete outgoing messages in channels. + - If the bot is an administrator of a group, it can delete any message there. + - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. + Returns True on success. + + 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) + :type chat_id: :obj:`Union[int, str]` + :param message_id: Identifier of the message to delete + :type message_id: :obj:`int` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = DeleteMessage(chat_id=chat_id, message_id=message_id,) + return await self.emit(call) + + # ============================================================================================= + # Group: Stickers + # Source: https://core.telegram.org/bots/api#stickers + # ============================================================================================= + + async def send_sticker( + self, + chat_id: Union[int, str], + sticker: Union[InputFile, str], + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[ + Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] + ] = None, + ) -> Message: + """ + Use this method to send static .WEBP or animated .TGS stickers. On success, the sent Message is returned. + + 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) + :type chat_id: :obj:`Union[int, str]` + :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. + :type sticker: :obj:`Union[InputFile, str]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendSticker( + chat_id=chat_id, + sticker=sticker, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def get_sticker_set(self, name: str,) -> StickerSet: + """ + Use this method to get a sticker set. On success, a StickerSet object is returned. + + Source: https://core.telegram.org/bots/api#getstickerset + + :param name: Name of the sticker set + :type name: :obj:`str` + :return: On success, a StickerSet object is returned. + :rtype: :obj:`StickerSet` + """ + call = GetStickerSet(name=name,) + return await self.emit(call) + + async def upload_sticker_file(self, user_id: int, png_sticker: InputFile,) -> File: + """ + Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. + + Source: https://core.telegram.org/bots/api#uploadstickerfile + + :param user_id: User identifier of sticker file owner + :type user_id: :obj:`int` + :param png_sticker: Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. + :type png_sticker: :obj:`InputFile` + :return: Returns the uploaded File on success. + :rtype: :obj:`File` + """ + call = UploadStickerFile(user_id=user_id, png_sticker=png_sticker,) + return await self.emit(call) + + async def create_new_sticker_set( + self, + user_id: int, + name: str, + title: str, + png_sticker: Union[InputFile, str], + emojis: str, + contains_masks: Optional[bool] = None, + mask_position: Optional[MaskPosition] = None, + ) -> bool: + """ + Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success. + + Source: https://core.telegram.org/bots/api#createnewstickerset + + :param user_id: User identifier of created sticker set owner + :type user_id: :obj:`int` + :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. + :type name: :obj:`str` + :param title: Sticker set title, 1-64 characters + :type title: :obj:`str` + :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. + :type png_sticker: :obj:`Union[InputFile, str]` + :param emojis: One or more emoji corresponding to the sticker + :type emojis: :obj:`str` + :param contains_masks: Pass True, if a set of mask stickers should be created + :type contains_masks: :obj:`Optional[bool]` + :param mask_position: A JSON-serialized object for position where the mask should be placed on faces + :type mask_position: :obj:`Optional[MaskPosition]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = CreateNewStickerSet( + user_id=user_id, + name=name, + title=title, + png_sticker=png_sticker, + emojis=emojis, + contains_masks=contains_masks, + mask_position=mask_position, + ) + return await self.emit(call) + + async def add_sticker_to_set( + self, + user_id: int, + name: str, + png_sticker: Union[InputFile, str], + emojis: str, + mask_position: Optional[MaskPosition] = None, + ) -> bool: + """ + Use this method to add a new sticker to a set created by the bot. Returns True on success. + + Source: https://core.telegram.org/bots/api#addstickertoset + + :param user_id: User identifier of sticker set owner + :type user_id: :obj:`int` + :param name: Sticker set name + :type name: :obj:`str` + :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. + :type png_sticker: :obj:`Union[InputFile, str]` + :param emojis: One or more emoji corresponding to the sticker + :type emojis: :obj:`str` + :param mask_position: A JSON-serialized object for position where the mask should be placed on faces + :type mask_position: :obj:`Optional[MaskPosition]` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = AddStickerToSet( + user_id=user_id, + name=name, + png_sticker=png_sticker, + emojis=emojis, + mask_position=mask_position, + ) + return await self.emit(call) + + async def set_sticker_position_in_set(self, sticker: str, position: int,) -> bool: + """ + Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success. + + Source: https://core.telegram.org/bots/api#setstickerpositioninset + + :param sticker: File identifier of the sticker + :type sticker: :obj:`str` + :param position: New sticker position in the set, zero-based + :type position: :obj:`int` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = SetStickerPositionInSet(sticker=sticker, position=position,) + return await self.emit(call) + + async def delete_sticker_from_set(self, sticker: str,) -> bool: + """ + Use this method to delete a sticker from a set created by the bot. Returns True on success. + + Source: https://core.telegram.org/bots/api#deletestickerfromset + + :param sticker: File identifier of the sticker + :type sticker: :obj:`str` + :return: Returns True on success. + :rtype: :obj:`bool` + """ + call = DeleteStickerFromSet(sticker=sticker,) + return await self.emit(call) + + # ============================================================================================= + # Group: Inline mode + # Source: https://core.telegram.org/bots/api#inline-mode + # ============================================================================================= + + async def answer_inline_query( + self, + inline_query_id: str, + results: List[InlineQueryResult], + cache_time: Optional[int] = None, + is_personal: Optional[bool] = None, + next_offset: Optional[str] = None, + switch_pm_text: Optional[str] = None, + switch_pm_parameter: Optional[str] = None, + ) -> bool: + """ + Use this method to send answers to an inline query. On success, True is returned. + No more than 50 results per query are allowed. + + Source: https://core.telegram.org/bots/api#answerinlinequery + + :param inline_query_id: Unique identifier for the answered query + :type inline_query_id: :obj:`str` + :param results: A JSON-serialized array of results for the inline query + :type results: :obj:`List[InlineQueryResult]` + :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. + :type cache_time: :obj:`Optional[int]` + :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 + :type is_personal: :obj:`Optional[bool]` + :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. + :type next_offset: :obj:`Optional[str]` + :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 + :type switch_pm_text: :obj:`Optional[str]` + :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. + :type switch_pm_parameter: :obj:`Optional[str]` + :return: On success, True is returned. + :rtype: :obj:`bool` + """ + call = AnswerInlineQuery( + inline_query_id=inline_query_id, + results=results, + cache_time=cache_time, + is_personal=is_personal, + next_offset=next_offset, + switch_pm_text=switch_pm_text, + switch_pm_parameter=switch_pm_parameter, + ) + return await self.emit(call) + + # ============================================================================================= + # Group: Payments + # Source: https://core.telegram.org/bots/api#payments + # ============================================================================================= + + async def send_invoice( + self, + chat_id: int, + title: str, + description: str, + payload: str, + provider_token: str, + start_parameter: str, + currency: str, + prices: List[LabeledPrice], + provider_data: Optional[str] = None, + photo_url: Optional[str] = None, + photo_size: Optional[int] = None, + photo_width: Optional[int] = None, + photo_height: Optional[int] = None, + need_name: Optional[bool] = None, + need_phone_number: Optional[bool] = None, + need_email: Optional[bool] = None, + need_shipping_address: Optional[bool] = None, + send_phone_number_to_provider: Optional[bool] = None, + send_email_to_provider: Optional[bool] = None, + is_flexible: Optional[bool] = None, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[InlineKeyboardMarkup] = None, + ) -> Message: + """ + Use this method to send invoices. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendinvoice + + :param chat_id: Unique identifier for the target private chat + :type chat_id: :obj:`int` + :param title: Product name, 1-32 characters + :type title: :obj:`str` + :param description: Product description, 1-255 characters + :type description: :obj:`str` + :param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + :type payload: :obj:`str` + :param provider_token: Payments provider token, obtained via Botfather + :type provider_token: :obj:`str` + :param start_parameter: Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter + :type start_parameter: :obj:`str` + :param currency: Three-letter ISO 4217 currency code, see more on currencies + :type currency: :obj:`str` + :param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + :type prices: :obj:`List[LabeledPrice]` + :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. + :type provider_data: :obj:`Optional[str]` + :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. + :type photo_url: :obj:`Optional[str]` + :param photo_size: Photo size + :type photo_size: :obj:`Optional[int]` + :param photo_width: Photo width + :type photo_width: :obj:`Optional[int]` + :param photo_height: Photo height + :type photo_height: :obj:`Optional[int]` + :param need_name: Pass True, if you require the user's full name to complete the order + :type need_name: :obj:`Optional[bool]` + :param need_phone_number: Pass True, if you require the user's phone number to complete the order + :type need_phone_number: :obj:`Optional[bool]` + :param need_email: Pass True, if you require the user's email address to complete the order + :type need_email: :obj:`Optional[bool]` + :param need_shipping_address: Pass True, if you require the user's shipping address to complete the order + :type need_shipping_address: :obj:`Optional[bool]` + :param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider + :type send_phone_number_to_provider: :obj:`Optional[bool]` + :param send_email_to_provider: Pass True, if user's email address should be sent to provider + :type send_email_to_provider: :obj:`Optional[bool]` + :param is_flexible: Pass True, if the final price depends on the shipping method + :type is_flexible: :obj:`Optional[bool]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendInvoice( + chat_id=chat_id, + title=title, + description=description, + payload=payload, + provider_token=provider_token, + start_parameter=start_parameter, + currency=currency, + prices=prices, + provider_data=provider_data, + photo_url=photo_url, + photo_size=photo_size, + photo_width=photo_width, + photo_height=photo_height, + need_name=need_name, + need_phone_number=need_phone_number, + need_email=need_email, + need_shipping_address=need_shipping_address, + send_phone_number_to_provider=send_phone_number_to_provider, + send_email_to_provider=send_email_to_provider, + is_flexible=is_flexible, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def answer_shipping_query( + self, + shipping_query_id: str, + ok: bool, + shipping_options: Optional[List[ShippingOption]] = None, + error_message: Optional[str] = None, + ) -> bool: + """ + If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned. + + Source: https://core.telegram.org/bots/api#answershippingquery + + :param shipping_query_id: Unique identifier for the query to be answered + :type shipping_query_id: :obj:`str` + :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) + :type ok: :obj:`bool` + :param shipping_options: Required if ok is True. A JSON-serialized array of available shipping options. + :type shipping_options: :obj:`Optional[List[ShippingOption]]` + :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. + :type error_message: :obj:`Optional[str]` + :return: On success, True is returned. + :rtype: :obj:`bool` + """ + call = AnswerShippingQuery( + shipping_query_id=shipping_query_id, + ok=ok, + shipping_options=shipping_options, + error_message=error_message, + ) + return await self.emit(call) + + async def answer_pre_checkout_query( + self, pre_checkout_query_id: str, ok: bool, error_message: Optional[str] = None, + ) -> bool: + """ + Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + + Source: https://core.telegram.org/bots/api#answerprecheckoutquery + + :param pre_checkout_query_id: Unique identifier for the query to be answered + :type pre_checkout_query_id: :obj:`str` + :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. + :type ok: :obj:`bool` + :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. + :type error_message: :obj:`Optional[str]` + :return: On success, True is returned. + :rtype: :obj:`bool` + """ + call = AnswerPreCheckoutQuery( + pre_checkout_query_id=pre_checkout_query_id, ok=ok, error_message=error_message, + ) + return await self.emit(call) + + # ============================================================================================= + # Group: Telegram Passport + # Source: https://core.telegram.org/bots/api#telegram-passport + # ============================================================================================= + + async def set_passport_data_errors( + self, user_id: int, errors: List[PassportElementError], + ) -> bool: + """ + Informs a user that some of the Telegram Passport elements they provided contains errors. 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. + Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues. + + Source: https://core.telegram.org/bots/api#setpassportdataerrors + + :param user_id: User identifier + :type user_id: :obj:`int` + :param errors: A JSON-serialized array describing the errors + :type errors: :obj:`List[PassportElementError]` + :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. + :rtype: :obj:`bool` + """ + call = SetPassportDataErrors(user_id=user_id, errors=errors,) + return await self.emit(call) + + # ============================================================================================= + # Group: Games + # Source: https://core.telegram.org/bots/api#games + # ============================================================================================= + + async def send_game( + self, + chat_id: int, + game_short_name: str, + disable_notification: Optional[bool] = None, + reply_to_message_id: Optional[int] = None, + reply_markup: Optional[InlineKeyboardMarkup] = None, + ) -> Message: + """ + Use this method to send a game. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendgame + + :param chat_id: Unique identifier for the target chat + :type chat_id: :obj:`int` + :param game_short_name: Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather. + :type game_short_name: :obj:`str` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound. + :type disable_notification: :obj:`Optional[bool]` + :param reply_to_message_id: If the message is a reply, ID of the original message + :type reply_to_message_id: :obj:`Optional[int]` + :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. + :type reply_markup: :obj:`Optional[InlineKeyboardMarkup]` + :return: On success, the sent Message is returned. + :rtype: :obj:`Message` + """ + call = SendGame( + chat_id=chat_id, + game_short_name=game_short_name, + disable_notification=disable_notification, + reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup, + ) + return await self.emit(call) + + async def set_game_score( + self, + user_id: int, + score: int, + force: Optional[bool] = None, + disable_edit_message: Optional[bool] = None, + chat_id: Optional[int] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + ) -> Union[Message, bool]: + """ + Use this method to set the score of the specified user in a game. 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. + + Source: https://core.telegram.org/bots/api#setgamescore + + :param user_id: User identifier + :type user_id: :obj:`int` + :param score: New score, must be non-negative + :type score: :obj:`int` + :param force: Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters + :type force: :obj:`Optional[bool]` + :param disable_edit_message: Pass True, if the game message should not be automatically edited to include the current scoreboard + :type disable_edit_message: :obj:`Optional[bool]` + :param chat_id: Required if inline_message_id is not specified. Unique identifier for the target chat + :type chat_id: :obj:`Optional[int]` + :param message_id: Required if inline_message_id is not specified. Identifier of the sent message + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :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. + :rtype: :obj:`Union[Message, bool]` + """ + call = SetGameScore( + user_id=user_id, + score=score, + force=force, + disable_edit_message=disable_edit_message, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + ) + return await self.emit(call) + + async def get_game_high_scores( + self, + user_id: int, + chat_id: Optional[int] = None, + message_id: Optional[int] = None, + inline_message_id: Optional[str] = None, + ) -> List[GameHighScore]: + """ + Use this method to get data for high score tables. Will return the score of the specified user and several of his 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 his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change. + + Source: https://core.telegram.org/bots/api#getgamehighscores + + :param user_id: Target user id + :type user_id: :obj:`int` + :param chat_id: Required if inline_message_id is not specified. Unique identifier for the target chat + :type chat_id: :obj:`Optional[int]` + :param message_id: Required if inline_message_id is not specified. Identifier of the sent message + :type message_id: :obj:`Optional[int]` + :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of the inline message + :type inline_message_id: :obj:`Optional[str]` + :return: Will return the score of the specified user and several of his 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 his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. + :rtype: :obj:`List[GameHighScore]` + """ + call = GetGameHighScores( + user_id=user_id, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + ) + return await self.emit(call) diff --git a/aiogram/api/methods/__init__.py b/aiogram/api/methods/__init__.py new file mode 100644 index 00000000..39095df7 --- /dev/null +++ b/aiogram/api/methods/__init__.py @@ -0,0 +1,137 @@ +from .add_sticker_to_set import AddStickerToSet +from .answer_callback_query import AnswerCallbackQuery +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 .create_new_sticker_set import CreateNewStickerSet +from .delete_chat_photo import DeleteChatPhoto +from .delete_chat_sticker_set import DeleteChatStickerSet +from .delete_message import DeleteMessage +from .delete_sticker_from_set import DeleteStickerFromSet +from .delete_webhook import DeleteWebhook +from .edit_message_caption import EditMessageCaption +from .edit_message_live_location import EditMessageLiveLocation +from .edit_message_media import EditMessageMedia +from .edit_message_reply_markup import EditMessageReplyMarkup +from .edit_message_text import EditMessageText +from .export_chat_invite_link import ExportChatInviteLink +from .forward_message import ForwardMessage +from .get_chat import GetChat +from .get_chat_administrators import GetChatAdministrators +from .get_chat_member import GetChatMember +from .get_chat_members_count import GetChatMembersCount +from .get_file import GetFile +from .get_game_high_scores import GetGameHighScores +from .get_me import GetMe +from .get_sticker_set import GetStickerSet +from .get_updates import GetUpdates +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 .pin_chat_message import PinChatMessage +from .promote_chat_member import PromoteChatMember +from .restrict_chat_member import RestrictChatMember +from .send_animation import SendAnimation +from .send_audio import SendAudio +from .send_chat_action import SendChatAction +from .send_contact import SendContact +from .send_document import SendDocument +from .send_game import SendGame +from .send_invoice import SendInvoice +from .send_location import SendLocation +from .send_media_group import SendMediaGroup +from .send_message import SendMessage +from .send_photo import SendPhoto +from .send_poll import SendPoll +from .send_sticker import SendSticker +from .send_venue import SendVenue +from .send_video import SendVideo +from .send_video_note import SendVideoNote +from .send_voice import SendVoice +from .set_chat_description import SetChatDescription +from .set_chat_permissions import SetChatPermissions +from .set_chat_photo import SetChatPhoto +from .set_chat_sticker_set import SetChatStickerSet +from .set_chat_title import SetChatTitle +from .set_game_score import SetGameScore +from .set_passport_data_errors import SetPassportDataErrors +from .set_sticker_position_in_set import SetStickerPositionInSet +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_chat_message import UnpinChatMessage +from .upload_sticker_file import UploadStickerFile + +__all__ = ( + "TelegramMethod", + "Request", + "Response", + "GetUpdates", + "SetWebhook", + "DeleteWebhook", + "GetWebhookInfo", + "GetMe", + "SendMessage", + "ForwardMessage", + "SendPhoto", + "SendAudio", + "SendDocument", + "SendVideo", + "SendAnimation", + "SendVoice", + "SendVideoNote", + "SendMediaGroup", + "SendLocation", + "EditMessageLiveLocation", + "StopMessageLiveLocation", + "SendVenue", + "SendContact", + "SendPoll", + "SendChatAction", + "GetUserProfilePhotos", + "GetFile", + "KickChatMember", + "UnbanChatMember", + "RestrictChatMember", + "PromoteChatMember", + "SetChatPermissions", + "ExportChatInviteLink", + "SetChatPhoto", + "DeleteChatPhoto", + "SetChatTitle", + "SetChatDescription", + "PinChatMessage", + "UnpinChatMessage", + "LeaveChat", + "GetChat", + "GetChatAdministrators", + "GetChatMembersCount", + "GetChatMember", + "SetChatStickerSet", + "DeleteChatStickerSet", + "AnswerCallbackQuery", + "EditMessageText", + "EditMessageCaption", + "EditMessageMedia", + "EditMessageReplyMarkup", + "StopPoll", + "DeleteMessage", + "SendSticker", + "GetStickerSet", + "UploadStickerFile", + "CreateNewStickerSet", + "AddStickerToSet", + "SetStickerPositionInSet", + "DeleteStickerFromSet", + "AnswerInlineQuery", + "SendInvoice", + "AnswerShippingQuery", + "AnswerPreCheckoutQuery", + "SetPassportDataErrors", + "SendGame", + "SetGameScore", + "GetGameHighScores", +) diff --git a/aiogram/api/methods/add_sticker_to_set.py b/aiogram/api/methods/add_sticker_to_set.py new file mode 100644 index 00000000..de458cb0 --- /dev/null +++ b/aiogram/api/methods/add_sticker_to_set.py @@ -0,0 +1,34 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InputFile, MaskPosition +from .base import Request, TelegramMethod + + +class AddStickerToSet(TelegramMethod[bool]): + """ + Use this method to add a new sticker to a set created by the bot. Returns True on success. + + Source: https://core.telegram.org/bots/api#addstickertoset + """ + + __returning__ = bool + + user_id: int + """User identifier of sticker set owner""" + + name: str + """Sticker set name""" + + png_sticker: Union[InputFile, str] + """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.""" + + emojis: str + """One or more emoji corresponding to the sticker""" + + mask_position: Optional[MaskPosition] = None + """A JSON-serialized object for position where the mask should be placed on faces""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="addStickerToSet", data=data, files=files) diff --git a/aiogram/api/methods/answer_callback_query.py b/aiogram/api/methods/answer_callback_query.py new file mode 100644 index 00000000..6e59ff85 --- /dev/null +++ b/aiogram/api/methods/answer_callback_query.py @@ -0,0 +1,36 @@ +from typing import Any, Dict, Optional + +from .base import Request, TelegramMethod + + +class AnswerCallbackQuery(TelegramMethod[bool]): + """ + Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned. + Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter. + + Source: https://core.telegram.org/bots/api#answercallbackquery + """ + + __returning__ = bool + + callback_query_id: str + """Unique identifier for the query to be answered""" + + text: Optional[str] = None + """Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters""" + + show_alert: Optional[bool] = None + """If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.""" + + url: Optional[str] = None + """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. + + Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.""" + + cache_time: Optional[int] = None + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="answerCallbackQuery", data=data, files=files) diff --git a/aiogram/api/methods/answer_inline_query.py b/aiogram/api/methods/answer_inline_query.py new file mode 100644 index 00000000..d0803347 --- /dev/null +++ b/aiogram/api/methods/answer_inline_query.py @@ -0,0 +1,43 @@ +from typing import Any, Dict, List, Optional + +from ..types import InlineQueryResult +from .base import Request, TelegramMethod + + +class AnswerInlineQuery(TelegramMethod[bool]): + """ + Use this method to send answers to an inline query. On success, True is returned. + No more than 50 results per query are allowed. + + Source: https://core.telegram.org/bots/api#answerinlinequery + """ + + __returning__ = bool + + inline_query_id: str + """Unique identifier for the answered query""" + + results: List[InlineQueryResult] + """A JSON-serialized array of results for the inline query""" + + cache_time: Optional[int] = None + """The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.""" + + is_personal: Optional[bool] = None + """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""" + + next_offset: Optional[str] = None + """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.""" + + switch_pm_text: Optional[str] = None + """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""" + + switch_pm_parameter: Optional[str] = None + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="answerInlineQuery", data=data, files=files) diff --git a/aiogram/api/methods/answer_pre_checkout_query.py b/aiogram/api/methods/answer_pre_checkout_query.py new file mode 100644 index 00000000..be25b0a3 --- /dev/null +++ b/aiogram/api/methods/answer_pre_checkout_query.py @@ -0,0 +1,27 @@ +from typing import Any, Dict, Optional + +from .base import Request, TelegramMethod + + +class AnswerPreCheckoutQuery(TelegramMethod[bool]): + """ + Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + + Source: https://core.telegram.org/bots/api#answerprecheckoutquery + """ + + __returning__ = bool + + pre_checkout_query_id: str + """Unique identifier for the query to be answered""" + + ok: bool + """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.""" + + error_message: Optional[str] = None + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="answerPreCheckoutQuery", data=data, files=files) diff --git a/aiogram/api/methods/answer_shipping_query.py b/aiogram/api/methods/answer_shipping_query.py new file mode 100644 index 00000000..dfafbc8d --- /dev/null +++ b/aiogram/api/methods/answer_shipping_query.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, List, Optional + +from ..types import ShippingOption +from .base import Request, TelegramMethod + + +class AnswerShippingQuery(TelegramMethod[bool]): + """ + If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned. + + Source: https://core.telegram.org/bots/api#answershippingquery + """ + + __returning__ = bool + + shipping_query_id: str + """Unique identifier for the query to be answered""" + + ok: bool + """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)""" + + shipping_options: Optional[List[ShippingOption]] = None + """Required if ok is True. A JSON-serialized array of available shipping options.""" + + error_message: Optional[str] = None + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="answerShippingQuery", data=data, files=files) diff --git a/aiogram/api/methods/base.py b/aiogram/api/methods/base.py new file mode 100644 index 00000000..35ef997b --- /dev/null +++ b/aiogram/api/methods/base.py @@ -0,0 +1,49 @@ +import abc +import io +from typing import Any, Dict, Generic, Optional, Type, TypeVar, Union + +from pydantic import BaseConfig, BaseModel, Extra +from pydantic.generics import GenericModel + +from aiogram.api.types import InputFile, ResponseParameters + +T = TypeVar("T") + + +class Request(BaseModel): + method: str + + data: Dict[str, Optional[Any]] + files: Optional[Dict[str, Union[io.BytesIO, bytes, InputFile]]] + + class Config(BaseConfig): + arbitrary_types_allowed = True + + +class Response(ResponseParameters, GenericModel, Generic[T]): + ok: bool + result: Optional[T] = None + description: Optional[str] = None + error_code: Optional[int] = None + + +class TelegramMethod(abc.ABC, BaseModel, Generic[T]): + class Config(BaseConfig): + use_enum_values = True + extra = Extra.allow + allow_population_by_field_name = True + arbitrary_types_allowed = True + # orm_mode = True + + @property + @abc.abstractmethod + def __returning__(self) -> Type: + pass + + @abc.abstractmethod + def build_request(self) -> Request: + pass + + def build_response(self, data: Dict[str, Any]) -> Response[T]: + # noinspection PyTypeChecker + return Response[self.__returning__](**data) # type: ignore diff --git a/aiogram/api/methods/create_new_sticker_set.py b/aiogram/api/methods/create_new_sticker_set.py new file mode 100644 index 00000000..e53b7bfb --- /dev/null +++ b/aiogram/api/methods/create_new_sticker_set.py @@ -0,0 +1,40 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InputFile, MaskPosition +from .base import Request, TelegramMethod + + +class CreateNewStickerSet(TelegramMethod[bool]): + """ + Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success. + + Source: https://core.telegram.org/bots/api#createnewstickerset + """ + + __returning__ = bool + + user_id: int + """User identifier of created sticker set owner""" + + name: str + """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.""" + + title: str + """Sticker set title, 1-64 characters""" + + png_sticker: Union[InputFile, str] + """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.""" + + emojis: str + """One or more emoji corresponding to the sticker""" + + contains_masks: Optional[bool] = None + """Pass True, if a set of mask stickers should be created""" + + mask_position: Optional[MaskPosition] = None + """A JSON-serialized object for position where the mask should be placed on faces""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="createNewStickerSet", data=data, files=files) diff --git a/aiogram/api/methods/delete_chat_photo.py b/aiogram/api/methods/delete_chat_photo.py new file mode 100644 index 00000000..60a20ddf --- /dev/null +++ b/aiogram/api/methods/delete_chat_photo.py @@ -0,0 +1,21 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class DeleteChatPhoto(TelegramMethod[bool]): + """ + Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + Source: https://core.telegram.org/bots/api#deletechatphoto + """ + + __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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="deleteChatPhoto", data=data, files=files) diff --git a/aiogram/api/methods/delete_chat_sticker_set.py b/aiogram/api/methods/delete_chat_sticker_set.py new file mode 100644 index 00000000..0091171b --- /dev/null +++ b/aiogram/api/methods/delete_chat_sticker_set.py @@ -0,0 +1,21 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class DeleteChatStickerSet(TelegramMethod[bool]): + """ + Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 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. + + Source: https://core.telegram.org/bots/api#deletechatstickerset + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="deleteChatStickerSet", data=data, files=files) diff --git a/aiogram/api/methods/delete_message.py b/aiogram/api/methods/delete_message.py new file mode 100644 index 00000000..a682b789 --- /dev/null +++ b/aiogram/api/methods/delete_message.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class DeleteMessage(TelegramMethod[bool]): + """ + Use this method to delete a message, including service messages, with the following limitations: + - A message can only be deleted if it was sent less than 48 hours ago. + - Bots can delete outgoing messages in private chats, groups, and supergroups. + - Bots can delete incoming messages in private chats. + - Bots granted can_post_messages permissions can delete outgoing messages in channels. + - If the bot is an administrator of a group, it can delete any message there. + - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. + Returns True on success. + + Source: https://core.telegram.org/bots/api#deletemessage + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: int + """Identifier of the message to delete""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="deleteMessage", data=data, files=files) diff --git a/aiogram/api/methods/delete_sticker_from_set.py b/aiogram/api/methods/delete_sticker_from_set.py new file mode 100644 index 00000000..0f592edb --- /dev/null +++ b/aiogram/api/methods/delete_sticker_from_set.py @@ -0,0 +1,21 @@ +from typing import Any, Dict + +from .base import Request, TelegramMethod + + +class DeleteStickerFromSet(TelegramMethod[bool]): + """ + Use this method to delete a sticker from a set created by the bot. Returns True on success. + + Source: https://core.telegram.org/bots/api#deletestickerfromset + """ + + __returning__ = bool + + sticker: str + """File identifier of the sticker""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="deleteStickerFromSet", data=data, files=files) diff --git a/aiogram/api/methods/delete_webhook.py b/aiogram/api/methods/delete_webhook.py new file mode 100644 index 00000000..d9f1232e --- /dev/null +++ b/aiogram/api/methods/delete_webhook.py @@ -0,0 +1,18 @@ +from typing import Any, Dict + +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#deletewebhook + """ + + __returning__ = bool + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="deleteWebhook", data=data, files=files) diff --git a/aiogram/api/methods/edit_message_caption.py b/aiogram/api/methods/edit_message_caption.py new file mode 100644 index 00000000..4069b39c --- /dev/null +++ b/aiogram/api/methods/edit_message_caption.py @@ -0,0 +1,37 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, Message +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#editmessagecaption + """ + + __returning__ = Union[Message, bool] + + chat_id: Optional[Union[int, str]] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: Optional[int] = None + """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""" + + caption: Optional[str] = None + """New caption of the message""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for an inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="editMessageCaption", data=data, files=files) diff --git a/aiogram/api/methods/edit_message_live_location.py b/aiogram/api/methods/edit_message_live_location.py new file mode 100644 index 00000000..1cebf23b --- /dev/null +++ b/aiogram/api/methods/edit_message_live_location.py @@ -0,0 +1,37 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, Message +from .base import Request, TelegramMethod + + +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 returned. + + Source: https://core.telegram.org/bots/api#editmessagelivelocation + """ + + __returning__ = Union[Message, bool] + + latitude: float + """Latitude of new location""" + + longitude: float + """Longitude of new location""" + + chat_id: Optional[Union[int, str]] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: Optional[int] = None + """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""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for a new inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="editMessageLiveLocation", data=data, files=files) diff --git a/aiogram/api/methods/edit_message_media.py b/aiogram/api/methods/edit_message_media.py new file mode 100644 index 00000000..251e7053 --- /dev/null +++ b/aiogram/api/methods/edit_message_media.py @@ -0,0 +1,34 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, InputMedia, Message +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#editmessagemedia + """ + + __returning__ = Union[Message, bool] + + media: InputMedia + """A JSON-serialized object for a new media content of the message""" + + chat_id: Optional[Union[int, str]] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: Optional[int] = None + """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""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for a new inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="editMessageMedia", data=data, files=files) diff --git a/aiogram/api/methods/edit_message_reply_markup.py b/aiogram/api/methods/edit_message_reply_markup.py new file mode 100644 index 00000000..8651bc52 --- /dev/null +++ b/aiogram/api/methods/edit_message_reply_markup.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, Message +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#editmessagereplymarkup + """ + + __returning__ = Union[Message, bool] + + chat_id: Optional[Union[int, str]] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: Optional[int] = None + """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""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for an inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="editMessageReplyMarkup", data=data, files=files) diff --git a/aiogram/api/methods/edit_message_text.py b/aiogram/api/methods/edit_message_text.py new file mode 100644 index 00000000..96886e80 --- /dev/null +++ b/aiogram/api/methods/edit_message_text.py @@ -0,0 +1,40 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, Message +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#editmessagetext + """ + + __returning__ = Union[Message, bool] + + text: str + """New text of the message""" + + chat_id: Optional[Union[int, str]] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: Optional[int] = None + """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""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.""" + + disable_web_page_preview: Optional[bool] = None + """Disables link previews for links in this message""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for an inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="editMessageText", data=data, files=files) diff --git a/aiogram/api/methods/export_chat_invite_link.py b/aiogram/api/methods/export_chat_invite_link.py new file mode 100644 index 00000000..a7035c80 --- /dev/null +++ b/aiogram/api/methods/export_chat_invite_link.py @@ -0,0 +1,22 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class ExportChatInviteLink(TelegramMethod[str]): + """ + Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as String on success. + Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink – after this the link will become available to the bot via the getChat method. If your bot needs to generate a new invite link replacing its previous one, use exportChatInviteLink again. + + Source: https://core.telegram.org/bots/api#exportchatinvitelink + """ + + __returning__ = str + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="exportChatInviteLink", data=data, files=files) diff --git a/aiogram/api/methods/forward_message.py b/aiogram/api/methods/forward_message.py new file mode 100644 index 00000000..cc9f95fa --- /dev/null +++ b/aiogram/api/methods/forward_message.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, Optional, Union + +from ..types import Message +from .base import Request, TelegramMethod + + +class ForwardMessage(TelegramMethod[Message]): + """ + Use this method to forward messages of any kind. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#forwardmessage + """ + + __returning__ = Message + + 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""" + + disable_notification: Optional[bool] = None + """Sends the message silently. Users will receive a notification with no sound.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="forwardMessage", data=data, files=files) diff --git a/aiogram/api/methods/get_chat.py b/aiogram/api/methods/get_chat.py new file mode 100644 index 00000000..a4833fcb --- /dev/null +++ b/aiogram/api/methods/get_chat.py @@ -0,0 +1,22 @@ +from typing import Any, Dict, Union + +from ..types import Chat +from .base import Request, TelegramMethod + + +class GetChat(TelegramMethod[Chat]): + """ + Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. + + Source: https://core.telegram.org/bots/api#getchat + """ + + __returning__ = Chat + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getChat", data=data, files=files) diff --git a/aiogram/api/methods/get_chat_administrators.py b/aiogram/api/methods/get_chat_administrators.py new file mode 100644 index 00000000..ba01f7b2 --- /dev/null +++ b/aiogram/api/methods/get_chat_administrators.py @@ -0,0 +1,22 @@ +from typing import Any, Dict, List, Union + +from ..types import ChatMember +from .base import Request, TelegramMethod + + +class GetChatAdministrators(TelegramMethod[List[ChatMember]]): + """ + Use this method to get a list of administrators in a chat. 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. + + Source: https://core.telegram.org/bots/api#getchatadministrators + """ + + __returning__ = List[ChatMember] + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getChatAdministrators", data=data, files=files) diff --git a/aiogram/api/methods/get_chat_member.py b/aiogram/api/methods/get_chat_member.py new file mode 100644 index 00000000..4a6e2e34 --- /dev/null +++ b/aiogram/api/methods/get_chat_member.py @@ -0,0 +1,25 @@ +from typing import Any, Dict, Union + +from ..types import ChatMember +from .base import Request, TelegramMethod + + +class GetChatMember(TelegramMethod[ChatMember]): + """ + Use this method to get information about a member of a chat. Returns a ChatMember object on success. + + Source: https://core.telegram.org/bots/api#getchatmember + """ + + __returning__ = ChatMember + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" + + user_id: int + """Unique identifier of the target user""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getChatMember", data=data, files=files) diff --git a/aiogram/api/methods/get_chat_members_count.py b/aiogram/api/methods/get_chat_members_count.py new file mode 100644 index 00000000..699b60e9 --- /dev/null +++ b/aiogram/api/methods/get_chat_members_count.py @@ -0,0 +1,21 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class GetChatMembersCount(TelegramMethod[int]): + """ + Use this method to get the number of members in a chat. Returns Int on success. + + Source: https://core.telegram.org/bots/api#getchatmemberscount + """ + + __returning__ = int + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getChatMembersCount", data=data, files=files) diff --git a/aiogram/api/methods/get_file.py b/aiogram/api/methods/get_file.py new file mode 100644 index 00000000..7f18bc34 --- /dev/null +++ b/aiogram/api/methods/get_file.py @@ -0,0 +1,23 @@ +from typing import Any, Dict + +from ..types import File +from .base import Request, TelegramMethod + + +class GetFile(TelegramMethod[File]): + """ + Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. + Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received. + + Source: https://core.telegram.org/bots/api#getfile + """ + + __returning__ = File + + file_id: str + """File identifier to get info about""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getFile", data=data, files=files) diff --git a/aiogram/api/methods/get_game_high_scores.py b/aiogram/api/methods/get_game_high_scores.py new file mode 100644 index 00000000..b7b294aa --- /dev/null +++ b/aiogram/api/methods/get_game_high_scores.py @@ -0,0 +1,32 @@ +from typing import Any, Dict, List, Optional + +from ..types import GameHighScore +from .base import Request, TelegramMethod + + +class GetGameHighScores(TelegramMethod[List[GameHighScore]]): + """ + Use this method to get data for high score tables. Will return the score of the specified user and several of his 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 his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change. + + Source: https://core.telegram.org/bots/api#getgamehighscores + """ + + __returning__ = List[GameHighScore] + + user_id: int + """Target user id""" + + chat_id: Optional[int] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat""" + + message_id: Optional[int] = None + """Required if inline_message_id is not specified. Identifier of the sent message""" + + inline_message_id: Optional[str] = None + """Required if chat_id and message_id are not specified. Identifier of the inline message""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getGameHighScores", data=data, files=files) diff --git a/aiogram/api/methods/get_me.py b/aiogram/api/methods/get_me.py new file mode 100644 index 00000000..d4fc2980 --- /dev/null +++ b/aiogram/api/methods/get_me.py @@ -0,0 +1,19 @@ +from typing import Any, Dict + +from ..types import User +from .base import Request, TelegramMethod + + +class GetMe(TelegramMethod[User]): + """ + A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object. + + Source: https://core.telegram.org/bots/api#getme + """ + + __returning__ = User + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getMe", data=data, files=files) diff --git a/aiogram/api/methods/get_sticker_set.py b/aiogram/api/methods/get_sticker_set.py new file mode 100644 index 00000000..8fd9bcdb --- /dev/null +++ b/aiogram/api/methods/get_sticker_set.py @@ -0,0 +1,22 @@ +from typing import Any, Dict + +from ..types import StickerSet +from .base import Request, TelegramMethod + + +class GetStickerSet(TelegramMethod[StickerSet]): + """ + Use this method to get a sticker set. On success, a StickerSet object is returned. + + Source: https://core.telegram.org/bots/api#getstickerset + """ + + __returning__ = StickerSet + + name: str + """Name of the sticker set""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getStickerSet", data=data, files=files) diff --git a/aiogram/api/methods/get_updates.py b/aiogram/api/methods/get_updates.py new file mode 100644 index 00000000..15567f64 --- /dev/null +++ b/aiogram/api/methods/get_updates.py @@ -0,0 +1,36 @@ +from typing import Any, Dict, List, Optional + +from ..types import Update +from .base import Request, TelegramMethod + + +class GetUpdates(TelegramMethod[List[Update]]): + """ + Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. + Notes + 1. This method will not work if an outgoing webhook is set up. + 2. In order to avoid getting duplicate updates, recalculate offset after each server response. + + Source: https://core.telegram.org/bots/api#getupdates + """ + + __returning__ = List[Update] + + offset: Optional[int] = None + """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.""" + + limit: Optional[int] = None + """Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.""" + + timeout: Optional[int] = None + """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.""" + + allowed_updates: Optional[List[str]] = None + """List the types of updates 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. + + Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getUpdates", data=data, files=files) diff --git a/aiogram/api/methods/get_user_profile_photos.py b/aiogram/api/methods/get_user_profile_photos.py new file mode 100644 index 00000000..b42c0c73 --- /dev/null +++ b/aiogram/api/methods/get_user_profile_photos.py @@ -0,0 +1,28 @@ +from typing import Any, Dict, Optional + +from ..types import UserProfilePhotos +from .base import Request, TelegramMethod + + +class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): + """ + Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. + + Source: https://core.telegram.org/bots/api#getuserprofilephotos + """ + + __returning__ = UserProfilePhotos + + user_id: int + """Unique identifier of the target user""" + + offset: Optional[int] = None + """Sequential number of the first photo to be returned. By default, all photos are returned.""" + + limit: Optional[int] = None + """Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getUserProfilePhotos", data=data, files=files) diff --git a/aiogram/api/methods/get_webhook_info.py b/aiogram/api/methods/get_webhook_info.py new file mode 100644 index 00000000..a034039e --- /dev/null +++ b/aiogram/api/methods/get_webhook_info.py @@ -0,0 +1,19 @@ +from typing import Any, Dict + +from ..types import WebhookInfo +from .base import Request, TelegramMethod + + +class GetWebhookInfo(TelegramMethod[WebhookInfo]): + """ + Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty. + + Source: https://core.telegram.org/bots/api#getwebhookinfo + """ + + __returning__ = WebhookInfo + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="getWebhookInfo", data=data, files=files) diff --git a/aiogram/api/methods/kick_chat_member.py b/aiogram/api/methods/kick_chat_member.py new file mode 100644 index 00000000..1542ce79 --- /dev/null +++ b/aiogram/api/methods/kick_chat_member.py @@ -0,0 +1,27 @@ +from typing import Any, Dict, Optional, Union + +from .base import Request, TelegramMethod + + +class KickChatMember(TelegramMethod[bool]): + """ + Use this method to kick a user from a group, a supergroup or a channel. 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., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + Source: https://core.telegram.org/bots/api#kickchatmember + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)""" + + user_id: int + """Unique identifier of the target user""" + + until_date: Optional[int] = None + """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""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="kickChatMember", data=data, files=files) diff --git a/aiogram/api/methods/leave_chat.py b/aiogram/api/methods/leave_chat.py new file mode 100644 index 00000000..fafaf7a6 --- /dev/null +++ b/aiogram/api/methods/leave_chat.py @@ -0,0 +1,21 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class LeaveChat(TelegramMethod[bool]): + """ + Use this method for your bot to leave a group, supergroup or channel. Returns True on success. + + Source: https://core.telegram.org/bots/api#leavechat + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="leaveChat", data=data, files=files) diff --git a/aiogram/api/methods/pin_chat_message.py b/aiogram/api/methods/pin_chat_message.py new file mode 100644 index 00000000..6e4f5974 --- /dev/null +++ b/aiogram/api/methods/pin_chat_message.py @@ -0,0 +1,27 @@ +from typing import Any, Dict, Optional, Union + +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#pinchatmessage + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: int + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="pinChatMessage", data=data, files=files) diff --git a/aiogram/api/methods/promote_chat_member.py b/aiogram/api/methods/promote_chat_member.py new file mode 100644 index 00000000..34a30da9 --- /dev/null +++ b/aiogram/api/methods/promote_chat_member.py @@ -0,0 +1,48 @@ +from typing import Any, Dict, Optional, Union + +from .base import Request, TelegramMethod + + +class PromoteChatMember(TelegramMethod[bool]): + """ + Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. Returns True on success. + + Source: https://core.telegram.org/bots/api#promotechatmember + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + user_id: int + """Unique identifier of the target user""" + + 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 + """Pass True, if the administrator can create channel posts, channels only""" + + can_edit_messages: Optional[bool] = None + """Pass True, if the administrator can edit messages of other users and can pin messages, channels only""" + + can_delete_messages: Optional[bool] = None + """Pass True, if the administrator can delete messages of other users""" + + can_invite_users: Optional[bool] = None + """Pass True, if the administrator can invite new users to the chat""" + + can_restrict_members: Optional[bool] = None + """Pass True, if the administrator can restrict, ban or unban chat members""" + + can_pin_messages: Optional[bool] = None + """Pass True, if the administrator can pin messages, supergroups only""" + + can_promote_members: Optional[bool] = None + """Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="promoteChatMember", data=data, files=files) diff --git a/aiogram/api/methods/restrict_chat_member.py b/aiogram/api/methods/restrict_chat_member.py new file mode 100644 index 00000000..16ebe23e --- /dev/null +++ b/aiogram/api/methods/restrict_chat_member.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ChatPermissions +from .base import Request, TelegramMethod + + +class RestrictChatMember(TelegramMethod[bool]): + """ + Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns True on success. + + Source: https://core.telegram.org/bots/api#restrictchatmember + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)""" + + user_id: int + """Unique identifier of the target user""" + + permissions: ChatPermissions + """New user permissions""" + + until_date: Optional[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 restricted forever""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="restrictChatMember", data=data, files=files) diff --git a/aiogram/api/methods/send_animation.py b/aiogram/api/methods/send_animation.py new file mode 100644 index 00000000..36e1fe56 --- /dev/null +++ b/aiogram/api/methods/send_animation.py @@ -0,0 +1,61 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendAnimation(TelegramMethod[Message]): + """ + Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. + + Source: https://core.telegram.org/bots/api#sendanimation + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + animation: Union[InputFile, str] + """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.""" + + duration: Optional[int] = None + """Duration of sent animation in seconds""" + + width: Optional[int] = None + """Animation width""" + + height: Optional[int] = None + """Animation height""" + + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + + caption: Optional[str] = None + """Animation caption (may also be used when resending animation by file_id), 0-1024 characters""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendAnimation", data=data, files=files) diff --git a/aiogram/api/methods/send_audio.py b/aiogram/api/methods/send_audio.py new file mode 100644 index 00000000..e6ae098d --- /dev/null +++ b/aiogram/api/methods/send_audio.py @@ -0,0 +1,62 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendAudio(TelegramMethod[Message]): + """ + Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. + For sending voice messages, use the sendVoice method instead. + + Source: https://core.telegram.org/bots/api#sendaudio + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + audio: Union[InputFile, str] + """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.""" + + caption: Optional[str] = None + """Audio caption, 0-1024 characters""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + duration: Optional[int] = None + """Duration of the audio in seconds""" + + performer: Optional[str] = None + """Performer""" + + title: Optional[str] = None + """Track name""" + + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendAudio", data=data, files=files) diff --git a/aiogram/api/methods/send_chat_action.py b/aiogram/api/methods/send_chat_action.py new file mode 100644 index 00000000..0bbc81f1 --- /dev/null +++ b/aiogram/api/methods/send_chat_action.py @@ -0,0 +1,26 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class SendChatAction(TelegramMethod[bool]): + """ + Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. + Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of 'Retrieving image, please wait…', the bot may use sendChatAction with action = upload_photo. The user will see a 'sending photo' status for the bot. + We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. + + Source: https://core.telegram.org/bots/api#sendchataction + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + action: str + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendChatAction", data=data, files=files) diff --git a/aiogram/api/methods/send_contact.py b/aiogram/api/methods/send_contact.py new file mode 100644 index 00000000..4e620e8a --- /dev/null +++ b/aiogram/api/methods/send_contact.py @@ -0,0 +1,51 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendContact(TelegramMethod[Message]): + """ + Use this method to send phone contacts. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendcontact + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + phone_number: str + """Contact's phone number""" + + first_name: str + """Contact's first name""" + + last_name: Optional[str] = None + """Contact's last name""" + + vcard: Optional[str] = None + """Additional data about the contact in the form of a vCard, 0-2048 bytes""" + + 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""" + + 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 keyboard or to force a reply from the user.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendContact", data=data, files=files) diff --git a/aiogram/api/methods/send_document.py b/aiogram/api/methods/send_document.py new file mode 100644 index 00000000..93e0a2bc --- /dev/null +++ b/aiogram/api/methods/send_document.py @@ -0,0 +1,52 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendDocument(TelegramMethod[Message]): + """ + Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + + Source: https://core.telegram.org/bots/api#senddocument + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + document: Union[InputFile, str] + """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.""" + + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + + caption: Optional[str] = None + """Document caption (may also be used when resending documents by file_id), 0-1024 characters""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendDocument", data=data, files=files) diff --git a/aiogram/api/methods/send_game.py b/aiogram/api/methods/send_game.py new file mode 100644 index 00000000..33461b8d --- /dev/null +++ b/aiogram/api/methods/send_game.py @@ -0,0 +1,34 @@ +from typing import Any, Dict, Optional + +from ..types import InlineKeyboardMarkup, Message +from .base import Request, TelegramMethod + + +class SendGame(TelegramMethod[Message]): + """ + Use this method to send a game. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendgame + """ + + __returning__ = Message + + chat_id: int + """Unique identifier for the target chat""" + + game_short_name: str + """Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.""" + + 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""" + + 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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendGame", data=data, files=files) diff --git a/aiogram/api/methods/send_invoice.py b/aiogram/api/methods/send_invoice.py new file mode 100644 index 00000000..38b72a5a --- /dev/null +++ b/aiogram/api/methods/send_invoice.py @@ -0,0 +1,88 @@ +from typing import Any, Dict, List, Optional + +from ..types import InlineKeyboardMarkup, LabeledPrice, Message +from .base import Request, TelegramMethod + + +class SendInvoice(TelegramMethod[Message]): + """ + Use this method to send invoices. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendinvoice + """ + + __returning__ = Message + + chat_id: int + """Unique identifier for the target private chat""" + + title: str + """Product name, 1-32 characters""" + + description: str + """Product description, 1-255 characters""" + + payload: str + """Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.""" + + provider_token: str + """Payments provider token, obtained via Botfather""" + + start_parameter: str + """Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter""" + + currency: str + """Three-letter ISO 4217 currency code, see more on currencies""" + + prices: List[LabeledPrice] + """Price breakdown, a 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 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 for a service. People like it better when they see what they are paying for.""" + + photo_size: Optional[int] = None + """Photo size""" + + photo_width: Optional[int] = None + """Photo width""" + + photo_height: Optional[int] = None + """Photo height""" + + need_name: Optional[bool] = None + """Pass True, if you require the user's full name to complete the order""" + + need_phone_number: Optional[bool] = None + """Pass True, if you require the user's phone number to complete the order""" + + need_email: Optional[bool] = None + """Pass True, if you require the user's email address to complete the order""" + + need_shipping_address: Optional[bool] = None + """Pass True, if you require the user's shipping address to complete the order""" + + send_phone_number_to_provider: Optional[bool] = None + """Pass True, if user's phone number should be sent to provider""" + + send_email_to_provider: Optional[bool] = None + """Pass True, if user's email address should be sent to provider""" + + is_flexible: Optional[bool] = None + """Pass True, if the final price depends on the shipping method""" + + 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""" + + 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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendInvoice", data=data, files=files) diff --git a/aiogram/api/methods/send_location.py b/aiogram/api/methods/send_location.py new file mode 100644 index 00000000..e46a89a9 --- /dev/null +++ b/aiogram/api/methods/send_location.py @@ -0,0 +1,48 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendLocation(TelegramMethod[Message]): + """ + Use this method to send point on the map. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendlocation + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + latitude: float + """Latitude of the location""" + + longitude: float + """Longitude of the location""" + + live_period: Optional[int] = None + """Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendLocation", data=data, files=files) diff --git a/aiogram/api/methods/send_media_group.py b/aiogram/api/methods/send_media_group.py new file mode 100644 index 00000000..18c158dc --- /dev/null +++ b/aiogram/api/methods/send_media_group.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, List, Optional, Union + +from ..types import InputMediaPhoto, InputMediaVideo, Message +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#sendmediagroup + """ + + __returning__ = 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""" + + disable_notification: Optional[bool] = None + """Sends the 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""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendMediaGroup", data=data, files=files) diff --git a/aiogram/api/methods/send_message.py b/aiogram/api/methods/send_message.py new file mode 100644 index 00000000..c5927651 --- /dev/null +++ b/aiogram/api/methods/send_message.py @@ -0,0 +1,48 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendMessage(TelegramMethod[Message]): + """ + Use this method to send text messages. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendmessage + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + text: str + """Text of the message to be sent""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendMessage", data=data, files=files) diff --git a/aiogram/api/methods/send_photo.py b/aiogram/api/methods/send_photo.py new file mode 100644 index 00000000..d37c7dec --- /dev/null +++ b/aiogram/api/methods/send_photo.py @@ -0,0 +1,49 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendPhoto(TelegramMethod[Message]): + """ + Use this method to send photos. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendphoto + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + photo: Union[InputFile, str] + """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.""" + + caption: Optional[str] = None + """Photo caption (may also be used when resending photos by file_id), 0-1024 characters""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendPhoto", data=data, files=files) diff --git a/aiogram/api/methods/send_poll.py b/aiogram/api/methods/send_poll.py new file mode 100644 index 00000000..2da01454 --- /dev/null +++ b/aiogram/api/methods/send_poll.py @@ -0,0 +1,45 @@ +from typing import Any, Dict, List, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendPoll(TelegramMethod[Message]): + """ + Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendpoll + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername). A native poll can't be sent to a private chat.""" + + question: str + """Poll question, 1-255 characters""" + + options: List[str] + """List of answer options, 2-10 strings 1-100 characters each""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendPoll", data=data, files=files) diff --git a/aiogram/api/methods/send_sticker.py b/aiogram/api/methods/send_sticker.py new file mode 100644 index 00000000..c9adb11f --- /dev/null +++ b/aiogram/api/methods/send_sticker.py @@ -0,0 +1,43 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendSticker(TelegramMethod[Message]): + """ + Use this method to send static .WEBP or animated .TGS stickers. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendsticker + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + sticker: Union[InputFile, str] + """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.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendSticker", data=data, files=files) diff --git a/aiogram/api/methods/send_venue.py b/aiogram/api/methods/send_venue.py new file mode 100644 index 00000000..229c103a --- /dev/null +++ b/aiogram/api/methods/send_venue.py @@ -0,0 +1,57 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendVenue(TelegramMethod[Message]): + """ + Use this method to send information about a venue. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendvenue + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + latitude: float + """Latitude of the venue""" + + longitude: float + """Longitude of the venue""" + + title: str + """Name of the venue""" + + address: str + """Address of the venue""" + + foursquare_id: Optional[str] = None + """Foursquare identifier of the venue""" + + foursquare_type: Optional[str] = None + """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendVenue", data=data, files=files) diff --git a/aiogram/api/methods/send_video.py b/aiogram/api/methods/send_video.py new file mode 100644 index 00000000..34af89ab --- /dev/null +++ b/aiogram/api/methods/send_video.py @@ -0,0 +1,64 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendVideo(TelegramMethod[Message]): + """ + Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. + + Source: https://core.telegram.org/bots/api#sendvideo + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + video: Union[InputFile, str] + """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.""" + + duration: Optional[int] = None + """Duration of sent video in seconds""" + + width: Optional[int] = None + """Video width""" + + height: Optional[int] = None + """Video height""" + + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + + caption: Optional[str] = None + """Video caption (may also be used when resending videos by file_id), 0-1024 characters""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendVideo", data=data, files=files) diff --git a/aiogram/api/methods/send_video_note.py b/aiogram/api/methods/send_video_note.py new file mode 100644 index 00000000..b856e082 --- /dev/null +++ b/aiogram/api/methods/send_video_note.py @@ -0,0 +1,52 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendVideoNote(TelegramMethod[Message]): + """ + As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned. + + Source: https://core.telegram.org/bots/api#sendvideonote + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + video_note: Union[InputFile, str] + """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""" + + duration: Optional[int] = None + """Duration of sent video in seconds""" + + length: Optional[int] = None + """Video width and height, i.e. diameter of the video message""" + + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendVideoNote", data=data, files=files) diff --git a/aiogram/api/methods/send_voice.py b/aiogram/api/methods/send_voice.py new file mode 100644 index 00000000..7988310f --- /dev/null +++ b/aiogram/api/methods/send_voice.py @@ -0,0 +1,52 @@ +from typing import Any, Dict, Optional, Union + +from ..types import ( + ForceReply, + InlineKeyboardMarkup, + InputFile, + Message, + ReplyKeyboardMarkup, + ReplyKeyboardRemove, +) +from .base import Request, TelegramMethod + + +class SendVoice(TelegramMethod[Message]): + """ + Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. + + Source: https://core.telegram.org/bots/api#sendvoice + """ + + __returning__ = Message + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + voice: Union[InputFile, str] + """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.""" + + caption: Optional[str] = None + """Voice message caption, 0-1024 characters""" + + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + + 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""" + + 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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="sendVoice", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_description.py b/aiogram/api/methods/set_chat_description.py new file mode 100644 index 00000000..ebbb62c0 --- /dev/null +++ b/aiogram/api/methods/set_chat_description.py @@ -0,0 +1,24 @@ +from typing import Any, Dict, Optional, Union + +from .base import Request, TelegramMethod + + +class SetChatDescription(TelegramMethod[bool]): + """ + Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + Source: https://core.telegram.org/bots/api#setchatdescription + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + description: Optional[str] = None + """New chat description, 0-255 characters""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setChatDescription", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_permissions.py b/aiogram/api/methods/set_chat_permissions.py new file mode 100644 index 00000000..906c9739 --- /dev/null +++ b/aiogram/api/methods/set_chat_permissions.py @@ -0,0 +1,25 @@ +from typing import Any, Dict, Union + +from ..types import ChatPermissions +from .base import Request, TelegramMethod + + +class SetChatPermissions(TelegramMethod[bool]): + """ + Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success. + + Source: https://core.telegram.org/bots/api#setchatpermissions + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)""" + + permissions: ChatPermissions + """New default chat permissions""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setChatPermissions", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_photo.py b/aiogram/api/methods/set_chat_photo.py new file mode 100644 index 00000000..6b835f6a --- /dev/null +++ b/aiogram/api/methods/set_chat_photo.py @@ -0,0 +1,25 @@ +from typing import Any, Dict, Union + +from ..types import InputFile +from .base import Request, TelegramMethod + + +class SetChatPhoto(TelegramMethod[bool]): + """ + Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + Source: https://core.telegram.org/bots/api#setchatphoto + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + photo: InputFile + """New chat photo, uploaded using multipart/form-data""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setChatPhoto", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_sticker_set.py b/aiogram/api/methods/set_chat_sticker_set.py new file mode 100644 index 00000000..002dcafc --- /dev/null +++ b/aiogram/api/methods/set_chat_sticker_set.py @@ -0,0 +1,24 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class SetChatStickerSet(TelegramMethod[bool]): + """ + Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 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. + + Source: https://core.telegram.org/bots/api#setchatstickerset + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)""" + + sticker_set_name: str + """Name of the sticker set to be set as the group sticker set""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setChatStickerSet", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_title.py b/aiogram/api/methods/set_chat_title.py new file mode 100644 index 00000000..037c268e --- /dev/null +++ b/aiogram/api/methods/set_chat_title.py @@ -0,0 +1,24 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +class SetChatTitle(TelegramMethod[bool]): + """ + Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. + + Source: https://core.telegram.org/bots/api#setchattitle + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + title: str + """New chat title, 1-255 characters""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setChatTitle", data=data, files=files) diff --git a/aiogram/api/methods/set_game_score.py b/aiogram/api/methods/set_game_score.py new file mode 100644 index 00000000..fa8675f1 --- /dev/null +++ b/aiogram/api/methods/set_game_score.py @@ -0,0 +1,40 @@ +from typing import Any, Dict, Optional, Union + +from ..types import Message +from .base import Request, TelegramMethod + + +class SetGameScore(TelegramMethod[Union[Message, bool]]): + """ + Use this method to set the score of the specified user in a game. 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. + + Source: https://core.telegram.org/bots/api#setgamescore + """ + + __returning__ = Union[Message, bool] + + user_id: int + """User identifier""" + + score: int + """New score, must be non-negative""" + + force: Optional[bool] = None + """Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters""" + + disable_edit_message: Optional[bool] = None + """Pass True, if the game message should not be automatically edited to include the current scoreboard""" + + chat_id: Optional[int] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat""" + + message_id: Optional[int] = None + """Required if inline_message_id is not specified. Identifier of the sent message""" + + inline_message_id: Optional[str] = None + """Required if chat_id and message_id are not specified. Identifier of the inline message""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setGameScore", data=data, files=files) diff --git a/aiogram/api/methods/set_passport_data_errors.py b/aiogram/api/methods/set_passport_data_errors.py new file mode 100644 index 00000000..65c4ac43 --- /dev/null +++ b/aiogram/api/methods/set_passport_data_errors.py @@ -0,0 +1,26 @@ +from typing import Any, Dict, List + +from ..types import PassportElementError +from .base import Request, TelegramMethod + + +class SetPassportDataErrors(TelegramMethod[bool]): + """ + Informs a user that some of the Telegram Passport elements they provided contains errors. 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. + Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues. + + Source: https://core.telegram.org/bots/api#setpassportdataerrors + """ + + __returning__ = bool + + user_id: int + """User identifier""" + + errors: List[PassportElementError] + """A JSON-serialized array describing the errors""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setPassportDataErrors", data=data, files=files) diff --git a/aiogram/api/methods/set_sticker_position_in_set.py b/aiogram/api/methods/set_sticker_position_in_set.py new file mode 100644 index 00000000..844c9fd8 --- /dev/null +++ b/aiogram/api/methods/set_sticker_position_in_set.py @@ -0,0 +1,24 @@ +from typing import Any, Dict + +from .base import Request, TelegramMethod + + +class SetStickerPositionInSet(TelegramMethod[bool]): + """ + Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success. + + Source: https://core.telegram.org/bots/api#setstickerpositioninset + """ + + __returning__ = bool + + sticker: str + """File identifier of the sticker""" + + position: int + """New sticker position in the set, zero-based""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setStickerPositionInSet", data=data, files=files) diff --git a/aiogram/api/methods/set_webhook.py b/aiogram/api/methods/set_webhook.py new file mode 100644 index 00000000..05b2cfed --- /dev/null +++ b/aiogram/api/methods/set_webhook.py @@ -0,0 +1,39 @@ +from typing import Any, Dict, List, Optional + +from ..types import InputFile +from .base import Request, TelegramMethod + + +class SetWebhook(TelegramMethod[bool]): + """ + Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success. + If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. + Notes + 1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up. + 2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work. + 3. Ports currently supported for Webhooks: 443, 80, 88, 8443. + NEW! If you're having any trouble setting up webhooks, please check out this amazing guide to Webhooks. + + Source: https://core.telegram.org/bots/api#setwebhook + """ + + __returning__ = bool + + url: str + """HTTPS url to send updates to. Use an empty string to remove webhook integration""" + + 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.""" + + 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, and higher values to increase your bot’s throughput.""" + + allowed_updates: Optional[List[str]] = None + """List the types of updates 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. + + Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="setWebhook", data=data, files=files) diff --git a/aiogram/api/methods/stop_message_live_location.py b/aiogram/api/methods/stop_message_live_location.py new file mode 100644 index 00000000..5d3591da --- /dev/null +++ b/aiogram/api/methods/stop_message_live_location.py @@ -0,0 +1,31 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, Message +from .base import Request, TelegramMethod + + +class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): + """ + Use this method to stop updating a live location message before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned. + + Source: https://core.telegram.org/bots/api#stopmessagelivelocation + """ + + __returning__ = Union[Message, bool] + + chat_id: Optional[Union[int, str]] = None + """Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: Optional[int] = None + """Required if inline_message_id is not specified. Identifier of the message with live location to stop""" + + inline_message_id: Optional[str] = None + """Required if chat_id and message_id are not specified. Identifier of the inline message""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for a new inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="stopMessageLiveLocation", data=data, files=files) diff --git a/aiogram/api/methods/stop_poll.py b/aiogram/api/methods/stop_poll.py new file mode 100644 index 00000000..8a93235d --- /dev/null +++ b/aiogram/api/methods/stop_poll.py @@ -0,0 +1,28 @@ +from typing import Any, Dict, Optional, Union + +from ..types import InlineKeyboardMarkup, Poll +from .base import Request, TelegramMethod + + +class StopPoll(TelegramMethod[Poll]): + """ + Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned. + + Source: https://core.telegram.org/bots/api#stoppoll + """ + + __returning__ = Poll + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" + + message_id: int + """Identifier of the original message with the poll""" + + reply_markup: Optional[InlineKeyboardMarkup] = None + """A JSON-serialized object for a new message inline keyboard.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="stopPoll", data=data, files=files) diff --git a/aiogram/api/methods/unban_chat_member.py b/aiogram/api/methods/unban_chat_member.py new file mode 100644 index 00000000..315f9a8e --- /dev/null +++ b/aiogram/api/methods/unban_chat_member.py @@ -0,0 +1,24 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#unbanchatmember + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target group or username of the target supergroup or channel (in the format @username)""" + + user_id: int + """Unique identifier of the target user""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="unbanChatMember", data=data, files=files) diff --git a/aiogram/api/methods/unpin_chat_message.py b/aiogram/api/methods/unpin_chat_message.py new file mode 100644 index 00000000..b9a5f14d --- /dev/null +++ b/aiogram/api/methods/unpin_chat_message.py @@ -0,0 +1,21 @@ +from typing import Any, Dict, Union + +from .base import Request, TelegramMethod + + +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. + + Source: https://core.telegram.org/bots/api#unpinchatmessage + """ + + __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) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="unpinChatMessage", data=data, files=files) diff --git a/aiogram/api/methods/upload_sticker_file.py b/aiogram/api/methods/upload_sticker_file.py new file mode 100644 index 00000000..f095dcdc --- /dev/null +++ b/aiogram/api/methods/upload_sticker_file.py @@ -0,0 +1,25 @@ +from typing import Any, Dict + +from ..types import File, InputFile +from .base import Request, TelegramMethod + + +class UploadStickerFile(TelegramMethod[File]): + """ + Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. + + Source: https://core.telegram.org/bots/api#uploadstickerfile + """ + + __returning__ = File + + user_id: int + """User identifier of sticker file owner""" + + png_sticker: InputFile + """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.""" + + def build_request(self) -> Request: + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + files: Dict[str, Any] = {} + return Request(method="uploadStickerFile", data=data, files=files) diff --git a/aiogram/api/session/__init__.py b/aiogram/api/session/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/aiogram/api/session/aiohttp.py b/aiogram/api/session/aiohttp.py new file mode 100644 index 00000000..4378e4d1 --- /dev/null +++ b/aiogram/api/session/aiohttp.py @@ -0,0 +1,51 @@ +from typing import Optional, TypeVar + +from aiohttp import ClientSession, FormData +from pydantic import BaseModel + +from .base import BaseSession, TelegramAPIServer, PRODUCTION +from ..methods import TelegramMethod, Request + +T = TypeVar('T') + + +class AiohttpSession(BaseSession): + def __init__(self, api: TelegramAPIServer = PRODUCTION): + super(AiohttpSession, self).__init__(api=api) + self._session: Optional[ClientSession] = None + + async def create_session(self): + if self._session is None or self._session.closed: + self._session = ClientSession() + + async def close(self): + if self._session is not None and not self._session.closed: + await self._session.close() + + def build_form_data(self, request: Request): + form = FormData() + for key, value in request.data.items(): + if value is None: + continue + if isinstance(value, bool): + print("elif isinstance(value, bool):", key, value) + form.add_field(key, value) + else: + print("else:", key, value) + form.add_field(key, str(value)) + return form + + async def make_request(self, token: str, call: TelegramMethod[T]) -> T: + await self.create_session() + + request = call.build_request() + url = self.api.api_url(token=token, method=request.method) + form = self.build_form_data(request) + + async with self._session.post(url, data=form) as response: + raw_result = await response.json() + + response = call.build_response(raw_result) + if not response.ok: + self.raise_for_status(response) + return response.result diff --git a/aiogram/api/session/api.py b/aiogram/api/session/api.py new file mode 100644 index 00000000..e69de29b diff --git a/aiogram/api/session/base.py b/aiogram/api/session/base.py new file mode 100644 index 00000000..323ec98d --- /dev/null +++ b/aiogram/api/session/base.py @@ -0,0 +1,54 @@ +import abc +import asyncio +from typing import TypeVar, Generic + +from pydantic.dataclasses import dataclass + +from aiogram.api.methods import Response, TelegramMethod + +T = TypeVar('T') + + +@dataclass +class TelegramAPIServer: + base: str + file: str + + def api_url(self, token: str, method: str) -> str: + return self.base.format(token=token, method=method) + + def file_url(self, token: str, path: str) -> str: + return self.file.format(token=token, path=path) + + +PRODUCTION = TelegramAPIServer( + base='https://api.telegram.org/bot{token}/{method}', + file='https://api.telegram.org/file/bot{token}/{path}' +) + + +class BaseSession(abc.ABC, Generic[T]): + def __init__(self, api: TelegramAPIServer = PRODUCTION): + self.api = api + + def raise_for_status(self, response: Response[T]): + print(f"ERROR: {response}") + + @abc.abstractmethod + async def close(self): + pass + + @abc.abstractmethod + async def make_request(self, token: str, method: TelegramMethod[T]) -> T: + pass + + def __del__(self): + try: + loop = asyncio.get_running_loop() + except RuntimeError: + loop = None + if loop is None or loop.is_closed(): + loop = asyncio.new_event_loop() + loop.run_until_complete(self.close()) + return + loop.create_task(self.close()) diff --git a/aiogram/api/types/__init__.py b/aiogram/api/types/__init__.py new file mode 100644 index 00000000..60a1e497 --- /dev/null +++ b/aiogram/api/types/__init__.py @@ -0,0 +1,199 @@ +from .animation import Animation +from .audio import Audio +from .base import TelegramObject +from .callback_game import CallbackGame +from .callback_query import CallbackQuery +from .chat import Chat +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 .document import Document +from .encrypted_credentials import EncryptedCredentials +from .encrypted_passport_element import EncryptedPassportElement +from .file import File +from .force_reply import ForceReply +from .game import Game +from .game_high_score import GameHighScore +from .inline_keyboard_button import InlineKeyboardButton +from .inline_keyboard_markup import InlineKeyboardMarkup +from .inline_query import InlineQuery +from .inline_query_result import InlineQueryResult +from .inline_query_result_article import InlineQueryResultArticle +from .inline_query_result_audio import InlineQueryResultAudio +from .inline_query_result_cached_audio import InlineQueryResultCachedAudio +from .inline_query_result_cached_document import InlineQueryResultCachedDocument +from .inline_query_result_cached_gif import InlineQueryResultCachedGif +from .inline_query_result_cached_mpeg4_gif import InlineQueryResultCachedMpeg4Gif +from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto +from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker +from .inline_query_result_cached_video import InlineQueryResultCachedVideo +from .inline_query_result_cached_voice import InlineQueryResultCachedVoice +from .inline_query_result_contact import InlineQueryResultContact +from .inline_query_result_document import InlineQueryResultDocument +from .inline_query_result_game import InlineQueryResultGame +from .inline_query_result_gif import InlineQueryResultGif +from .inline_query_result_location import InlineQueryResultLocation +from .inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif +from .inline_query_result_photo import InlineQueryResultPhoto +from .inline_query_result_venue import InlineQueryResultVenue +from .inline_query_result_video import InlineQueryResultVideo +from .inline_query_result_voice import InlineQueryResultVoice +from .input_contact_message_content import InputContactMessageContent +from .input_file import InputFile +from .input_location_message_content import InputLocationMessageContent +from .input_media import InputMedia +from .input_media_animation import InputMediaAnimation +from .input_media_audio import InputMediaAudio +from .input_media_document import InputMediaDocument +from .input_media_photo import InputMediaPhoto +from .input_media_video import InputMediaVideo +from .input_message_content import InputMessageContent +from .input_text_message_content import InputTextMessageContent +from .input_venue_message_content import InputVenueMessageContent +from .invoice import Invoice +from .keyboard_button import KeyboardButton +from .labeled_price import LabeledPrice +from .location import Location +from .login_url import LoginUrl +from .mask_position import MaskPosition +from .message import Message +from .message_entity import MessageEntity +from .order_info import OrderInfo +from .passport_data import PassportData +from .passport_element_error import PassportElementError +from .passport_element_error_data_field import PassportElementErrorDataField +from .passport_element_error_file import PassportElementErrorFile +from .passport_element_error_files import PassportElementErrorFiles +from .passport_element_error_front_side import PassportElementErrorFrontSide +from .passport_element_error_reverse_side import PassportElementErrorReverseSide +from .passport_element_error_selfie import PassportElementErrorSelfie +from .passport_element_error_translation_file import PassportElementErrorTranslationFile +from .passport_element_error_translation_files import PassportElementErrorTranslationFiles +from .passport_element_error_unspecified import PassportElementErrorUnspecified +from .passport_file import PassportFile +from .photo_size import PhotoSize +from .poll import Poll +from .poll_option import PollOption +from .pre_checkout_query import PreCheckoutQuery +from .reply_keyboard_markup import ReplyKeyboardMarkup +from .reply_keyboard_remove import ReplyKeyboardRemove +from .response_parameters import ResponseParameters +from .shipping_address import ShippingAddress +from .shipping_option import ShippingOption +from .shipping_query import ShippingQuery +from .sticker import Sticker +from .sticker_set import StickerSet +from .successful_payment import SuccessfulPayment +from .update import Update +from .user import User +from .user_profile_photos import UserProfilePhotos +from .venue import Venue +from .video import Video +from .video_note import VideoNote +from .voice import Voice +from .webhook_info import WebhookInfo + +__all__ = ( + "TelegramObject", + "Update", + "WebhookInfo", + "User", + "Chat", + "Message", + "MessageEntity", + "PhotoSize", + "Audio", + "Document", + "Video", + "Animation", + "Voice", + "VideoNote", + "Contact", + "Location", + "Venue", + "PollOption", + "Poll", + "UserProfilePhotos", + "File", + "ReplyKeyboardMarkup", + "KeyboardButton", + "ReplyKeyboardRemove", + "InlineKeyboardMarkup", + "InlineKeyboardButton", + "LoginUrl", + "CallbackQuery", + "ForceReply", + "ChatPhoto", + "ChatMember", + "ChatPermissions", + "ResponseParameters", + "InputMedia", + "InputMediaPhoto", + "InputMediaVideo", + "InputMediaAnimation", + "InputMediaAudio", + "InputMediaDocument", + "InputFile", + "Sticker", + "StickerSet", + "MaskPosition", + "InlineQuery", + "InlineQueryResult", + "InlineQueryResultArticle", + "InlineQueryResultPhoto", + "InlineQueryResultGif", + "InlineQueryResultMpeg4Gif", + "InlineQueryResultVideo", + "InlineQueryResultAudio", + "InlineQueryResultVoice", + "InlineQueryResultDocument", + "InlineQueryResultLocation", + "InlineQueryResultVenue", + "InlineQueryResultContact", + "InlineQueryResultGame", + "InlineQueryResultCachedPhoto", + "InlineQueryResultCachedGif", + "InlineQueryResultCachedMpeg4Gif", + "InlineQueryResultCachedSticker", + "InlineQueryResultCachedDocument", + "InlineQueryResultCachedVideo", + "InlineQueryResultCachedVoice", + "InlineQueryResultCachedAudio", + "InputMessageContent", + "InputTextMessageContent", + "InputLocationMessageContent", + "InputVenueMessageContent", + "InputContactMessageContent", + "ChosenInlineResult", + "LabeledPrice", + "Invoice", + "ShippingAddress", + "OrderInfo", + "ShippingOption", + "SuccessfulPayment", + "ShippingQuery", + "PreCheckoutQuery", + "PassportData", + "PassportFile", + "EncryptedPassportElement", + "EncryptedCredentials", + "PassportElementError", + "PassportElementErrorDataField", + "PassportElementErrorFrontSide", + "PassportElementErrorReverseSide", + "PassportElementErrorSelfie", + "PassportElementErrorFile", + "PassportElementErrorFiles", + "PassportElementErrorTranslationFile", + "PassportElementErrorTranslationFiles", + "PassportElementErrorUnspecified", + "Game", + "CallbackGame", + "GameHighScore", +) + +# Load typing forward refs for every TelegramObject +for entity in __all__[1:]: + globals()[entity].update_forward_refs(**globals()) diff --git a/aiogram/api/types/animation.py b/aiogram/api/types/animation.py new file mode 100644 index 00000000..c4b2e7c4 --- /dev/null +++ b/aiogram/api/types/animation.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + + +class Animation(TelegramObject): + """ + This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). + + Source: https://core.telegram.org/bots/api#animation + """ + + file_id: str + """Identifier for this file""" + width: int + """Video width as defined by sender""" + height: int + """Video height as defined by sender""" + duration: int + """Duration of the video in seconds as defined by sender""" + thumb: Optional[PhotoSize] = None + """Animation thumbnail as defined by sender""" + file_name: Optional[str] = None + """Original animation filename as defined by sender""" + mime_type: Optional[str] = None + """MIME type of the file as defined by sender""" + file_size: Optional[int] = None + """File size""" diff --git a/aiogram/api/types/audio.py b/aiogram/api/types/audio.py new file mode 100644 index 00000000..6c8c66ec --- /dev/null +++ b/aiogram/api/types/audio.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + + +class Audio(TelegramObject): + """ + This object represents an audio file to be treated as music by the Telegram clients. + + Source: https://core.telegram.org/bots/api#audio + """ + + file_id: str + """Identifier for this file""" + duration: int + """Duration of the audio in seconds as defined by sender""" + performer: Optional[str] = None + """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""" + mime_type: Optional[str] = None + """MIME type of the file as defined by sender""" + file_size: Optional[int] = None + """File size""" + thumb: Optional[PhotoSize] = None + """Thumbnail of the album cover to which the music file belongs""" diff --git a/aiogram/api/types/base.py b/aiogram/api/types/base.py new file mode 100644 index 00000000..4b5ca3be --- /dev/null +++ b/aiogram/api/types/base.py @@ -0,0 +1,10 @@ +from pydantic import BaseConfig, BaseModel, Extra + + +class TelegramObject(BaseModel): + class Config(BaseConfig): + use_enum_values = True + orm_mode = True + extra = Extra.allow + allow_mutation = False + allow_population_by_field_name = True diff --git a/aiogram/api/types/callback_game.py b/aiogram/api/types/callback_game.py new file mode 100644 index 00000000..fe0676d5 --- /dev/null +++ b/aiogram/api/types/callback_game.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class CallbackGame(TelegramObject): + """ + A placeholder, currently holds no information. Use BotFather to set up your game. + + Source: https://core.telegram.org/bots/api#callbackgame + """ diff --git a/aiogram/api/types/callback_query.py b/aiogram/api/types/callback_query.py new file mode 100644 index 00000000..57a9f396 --- /dev/null +++ b/aiogram/api/types/callback_query.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .message import Message + from .user import User + + +class CallbackQuery(TelegramObject): + """ + This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present. + NOTE: After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery. It is, therefore, necessary to react by calling answerCallbackQuery even if no notification to the user is needed (e.g., without specifying any of the optional parameters). + + Source: https://core.telegram.org/bots/api#callbackquery + """ + + id: str + """Unique identifier for this query""" + from_user: User = Field(..., alias="from") + """Sender""" + chat_instance: str + """Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.""" + message: Optional[Message] = None + """Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old""" + inline_message_id: Optional[str] = None + """Identifier of the message sent via the bot in inline mode, that originated the query.""" + data: Optional[str] = None + """Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.""" + game_short_name: Optional[str] = None + """Short name of a Game to be returned, serves as the unique identifier for the game""" diff --git a/aiogram/api/types/chat.py b/aiogram/api/types/chat.py new file mode 100644 index 00000000..63d866ae --- /dev/null +++ b/aiogram/api/types/chat.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .chat_permissions import ChatPermissions + from .message import Message + from .chat_photo import ChatPhoto + + +class Chat(TelegramObject): + """ + This object represents a chat. + + Source: https://core.telegram.org/bots/api#chat + """ + + id: int + """Unique identifier for this chat. This number 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.""" + type: str + """Type of chat, can be either 'private', 'group', 'supergroup' or 'channel'""" + title: Optional[str] = None + """Title, for supergroups, channels and group chats""" + username: Optional[str] = None + """Username, for private chats, supergroups and channels if available""" + first_name: Optional[str] = None + """First name of the other party in a private chat""" + last_name: Optional[str] = None + """Last name of the other party in a private chat""" + photo: Optional[ChatPhoto] = None + """Chat photo. Returned only in getChat.""" + description: Optional[str] = None + """Description, for groups, supergroups and channel chats. Returned only in getChat.""" + invite_link: Optional[str] = None + """Chat invite link, for groups, supergroups and channel chats. Each administrator in a chat 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.""" + permissions: Optional[ChatPermissions] = None + """Default chat member permissions, for groups and supergroups. Returned only in getChat.""" + sticker_set_name: Optional[str] = None + """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.""" diff --git a/aiogram/api/types/chat_member.py b/aiogram/api/types/chat_member.py new file mode 100644 index 00000000..c67b5f57 --- /dev/null +++ b/aiogram/api/types/chat_member.py @@ -0,0 +1,53 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .user import User + + +class ChatMember(TelegramObject): + """ + This object contains information about one member of a chat. + + Source: https://core.telegram.org/bots/api#chatmember + """ + + user: User + """Information about the user""" + status: str + """The member's status in the chat. Can be 'creator', 'administrator', 'member', 'restricted', 'left' or 'kicked'""" + until_date: Optional[int] = None + """Restricted and kicked only. Date when restrictions will be lifted for this user; unix time""" + can_be_edited: Optional[bool] = None + """Administrators only. True, if the bot is allowed to edit administrator privileges of that user""" + can_post_messages: Optional[bool] = None + """Administrators only. True, if the administrator can post in the channel; channels only""" + can_edit_messages: Optional[bool] = None + """Administrators only. True, if the administrator can edit messages of other users and can pin messages; channels only""" + can_delete_messages: Optional[bool] = None + """Administrators only. True, if the administrator can delete messages of other users""" + can_restrict_members: Optional[bool] = None + """Administrators only. True, if the administrator can restrict, ban or unban chat members""" + can_promote_members: Optional[bool] = None + """Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)""" + can_change_info: Optional[bool] = None + """Administrators and restricted only. True, if the user is allowed to change the chat title, photo and other settings""" + can_invite_users: Optional[bool] = None + """Administrators and restricted only. True, if the user is allowed to invite new users to the chat""" + can_pin_messages: Optional[bool] = None + """Administrators and restricted only. True, if the user is allowed to pin messages; groups and supergroups only""" + is_member: Optional[bool] = None + """Restricted only. True, if the user is a member of the chat at the moment of the request""" + can_send_messages: Optional[bool] = None + """Restricted only. True, if the user is allowed to send text messages, contacts, locations and venues""" + can_send_media_messages: Optional[bool] = None + """Restricted only. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes""" + can_send_polls: Optional[bool] = None + """Restricted only. True, if the user is allowed to send polls""" + can_send_other_messages: Optional[bool] = None + """Restricted only. True, if the user is allowed to send animations, games, stickers and use 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""" diff --git a/aiogram/api/types/chat_permissions.py b/aiogram/api/types/chat_permissions.py new file mode 100644 index 00000000..aa57baae --- /dev/null +++ b/aiogram/api/types/chat_permissions.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class ChatPermissions(TelegramObject): + """ + Describes actions that a non-administrator user is allowed to take in a chat. + + Source: https://core.telegram.org/bots/api#chatpermissions + """ + + can_send_messages: Optional[bool] = None + """True, if the user is allowed to send text messages, contacts, locations and venues""" + can_send_media_messages: Optional[bool] = None + """True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages""" + can_send_polls: Optional[bool] = None + """True, if the user is allowed to send polls, implies can_send_messages""" + can_send_other_messages: Optional[bool] = None + """True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages""" + can_add_web_page_previews: Optional[bool] = None + """True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages""" + can_change_info: Optional[bool] = None + """True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups""" + can_invite_users: Optional[bool] = None + """True, if the user is allowed to invite new users to the chat""" + can_pin_messages: Optional[bool] = None + """True, if the user is allowed to pin messages. Ignored in public supergroups""" diff --git a/aiogram/api/types/chat_photo.py b/aiogram/api/types/chat_photo.py new file mode 100644 index 00000000..e1c9f21e --- /dev/null +++ b/aiogram/api/types/chat_photo.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class ChatPhoto(TelegramObject): + """ + This object represents a chat photo. + + Source: https://core.telegram.org/bots/api#chatphoto + """ + + small_file_id: str + """File identifier of small (160x160) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed.""" + big_file_id: str + """File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed.""" diff --git a/aiogram/api/types/chosen_inline_result.py b/aiogram/api/types/chosen_inline_result.py new file mode 100644 index 00000000..4984b1a2 --- /dev/null +++ b/aiogram/api/types/chosen_inline_result.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .location import Location + from .user import User + + +class ChosenInlineResult(TelegramObject): + """ + Represents a result of an inline query that was chosen by the user and sent to their chat partner. + Note: It is necessary to enable inline feedback via @Botfather in order to receive these objects in updates. + + Source: https://core.telegram.org/bots/api#choseninlineresult + """ + + result_id: str + """The unique identifier for the result that was chosen""" + from_user: User = Field(..., alias="from") + """The user that chose the result""" + query: str + """The query that was used to obtain the result""" + location: Optional[Location] = None + """Sender location, only for bots that require user location""" + inline_message_id: Optional[str] = None + """Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.""" diff --git a/aiogram/api/types/contact.py b/aiogram/api/types/contact.py new file mode 100644 index 00000000..1c005a7d --- /dev/null +++ b/aiogram/api/types/contact.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class Contact(TelegramObject): + """ + This object represents a phone contact. + + Source: https://core.telegram.org/bots/api#contact + """ + + phone_number: str + """Contact's phone number""" + first_name: str + """Contact's first name""" + last_name: Optional[str] = None + """Contact's last name""" + user_id: Optional[int] = None + """Contact's user identifier in Telegram""" + vcard: Optional[str] = None + """Additional data about the contact in the form of a vCard""" diff --git a/aiogram/api/types/document.py b/aiogram/api/types/document.py new file mode 100644 index 00000000..4d01f7cb --- /dev/null +++ b/aiogram/api/types/document.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + + +class Document(TelegramObject): + """ + This object represents a general file (as opposed to photos, voice messages and audio files). + + Source: https://core.telegram.org/bots/api#document + """ + + file_id: str + """Identifier for this file""" + thumb: Optional[PhotoSize] = None + """Document thumbnail as defined by sender""" + 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 + """File size""" diff --git a/aiogram/api/types/encrypted_credentials.py b/aiogram/api/types/encrypted_credentials.py new file mode 100644 index 00000000..a28d5cd3 --- /dev/null +++ b/aiogram/api/types/encrypted_credentials.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class EncryptedCredentials(TelegramObject): + """ + Contains data required for decrypting and authenticating EncryptedPassportElement. See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes. + + Source: https://core.telegram.org/bots/api#encryptedcredentials + """ + + data: str + """Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for EncryptedPassportElement decryption and authentication""" + hash: str + """Base64-encoded data hash for data authentication""" + secret: str + """Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption""" diff --git a/aiogram/api/types/encrypted_passport_element.py b/aiogram/api/types/encrypted_passport_element.py new file mode 100644 index 00000000..73c5d220 --- /dev/null +++ b/aiogram/api/types/encrypted_passport_element.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .passport_file import PassportFile + + +class EncryptedPassportElement(TelegramObject): + """ + Contains information about documents or other Telegram Passport elements shared with the bot by the user. + + Source: https://core.telegram.org/bots/api#encryptedpassportelement + """ + + type: str + """Element type. One of 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport', 'address', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration', 'phone_number', 'email'.""" + hash: str + """Base64-encoded element hash for using in PassportElementErrorUnspecified""" + data: Optional[str] = None + """Base64-encoded encrypted Telegram Passport element data provided by the user, available for 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport' and 'address' types. Can be decrypted and verified using the accompanying EncryptedCredentials.""" + phone_number: Optional[str] = None + """User's verified phone number, available only for 'phone_number' type""" + email: Optional[str] = None + """User's verified email address, available only for 'email' type""" + files: Optional[List[PassportFile]] = None + """Array of encrypted files with documents provided by the user, available for 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration' and 'temporary_registration' types. Files can be decrypted and verified using the accompanying EncryptedCredentials.""" + front_side: Optional[PassportFile] = None + """Encrypted file with the front side of the document, provided by the user. Available for 'passport', 'driver_license', 'identity_card' and 'internal_passport'. The file can be decrypted and verified using the accompanying EncryptedCredentials.""" + reverse_side: Optional[PassportFile] = None + """Encrypted file with the reverse side of the document, provided by the user. Available for 'driver_license' and 'identity_card'. The file can be decrypted and verified using the accompanying EncryptedCredentials.""" + selfie: Optional[PassportFile] = None + """Encrypted file with the selfie of the user holding a document, provided by the user; available for 'passport', 'driver_license', 'identity_card' and 'internal_passport'. The file can be decrypted and verified using the accompanying EncryptedCredentials.""" + translation: Optional[List[PassportFile]] = None + """Array of encrypted files with translated versions of documents provided by the user. Available if requested for 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration' and 'temporary_registration' types. Files can be decrypted and verified using the accompanying EncryptedCredentials.""" diff --git a/aiogram/api/types/file.py b/aiogram/api/types/file.py new file mode 100644 index 00000000..1880f52a --- /dev/null +++ b/aiogram/api/types/file.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class File(TelegramObject): + """ + This object represents a file ready to be downloaded. The file can be downloaded via the link https://api.telegram.org/file/bot/. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile. + Maximum file size to download is 20 MB + + Source: https://core.telegram.org/bots/api#file + """ + + file_id: str + """Identifier for this file""" + file_size: Optional[int] = None + """File size, if known""" + file_path: Optional[str] = None + """File path. Use https://api.telegram.org/file/bot/ to get the file.""" diff --git a/aiogram/api/types/force_reply.py b/aiogram/api/types/force_reply.py new file mode 100644 index 00000000..6a9c2c44 --- /dev/null +++ b/aiogram/api/types/force_reply.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class ForceReply(TelegramObject): + """ + Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. + Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). There could be two ways to create a new poll: + + Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). May be appealing for hardcore users but lacks modern day polish. + Guide the user through a step-by-step process. ‘Please send me your question’, ‘Cool, now let’s add the first answer option‘, ’Great. Keep adding answer options, then send /done when you‘re ready’. + The last option is definitely more attractive. And if you use ForceReply in your bot‘s questions, it will receive the user’s answers even if it only receives replies, commands and mentions — without any extra work for the user. + + Source: https://core.telegram.org/bots/api#forcereply + """ + + force_reply: bool + """Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'""" + selective: Optional[bool] = None + """Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.""" diff --git a/aiogram/api/types/game.py b/aiogram/api/types/game.py new file mode 100644 index 00000000..b75d04da --- /dev/null +++ b/aiogram/api/types/game.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + from .animation import Animation + from .message_entity import MessageEntity + + +class Game(TelegramObject): + """ + This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. + + Source: https://core.telegram.org/bots/api#game + """ + + title: str + """Title of the game""" + description: str + """Description of the game""" + photo: List[PhotoSize] + """Photo that will be displayed in the game message in chats.""" + text: Optional[str] = None + """Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.""" + text_entities: Optional[List[MessageEntity]] = None + """Special entities that appear in text, such as usernames, URLs, bot commands, etc.""" + animation: Optional[Animation] = None + """Animation that will be displayed in the game message in chats. Upload via BotFather""" diff --git a/aiogram/api/types/game_high_score.py b/aiogram/api/types/game_high_score.py new file mode 100644 index 00000000..e4b3ccaf --- /dev/null +++ b/aiogram/api/types/game_high_score.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from .base import TelegramObject + +if TYPE_CHECKING: + from .user import User + + +class GameHighScore(TelegramObject): + """ + This object represents one row of the high scores table for a game. + And that‘s about all we’ve got for now. + If you've got any questions, please check out our Bot FAQ + + Source: https://core.telegram.org/bots/api#gamehighscore + """ + + position: int + """Position in high score table for the game""" + user: User + """User""" + score: int + """Score""" diff --git a/aiogram/api/types/inline_keyboard_button.py b/aiogram/api/types/inline_keyboard_button.py new file mode 100644 index 00000000..6a092c60 --- /dev/null +++ b/aiogram/api/types/inline_keyboard_button.py @@ -0,0 +1,42 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .callback_game import CallbackGame + from .login_url import LoginUrl + + +class InlineKeyboardButton(TelegramObject): + """ + This object represents one button of an inline keyboard. You must use exactly one of the optional fields. + + Source: https://core.telegram.org/bots/api#inlinekeyboardbutton + """ + + text: str + """Label text on the button""" + url: Optional[str] = None + """HTTP or tg:// url to be opened when button is pressed""" + login_url: Optional[LoginUrl] = None + """An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.""" + callback_data: Optional[str] = None + """Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes""" + switch_inline_query: Optional[str] = None + """If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. + + Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm… actions – in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.""" + switch_inline_query_current_chat: Optional[str] = None + """If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. + + This offers a quick way for the user to open your bot in inline mode in the same chat – good for selecting something from multiple options.""" + callback_game: Optional[CallbackGame] = None + """Description of the game that will be launched when the user presses the button. + + NOTE: This type of button must always be the first button in the first row.""" + pay: Optional[bool] = None + """Specify True, to send a Pay button. + + NOTE: This type of button must always be the first button in the first row.""" diff --git a/aiogram/api/types/inline_keyboard_markup.py b/aiogram/api/types/inline_keyboard_markup.py new file mode 100644 index 00000000..3237d633 --- /dev/null +++ b/aiogram/api/types/inline_keyboard_markup.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from .base import TelegramObject + +if TYPE_CHECKING: + from .inline_keyboard_button import InlineKeyboardButton + + +class InlineKeyboardMarkup(TelegramObject): + """ + This object represents an inline keyboard that appears right next to the message it belongs to. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will display unsupported message. + + Source: https://core.telegram.org/bots/api#inlinekeyboardmarkup + """ + + inline_keyboard: List[List[InlineKeyboardButton]] + """Array of button rows, each represented by an Array of InlineKeyboardButton objects""" diff --git a/aiogram/api/types/inline_query.py b/aiogram/api/types/inline_query.py new file mode 100644 index 00000000..84b1666f --- /dev/null +++ b/aiogram/api/types/inline_query.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .location import Location + from .user import User + + +class InlineQuery(TelegramObject): + """ + This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results. + + Source: https://core.telegram.org/bots/api#inlinequery + """ + + id: str + """Unique identifier for this query""" + from_user: User = Field(..., alias="from") + """Sender""" + query: str + """Text of the query (up to 512 characters)""" + offset: str + """Offset of the results to be returned, can be controlled by the bot""" + location: Optional[Location] = None + """Sender location, only for bots that request user location""" diff --git a/aiogram/api/types/inline_query_result.py b/aiogram/api/types/inline_query_result.py new file mode 100644 index 00000000..eb780354 --- /dev/null +++ b/aiogram/api/types/inline_query_result.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class InlineQueryResult(TelegramObject): + """ + This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: + - InlineQueryResultCachedAudio + - InlineQueryResultCachedDocument + - InlineQueryResultCachedGif + - InlineQueryResultCachedMpeg4Gif + - InlineQueryResultCachedPhoto + - InlineQueryResultCachedSticker + - InlineQueryResultCachedVideo + - InlineQueryResultCachedVoice + - InlineQueryResultArticle + - InlineQueryResultAudio + - InlineQueryResultContact + - InlineQueryResultGame + - InlineQueryResultDocument + - InlineQueryResultGif + - InlineQueryResultLocation + - InlineQueryResultMpeg4Gif + - InlineQueryResultPhoto + - InlineQueryResultVenue + - InlineQueryResultVideo + - InlineQueryResultVoice + + Source: https://core.telegram.org/bots/api#inlinequeryresult + """ diff --git a/aiogram/api/types/inline_query_result_article.py b/aiogram/api/types/inline_query_result_article.py new file mode 100644 index 00000000..4860e396 --- /dev/null +++ b/aiogram/api/types/inline_query_result_article.py @@ -0,0 +1,42 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultArticle(InlineQueryResult): + """ + Represents a link to an article or web page. + + Source: https://core.telegram.org/bots/api#inlinequeryresultarticle + """ + + type: str = Field("article", const=True) + """Type of the result, must be article""" + id: str + """Unique identifier for this result, 1-64 Bytes""" + title: str + """Title of the result""" + input_message_content: InputMessageContent + """Content of the message to be sent""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + url: Optional[str] = None + """URL of the result""" + hide_url: Optional[bool] = None + """Pass True, if you don't want the URL to be shown in the message""" + description: Optional[str] = None + """Short description of the result""" + thumb_url: Optional[str] = None + """Url of the thumbnail for the result""" + thumb_width: Optional[int] = None + """Thumbnail width""" + thumb_height: Optional[int] = None + """Thumbnail height""" diff --git a/aiogram/api/types/inline_query_result_audio.py b/aiogram/api/types/inline_query_result_audio.py new file mode 100644 index 00000000..4f48e4e1 --- /dev/null +++ b/aiogram/api/types/inline_query_result_audio.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultAudio(InlineQueryResult): + """ + Represents a link to an MP3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultaudio + """ + + type: str = Field("audio", const=True) + """Type of the result, must be audio""" + id: str + """Unique identifier for this result, 1-64 bytes""" + audio_url: str + """A valid URL for the audio file""" + title: str + """Title""" + caption: Optional[str] = None + """Caption, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + performer: Optional[str] = None + """Performer""" + audio_duration: Optional[int] = None + """Audio duration in seconds""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the audio""" diff --git a/aiogram/api/types/inline_query_result_cached_audio.py b/aiogram/api/types/inline_query_result_cached_audio.py new file mode 100644 index 00000000..4eaee573 --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_audio.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedAudio(InlineQueryResult): + """ + Represents a link to an MP3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedaudio + """ + + type: str = Field("audio", const=True) + """Type of the result, must be audio""" + id: str + """Unique identifier for this result, 1-64 bytes""" + audio_file_id: str + """A valid file identifier for the audio file""" + caption: Optional[str] = None + """Caption, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the audio""" diff --git a/aiogram/api/types/inline_query_result_cached_document.py b/aiogram/api/types/inline_query_result_cached_document.py new file mode 100644 index 00000000..ed71b478 --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_document.py @@ -0,0 +1,39 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedDocument(InlineQueryResult): + """ + Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcacheddocument + """ + + type: str = Field("document", const=True) + """Type of the result, must be document""" + id: str + """Unique identifier for this result, 1-64 bytes""" + title: str + """Title for the result""" + document_file_id: str + """A valid file identifier for the file""" + description: Optional[str] = None + """Short description of the result""" + caption: Optional[str] = None + """Caption of the document to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the file""" diff --git a/aiogram/api/types/inline_query_result_cached_gif.py b/aiogram/api/types/inline_query_result_cached_gif.py new file mode 100644 index 00000000..01417ee6 --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_gif.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedGif(InlineQueryResult): + """ + Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedgif + """ + + type: str = Field("gif", const=True) + """Type of the result, must be gif""" + id: str + """Unique identifier for this result, 1-64 bytes""" + gif_file_id: str + """A valid file identifier for the GIF file""" + title: Optional[str] = None + """Title for the result""" + caption: Optional[str] = None + """Caption of the GIF file to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the GIF animation""" diff --git a/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py b/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py new file mode 100644 index 00000000..a6e06d80 --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): + """ + Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif + """ + + type: str = Field("mpeg4_gif", const=True) + """Type of the result, must be mpeg4_gif""" + id: str + """Unique identifier for this result, 1-64 bytes""" + mpeg4_file_id: str + """A valid file identifier for the MP4 file""" + title: Optional[str] = None + """Title for the result""" + caption: Optional[str] = None + """Caption of the MPEG-4 file to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the video animation""" diff --git a/aiogram/api/types/inline_query_result_cached_photo.py b/aiogram/api/types/inline_query_result_cached_photo.py new file mode 100644 index 00000000..8605f262 --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_photo.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedPhoto(InlineQueryResult): + """ + Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedphoto + """ + + type: str = Field("photo", const=True) + """Type of the result, must be photo""" + id: str + """Unique identifier for this result, 1-64 bytes""" + photo_file_id: str + """A valid file identifier of the photo""" + title: Optional[str] = None + """Title for the result""" + description: Optional[str] = None + """Short description of the result""" + caption: Optional[str] = None + """Caption of the photo to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the photo""" diff --git a/aiogram/api/types/inline_query_result_cached_sticker.py b/aiogram/api/types/inline_query_result_cached_sticker.py new file mode 100644 index 00000000..8909eaee --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_sticker.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedSticker(InlineQueryResult): + """ + Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker. + Note: This will only work in Telegram versions released after 9 April, 2016 for static stickers and after 06 July, 2019 for animated stickers. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedsticker + """ + + type: str = Field("sticker", const=True) + """Type of the result, must be sticker""" + id: str + """Unique identifier for this result, 1-64 bytes""" + sticker_file_id: str + """A valid file identifier of the sticker""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the sticker""" diff --git a/aiogram/api/types/inline_query_result_cached_video.py b/aiogram/api/types/inline_query_result_cached_video.py new file mode 100644 index 00000000..52d9154e --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_video.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedVideo(InlineQueryResult): + """ + Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvideo + """ + + type: str = Field("video", const=True) + """Type of the result, must be video""" + id: str + """Unique identifier for this result, 1-64 bytes""" + video_file_id: str + """A valid file identifier for the video file""" + title: str + """Title for the result""" + description: Optional[str] = None + """Short description of the result""" + caption: Optional[str] = None + """Caption of the video to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the video""" diff --git a/aiogram/api/types/inline_query_result_cached_voice.py b/aiogram/api/types/inline_query_result_cached_voice.py new file mode 100644 index 00000000..83446125 --- /dev/null +++ b/aiogram/api/types/inline_query_result_cached_voice.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultCachedVoice(InlineQueryResult): + """ + Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvoice + """ + + type: str = Field("voice", const=True) + """Type of the result, must be voice""" + id: str + """Unique identifier for this result, 1-64 bytes""" + voice_file_id: str + """A valid file identifier for the voice message""" + title: str + """Voice message title""" + caption: Optional[str] = None + """Caption, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the voice message""" diff --git a/aiogram/api/types/inline_query_result_contact.py b/aiogram/api/types/inline_query_result_contact.py new file mode 100644 index 00000000..bc2c257e --- /dev/null +++ b/aiogram/api/types/inline_query_result_contact.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultContact(InlineQueryResult): + """ + Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultcontact + """ + + type: str = Field("contact", const=True) + """Type of the result, must be contact""" + id: str + """Unique identifier for this result, 1-64 Bytes""" + phone_number: str + """Contact's phone number""" + first_name: str + """Contact's first name""" + last_name: Optional[str] = None + """Contact's last name""" + vcard: Optional[str] = None + """Additional data about the contact in the form of a vCard, 0-2048 bytes""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the contact""" + thumb_url: Optional[str] = None + """Url of the thumbnail for the result""" + thumb_width: Optional[int] = None + """Thumbnail width""" + thumb_height: Optional[int] = None + """Thumbnail height""" diff --git a/aiogram/api/types/inline_query_result_document.py b/aiogram/api/types/inline_query_result_document.py new file mode 100644 index 00000000..762336da --- /dev/null +++ b/aiogram/api/types/inline_query_result_document.py @@ -0,0 +1,47 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultDocument(InlineQueryResult): + """ + Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultdocument + """ + + type: str = Field("document", const=True) + """Type of the result, must be document""" + id: str + """Unique identifier for this result, 1-64 bytes""" + title: str + """Title for the result""" + document_url: str + """A valid URL for the file""" + mime_type: str + """Mime type of the content of the file, either 'application/pdf' or 'application/zip'""" + caption: Optional[str] = None + """Caption of the document to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + description: Optional[str] = None + """Short description of the result""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the file""" + thumb_url: Optional[str] = None + """URL of the thumbnail (jpeg only) for the file""" + thumb_width: Optional[int] = None + """Thumbnail width""" + thumb_height: Optional[int] = None + """Thumbnail height""" diff --git a/aiogram/api/types/inline_query_result_game.py b/aiogram/api/types/inline_query_result_game.py new file mode 100644 index 00000000..46217690 --- /dev/null +++ b/aiogram/api/types/inline_query_result_game.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + + +class InlineQueryResultGame(InlineQueryResult): + """ + Represents a Game. + Note: This will only work in Telegram versions released after October 1, 2016. Older clients will not display any inline results if a game result is among them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultgame + """ + + type: str = Field("game", const=True) + """Type of the result, must be game""" + id: str + """Unique identifier for this result, 1-64 bytes""" + game_short_name: str + """Short name of the game""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" diff --git a/aiogram/api/types/inline_query_result_gif.py b/aiogram/api/types/inline_query_result_gif.py new file mode 100644 index 00000000..0e82679e --- /dev/null +++ b/aiogram/api/types/inline_query_result_gif.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultGif(InlineQueryResult): + """ + Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. + + Source: https://core.telegram.org/bots/api#inlinequeryresultgif + """ + + type: str = Field("gif", const=True) + """Type of the result, must be gif""" + id: str + """Unique identifier for this result, 1-64 bytes""" + gif_url: str + """A valid URL for the GIF file. File size must not exceed 1MB""" + thumb_url: str + """URL of the static thumbnail for the result (jpeg or gif)""" + gif_width: Optional[int] = None + """Width of the GIF""" + gif_height: Optional[int] = None + """Height of the GIF""" + gif_duration: Optional[int] = None + """Duration of the GIF""" + title: Optional[str] = None + """Title for the result""" + caption: Optional[str] = None + """Caption of the GIF file to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the GIF animation""" diff --git a/aiogram/api/types/inline_query_result_location.py b/aiogram/api/types/inline_query_result_location.py new file mode 100644 index 00000000..18f0f756 --- /dev/null +++ b/aiogram/api/types/inline_query_result_location.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultLocation(InlineQueryResult): + """ + Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultlocation + """ + + type: str = Field("location", const=True) + """Type of the result, must be location""" + id: str + """Unique identifier for this result, 1-64 Bytes""" + latitude: float + """Location latitude in degrees""" + longitude: float + """Location longitude in degrees""" + title: str + """Location title""" + live_period: Optional[int] = None + """Period in seconds for which the location can be updated, should be between 60 and 86400.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the location""" + thumb_url: Optional[str] = None + """Url of the thumbnail for the result""" + thumb_width: Optional[int] = None + """Thumbnail width""" + thumb_height: Optional[int] = None + """Thumbnail height""" diff --git a/aiogram/api/types/inline_query_result_mpeg4_gif.py b/aiogram/api/types/inline_query_result_mpeg4_gif.py new file mode 100644 index 00000000..173acc70 --- /dev/null +++ b/aiogram/api/types/inline_query_result_mpeg4_gif.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultMpeg4Gif(InlineQueryResult): + """ + Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. + + Source: https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif + """ + + type: str = Field("mpeg4_gif", const=True) + """Type of the result, must be mpeg4_gif""" + id: str + """Unique identifier for this result, 1-64 bytes""" + mpeg4_url: str + """A valid URL for the MP4 file. File size must not exceed 1MB""" + thumb_url: str + """URL of the static thumbnail (jpeg or gif) for the result""" + mpeg4_width: Optional[int] = None + """Video width""" + mpeg4_height: Optional[int] = None + """Video height""" + mpeg4_duration: Optional[int] = None + """Video duration""" + title: Optional[str] = None + """Title for the result""" + caption: Optional[str] = None + """Caption of the MPEG-4 file to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the video animation""" diff --git a/aiogram/api/types/inline_query_result_photo.py b/aiogram/api/types/inline_query_result_photo.py new file mode 100644 index 00000000..f2356c1e --- /dev/null +++ b/aiogram/api/types/inline_query_result_photo.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultPhoto(InlineQueryResult): + """ + Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. + + Source: https://core.telegram.org/bots/api#inlinequeryresultphoto + """ + + type: str = Field("photo", const=True) + """Type of the result, must be photo""" + id: str + """Unique identifier for this result, 1-64 bytes""" + photo_url: str + """A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB""" + thumb_url: str + """URL of the thumbnail for the photo""" + photo_width: Optional[int] = None + """Width of the photo""" + photo_height: Optional[int] = None + """Height of the photo""" + title: Optional[str] = None + """Title for the result""" + description: Optional[str] = None + """Short description of the result""" + caption: Optional[str] = None + """Caption of the photo to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the photo""" diff --git a/aiogram/api/types/inline_query_result_venue.py b/aiogram/api/types/inline_query_result_venue.py new file mode 100644 index 00000000..7d3029b1 --- /dev/null +++ b/aiogram/api/types/inline_query_result_venue.py @@ -0,0 +1,47 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultVenue(InlineQueryResult): + """ + Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultvenue + """ + + type: str = Field("venue", const=True) + """Type of the result, must be venue""" + id: str + """Unique identifier for this result, 1-64 Bytes""" + latitude: float + """Latitude of the venue location in degrees""" + longitude: float + """Longitude of the venue location in degrees""" + title: str + """Title of the venue""" + address: str + """Address of the venue""" + foursquare_id: Optional[str] = None + """Foursquare identifier of the venue if known""" + foursquare_type: Optional[str] = None + """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the venue""" + thumb_url: Optional[str] = None + """Url of the thumbnail for the result""" + thumb_width: Optional[int] = None + """Thumbnail width""" + thumb_height: Optional[int] = None + """Thumbnail height""" diff --git a/aiogram/api/types/inline_query_result_video.py b/aiogram/api/types/inline_query_result_video.py new file mode 100644 index 00000000..41f7d442 --- /dev/null +++ b/aiogram/api/types/inline_query_result_video.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultVideo(InlineQueryResult): + """ + Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. + If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must replace its content using input_message_content. + + Source: https://core.telegram.org/bots/api#inlinequeryresultvideo + """ + + type: str = Field("video", const=True) + """Type of the result, must be video""" + id: str + """Unique identifier for this result, 1-64 bytes""" + video_url: str + """A valid URL for the embedded video player or video file""" + mime_type: str + """Mime type of the content of video url, 'text/html' or 'video/mp4'""" + thumb_url: str + """URL of the thumbnail (jpeg only) for the video""" + title: str + """Title for the result""" + caption: Optional[str] = None + """Caption of the video to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + video_width: Optional[int] = None + """Video width""" + video_height: Optional[int] = None + """Video height""" + video_duration: Optional[int] = None + """Video duration in seconds""" + description: Optional[str] = None + """Short description of the result""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video).""" diff --git a/aiogram/api/types/inline_query_result_voice.py b/aiogram/api/types/inline_query_result_voice.py new file mode 100644 index 00000000..d71df302 --- /dev/null +++ b/aiogram/api/types/inline_query_result_voice.py @@ -0,0 +1,39 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .inline_query_result import InlineQueryResult + +if TYPE_CHECKING: + from .inline_keyboard_markup import InlineKeyboardMarkup + from .input_message_content import InputMessageContent + + +class InlineQueryResultVoice(InlineQueryResult): + """ + Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message. + Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#inlinequeryresultvoice + """ + + type: str = Field("voice", const=True) + """Type of the result, must be voice""" + id: str + """Unique identifier for this result, 1-64 bytes""" + voice_url: str + """A valid URL for the voice recording""" + title: str + """Recording title""" + caption: Optional[str] = None + """Caption, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + voice_duration: Optional[int] = None + """Recording duration in seconds""" + reply_markup: Optional[InlineKeyboardMarkup] = None + """Inline keyboard attached to the message""" + input_message_content: Optional[InputMessageContent] = None + """Content of the message to be sent instead of the voice recording""" diff --git a/aiogram/api/types/input_contact_message_content.py b/aiogram/api/types/input_contact_message_content.py new file mode 100644 index 00000000..6630d7c7 --- /dev/null +++ b/aiogram/api/types/input_contact_message_content.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from typing import Optional + +from .input_message_content import InputMessageContent + + +class InputContactMessageContent(InputMessageContent): + """ + Represents the content of a contact message to be sent as the result of an inline query. + + Source: https://core.telegram.org/bots/api#inputcontactmessagecontent + """ + + phone_number: str + """Contact's phone number""" + first_name: str + """Contact's first name""" + last_name: Optional[str] = None + """Contact's last name""" + vcard: Optional[str] = None + """Additional data about the contact in the form of a vCard, 0-2048 bytes""" diff --git a/aiogram/api/types/input_file.py b/aiogram/api/types/input_file.py new file mode 100644 index 00000000..8f8a8e4d --- /dev/null +++ b/aiogram/api/types/input_file.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class InputFile(TelegramObject): + """ + This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser. + + Source: https://core.telegram.org/bots/api#inputfile + """ diff --git a/aiogram/api/types/input_location_message_content.py b/aiogram/api/types/input_location_message_content.py new file mode 100644 index 00000000..c1ee650f --- /dev/null +++ b/aiogram/api/types/input_location_message_content.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import Optional + +from .input_message_content import InputMessageContent + + +class InputLocationMessageContent(InputMessageContent): + """ + Represents the content of a location message to be sent as the result of an inline query. + + Source: https://core.telegram.org/bots/api#inputlocationmessagecontent + """ + + latitude: float + """Latitude of the location in degrees""" + longitude: float + """Longitude of the location in degrees""" + live_period: Optional[int] = None + """Period in seconds for which the location can be updated, should be between 60 and 86400.""" diff --git a/aiogram/api/types/input_media.py b/aiogram/api/types/input_media.py new file mode 100644 index 00000000..17d05096 --- /dev/null +++ b/aiogram/api/types/input_media.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class InputMedia(TelegramObject): + """ + This object represents the content of a media message to be sent. It should be one of + - InputMediaAnimation + - InputMediaDocument + - InputMediaAudio + - InputMediaPhoto + - InputMediaVideo + + Source: https://core.telegram.org/bots/api#inputmedia + """ diff --git a/aiogram/api/types/input_media_animation.py b/aiogram/api/types/input_media_animation.py new file mode 100644 index 00000000..58410fe4 --- /dev/null +++ b/aiogram/api/types/input_media_animation.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional, Union + +from pydantic import Field + +from .input_media import InputMedia + +if TYPE_CHECKING: + from .input_file import InputFile + + +class InputMediaAnimation(InputMedia): + """ + Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. + + Source: https://core.telegram.org/bots/api#inputmediaanimation + """ + + type: str = Field("animation", const=True) + """Type of the result, must be animation""" + media: str + """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + caption: Optional[str] = None + """Caption of the animation to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + width: Optional[int] = None + """Animation width""" + height: Optional[int] = None + """Animation height""" + duration: Optional[int] = None + """Animation duration""" diff --git a/aiogram/api/types/input_media_audio.py b/aiogram/api/types/input_media_audio.py new file mode 100644 index 00000000..4b38b5b1 --- /dev/null +++ b/aiogram/api/types/input_media_audio.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional, Union + +from pydantic import Field + +from .input_media import InputMedia + +if TYPE_CHECKING: + from .input_file import InputFile + + +class InputMediaAudio(InputMedia): + """ + Represents an audio file to be treated as music to be sent. + + Source: https://core.telegram.org/bots/api#inputmediaaudio + """ + + type: str = Field("audio", const=True) + """Type of the result, must be audio""" + media: str + """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + caption: Optional[str] = None + """Caption of the audio to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + duration: Optional[int] = None + """Duration of the audio in seconds""" + performer: Optional[str] = None + """Performer of the audio""" + title: Optional[str] = None + """Title of the audio""" diff --git a/aiogram/api/types/input_media_document.py b/aiogram/api/types/input_media_document.py new file mode 100644 index 00000000..9c353d1a --- /dev/null +++ b/aiogram/api/types/input_media_document.py @@ -0,0 +1,29 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional, Union + +from pydantic import Field + +from .input_media import InputMedia + +if TYPE_CHECKING: + from .input_file import InputFile + + +class InputMediaDocument(InputMedia): + """ + Represents a general file to be sent. + + Source: https://core.telegram.org/bots/api#inputmediadocument + """ + + type: str = Field("document", const=True) + """Type of the result, must be document""" + media: str + """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + caption: Optional[str] = None + """Caption of the document to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" diff --git a/aiogram/api/types/input_media_photo.py b/aiogram/api/types/input_media_photo.py new file mode 100644 index 00000000..2a9794a0 --- /dev/null +++ b/aiogram/api/types/input_media_photo.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from typing import Optional + +from pydantic import Field + +from .input_media import InputMedia + + +class InputMediaPhoto(InputMedia): + """ + Represents a photo to be sent. + + Source: https://core.telegram.org/bots/api#inputmediaphoto + """ + + type: str = Field("photo", const=True) + """Type of the result, must be photo""" + media: str + """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" + caption: Optional[str] = None + """Caption of the photo to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" diff --git a/aiogram/api/types/input_media_video.py b/aiogram/api/types/input_media_video.py new file mode 100644 index 00000000..9a03a767 --- /dev/null +++ b/aiogram/api/types/input_media_video.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional, Union + +from pydantic import Field + +from .input_media import InputMedia + +if TYPE_CHECKING: + from .input_file import InputFile + + +class InputMediaVideo(InputMedia): + """ + Represents a video to be sent. + + Source: https://core.telegram.org/bots/api#inputmediavideo + """ + + type: str = Field("video", const=True) + """Type of the result, must be video""" + media: str + """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name.""" + thumb: Optional[Union[InputFile, str]] = None + """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 .""" + caption: Optional[str] = None + """Caption of the video to be sent, 0-1024 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.""" + width: Optional[int] = None + """Video width""" + height: Optional[int] = None + """Video height""" + duration: Optional[int] = None + """Video duration""" + supports_streaming: Optional[bool] = None + """Pass True, if the uploaded video is suitable for streaming""" diff --git a/aiogram/api/types/input_message_content.py b/aiogram/api/types/input_message_content.py new file mode 100644 index 00000000..e6260cb1 --- /dev/null +++ b/aiogram/api/types/input_message_content.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from .base import TelegramObject + + +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: + - InputTextMessageContent + - InputLocationMessageContent + - InputVenueMessageContent + - InputContactMessageContent + + Source: https://core.telegram.org/bots/api#inputmessagecontent + """ diff --git a/aiogram/api/types/input_text_message_content.py b/aiogram/api/types/input_text_message_content.py new file mode 100644 index 00000000..e042adb9 --- /dev/null +++ b/aiogram/api/types/input_text_message_content.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import Optional + +from .input_message_content import InputMessageContent + + +class InputTextMessageContent(InputMessageContent): + """ + Represents the content of a text message to be sent as the result of an inline query. + + Source: https://core.telegram.org/bots/api#inputtextmessagecontent + """ + + message_text: str + """Text of the message to be sent, 1-4096 characters""" + parse_mode: Optional[str] = None + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.""" + 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 new file mode 100644 index 00000000..b7488856 --- /dev/null +++ b/aiogram/api/types/input_venue_message_content.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from typing import Optional + +from .input_message_content import InputMessageContent + + +class InputVenueMessageContent(InputMessageContent): + """ + Represents the content of a venue message to be sent as the result of an inline query. + + Source: https://core.telegram.org/bots/api#inputvenuemessagecontent + """ + + latitude: float + """Latitude of the venue in degrees""" + longitude: float + """Longitude of the venue in degrees""" + title: str + """Name of the venue""" + address: str + """Address of the venue""" + foursquare_id: Optional[str] = None + """Foursquare identifier of the venue, if known""" + foursquare_type: Optional[str] = None + """Foursquare type of the venue, if known. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" diff --git a/aiogram/api/types/invoice.py b/aiogram/api/types/invoice.py new file mode 100644 index 00000000..daba7003 --- /dev/null +++ b/aiogram/api/types/invoice.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class Invoice(TelegramObject): + """ + This object contains basic information about an invoice. + + Source: https://core.telegram.org/bots/api#invoice + """ + + title: str + """Product name""" + description: str + """Product description""" + start_parameter: str + """Unique bot deep-linking parameter that can be used to generate this invoice""" + currency: str + """Three-letter ISO 4217 currency code""" + total_amount: int + """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" diff --git a/aiogram/api/types/keyboard_button.py b/aiogram/api/types/keyboard_button.py new file mode 100644 index 00000000..e6818c5e --- /dev/null +++ b/aiogram/api/types/keyboard_button.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class KeyboardButton(TelegramObject): + """ + This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive. + Note: request_contact and request_location options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. + + Source: https://core.telegram.org/bots/api#keyboardbutton + """ + + text: str + """Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed""" + request_contact: Optional[bool] = None + """If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only""" + request_location: Optional[bool] = None + """If True, the user's current location will be sent when the button is pressed. Available in private chats only""" diff --git a/aiogram/api/types/labeled_price.py b/aiogram/api/types/labeled_price.py new file mode 100644 index 00000000..59841147 --- /dev/null +++ b/aiogram/api/types/labeled_price.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class LabeledPrice(TelegramObject): + """ + This object represents a portion of the price for goods or services. + + Source: https://core.telegram.org/bots/api#labeledprice + """ + + label: str + """Portion label""" + amount: int + """Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" diff --git a/aiogram/api/types/location.py b/aiogram/api/types/location.py new file mode 100644 index 00000000..99c7ffc4 --- /dev/null +++ b/aiogram/api/types/location.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class Location(TelegramObject): + """ + This object represents a point on the map. + + Source: https://core.telegram.org/bots/api#location + """ + + longitude: float + """Longitude as defined by sender""" + latitude: float + """Latitude as defined by sender""" diff --git a/aiogram/api/types/login_url.py b/aiogram/api/types/login_url.py new file mode 100644 index 00000000..ce063665 --- /dev/null +++ b/aiogram/api/types/login_url.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class LoginUrl(TelegramObject): + """ + This object represents a parameter of the inline keyboard button used to automatically authorize a user. Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram. All the user needs to do is tap/click a button and confirm that they want to log in: + Telegram apps support these buttons as of version 5.7. + Sample bot: @discussbot + + Source: https://core.telegram.org/bots/api#loginurl + """ + + url: str + """An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in Receiving authorization data. + + NOTE: You must always check the hash of the received data to verify the authentication and the integrity of the data as described in Checking authorization.""" + forward_text: Optional[str] = None + """New text of the button in forwarded messages.""" + bot_username: Optional[str] = None + """Username of a bot, which will be used for user authorization. See Setting up a bot for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the bot. See Linking your domain to the bot for more details.""" + request_write_access: Optional[bool] = None + """Pass True to request the permission for your bot to send messages to the user.""" diff --git a/aiogram/api/types/mask_position.py b/aiogram/api/types/mask_position.py new file mode 100644 index 00000000..3eea5bda --- /dev/null +++ b/aiogram/api/types/mask_position.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class MaskPosition(TelegramObject): + """ + This object describes the position on faces where a mask should be placed by default. + + Source: https://core.telegram.org/bots/api#maskposition + """ + + point: str + """The part of the face relative to which the mask should be placed. One of 'forehead', 'eyes', 'mouth', or 'chin'.""" + x_shift: float + """Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position.""" + y_shift: float + """Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position.""" + scale: float + """Mask scaling coefficient. For example, 2.0 means double size.""" diff --git a/aiogram/api/types/message.py b/aiogram/api/types/message.py new file mode 100644 index 00000000..37029e26 --- /dev/null +++ b/aiogram/api/types/message.py @@ -0,0 +1,133 @@ +from __future__ import annotations + +import datetime +from typing import TYPE_CHECKING, List, Optional + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .contact import Contact + from .audio import Audio + from .inline_keyboard_markup import InlineKeyboardMarkup + from .game import Game + from .passport_data import PassportData + from .voice import Voice + from .venue import Venue + from .location import Location + from .animation import Animation + from .user import User + from .video import Video + from .message_entity import MessageEntity + from .sticker import Sticker + from .document import Document + from .invoice import Invoice + from .video_note import VideoNote + from .chat import Chat + from .successful_payment import SuccessfulPayment + from .photo_size import PhotoSize + from .poll import Poll + + +class Message(TelegramObject): + """ + This object represents a message. + + Source: https://core.telegram.org/bots/api#message + """ + + message_id: int + """Unique message identifier inside this chat""" + date: datetime.datetime + """Date the message was sent in Unix time""" + chat: Chat + """Conversation the message belongs to""" + from_user: Optional[User] = Field(None, alias="from") + """Sender, empty for messages sent to channels""" + 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""" + 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 + """For messages forwarded from channels, signature of the post author if present""" + forward_sender_name: Optional[str] = None + """Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages""" + forward_date: Optional[int] = None + """For forwarded messages, date the original message was sent in Unix time""" + reply_to_message: Optional[Message] = None + """For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.""" + edit_date: Optional[int] = None + """Date the message was last edited in Unix time""" + 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""" + text: Optional[str] = None + """For text messages, the actual UTF-8 text of the message, 0-4096 characters.""" + entities: Optional[List[MessageEntity]] = None + """For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text""" + caption_entities: Optional[List[MessageEntity]] = None + """For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption""" + audio: Optional[Audio] = None + """Message is an audio file, information about the file""" + document: Optional[Document] = None + """Message is a general file, information about the file""" + animation: Optional[Animation] = None + """Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set""" + game: Optional[Game] = None + """Message is a game, information about the game.""" + photo: Optional[List[PhotoSize]] = None + """Message is a photo, available sizes of the photo""" + sticker: Optional[Sticker] = None + """Message is a sticker, information about the sticker""" + video: Optional[Video] = None + """Message is a video, information about the video""" + voice: Optional[Voice] = None + """Message is a voice message, information about the file""" + video_note: Optional[VideoNote] = None + """Message is a video note, information about the video message""" + caption: Optional[str] = None + """Caption for the animation, audio, document, photo, video or voice, 0-1024 characters""" + contact: Optional[Contact] = None + """Message is a shared contact, information about the contact""" + location: Optional[Location] = None + """Message is a shared location, information about the location""" + venue: Optional[Venue] = None + """Message is a venue, information about the venue""" + poll: Optional[Poll] = None + """Message is a native poll, information about the poll""" + new_chat_members: Optional[List[User]] = None + """New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)""" + left_chat_member: Optional[User] = None + """A member was removed from the group, information about them (this member may be the bot itself)""" + new_chat_title: Optional[str] = None + """A chat title was changed to this value""" + new_chat_photo: Optional[List[PhotoSize]] = None + """A chat photo was change to this value""" + delete_chat_photo: Optional[bool] = None + """Service message: the chat photo was deleted""" + group_chat_created: Optional[bool] = None + """Service message: the group has been created""" + supergroup_chat_created: Optional[bool] = None + """Service message: the supergroup has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.""" + channel_chat_created: Optional[bool] = None + """Service message: the channel has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.""" + migrate_to_chat_id: Optional[int] = None + """The group has been migrated to a supergroup with the specified identifier. This number 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.""" + migrate_from_chat_id: Optional[int] = None + """The supergroup has been migrated from a group with the specified identifier. This number 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.""" + pinned_message: Optional[Message] = None + """Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.""" + invoice: Optional[Invoice] = None + """Message is an invoice for a payment, information about the invoice.""" + successful_payment: Optional[SuccessfulPayment] = None + """Message is a service message about a successful payment, information about the payment.""" + connected_website: Optional[str] = None + """The domain name of the website on which the user has logged in.""" + passport_data: Optional[PassportData] = None + """Telegram Passport data""" + 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_entity.py b/aiogram/api/types/message_entity.py new file mode 100644 index 00000000..8dbe6d11 --- /dev/null +++ b/aiogram/api/types/message_entity.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .user import User + + +class MessageEntity(TelegramObject): + """ + This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. + + Source: https://core.telegram.org/bots/api#messageentity + """ + + type: str + """Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)""" + offset: int + """Offset in UTF-16 code units to the start of the entity""" + length: int + """Length of the entity in UTF-16 code units""" + url: Optional[str] = None + """For 'text_link' only, url that will be opened after user taps on the text""" + user: Optional[User] = None + """For 'text_mention' only, the mentioned user""" diff --git a/aiogram/api/types/order_info.py b/aiogram/api/types/order_info.py new file mode 100644 index 00000000..d84f8b0e --- /dev/null +++ b/aiogram/api/types/order_info.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .shipping_address import ShippingAddress + + +class OrderInfo(TelegramObject): + """ + This object represents information about an order. + + Source: https://core.telegram.org/bots/api#orderinfo + """ + + name: Optional[str] = None + """User name""" + phone_number: Optional[str] = None + """User's phone number""" + email: Optional[str] = None + """User email""" + shipping_address: Optional[ShippingAddress] = None + """User shipping address""" diff --git a/aiogram/api/types/passport_data.py b/aiogram/api/types/passport_data.py new file mode 100644 index 00000000..96608226 --- /dev/null +++ b/aiogram/api/types/passport_data.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from .base import TelegramObject + +if TYPE_CHECKING: + from .encrypted_credentials import EncryptedCredentials + from .encrypted_passport_element import EncryptedPassportElement + + +class PassportData(TelegramObject): + """ + Contains information about Telegram Passport data shared with the bot by the user. + + Source: https://core.telegram.org/bots/api#passportdata + """ + + data: List[EncryptedPassportElement] + """Array with information about documents and other Telegram Passport elements that was shared with the bot""" + credentials: EncryptedCredentials + """Encrypted credentials required to decrypt the data""" diff --git a/aiogram/api/types/passport_element_error.py b/aiogram/api/types/passport_element_error.py new file mode 100644 index 00000000..3acdc325 --- /dev/null +++ b/aiogram/api/types/passport_element_error.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class PassportElementError(TelegramObject): + """ + This object represents an error in the Telegram Passport element which was submitted that should be resolved by the user. It should be one of: + - PassportElementErrorDataField + - PassportElementErrorFrontSide + - PassportElementErrorReverseSide + - PassportElementErrorSelfie + - PassportElementErrorFile + - PassportElementErrorFiles + - PassportElementErrorTranslationFile + - PassportElementErrorTranslationFiles + - PassportElementErrorUnspecified + + Source: https://core.telegram.org/bots/api#passportelementerror + """ diff --git a/aiogram/api/types/passport_element_error_data_field.py b/aiogram/api/types/passport_element_error_data_field.py new file mode 100644 index 00000000..dab01856 --- /dev/null +++ b/aiogram/api/types/passport_element_error_data_field.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorDataField(PassportElementError): + """ + Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes. + + Source: https://core.telegram.org/bots/api#passportelementerrordatafield + """ + + source: str = Field("data", const=True) + """Error source, must be data""" + type: str + """The section of the user's Telegram Passport which has the error, one of 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport', 'address'""" + field_name: str + """Name of the data field which has the error""" + data_hash: str + """Base64-encoded data hash""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_file.py b/aiogram/api/types/passport_element_error_file.py new file mode 100644 index 00000000..e2770956 --- /dev/null +++ b/aiogram/api/types/passport_element_error_file.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorFile(PassportElementError): + """ + Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes. + + Source: https://core.telegram.org/bots/api#passportelementerrorfile + """ + + source: str = Field("file", const=True) + """Error source, must be file""" + type: str + """The section of the user's Telegram Passport which has the issue, one of 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" + file_hash: str + """Base64-encoded file hash""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_files.py b/aiogram/api/types/passport_element_error_files.py new file mode 100644 index 00000000..d3a9cfb2 --- /dev/null +++ b/aiogram/api/types/passport_element_error_files.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from typing import List + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorFiles(PassportElementError): + """ + Represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes. + + Source: https://core.telegram.org/bots/api#passportelementerrorfiles + """ + + source: str = Field("files", const=True) + """Error source, must be files""" + type: str + """The section of the user's Telegram Passport which has the issue, one of 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" + file_hashes: List[str] + """List of base64-encoded file hashes""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_front_side.py b/aiogram/api/types/passport_element_error_front_side.py new file mode 100644 index 00000000..2110b595 --- /dev/null +++ b/aiogram/api/types/passport_element_error_front_side.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorFrontSide(PassportElementError): + """ + Represents an issue with the front side of a document. The error is considered resolved when the file with the front side of the document changes. + + Source: https://core.telegram.org/bots/api#passportelementerrorfrontside + """ + + source: str = Field("front_side", const=True) + """Error source, must be front_side""" + type: str + """The section of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport'""" + file_hash: str + """Base64-encoded hash of the file with the front side of the document""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_reverse_side.py b/aiogram/api/types/passport_element_error_reverse_side.py new file mode 100644 index 00000000..bf16ab02 --- /dev/null +++ b/aiogram/api/types/passport_element_error_reverse_side.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorReverseSide(PassportElementError): + """ + Represents an issue with the reverse side of a document. The error is considered resolved when the file with reverse side of the document changes. + + Source: https://core.telegram.org/bots/api#passportelementerrorreverseside + """ + + source: str = Field("reverse_side", const=True) + """Error source, must be reverse_side""" + type: str + """The section of the user's Telegram Passport which has the issue, one of 'driver_license', 'identity_card'""" + file_hash: str + """Base64-encoded hash of the file with the reverse side of the document""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_selfie.py b/aiogram/api/types/passport_element_error_selfie.py new file mode 100644 index 00000000..671bbbff --- /dev/null +++ b/aiogram/api/types/passport_element_error_selfie.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorSelfie(PassportElementError): + """ + Represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes. + + Source: https://core.telegram.org/bots/api#passportelementerrorselfie + """ + + source: str = Field("selfie", const=True) + """Error source, must be selfie""" + type: str + """The section of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport'""" + file_hash: str + """Base64-encoded hash of the file with the selfie""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_translation_file.py b/aiogram/api/types/passport_element_error_translation_file.py new file mode 100644 index 00000000..4423aab7 --- /dev/null +++ b/aiogram/api/types/passport_element_error_translation_file.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorTranslationFile(PassportElementError): + """ + Represents an issue with one of the files that constitute the translation of a document. The error is considered resolved when the file changes. + + Source: https://core.telegram.org/bots/api#passportelementerrortranslationfile + """ + + source: str = Field("translation_file", const=True) + """Error source, must be translation_file""" + type: str + """Type of element of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" + file_hash: str + """Base64-encoded file hash""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_translation_files.py b/aiogram/api/types/passport_element_error_translation_files.py new file mode 100644 index 00000000..254df473 --- /dev/null +++ b/aiogram/api/types/passport_element_error_translation_files.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from typing import List + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorTranslationFiles(PassportElementError): + """ + Represents an issue with the translated version of a document. The error is considered resolved when a file with the document translation change. + + Source: https://core.telegram.org/bots/api#passportelementerrortranslationfiles + """ + + source: str = Field("translation_files", const=True) + """Error source, must be translation_files""" + type: str + """Type of element of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'""" + file_hashes: List[str] + """List of base64-encoded file hashes""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_element_error_unspecified.py b/aiogram/api/types/passport_element_error_unspecified.py new file mode 100644 index 00000000..9a107dc4 --- /dev/null +++ b/aiogram/api/types/passport_element_error_unspecified.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pydantic import Field + +from .passport_element_error import PassportElementError + + +class PassportElementErrorUnspecified(PassportElementError): + """ + Represents an issue in an unspecified place. The error is considered resolved when new data is added. + + Source: https://core.telegram.org/bots/api#passportelementerrorunspecified + """ + + source: str = Field("unspecified", const=True) + """Error source, must be unspecified""" + type: str + """Type of element of the user's Telegram Passport which has the issue""" + element_hash: str + """Base64-encoded element hash""" + message: str + """Error message""" diff --git a/aiogram/api/types/passport_file.py b/aiogram/api/types/passport_file.py new file mode 100644 index 00000000..bbae3db6 --- /dev/null +++ b/aiogram/api/types/passport_file.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class PassportFile(TelegramObject): + """ + This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB. + + Source: https://core.telegram.org/bots/api#passportfile + """ + + file_id: str + """Identifier for this file""" + file_size: int + """File size""" + file_date: int + """Unix time when the file was uploaded""" diff --git a/aiogram/api/types/photo_size.py b/aiogram/api/types/photo_size.py new file mode 100644 index 00000000..e0d18ac9 --- /dev/null +++ b/aiogram/api/types/photo_size.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class PhotoSize(TelegramObject): + """ + This object represents one size of a photo or a file / sticker thumbnail. + + Source: https://core.telegram.org/bots/api#photosize + """ + + file_id: str + """Identifier for this file""" + width: int + """Photo width""" + height: int + """Photo height""" + file_size: Optional[int] = None + """File size""" diff --git a/aiogram/api/types/poll.py b/aiogram/api/types/poll.py new file mode 100644 index 00000000..30f3da1d --- /dev/null +++ b/aiogram/api/types/poll.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from .base import TelegramObject + +if TYPE_CHECKING: + from .poll_option import PollOption + + +class Poll(TelegramObject): + """ + This object contains information about a poll. + + Source: https://core.telegram.org/bots/api#poll + """ + + id: str + """Unique poll identifier""" + question: str + """Poll question, 1-255 characters""" + options: List[PollOption] + """List of poll options""" + is_closed: bool + """True, if the poll is closed""" diff --git a/aiogram/api/types/poll_option.py b/aiogram/api/types/poll_option.py new file mode 100644 index 00000000..cb69aa49 --- /dev/null +++ b/aiogram/api/types/poll_option.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class PollOption(TelegramObject): + """ + This object contains information about one answer option in a poll. + + Source: https://core.telegram.org/bots/api#polloption + """ + + text: str + """Option text, 1-100 characters""" + voter_count: int + """Number of users that voted for this option""" diff --git a/aiogram/api/types/pre_checkout_query.py b/aiogram/api/types/pre_checkout_query.py new file mode 100644 index 00000000..68487e28 --- /dev/null +++ b/aiogram/api/types/pre_checkout_query.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .order_info import OrderInfo + from .user import User + + +class PreCheckoutQuery(TelegramObject): + """ + This object contains information about an incoming pre-checkout query. + + Source: https://core.telegram.org/bots/api#precheckoutquery + """ + + id: str + """Unique query identifier""" + from_user: User = Field(..., alias="from") + """User who sent the query""" + currency: str + """Three-letter ISO 4217 currency code""" + total_amount: int + """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" + invoice_payload: str + """Bot specified invoice payload""" + shipping_option_id: Optional[str] = None + """Identifier of the shipping option chosen by the user""" + order_info: Optional[OrderInfo] = None + """Order info provided by the user""" diff --git a/aiogram/api/types/reply_keyboard_markup.py b/aiogram/api/types/reply_keyboard_markup.py new file mode 100644 index 00000000..0f8da869 --- /dev/null +++ b/aiogram/api/types/reply_keyboard_markup.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .keyboard_button import KeyboardButton + + +class ReplyKeyboardMarkup(TelegramObject): + """ + This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). + + Source: https://core.telegram.org/bots/api#replykeyboardmarkup + """ + + keyboard: List[List[KeyboardButton]] + """Array of button rows, each represented by an Array of KeyboardButton objects""" + resize_keyboard: Optional[bool] = None + """Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.""" + one_time_keyboard: Optional[bool] = None + """Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat – the user can press a special button in the input field to see the custom keyboard again. Defaults to false.""" + selective: Optional[bool] = None + """Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + + Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.""" diff --git a/aiogram/api/types/reply_keyboard_remove.py b/aiogram/api/types/reply_keyboard_remove.py new file mode 100644 index 00000000..86319602 --- /dev/null +++ b/aiogram/api/types/reply_keyboard_remove.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class ReplyKeyboardRemove(TelegramObject): + """ + Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup). + + Source: https://core.telegram.org/bots/api#replykeyboardremove + """ + + remove_keyboard: bool + """Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)""" + selective: Optional[bool] = None + """Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + + Example: A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.""" diff --git a/aiogram/api/types/response_parameters.py b/aiogram/api/types/response_parameters.py new file mode 100644 index 00000000..37dad468 --- /dev/null +++ b/aiogram/api/types/response_parameters.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class ResponseParameters(TelegramObject): + """ + Contains information about why a request was unsuccessful. + + Source: https://core.telegram.org/bots/api#responseparameters + """ + + migrate_to_chat_id: Optional[int] = None + """The group has been migrated to a supergroup with the specified identifier. This number 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.""" + retry_after: Optional[int] = None + """In case of exceeding flood control, the number of seconds left to wait before the request can be repeated""" diff --git a/aiogram/api/types/shipping_address.py b/aiogram/api/types/shipping_address.py new file mode 100644 index 00000000..4ef322c7 --- /dev/null +++ b/aiogram/api/types/shipping_address.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class ShippingAddress(TelegramObject): + """ + This object represents a shipping address. + + Source: https://core.telegram.org/bots/api#shippingaddress + """ + + country_code: str + """ISO 3166-1 alpha-2 country code""" + state: str + """State, if applicable""" + city: str + """City""" + street_line1: str + """First line for the address""" + street_line2: str + """Second line for the address""" + post_code: str + """Address post code""" diff --git a/aiogram/api/types/shipping_option.py b/aiogram/api/types/shipping_option.py new file mode 100644 index 00000000..6caa84a5 --- /dev/null +++ b/aiogram/api/types/shipping_option.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from .base import TelegramObject + +if TYPE_CHECKING: + from .labeled_price import LabeledPrice + + +class ShippingOption(TelegramObject): + """ + This object represents one shipping option. + + Source: https://core.telegram.org/bots/api#shippingoption + """ + + id: str + """Shipping option identifier""" + title: str + """Option title""" + prices: List[LabeledPrice] + """List of price portions""" diff --git a/aiogram/api/types/shipping_query.py b/aiogram/api/types/shipping_query.py new file mode 100644 index 00000000..8138ad66 --- /dev/null +++ b/aiogram/api/types/shipping_query.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from pydantic import Field + +from .base import TelegramObject + +if TYPE_CHECKING: + from .shipping_address import ShippingAddress + from .user import User + + +class ShippingQuery(TelegramObject): + """ + This object contains information about an incoming shipping query. + + Source: https://core.telegram.org/bots/api#shippingquery + """ + + id: str + """Unique query identifier""" + from_user: User = Field(..., alias="from") + """User who sent the query""" + invoice_payload: str + """Bot specified invoice payload""" + shipping_address: ShippingAddress + """User specified shipping address""" diff --git a/aiogram/api/types/sticker.py b/aiogram/api/types/sticker.py new file mode 100644 index 00000000..a92f5d98 --- /dev/null +++ b/aiogram/api/types/sticker.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + from .mask_position import MaskPosition + + +class Sticker(TelegramObject): + """ + This object represents a sticker. + + Source: https://core.telegram.org/bots/api#sticker + """ + + file_id: str + """Identifier for this file""" + width: int + """Sticker width""" + height: int + """Sticker height""" + is_animated: bool + """True, if the sticker is animated""" + thumb: Optional[PhotoSize] = None + """Sticker thumbnail in the .webp or .jpg format""" + emoji: Optional[str] = None + """Emoji associated with the sticker""" + set_name: Optional[str] = None + """Name of the sticker set to which the sticker belongs""" + mask_position: Optional[MaskPosition] = None + """For mask stickers, the position where the mask should be placed""" + file_size: Optional[int] = None + """File size""" diff --git a/aiogram/api/types/sticker_set.py b/aiogram/api/types/sticker_set.py new file mode 100644 index 00000000..05917c32 --- /dev/null +++ b/aiogram/api/types/sticker_set.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from .base import TelegramObject + +if TYPE_CHECKING: + from .sticker import Sticker + + +class StickerSet(TelegramObject): + """ + This object represents a sticker set. + + Source: https://core.telegram.org/bots/api#stickerset + """ + + name: str + """Sticker set name""" + title: str + """Sticker set title""" + is_animated: bool + """True, if the sticker set contains animated stickers""" + contains_masks: bool + """True, if the sticker set contains masks""" + stickers: List[Sticker] + """List of all set stickers""" diff --git a/aiogram/api/types/successful_payment.py b/aiogram/api/types/successful_payment.py new file mode 100644 index 00000000..e33ca37c --- /dev/null +++ b/aiogram/api/types/successful_payment.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .order_info import OrderInfo + + +class SuccessfulPayment(TelegramObject): + """ + This object contains basic information about a successful payment. + + Source: https://core.telegram.org/bots/api#successfulpayment + """ + + currency: str + """Three-letter ISO 4217 currency code""" + total_amount: int + """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).""" + invoice_payload: str + """Bot specified invoice payload""" + telegram_payment_charge_id: str + """Telegram payment identifier""" + provider_payment_charge_id: str + """Provider payment identifier""" + shipping_option_id: Optional[str] = None + """Identifier of the shipping option chosen by the user""" + order_info: Optional[OrderInfo] = None + """Order info provided by the user""" diff --git a/aiogram/api/types/update.py b/aiogram/api/types/update.py new file mode 100644 index 00000000..41dd3cf8 --- /dev/null +++ b/aiogram/api/types/update.py @@ -0,0 +1,46 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .shipping_query import ShippingQuery + from .pre_checkout_query import PreCheckoutQuery + from .message import Message + from .inline_query import InlineQuery + from .chosen_inline_result import ChosenInlineResult + from .callback_query import CallbackQuery + from .poll import Poll + + +class Update(TelegramObject): + """ + This object represents an incoming update. + At most one of the optional parameters can be present in any given update. + + Source: https://core.telegram.org/bots/api#update + """ + + update_id: int + """The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.""" + message: Optional[Message] = None + """New incoming message of any kind — text, photo, sticker, etc.""" + edited_message: Optional[Message] = None + """New version of a message that is known to the bot and was edited""" + channel_post: Optional[Message] = None + """New incoming channel post of any kind — text, photo, sticker, etc.""" + edited_channel_post: Optional[Message] = None + """New version of a channel post that is known to the bot and was edited""" + inline_query: Optional[InlineQuery] = None + """New incoming inline query""" + chosen_inline_result: Optional[ChosenInlineResult] = None + """The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.""" + callback_query: Optional[CallbackQuery] = None + """New incoming callback query""" + shipping_query: Optional[ShippingQuery] = None + """New incoming shipping query. Only for invoices with flexible price""" + pre_checkout_query: Optional[PreCheckoutQuery] = None + """New incoming pre-checkout query. Contains full information about checkout""" + poll: Optional[Poll] = None + """New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot""" diff --git a/aiogram/api/types/user.py b/aiogram/api/types/user.py new file mode 100644 index 00000000..1c2a9df0 --- /dev/null +++ b/aiogram/api/types/user.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class User(TelegramObject): + """ + This object represents a Telegram user or bot. + + Source: https://core.telegram.org/bots/api#user + """ + + id: int + """Unique identifier for this user or bot""" + is_bot: bool + """True, if this user is a bot""" + first_name: str + """User‘s or bot’s first name""" + last_name: Optional[str] = None + """User‘s or bot’s last name""" + username: Optional[str] = None + """User‘s or bot’s username""" + language_code: Optional[str] = None + """IETF language tag of the user's language""" diff --git a/aiogram/api/types/user_profile_photos.py b/aiogram/api/types/user_profile_photos.py new file mode 100644 index 00000000..ad1197bf --- /dev/null +++ b/aiogram/api/types/user_profile_photos.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + + +class UserProfilePhotos(TelegramObject): + """ + This object represent a user's profile pictures. + + Source: https://core.telegram.org/bots/api#userprofilephotos + """ + + total_count: int + """Total number of profile pictures the target user has""" + photos: List[List[PhotoSize]] + """Requested profile pictures (in up to 4 sizes each)""" diff --git a/aiogram/api/types/venue.py b/aiogram/api/types/venue.py new file mode 100644 index 00000000..0c844480 --- /dev/null +++ b/aiogram/api/types/venue.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .location import Location + + +class Venue(TelegramObject): + """ + This object represents a venue. + + Source: https://core.telegram.org/bots/api#venue + """ + + location: Location + """Venue location""" + title: str + """Name of the venue""" + address: str + """Address of the venue""" + foursquare_id: Optional[str] = None + """Foursquare identifier of the venue""" + foursquare_type: Optional[str] = None + """Foursquare type of the venue. (For example, 'arts_entertainment/default', 'arts_entertainment/aquarium' or 'food/icecream'.)""" diff --git a/aiogram/api/types/video.py b/aiogram/api/types/video.py new file mode 100644 index 00000000..34bb658c --- /dev/null +++ b/aiogram/api/types/video.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + + +class Video(TelegramObject): + """ + This object represents a video file. + + Source: https://core.telegram.org/bots/api#video + """ + + file_id: str + """Identifier for this file""" + width: int + """Video width as defined by sender""" + height: int + """Video height as defined by sender""" + duration: int + """Duration of the video in seconds as defined by sender""" + thumb: Optional[PhotoSize] = None + """Video thumbnail""" + mime_type: Optional[str] = None + """Mime type of a file as defined by sender""" + file_size: Optional[int] = None + """File size""" diff --git a/aiogram/api/types/video_note.py b/aiogram/api/types/video_note.py new file mode 100644 index 00000000..d81c2f2b --- /dev/null +++ b/aiogram/api/types/video_note.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .base import TelegramObject + +if TYPE_CHECKING: + from .photo_size import PhotoSize + + +class VideoNote(TelegramObject): + """ + This object represents a video message (available in Telegram apps as of v.4.0). + + Source: https://core.telegram.org/bots/api#videonote + """ + + file_id: str + """Identifier for this file""" + length: int + """Video width and height (diameter of the video message) as defined by sender""" + duration: int + """Duration of the video in seconds as defined by sender""" + thumb: Optional[PhotoSize] = None + """Video thumbnail""" + file_size: Optional[int] = None + """File size""" diff --git a/aiogram/api/types/voice.py b/aiogram/api/types/voice.py new file mode 100644 index 00000000..634571ec --- /dev/null +++ b/aiogram/api/types/voice.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from typing import Optional + +from .base import TelegramObject + + +class Voice(TelegramObject): + """ + This object represents a voice note. + + Source: https://core.telegram.org/bots/api#voice + """ + + file_id: str + """Identifier for this file""" + duration: int + """Duration of the audio in seconds as defined by sender""" + mime_type: Optional[str] = None + """MIME type of the file as defined by sender""" + file_size: Optional[int] = None + """File size""" diff --git a/aiogram/api/types/webhook_info.py b/aiogram/api/types/webhook_info.py new file mode 100644 index 00000000..3149ea12 --- /dev/null +++ b/aiogram/api/types/webhook_info.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from typing import List, Optional + +from .base import TelegramObject + + +class WebhookInfo(TelegramObject): + """ + Contains information about the current status of a webhook. + + Source: https://core.telegram.org/bots/api#webhookinfo + """ + + url: str + """Webhook URL, may be empty if webhook is not set up""" + has_custom_certificate: bool + """True, if a custom certificate was provided for webhook certificate checks""" + pending_update_count: int + """Number of updates awaiting delivery""" + last_error_date: Optional[int] = None + """Unix time for the most recent error that happened when trying to deliver an update via webhook""" + last_error_message: Optional[str] = None + """Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook""" + max_connections: Optional[int] = None + """Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery""" + allowed_updates: Optional[List[str]] = None + """A list of update types the bot is subscribed to. Defaults to all update types"""