Added full support for Bot API 8.0 (#1606)

* Added full support of Bot API 8.0

* Added tests

* Reformat code

* Added changelog

* Bump API version
This commit is contained in:
Alex Root Junior 2024-11-17 23:18:42 +02:00 committed by GitHub
parent f2916ca03f
commit dfc88fc907
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
169 changed files with 1890 additions and 162 deletions

View file

@ -37,9 +37,11 @@ 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 .edit_user_star_subscription import EditUserStarSubscription
from .export_chat_invite_link import ExportChatInviteLink
from .forward_message import ForwardMessage
from .forward_messages import ForwardMessages
from .get_available_gifts import GetAvailableGifts
from .get_business_connection import GetBusinessConnection
from .get_chat import GetChat
from .get_chat_administrators import GetChatAdministrators
@ -73,6 +75,7 @@ from .reopen_general_forum_topic import ReopenGeneralForumTopic
from .replace_sticker_in_set import ReplaceStickerInSet
from .restrict_chat_member import RestrictChatMember
from .revoke_chat_invite_link import RevokeChatInviteLink
from .save_prepared_inline_message import SavePreparedInlineMessage
from .send_animation import SendAnimation
from .send_audio import SendAudio
from .send_chat_action import SendChatAction
@ -80,6 +83,7 @@ from .send_contact import SendContact
from .send_dice import SendDice
from .send_document import SendDocument
from .send_game import SendGame
from .send_gift import SendGift
from .send_invoice import SendInvoice
from .send_location import SendLocation
from .send_media_group import SendMediaGroup
@ -114,6 +118,7 @@ from .set_sticker_mask_position import SetStickerMaskPosition
from .set_sticker_position_in_set import SetStickerPositionInSet
from .set_sticker_set_thumbnail import SetStickerSetThumbnail
from .set_sticker_set_title import SetStickerSetTitle
from .set_user_emoji_status import SetUserEmojiStatus
from .set_webhook import SetWebhook
from .stop_message_live_location import StopMessageLiveLocation
from .stop_poll import StopPoll
@ -165,9 +170,11 @@ __all__ = (
"EditMessageMedia",
"EditMessageReplyMarkup",
"EditMessageText",
"EditUserStarSubscription",
"ExportChatInviteLink",
"ForwardMessage",
"ForwardMessages",
"GetAvailableGifts",
"GetBusinessConnection",
"GetChat",
"GetChatAdministrators",
@ -203,6 +210,7 @@ __all__ = (
"Response",
"RestrictChatMember",
"RevokeChatInviteLink",
"SavePreparedInlineMessage",
"SendAnimation",
"SendAudio",
"SendChatAction",
@ -210,6 +218,7 @@ __all__ = (
"SendDice",
"SendDocument",
"SendGame",
"SendGift",
"SendInvoice",
"SendLocation",
"SendMediaGroup",
@ -244,6 +253,7 @@ __all__ = (
"SetStickerPositionInSet",
"SetStickerSetThumbnail",
"SetStickerSetTitle",
"SetUserEmojiStatus",
"SetWebhook",
"StopMessageLiveLocation",
"StopPoll",

View file

@ -26,8 +26,12 @@ class CreateInvoiceLink(TelegramMethod[str]):
"""Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_. Pass 'XTR' for payments in `Telegram Stars <https://t.me/BotNews/90>`_."""
prices: list[LabeledPrice]
"""Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in `Telegram Stars <https://t.me/BotNews/90>`_."""
business_connection_id: Optional[str] = None
"""Unique identifier of the business connection on behalf of which the link will be created"""
provider_token: Optional[str] = None
"""Payment provider token, obtained via `@BotFather <https://t.me/botfather>`_. Pass an empty string for payments in `Telegram Stars <https://t.me/BotNews/90>`_."""
subscription_period: Optional[int] = None
"""The number of seconds the subscription will be active for before the next payment. The currency must be set to 'XTR' (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified."""
max_tip_amount: Optional[int] = None
"""The maximum accepted amount for tips in the *smallest units* of the currency (integer, **not** float/double). For example, for a maximum tip of :code:`US$ 1.45` pass :code:`max_tip_amount = 145`. See the *exp* parameter in `currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in `Telegram Stars <https://t.me/BotNews/90>`_."""
suggested_tip_amounts: Optional[list[int]] = None
@ -69,7 +73,9 @@ class CreateInvoiceLink(TelegramMethod[str]):
payload: str,
currency: str,
prices: list[LabeledPrice],
business_connection_id: Optional[str] = None,
provider_token: Optional[str] = None,
subscription_period: Optional[int] = None,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[list[int]] = None,
provider_data: Optional[str] = None,
@ -96,7 +102,9 @@ class CreateInvoiceLink(TelegramMethod[str]):
payload=payload,
currency=currency,
prices=prices,
business_connection_id=business_connection_id,
provider_token=provider_token,
subscription_period=subscription_period,
max_tip_amount=max_tip_amount,
suggested_tip_amounts=suggested_tip_amounts,
provider_data=provider_data,

View file

@ -1,17 +1,11 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any, List, Optional, Union
from typing import TYPE_CHECKING, Any, Optional, Union
from pydantic import Field
from ..client.default import Default
from ..types import (
UNSET_PARSE_MODE,
InlineKeyboardMarkup,
LinkPreviewOptions,
Message,
MessageEntity,
)
from ..types import InlineKeyboardMarkup, LinkPreviewOptions, Message, MessageEntity
from .base import TelegramMethod

View file

@ -0,0 +1,46 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from .base import TelegramMethod
class EditUserStarSubscription(TelegramMethod[bool]):
"""
Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#edituserstarsubscription
"""
__returning__ = bool
__api_method__ = "editUserStarSubscription"
user_id: int
"""Identifier of the user whose subscription will be edited"""
telegram_payment_charge_id: str
"""Telegram payment identifier for the subscription"""
is_canceled: bool
"""Pass :code:`True` to cancel extension of the user subscription; the subscription must be active up to the end of the current subscription period. Pass :code:`False` to allow the user to re-enable a subscription that was previously canceled by the bot."""
if TYPE_CHECKING:
# DO NOT EDIT MANUALLY!!!
# This section was auto-generated via `butcher`
def __init__(
__pydantic__self__,
*,
user_id: int,
telegram_payment_charge_id: str,
is_canceled: bool,
**__pydantic_kwargs: Any,
) -> None:
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
# Is needed only for type checking and IDE support without any additional plugins
super().__init__(
user_id=user_id,
telegram_payment_charge_id=telegram_payment_charge_id,
is_canceled=is_canceled,
**__pydantic_kwargs,
)

View file

@ -0,0 +1,15 @@
from __future__ import annotations
from ..types.gifts import Gifts
from .base import TelegramMethod
class GetAvailableGifts(TelegramMethod[Gifts]):
"""
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a :class:`aiogram.types.gifts.Gifts` object.
Source: https://core.telegram.org/bots/api#getavailablegifts
"""
__returning__ = Gifts
__api_method__ = "getAvailableGifts"

View file

@ -0,0 +1,121 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, Union
from ..types.inline_query_result_article import InlineQueryResultArticle
from ..types.inline_query_result_audio import InlineQueryResultAudio
from ..types.inline_query_result_cached_audio import InlineQueryResultCachedAudio
from ..types.inline_query_result_cached_document import InlineQueryResultCachedDocument
from ..types.inline_query_result_cached_gif import InlineQueryResultCachedGif
from ..types.inline_query_result_cached_mpeg4_gif import InlineQueryResultCachedMpeg4Gif
from ..types.inline_query_result_cached_photo import InlineQueryResultCachedPhoto
from ..types.inline_query_result_cached_sticker import InlineQueryResultCachedSticker
from ..types.inline_query_result_cached_video import InlineQueryResultCachedVideo
from ..types.inline_query_result_cached_voice import InlineQueryResultCachedVoice
from ..types.inline_query_result_contact import InlineQueryResultContact
from ..types.inline_query_result_document import InlineQueryResultDocument
from ..types.inline_query_result_game import InlineQueryResultGame
from ..types.inline_query_result_gif import InlineQueryResultGif
from ..types.inline_query_result_location import InlineQueryResultLocation
from ..types.inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif
from ..types.inline_query_result_photo import InlineQueryResultPhoto
from ..types.inline_query_result_venue import InlineQueryResultVenue
from ..types.inline_query_result_video import InlineQueryResultVideo
from ..types.inline_query_result_voice import InlineQueryResultVoice
from ..types.prepared_inline_message import PreparedInlineMessage
from .base import TelegramMethod
class SavePreparedInlineMessage(TelegramMethod[PreparedInlineMessage]):
"""
Stores a message that can be sent by a user of a Mini App. Returns a :class:`aiogram.types.prepared_inline_message.PreparedInlineMessage` object.
Source: https://core.telegram.org/bots/api#savepreparedinlinemessage
"""
__returning__ = PreparedInlineMessage
__api_method__ = "savePreparedInlineMessage"
user_id: int
"""Unique identifier of the target user that can use the prepared message"""
result: Union[
InlineQueryResultCachedAudio,
InlineQueryResultCachedDocument,
InlineQueryResultCachedGif,
InlineQueryResultCachedMpeg4Gif,
InlineQueryResultCachedPhoto,
InlineQueryResultCachedSticker,
InlineQueryResultCachedVideo,
InlineQueryResultCachedVoice,
InlineQueryResultArticle,
InlineQueryResultAudio,
InlineQueryResultContact,
InlineQueryResultGame,
InlineQueryResultDocument,
InlineQueryResultGif,
InlineQueryResultLocation,
InlineQueryResultMpeg4Gif,
InlineQueryResultPhoto,
InlineQueryResultVenue,
InlineQueryResultVideo,
InlineQueryResultVoice,
]
"""A JSON-serialized object describing the message to be sent"""
allow_user_chats: Optional[bool] = None
"""Pass :code:`True` if the message can be sent to private chats with users"""
allow_bot_chats: Optional[bool] = None
"""Pass :code:`True` if the message can be sent to private chats with bots"""
allow_group_chats: Optional[bool] = None
"""Pass :code:`True` if the message can be sent to group and supergroup chats"""
allow_channel_chats: Optional[bool] = None
"""Pass :code:`True` if the message can be sent to channel chats"""
if TYPE_CHECKING:
# DO NOT EDIT MANUALLY!!!
# This section was auto-generated via `butcher`
def __init__(
__pydantic__self__,
*,
user_id: int,
result: Union[
InlineQueryResultCachedAudio,
InlineQueryResultCachedDocument,
InlineQueryResultCachedGif,
InlineQueryResultCachedMpeg4Gif,
InlineQueryResultCachedPhoto,
InlineQueryResultCachedSticker,
InlineQueryResultCachedVideo,
InlineQueryResultCachedVoice,
InlineQueryResultArticle,
InlineQueryResultAudio,
InlineQueryResultContact,
InlineQueryResultGame,
InlineQueryResultDocument,
InlineQueryResultGif,
InlineQueryResultLocation,
InlineQueryResultMpeg4Gif,
InlineQueryResultPhoto,
InlineQueryResultVenue,
InlineQueryResultVideo,
InlineQueryResultVoice,
],
allow_user_chats: Optional[bool] = None,
allow_bot_chats: Optional[bool] = None,
allow_group_chats: Optional[bool] = None,
allow_channel_chats: Optional[bool] = None,
**__pydantic_kwargs: Any,
) -> None:
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
# Is needed only for type checking and IDE support without any additional plugins
super().__init__(
user_id=user_id,
result=result,
allow_user_chats=allow_user_chats,
allow_bot_chats=allow_bot_chats,
allow_group_chats=allow_group_chats,
allow_channel_chats=allow_channel_chats,
**__pydantic_kwargs,
)

View file

@ -0,0 +1,55 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional
from ..types.message_entity import MessageEntity
from .base import TelegramMethod
class SendGift(TelegramMethod[bool]):
"""
Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#sendgift
"""
__returning__ = bool
__api_method__ = "sendGift"
user_id: int
"""Unique identifier of the target user that will receive the gift"""
gift_id: str
"""Identifier of the gift"""
text: Optional[str] = None
"""Text that will be shown along with the gift; 0-255 characters"""
text_parse_mode: Optional[str] = None
"""Mode for parsing entities in the text. See `formatting options <https://core.telegram.org/bots/api#formatting-options>`_ for more details. Entities other than 'bold', 'italic', 'underline', 'strikethrough', 'spoiler', and 'custom_emoji' are ignored."""
text_entities: Optional[list[MessageEntity]] = None
"""A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of *text_parse_mode*. Entities other than 'bold', 'italic', 'underline', 'strikethrough', 'spoiler', and 'custom_emoji' are ignored."""
if TYPE_CHECKING:
# DO NOT EDIT MANUALLY!!!
# This section was auto-generated via `butcher`
def __init__(
__pydantic__self__,
*,
user_id: int,
gift_id: str,
text: Optional[str] = None,
text_parse_mode: Optional[str] = None,
text_entities: Optional[list[MessageEntity]] = None,
**__pydantic_kwargs: Any,
) -> None:
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
# Is needed only for type checking and IDE support without any additional plugins
super().__init__(
user_id=user_id,
gift_id=gift_id,
text=text,
text_parse_mode=text_parse_mode,
text_entities=text_entities,
**__pydantic_kwargs,
)

View file

@ -0,0 +1,51 @@
from __future__ import annotations
import datetime
from typing import TYPE_CHECKING, Any, Optional, Union
from .base import TelegramMethod
class SetUserEmojiStatus(TelegramMethod[bool]):
"""
Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method `requestEmojiStatusAccess <https://core.telegram.org/bots/webapps#initializing-mini-apps>`_. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setuseremojistatus
"""
__returning__ = bool
__api_method__ = "setUserEmojiStatus"
user_id: int
"""Unique identifier of the target user"""
emoji_status_custom_emoji_id: Optional[str] = None
"""Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status."""
emoji_status_expiration_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = (
None
)
"""Expiration date of the emoji status, if any"""
if TYPE_CHECKING:
# DO NOT EDIT MANUALLY!!!
# This section was auto-generated via `butcher`
def __init__(
__pydantic__self__,
*,
user_id: int,
emoji_status_custom_emoji_id: Optional[str] = None,
emoji_status_expiration_date: Optional[
Union[datetime.datetime, datetime.timedelta, int]
] = None,
**__pydantic_kwargs: Any,
) -> None:
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
# Is needed only for type checking and IDE support without any additional plugins
super().__init__(
user_id=user_id,
emoji_status_custom_emoji_id=emoji_status_custom_emoji_id,
emoji_status_expiration_date=emoji_status_expiration_date,
**__pydantic_kwargs,
)