mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add support of Bot API 4.7. Bump version
This commit is contained in:
parent
4cb9697cb4
commit
33003f2026
167 changed files with 996 additions and 504 deletions
|
|
@ -26,5 +26,5 @@ __all__ = (
|
|||
"handler",
|
||||
)
|
||||
|
||||
__version__ = "3.0.0a2"
|
||||
__api_version__ = "4.6"
|
||||
__version__ = "3.0.0a3"
|
||||
__api_version__ = "4.7"
|
||||
|
|
|
|||
|
|
@ -2,19 +2,12 @@ from __future__ import annotations
|
|||
|
||||
import datetime
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import (
|
||||
List,
|
||||
Optional,
|
||||
Union,
|
||||
TypeVar,
|
||||
AsyncIterator,
|
||||
Any,
|
||||
)
|
||||
from typing import Any, AsyncIterator, List, Optional, TypeVar, Union
|
||||
|
||||
from async_lru import alru_cache
|
||||
|
||||
from .session.aiohttp import AiohttpSession
|
||||
from .session.base import BaseSession
|
||||
from ...utils.mixins import ContextInstanceMixin
|
||||
from ...utils.token import extract_bot_id, validate_token
|
||||
from ..methods import (
|
||||
AddStickerToSet,
|
||||
AnswerCallbackQuery,
|
||||
|
|
@ -41,6 +34,7 @@ from ..methods import (
|
|||
GetFile,
|
||||
GetGameHighScores,
|
||||
GetMe,
|
||||
GetMyCommands,
|
||||
GetStickerSet,
|
||||
GetUpdates,
|
||||
GetUserProfilePhotos,
|
||||
|
|
@ -54,6 +48,7 @@ from ..methods import (
|
|||
SendAudio,
|
||||
SendChatAction,
|
||||
SendContact,
|
||||
SendDice,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
|
|
@ -74,17 +69,20 @@ from ..methods import (
|
|||
SetChatStickerSet,
|
||||
SetChatTitle,
|
||||
SetGameScore,
|
||||
SetMyCommands,
|
||||
SetPassportDataErrors,
|
||||
SetStickerPositionInSet,
|
||||
SetStickerSetThumb,
|
||||
SetWebhook,
|
||||
StopMessageLiveLocation,
|
||||
StopPoll,
|
||||
TelegramMethod,
|
||||
UnbanChatMember,
|
||||
UnpinChatMessage,
|
||||
UploadStickerFile,
|
||||
TelegramMethod,
|
||||
)
|
||||
from ..types import (
|
||||
BotCommand,
|
||||
Chat,
|
||||
ChatMember,
|
||||
ChatPermissions,
|
||||
|
|
@ -111,18 +109,15 @@ from ..types import (
|
|||
UserProfilePhotos,
|
||||
WebhookInfo,
|
||||
)
|
||||
from ...utils.mixins import ContextInstanceMixin
|
||||
from ...utils.token import (
|
||||
validate_token,
|
||||
extract_bot_id,
|
||||
)
|
||||
from .session.aiohttp import AiohttpSession
|
||||
from .session.base import BaseSession
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class Bot(ContextInstanceMixin["Bot"]):
|
||||
"""
|
||||
Class where located all API methods
|
||||
Main bot class
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
|
@ -146,21 +141,6 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
"""
|
||||
return extract_bot_id(self.__token)
|
||||
|
||||
async def __call__(self, method: TelegramMethod[T]) -> T:
|
||||
"""
|
||||
Call API method
|
||||
|
||||
:param method:
|
||||
:return:
|
||||
"""
|
||||
return await self.session.make_request(self.__token, method)
|
||||
|
||||
async def close(self) -> None:
|
||||
"""
|
||||
Close bot session
|
||||
"""
|
||||
await self.session.close()
|
||||
|
||||
@asynccontextmanager
|
||||
async def context(self, auto_close: bool = True) -> AsyncIterator[Bot]:
|
||||
"""
|
||||
|
|
@ -177,6 +157,25 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
await self.close()
|
||||
self.reset_current(token)
|
||||
|
||||
@alru_cache() # type: ignore
|
||||
async def me(self) -> User:
|
||||
return await self.get_me()
|
||||
|
||||
async def close(self) -> None:
|
||||
"""
|
||||
Close bot session
|
||||
"""
|
||||
await self.session.close()
|
||||
|
||||
async def __call__(self, method: TelegramMethod[T]) -> T:
|
||||
"""
|
||||
Call API method
|
||||
|
||||
:param method:
|
||||
:return:
|
||||
"""
|
||||
return await self.session.make_request(self.__token, method)
|
||||
|
||||
def __hash__(self) -> int:
|
||||
"""
|
||||
Get hash for the token
|
||||
|
|
@ -196,10 +195,6 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
return False
|
||||
return hash(self) == hash(other)
|
||||
|
||||
@alru_cache() # type: ignore
|
||||
async def me(self) -> User:
|
||||
return await self.get_me()
|
||||
|
||||
# =============================================================================================
|
||||
# Group: Getting updates
|
||||
# Source: https://core.telegram.org/bots/api#getting-updates
|
||||
|
|
@ -359,7 +354,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
|
||||
:param chat_id: Unique identifier for the target chat or username of the target channel
|
||||
(in the format @channelusername)
|
||||
:param text: Text of the message to be sent
|
||||
:param text: Text of the message to be sent, 1-4096 characters after entities parsing
|
||||
: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.
|
||||
:param disable_web_page_preview: Disables link previews for links in this message
|
||||
|
|
@ -435,7 +430,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
get a photo from the Internet, or upload a new photo using
|
||||
multipart/form-data.
|
||||
:param caption: Photo caption (may also be used when resending photos by file_id), 0-1024
|
||||
characters
|
||||
characters after entities parsing
|
||||
: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.
|
||||
:param disable_notification: Sends the message silently. Users will receive a notification
|
||||
|
|
@ -488,7 +483,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
exists on the Telegram servers (recommended), pass an HTTP URL as a String
|
||||
for Telegram to get an audio file from the Internet, or upload a new one
|
||||
using multipart/form-data.
|
||||
:param caption: Audio caption, 0-1024 characters
|
||||
:param caption: Audio caption, 0-1024 characters after entities parsing
|
||||
: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.
|
||||
:param duration: Duration of the audio in seconds
|
||||
|
|
@ -558,7 +553,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>.
|
||||
:param caption: Document caption (may also be used when resending documents by file_id),
|
||||
0-1024 characters
|
||||
0-1024 characters after entities parsing
|
||||
: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.
|
||||
:param disable_notification: Sends the message silently. Users will receive a notification
|
||||
|
|
@ -622,7 +617,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>.
|
||||
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024
|
||||
characters
|
||||
characters after entities parsing
|
||||
: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.
|
||||
:param supports_streaming: Pass True, if the uploaded video is suitable for streaming
|
||||
|
|
@ -690,7 +685,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>.
|
||||
:param caption: Animation caption (may also be used when resending animation by file_id),
|
||||
0-1024 characters
|
||||
0-1024 characters after entities parsing
|
||||
: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.
|
||||
:param disable_notification: Sends the message silently. Users will receive a notification
|
||||
|
|
@ -731,7 +726,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
) -> 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
|
||||
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.
|
||||
|
|
@ -744,7 +739,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
the Telegram servers (recommended), pass an HTTP URL as a String for
|
||||
Telegram to get a file from the Internet, or upload a new one using
|
||||
multipart/form-data.
|
||||
:param caption: Voice message caption, 0-1024 characters
|
||||
:param caption: Voice message caption, 0-1024 characters after entities parsing
|
||||
: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.
|
||||
:param duration: Duration of the voice message in seconds
|
||||
|
|
@ -1121,6 +1116,40 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
)
|
||||
return await self(call)
|
||||
|
||||
async def send_dice(
|
||||
self,
|
||||
chat_id: Union[int, 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 dice, which will have a random value from 1 to 6. On success,
|
||||
the sent Message is returned. (Yes, we're aware of the 'proper' singular of die. But it's
|
||||
awkward, and we decided to help it change. One dice at a time!)
|
||||
|
||||
Source: https://core.telegram.org/bots/api#senddice
|
||||
|
||||
:param chat_id: Unique identifier for the target chat or username of the target channel
|
||||
(in the format @channelusername)
|
||||
:param disable_notification: Sends the message silently. Users will receive a notification
|
||||
with no sound.
|
||||
:param reply_to_message_id: If the message is a reply, ID of the original message
|
||||
:param 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.
|
||||
:return: On success, the sent Message is returned.
|
||||
"""
|
||||
call = SendDice(
|
||||
chat_id=chat_id,
|
||||
disable_notification=disable_notification,
|
||||
reply_to_message_id=reply_to_message_id,
|
||||
reply_markup=reply_markup,
|
||||
)
|
||||
return await self(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
|
||||
|
|
@ -1631,6 +1660,31 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
)
|
||||
return await self(call)
|
||||
|
||||
async def set_my_commands(self, commands: List[BotCommand],) -> bool:
|
||||
"""
|
||||
Use this method to change the list of the bot's commands. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setmycommands
|
||||
|
||||
:param commands: A JSON-serialized list of bot commands to be set as the list of the bot's
|
||||
commands. At most 100 commands can be specified.
|
||||
:return: Returns True on success.
|
||||
"""
|
||||
call = SetMyCommands(commands=commands,)
|
||||
return await self(call)
|
||||
|
||||
async def get_my_commands(self,) -> List[BotCommand]:
|
||||
"""
|
||||
Use this method to get the current list of the bot's commands. Requires no parameters.
|
||||
Returns Array of BotCommand on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getmycommands
|
||||
|
||||
:return: Returns Array of BotCommand on success.
|
||||
"""
|
||||
call = GetMyCommands()
|
||||
return await self(call)
|
||||
|
||||
# =============================================================================================
|
||||
# Group: Updating messages
|
||||
# Source: https://core.telegram.org/bots/api#updating-messages
|
||||
|
|
@ -1652,7 +1706,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
|
||||
Source: https://core.telegram.org/bots/api#editmessagetext
|
||||
|
||||
:param text: New text of the message
|
||||
:param text: New text of the message, 1-4096 characters after entities parsing
|
||||
:param chat_id: Required if inline_message_id is not specified. Unique identifier for the
|
||||
target chat or username of the target channel (in the format
|
||||
@channelusername)
|
||||
|
|
@ -1700,7 +1754,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
message to edit
|
||||
:param inline_message_id: Required if chat_id and message_id are not specified. Identifier
|
||||
of the inline message
|
||||
:param caption: New caption of the message
|
||||
:param caption: New caption of the message, 0-1024 characters after entities parsing
|
||||
: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.
|
||||
:param reply_markup: A JSON-serialized object for an inline keyboard.
|
||||
|
|
@ -1814,6 +1868,8 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
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.
|
||||
- A dice message in a private chat can only be deleted if it was sent more than 24 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.
|
||||
|
|
@ -1857,7 +1913,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
(in the format @channelusername)
|
||||
:param sticker: Sticker to send. Pass a file_id as String to send a file that exists on
|
||||
the Telegram servers (recommended), pass an HTTP URL as a String for
|
||||
Telegram to get a .webp file from the Internet, or upload a new one using
|
||||
Telegram to get a .WEBP file from the Internet, or upload a new one using
|
||||
multipart/form-data.
|
||||
:param disable_notification: Sends the message silently. Users will receive a notification
|
||||
with no sound.
|
||||
|
|
@ -1890,7 +1946,7 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
|
||||
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
|
||||
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.
|
||||
|
||||
|
|
@ -1910,14 +1966,16 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
user_id: int,
|
||||
name: str,
|
||||
title: str,
|
||||
png_sticker: Union[InputFile, str],
|
||||
emojis: str,
|
||||
png_sticker: Optional[Union[InputFile, str]] = None,
|
||||
tgs_sticker: Optional[InputFile] = None,
|
||||
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.
|
||||
Use this method to create a new sticker set owned by a user. The bot will be able to edit
|
||||
the sticker set thus created. You must use exactly one of the fields png_sticker or
|
||||
tgs_sticker. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#createnewstickerset
|
||||
|
||||
|
|
@ -1927,13 +1985,16 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
begin with a letter, can't contain consecutive underscores and must end in
|
||||
'_by_<bot username>'. <bot_username> is case insensitive. 1-64 characters.
|
||||
:param title: Sticker set title, 1-64 characters
|
||||
:param png_sticker: Png image with the sticker, must be up to 512 kilobytes in size,
|
||||
:param emojis: One or more emoji corresponding to the sticker
|
||||
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size,
|
||||
dimensions must not exceed 512px, and either width or height must be
|
||||
exactly 512px. Pass a file_id as a String to send a file that already
|
||||
exists on the Telegram servers, pass an HTTP URL as a String for
|
||||
Telegram to get a file from the Internet, or upload a new one using
|
||||
multipart/form-data.
|
||||
:param emojis: One or more emoji corresponding to the sticker
|
||||
:param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data.
|
||||
See https://core.telegram.org/animated_stickers#technical-requirements
|
||||
for technical requirements
|
||||
:param contains_masks: Pass True, if a set of mask stickers should be created
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be
|
||||
placed on faces
|
||||
|
|
@ -1943,8 +2004,9 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
user_id=user_id,
|
||||
name=name,
|
||||
title=title,
|
||||
png_sticker=png_sticker,
|
||||
emojis=emojis,
|
||||
png_sticker=png_sticker,
|
||||
tgs_sticker=tgs_sticker,
|
||||
contains_masks=contains_masks,
|
||||
mask_position=mask_position,
|
||||
)
|
||||
|
|
@ -1956,22 +2018,29 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
name: str,
|
||||
png_sticker: Union[InputFile, str],
|
||||
emojis: str,
|
||||
tgs_sticker: Optional[InputFile] = None,
|
||||
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.
|
||||
Use this method to add a new sticker to a set created by the bot. You must use exactly one
|
||||
of the fields png_sticker or tgs_sticker. Animated stickers can be added to animated
|
||||
sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static
|
||||
sticker sets can have up to 120 stickers. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#addstickertoset
|
||||
|
||||
:param user_id: User identifier of sticker set owner
|
||||
:param name: Sticker set name
|
||||
:param png_sticker: Png image with the sticker, must be up to 512 kilobytes in size,
|
||||
: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.
|
||||
:param emojis: One or more emoji corresponding to the sticker
|
||||
:param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data.
|
||||
See https://core.telegram.org/animated_stickers#technical-requirements
|
||||
for technical requirements
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be
|
||||
placed on faces
|
||||
:return: Returns True on success.
|
||||
|
|
@ -1981,13 +2050,14 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
name=name,
|
||||
png_sticker=png_sticker,
|
||||
emojis=emojis,
|
||||
tgs_sticker=tgs_sticker,
|
||||
mask_position=mask_position,
|
||||
)
|
||||
return await self(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 .
|
||||
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
|
||||
|
|
@ -2012,6 +2082,31 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
call = DeleteStickerFromSet(sticker=sticker,)
|
||||
return await self(call)
|
||||
|
||||
async def set_sticker_set_thumb(
|
||||
self, name: str, user_id: int, thumb: Optional[Union[InputFile, str]] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for
|
||||
animated sticker sets only. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setstickersetthumb
|
||||
|
||||
:param name: Sticker set name
|
||||
:param user_id: User identifier of the sticker set owner
|
||||
:param thumb: A PNG image with the thumbnail, must be up to 128 kilobytes in size and have
|
||||
width and height exactly 100px, or a TGS animation with the thumbnail up to
|
||||
32 kilobytes in size; see
|
||||
https://core.telegram.org/animated_stickers#technical-requirements for
|
||||
animated sticker technical requirements. Pass a file_id as a String to send
|
||||
a file that already exists on the Telegram servers, pass an HTTP URL as a
|
||||
String for Telegram to get a file from the Internet, or upload a new one
|
||||
using multipart/form-data.. Animated sticker set thumbnail can't be uploaded
|
||||
via HTTP URL.
|
||||
:return: Returns True on success.
|
||||
"""
|
||||
call = SetStickerSetThumb(name=name, user_id=user_id, thumb=thumb,)
|
||||
return await self(call)
|
||||
|
||||
# =============================================================================================
|
||||
# Group: Inline mode
|
||||
# Source: https://core.telegram.org/bots/api#inline-mode
|
||||
|
|
|
|||
|
|
@ -4,15 +4,7 @@ import abc
|
|||
import datetime
|
||||
import json
|
||||
from types import TracebackType
|
||||
from typing import (
|
||||
Any,
|
||||
AsyncGenerator,
|
||||
Callable,
|
||||
Optional,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
)
|
||||
from typing import Any, AsyncGenerator, Callable, Optional, Type, TypeVar, Union
|
||||
|
||||
from aiogram.utils.exceptions import TelegramAPIError
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ 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_my_commands import GetMyCommands
|
||||
from .get_sticker_set import GetStickerSet
|
||||
from .get_updates import GetUpdates
|
||||
from .get_user_profile_photos import GetUserProfilePhotos
|
||||
|
|
@ -37,6 +38,7 @@ from .send_animation import SendAnimation
|
|||
from .send_audio import SendAudio
|
||||
from .send_chat_action import SendChatAction
|
||||
from .send_contact import SendContact
|
||||
from .send_dice import SendDice
|
||||
from .send_document import SendDocument
|
||||
from .send_game import SendGame
|
||||
from .send_invoice import SendInvoice
|
||||
|
|
@ -57,8 +59,10 @@ 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_my_commands import SetMyCommands
|
||||
from .set_passport_data_errors import SetPassportDataErrors
|
||||
from .set_sticker_position_in_set import SetStickerPositionInSet
|
||||
from .set_sticker_set_thumb import SetStickerSetThumb
|
||||
from .set_webhook import SetWebhook
|
||||
from .stop_message_live_location import StopMessageLiveLocation
|
||||
from .stop_poll import StopPoll
|
||||
|
|
@ -91,6 +95,7 @@ __all__ = (
|
|||
"SendVenue",
|
||||
"SendContact",
|
||||
"SendPoll",
|
||||
"SendDice",
|
||||
"SendChatAction",
|
||||
"GetUserProfilePhotos",
|
||||
"GetFile",
|
||||
|
|
@ -115,6 +120,8 @@ __all__ = (
|
|||
"SetChatStickerSet",
|
||||
"DeleteChatStickerSet",
|
||||
"AnswerCallbackQuery",
|
||||
"SetMyCommands",
|
||||
"GetMyCommands",
|
||||
"EditMessageText",
|
||||
"EditMessageCaption",
|
||||
"EditMessageMedia",
|
||||
|
|
@ -128,6 +135,7 @@ __all__ = (
|
|||
"AddStickerToSet",
|
||||
"SetStickerPositionInSet",
|
||||
"DeleteStickerFromSet",
|
||||
"SetStickerSetThumb",
|
||||
"AnswerInlineQuery",
|
||||
"SendInvoice",
|
||||
"AnswerShippingQuery",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ from .base import Request, TelegramMethod, prepare_file
|
|||
|
||||
class AddStickerToSet(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to add a new sticker to a set created by the bot. Returns True on success.
|
||||
Use this method to add a new sticker to a set created by the bot. You must use exactly one of
|
||||
the fields png_sticker or tgs_sticker. Animated stickers can be added to animated sticker sets
|
||||
and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can
|
||||
have up to 120 stickers. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#addstickertoset
|
||||
"""
|
||||
|
|
@ -18,19 +21,24 @@ class AddStickerToSet(TelegramMethod[bool]):
|
|||
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
|
||||
"""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"""
|
||||
tgs_sticker: Optional[InputFile] = None
|
||||
"""TGS animation with the sticker, uploaded using multipart/form-data. See
|
||||
https://core.telegram.org/animated_stickers#technical-requirements for technical
|
||||
requirements"""
|
||||
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={"png_sticker"})
|
||||
data: Dict[str, Any] = self.dict(exclude={"png_sticker", "tgs_sticker"})
|
||||
|
||||
files: Dict[str, InputFile] = {}
|
||||
prepare_file(data=data, files=files, name="png_sticker", value=self.png_sticker)
|
||||
prepare_file(data=data, files=files, name="tgs_sticker", value=self.tgs_sticker)
|
||||
|
||||
return Request(method="addStickerToSet", data=data, files=files)
|
||||
|
|
|
|||
|
|
@ -2,16 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import abc
|
||||
import secrets
|
||||
from typing import (
|
||||
Generator,
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Dict,
|
||||
Generic,
|
||||
Optional,
|
||||
TypeVar,
|
||||
Union,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any, Dict, Generator, Generic, Optional, TypeVar, Union
|
||||
|
||||
from pydantic import BaseConfig, BaseModel, Extra
|
||||
from pydantic.generics import GenericModel
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ from .base import Request, TelegramMethod, prepare_file
|
|||
|
||||
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.
|
||||
Use this method to create a new sticker set owned by a user. The bot will be able to edit the
|
||||
sticker set thus created. You must use exactly one of the fields png_sticker or tgs_sticker.
|
||||
Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#createnewstickerset
|
||||
"""
|
||||
|
|
@ -23,22 +24,27 @@ class CreateNewStickerSet(TelegramMethod[bool]):
|
|||
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
|
||||
emojis: str
|
||||
"""One or more emoji corresponding to the sticker"""
|
||||
png_sticker: Optional[Union[InputFile, str]] = None
|
||||
"""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"""
|
||||
tgs_sticker: Optional[InputFile] = None
|
||||
"""TGS animation with the sticker, uploaded using multipart/form-data. See
|
||||
https://core.telegram.org/animated_stickers#technical-requirements for technical
|
||||
requirements"""
|
||||
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={"png_sticker"})
|
||||
data: Dict[str, Any] = self.dict(exclude={"png_sticker", "tgs_sticker"})
|
||||
|
||||
files: Dict[str, InputFile] = {}
|
||||
prepare_file(data=data, files=files, name="png_sticker", value=self.png_sticker)
|
||||
prepare_file(data=data, files=files, name="tgs_sticker", value=self.tgs_sticker)
|
||||
|
||||
return Request(method="createNewStickerSet", data=data, files=files)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ 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.
|
||||
- A dice message in a private chat can only be deleted if it was sent more than 24 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.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]):
|
|||
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"""
|
||||
"""New caption of the message, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]):
|
|||
__returning__ = Union[Message, bool]
|
||||
|
||||
text: str
|
||||
"""New text of the message"""
|
||||
"""New text of the message, 1-4096 characters after entities parsing"""
|
||||
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)"""
|
||||
|
|
|
|||
20
aiogram/api/methods/get_my_commands.py
Normal file
20
aiogram/api/methods/get_my_commands.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from typing import Any, Dict, List
|
||||
|
||||
from ..types import BotCommand
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
|
||||
class GetMyCommands(TelegramMethod[List[BotCommand]]):
|
||||
"""
|
||||
Use this method to get the current list of the bot's commands. Requires no parameters. Returns
|
||||
Array of BotCommand on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getmycommands
|
||||
"""
|
||||
|
||||
__returning__ = List[BotCommand]
|
||||
|
||||
def build_request(self) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="getMyCommands", data=data)
|
||||
|
|
@ -43,7 +43,8 @@ class SendAnimation(TelegramMethod[Message]):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Animation caption (may also be used when resending animation by file_id), 0-1024 characters"""
|
||||
"""Animation caption (may also be used when resending animation by file_id), 0-1024 characters
|
||||
after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class SendAudio(TelegramMethod[Message]):
|
|||
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"""
|
||||
"""Audio caption, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
40
aiogram/api/methods/send_dice.py
Normal file
40
aiogram/api/methods/send_dice.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
from ..types import (
|
||||
ForceReply,
|
||||
InlineKeyboardMarkup,
|
||||
Message,
|
||||
ReplyKeyboardMarkup,
|
||||
ReplyKeyboardRemove,
|
||||
)
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
|
||||
class SendDice(TelegramMethod[Message]):
|
||||
"""
|
||||
Use this method to send a dice, which will have a random value from 1 to 6. On success, the
|
||||
sent Message is returned. (Yes, we're aware of the 'proper' singular of die. But it's awkward,
|
||||
and we decided to help it change. One dice at a time!)
|
||||
|
||||
Source: https://core.telegram.org/bots/api#senddice
|
||||
"""
|
||||
|
||||
__returning__ = Message
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target channel (in the format
|
||||
@channelusername)"""
|
||||
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()
|
||||
|
||||
return Request(method="sendDice", data=data)
|
||||
|
|
@ -37,7 +37,8 @@ class SendDocument(TelegramMethod[Message]):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Document caption (may also be used when resending documents by file_id), 0-1024 characters"""
|
||||
"""Document caption (may also be used when resending documents by file_id), 0-1024 characters
|
||||
after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class SendMessage(TelegramMethod[Message]):
|
|||
"""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"""
|
||||
"""Text of the message to be sent, 1-4096 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ class SendPhoto(TelegramMethod[Message]):
|
|||
(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"""
|
||||
"""Photo caption (may also be used when resending photos by file_id), 0-1024 characters after
|
||||
entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SendPoll(TelegramMethod[Message]):
|
|||
question: str
|
||||
"""Poll question, 1-255 characters"""
|
||||
options: List[str]
|
||||
"""List of answer options, 2-10 strings 1-100 characters each"""
|
||||
"""A JSON-serialized list of answer options, 2-10 strings 1-100 characters each"""
|
||||
is_anonymous: Optional[bool] = None
|
||||
"""True, if the poll needs to be anonymous, defaults to True"""
|
||||
type: Optional[str] = None
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class SendSticker(TelegramMethod[Message]):
|
|||
@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
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ class SendVideo(TelegramMethod[Message]):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Video caption (may also be used when resending videos by file_id), 0-1024 characters"""
|
||||
"""Video caption (may also be used when resending videos by file_id), 0-1024 characters after
|
||||
entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from .base import Request, TelegramMethod, prepare_file
|
|||
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
|
||||
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.
|
||||
|
|
@ -32,7 +32,7 @@ class SendVoice(TelegramMethod[Message]):
|
|||
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"""
|
||||
"""Voice message caption, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
23
aiogram/api/methods/set_my_commands.py
Normal file
23
aiogram/api/methods/set_my_commands.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from typing import Any, Dict, List
|
||||
|
||||
from ..types import BotCommand
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
|
||||
class SetMyCommands(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to change the list of the bot's commands. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setmycommands
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
commands: List[BotCommand]
|
||||
"""A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most
|
||||
100 commands can be specified."""
|
||||
|
||||
def build_request(self) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="setMyCommands", data=data)
|
||||
|
|
@ -5,7 +5,7 @@ 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
|
||||
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
|
||||
|
|
|
|||
36
aiogram/api/methods/set_sticker_set_thumb.py
Normal file
36
aiogram/api/methods/set_sticker_set_thumb.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
from ..types import InputFile
|
||||
from .base import Request, TelegramMethod, prepare_file
|
||||
|
||||
|
||||
class SetStickerSetThumb(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for
|
||||
animated sticker sets only. Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setstickersetthumb
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
name: str
|
||||
"""Sticker set name"""
|
||||
user_id: int
|
||||
"""User identifier of the sticker set owner"""
|
||||
thumb: Optional[Union[InputFile, str]] = None
|
||||
"""A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and
|
||||
height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see
|
||||
https://core.telegram.org/animated_stickers#technical-requirements for animated sticker
|
||||
technical requirements. Pass a file_id as a String to send a file that already exists on
|
||||
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the
|
||||
Internet, or upload a new one using multipart/form-data.. Animated sticker set thumbnail
|
||||
can't be uploaded via HTTP URL."""
|
||||
|
||||
def build_request(self) -> Request:
|
||||
data: Dict[str, Any] = self.dict(exclude={"thumb"})
|
||||
|
||||
files: Dict[str, InputFile] = {}
|
||||
prepare_file(data=data, files=files, name="thumb", value=self.thumb)
|
||||
|
||||
return Request(method="setStickerSetThumb", data=data, files=files)
|
||||
|
|
@ -6,7 +6,7 @@ from .base import Request, TelegramMethod, prepare_file
|
|||
|
||||
class UploadStickerFile(TelegramMethod[File]):
|
||||
"""
|
||||
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from .animation import Animation
|
||||
from .audio import Audio
|
||||
from .base import TelegramObject
|
||||
from .bot_command import BotCommand
|
||||
from .callback_game import CallbackGame
|
||||
from .callback_query import CallbackQuery
|
||||
from .chat import Chat
|
||||
|
|
@ -9,6 +10,7 @@ from .chat_permissions import ChatPermissions
|
|||
from .chat_photo import ChatPhoto
|
||||
from .chosen_inline_result import ChosenInlineResult
|
||||
from .contact import Contact
|
||||
from .dice import Dice
|
||||
from .document import Document
|
||||
from .encrypted_credentials import EncryptedCredentials
|
||||
from .encrypted_passport_element import EncryptedPassportElement
|
||||
|
|
@ -121,6 +123,7 @@ __all__ = (
|
|||
"PollOption",
|
||||
"PollAnswer",
|
||||
"Poll",
|
||||
"Dice",
|
||||
"UserProfilePhotos",
|
||||
"File",
|
||||
"ReplyKeyboardMarkup",
|
||||
|
|
@ -135,6 +138,7 @@ __all__ = (
|
|||
"ChatPhoto",
|
||||
"ChatMember",
|
||||
"ChatPermissions",
|
||||
"BotCommand",
|
||||
"ResponseParameters",
|
||||
"InputMedia",
|
||||
"InputMediaPhoto",
|
||||
|
|
|
|||
17
aiogram/api/types/bot_command.py
Normal file
17
aiogram/api/types/bot_command.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class BotCommand(MutableTelegramObject):
|
||||
"""
|
||||
This object represents a bot command.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#botcommand
|
||||
"""
|
||||
|
||||
command: str
|
||||
"""Text of the command, 1-32 characters. Can contain only lowercase English letters, digits
|
||||
and underscores."""
|
||||
description: str
|
||||
"""Description of the command, 3-256 characters."""
|
||||
15
aiogram/api/types/dice.py
Normal file
15
aiogram/api/types/dice.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
|
||||
class Dice(TelegramObject):
|
||||
"""
|
||||
This object represents a dice with random value from 1 to 6. (Yes, we're aware of the 'proper'
|
||||
singular of die. But it's awkward, and we decided to help it change. One dice at a time!)
|
||||
|
||||
Source: https://core.telegram.org/bots/api#dice
|
||||
"""
|
||||
|
||||
value: int
|
||||
"""Value of the dice, 1-6"""
|
||||
|
|
@ -31,7 +31,7 @@ class InlineQueryResultAudio(InlineQueryResult):
|
|||
title: str
|
||||
"""Title"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption, 0-1024 characters"""
|
||||
"""Caption, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
|||
audio_file_id: str
|
||||
"""A valid file identifier for the audio file"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption, 0-1024 characters"""
|
||||
"""Caption, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
|||
description: Optional[str] = None
|
||||
"""Short description of the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the document to be sent, 0-1024 characters"""
|
||||
"""Caption of the document to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
|||
title: Optional[str] = None
|
||||
"""Title for the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the GIF file to be sent, 0-1024 characters"""
|
||||
"""Caption of the GIF file to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
|||
title: Optional[str] = None
|
||||
"""Title for the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the MPEG-4 file to be sent, 0-1024 characters"""
|
||||
"""Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
|||
description: Optional[str] = None
|
||||
"""Short description of the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the photo to be sent, 0-1024 characters"""
|
||||
"""Caption of the photo to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
|||
description: Optional[str] = None
|
||||
"""Short description of the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the video to be sent, 0-1024 characters"""
|
||||
"""Caption of the video to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
|||
title: str
|
||||
"""Voice message title"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption, 0-1024 characters"""
|
||||
"""Caption, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
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"""
|
||||
"""Caption of the document to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
title: Optional[str] = None
|
||||
"""Title for the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the GIF file to be sent, 0-1024 characters"""
|
||||
"""Caption of the GIF file to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
title: Optional[str] = None
|
||||
"""Title for the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the MPEG-4 file to be sent, 0-1024 characters"""
|
||||
"""Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
description: Optional[str] = None
|
||||
"""Short description of the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the photo to be sent, 0-1024 characters"""
|
||||
"""Caption of the photo to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
title: str
|
||||
"""Title for the result"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the video to be sent, 0-1024 characters"""
|
||||
"""Caption of the video to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class InlineQueryResultVoice(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a voice recording in an .ogg container encoded with OPUS. By default,
|
||||
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.
|
||||
|
|
@ -32,7 +32,7 @@ class InlineQueryResultVoice(InlineQueryResult):
|
|||
title: str
|
||||
"""Recording title"""
|
||||
caption: Optional[str] = None
|
||||
"""Caption, 0-1024 characters"""
|
||||
"""Caption, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -4,13 +4,7 @@ import io
|
|||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import (
|
||||
AsyncGenerator,
|
||||
AsyncIterator,
|
||||
Iterator,
|
||||
Optional,
|
||||
Union,
|
||||
)
|
||||
from typing import AsyncGenerator, AsyncIterator, Iterator, Optional, Union
|
||||
|
||||
import aiofiles as aiofiles
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class InputMediaAnimation(InputMedia):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the animation to be sent, 0-1024 characters"""
|
||||
"""Caption of the animation to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class InputMediaAudio(InputMedia):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the audio to be sent, 0-1024 characters"""
|
||||
"""Caption of the audio to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class InputMediaDocument(InputMedia):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the document to be sent, 0-1024 characters"""
|
||||
"""Caption of the document to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class InputMediaPhoto(InputMedia):
|
|||
'attach://<file_attach_name>' to upload a new one using multipart/form-data under
|
||||
<file_attach_name> name."""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the photo to be sent, 0-1024 characters"""
|
||||
"""Caption of the photo to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class InputMediaVideo(InputMedia):
|
|||
file, so you can pass 'attach://<file_attach_name>' if the thumbnail was uploaded using
|
||||
multipart/form-data under <file_attach_name>."""
|
||||
caption: Optional[str] = None
|
||||
"""Caption of the video to be sent, 0-1024 characters"""
|
||||
"""Caption of the video to be sent, 0-1024 characters after entities parsing"""
|
||||
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."""
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
from .audio import Audio
|
||||
from .chat import Chat
|
||||
from .contact import Contact
|
||||
from .dice import Dice
|
||||
from .document import Document
|
||||
from .force_reply import ForceReply
|
||||
from .game import Game
|
||||
|
|
@ -95,7 +96,7 @@ class Message(TelegramObject):
|
|||
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."""
|
||||
"""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"""
|
||||
|
|
@ -131,6 +132,8 @@ class Message(TelegramObject):
|
|||
"""Message is a venue, information about the venue"""
|
||||
poll: Optional[Poll] = None
|
||||
"""Message is a native poll, information about the poll"""
|
||||
dice: Optional[Dice] = None
|
||||
"""Message is a dice with random value from 1 to 6"""
|
||||
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)"""
|
||||
|
|
@ -1479,7 +1482,8 @@ class ContentType(helper.Helper):
|
|||
DELETE_CHAT_PHOTO = helper.Item() # delete_chat_photo
|
||||
GROUP_CHAT_CREATED = helper.Item() # group_chat_created
|
||||
PASSPORT_DATA = helper.Item() # passport_data
|
||||
POLL = helper.Item()
|
||||
POLL = helper.Item() # poll
|
||||
DICE = helper.Item() # dice
|
||||
|
||||
UNKNOWN = helper.Item() # unknown
|
||||
ANY = helper.Item() # any
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class Sticker(TelegramObject):
|
|||
is_animated: bool
|
||||
"""True, if the sticker is animated"""
|
||||
thumb: Optional[PhotoSize] = None
|
||||
"""Sticker thumbnail in the .webp or .jpg format"""
|
||||
"""Sticker thumbnail in the .WEBP or .JPG format"""
|
||||
emoji: Optional[str] = None
|
||||
"""Emoji associated with the sticker"""
|
||||
set_name: Optional[str] = None
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List
|
||||
from typing import TYPE_CHECKING, List, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .photo_size import PhotoSize
|
||||
from .sticker import Sticker
|
||||
|
||||
|
||||
|
|
@ -25,3 +26,5 @@ class StickerSet(TelegramObject):
|
|||
"""True, if the sticker set contains masks"""
|
||||
stickers: List[Sticker]
|
||||
"""List of all set stickers"""
|
||||
thumb: Optional[PhotoSize] = None
|
||||
"""Sticker set thumbnail in the .WEBP or .TGS format"""
|
||||
|
|
|
|||
|
|
@ -1,17 +1,7 @@
|
|||
import inspect
|
||||
from dataclasses import dataclass, field
|
||||
from functools import partial
|
||||
from typing import (
|
||||
Any,
|
||||
Awaitable,
|
||||
Callable,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
Tuple,
|
||||
Union,
|
||||
Type,
|
||||
)
|
||||
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union
|
||||
|
||||
from aiogram.dispatcher.filters.base import BaseFilter
|
||||
from aiogram.dispatcher.handler.base import BaseHandler
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
from typing import (
|
||||
Dict,
|
||||
Tuple,
|
||||
Type,
|
||||
)
|
||||
from typing import Dict, Tuple, Type
|
||||
|
||||
from .base import BaseFilter
|
||||
from .command import Command, CommandObject
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Dict,
|
||||
Union,
|
||||
Callable,
|
||||
Awaitable,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Dict,
|
||||
Generic,
|
||||
TypeVar,
|
||||
cast,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any, Dict, Generic, TypeVar, cast
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.types import Update
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
from abc import ABC
|
||||
from typing import (
|
||||
Optional,
|
||||
cast,
|
||||
)
|
||||
from typing import Optional, cast
|
||||
|
||||
from aiogram.api.types import Chat, Message, User
|
||||
from aiogram.dispatcher.filters import CommandObject
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@ from __future__ import annotations
|
|||
import warnings
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from ..api.types import (
|
||||
Chat,
|
||||
TelegramObject,
|
||||
Update,
|
||||
User,
|
||||
)
|
||||
from ..api.types import Chat, TelegramObject, Update, User
|
||||
from ..utils.imports import import_module
|
||||
from ..utils.warnings import CodeHasNoEffect
|
||||
from .event.observer import EventObserver, SkipHandler, TelegramEventObserver
|
||||
|
|
|
|||
|
|
@ -14,15 +14,7 @@ Example:
|
|||
<<< ['barItem', 'bazItem', 'fooItem', 'lorem']
|
||||
"""
|
||||
import inspect
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Iterable,
|
||||
List,
|
||||
Optional,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
from typing import Any, Callable, Iterable, List, Optional, Union, cast
|
||||
|
||||
PROPS_KEYS_ATTR_NAME = "_props_keys"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
from __future__ import annotations
|
||||
import contextvars
|
||||
from typing import (
|
||||
Any,
|
||||
ClassVar,
|
||||
Generic,
|
||||
Optional,
|
||||
TypeVar,
|
||||
cast,
|
||||
overload,
|
||||
Dict,
|
||||
)
|
||||
|
||||
__all__ = ("ContextInstanceMixin", "DataMixin")
|
||||
import contextvars
|
||||
from typing import Any, ClassVar, Dict, Generic, Optional, TypeVar, cast, overload
|
||||
|
||||
from typing_extensions import Literal
|
||||
|
||||
__all__ = ("ContextInstanceMixin", "DataMixin")
|
||||
|
||||
|
||||
class DataMixin:
|
||||
@property
|
||||
|
|
@ -56,18 +48,24 @@ class ContextInstanceMixin(Generic[ContextInstance]):
|
|||
def get_current(cls) -> Optional[ContextInstance]: # pragma: no cover
|
||||
...
|
||||
|
||||
@overload # noqa: F811, it's overload, not redefinition
|
||||
@overload
|
||||
@classmethod
|
||||
def get_current(cls, no_error: Literal[True]) -> Optional[ContextInstance]: # pragma: no cover # noqa: F811
|
||||
def get_current( # noqa: F811
|
||||
cls, no_error: Literal[True]
|
||||
) -> Optional[ContextInstance]: # pragma: no cover
|
||||
...
|
||||
|
||||
@overload # noqa: F811, it's overload, not redefinition
|
||||
@overload
|
||||
@classmethod
|
||||
def get_current(cls, no_error: Literal[False]) -> ContextInstance: # pragma: no cover # noqa: F811
|
||||
def get_current( # noqa: F811
|
||||
cls, no_error: Literal[False]
|
||||
) -> ContextInstance: # pragma: no cover
|
||||
...
|
||||
|
||||
@classmethod # noqa: F811, it's overload, not redefinition
|
||||
def get_current(cls, no_error: bool = True) -> Optional[ContextInstance]: # pragma: no cover # noqa: F811
|
||||
@classmethod
|
||||
def get_current( # noqa: F811
|
||||
cls, no_error: bool = True
|
||||
) -> Optional[ContextInstance]: # pragma: no cover
|
||||
# on mypy 0.770 I catch that contextvars.ContextVar always contextvars.ContextVar[Any]
|
||||
cls.__context_instance = cast(
|
||||
contextvars.ContextVar[ContextInstance], cls.__context_instance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue