diff --git a/maxapi/types/attachments/audio.py b/maxapi/types/attachments/audio.py index f527456..d0ec827 100644 --- a/maxapi/types/attachments/audio.py +++ b/maxapi/types/attachments/audio.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional from ...enums.attachment import AttachmentType @@ -15,5 +15,5 @@ class Audio(Attachment): transcription (Optional[str]): Транскрипция аудио (если есть). """ - type: AttachmentType = AttachmentType.AUDIO + type: Literal[AttachmentType.AUDIO] transcription: Optional[str] = None \ No newline at end of file diff --git a/maxapi/types/attachments/buttons/attachment_button.py b/maxapi/types/attachments/buttons/attachment_button.py index ea213cf..732a5eb 100644 --- a/maxapi/types/attachments/buttons/attachment_button.py +++ b/maxapi/types/attachments/buttons/attachment_button.py @@ -1,10 +1,11 @@ from typing import Literal -from pydantic import BaseModel -from ..attachment import ButtonsPayload +from ....enums.attachment import AttachmentType + +from ..attachment import Attachment -class AttachmentButton(BaseModel): +class AttachmentButton(Attachment): """ Модель кнопки вложения для сообщения. @@ -14,5 +15,4 @@ class AttachmentButton(BaseModel): payload: Полезная нагрузка кнопки (массив рядов кнопок) """ - type: Literal['inline_keyboard'] = 'inline_keyboard' - payload: ButtonsPayload \ No newline at end of file + type: Literal[AttachmentType.INLINE_KEYBOARD] \ No newline at end of file diff --git a/maxapi/types/attachments/contact.py b/maxapi/types/attachments/contact.py index 177f969..d820d2f 100644 --- a/maxapi/types/attachments/contact.py +++ b/maxapi/types/attachments/contact.py @@ -1,3 +1,4 @@ +from typing import Literal from ...enums.attachment import AttachmentType from .attachment import Attachment @@ -12,4 +13,4 @@ class Contact(Attachment): type (Literal['contact']): Тип вложения, всегда 'contact'. """ - type: AttachmentType = AttachmentType.CONTACT \ No newline at end of file + type: Literal[AttachmentType.CONTACT] \ No newline at end of file diff --git a/maxapi/types/attachments/file.py b/maxapi/types/attachments/file.py index 3a3801a..c4fd0c7 100644 --- a/maxapi/types/attachments/file.py +++ b/maxapi/types/attachments/file.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional from ...enums.attachment import AttachmentType @@ -16,6 +16,6 @@ class File(Attachment): size (Optional[int]): Размер файла в байтах. """ - type: AttachmentType = AttachmentType.FILE + type: Literal[AttachmentType.FILE] filename: Optional[str] = None size: Optional[int] = None \ No newline at end of file diff --git a/maxapi/types/attachments/image.py b/maxapi/types/attachments/image.py index ac94c4a..5365ff7 100644 --- a/maxapi/types/attachments/image.py +++ b/maxapi/types/attachments/image.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional from pydantic import BaseModel @@ -31,4 +31,4 @@ class Image(Attachment): type (Literal['image']): Тип вложения, всегда 'image'. """ - type: AttachmentType = AttachmentType.IMAGE \ No newline at end of file + type: Literal[AttachmentType.IMAGE] \ No newline at end of file diff --git a/maxapi/types/attachments/location.py b/maxapi/types/attachments/location.py index d161ced..fe692d9 100644 --- a/maxapi/types/attachments/location.py +++ b/maxapi/types/attachments/location.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional from ...enums.attachment import AttachmentType @@ -16,6 +16,6 @@ class Location(Attachment): longitude (Optional[float]): Долгота. """ - type: AttachmentType = AttachmentType.LOCATION + type: Literal[AttachmentType.LOCATION] latitude: Optional[float] = None longitude: Optional[float] = None \ No newline at end of file diff --git a/maxapi/types/attachments/share.py b/maxapi/types/attachments/share.py index 8ca9bfa..f3967cd 100644 --- a/maxapi/types/attachments/share.py +++ b/maxapi/types/attachments/share.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional from ...enums.attachment import AttachmentType @@ -17,7 +17,7 @@ class Share(Attachment): image_url (Optional[str]): URL изображения для предпросмотра. """ - type: AttachmentType = AttachmentType.SHARE + type: Literal[AttachmentType.SHARE] title: Optional[str] = None description: Optional[str] = None image_url: Optional[str] = None diff --git a/maxapi/types/attachments/sticker.py b/maxapi/types/attachments/sticker.py index 5cdebd7..9da850c 100644 --- a/maxapi/types/attachments/sticker.py +++ b/maxapi/types/attachments/sticker.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional from ...enums.attachment import AttachmentType @@ -16,6 +16,6 @@ class Sticker(Attachment): height (Optional[int]): Высота стикера в пикселях. """ - type: AttachmentType = AttachmentType.STICKER + type: Literal[AttachmentType.STICKER] width: Optional[int] = None height: Optional[int] = None \ No newline at end of file diff --git a/maxapi/types/attachments/video.py b/maxapi/types/attachments/video.py index b0e00ee..7c948e0 100644 --- a/maxapi/types/attachments/video.py +++ b/maxapi/types/attachments/video.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Any, Optional +from typing import TYPE_CHECKING, Any, Literal, Optional from pydantic import BaseModel, Field from ...enums.attachment import AttachmentType @@ -61,7 +61,7 @@ class Video(Attachment): bot (Optional[Any]): Ссылка на экземпляр бота, не сериализуется. """ - type: AttachmentType = AttachmentType.VIDEO + type: Literal[AttachmentType.VIDEO] token: Optional[str] = None urls: Optional[VideoUrl] = None thumbnail: VideoThumbnail diff --git a/maxapi/types/message.py b/maxapi/types/message.py index 934651b..5202a03 100644 --- a/maxapi/types/message.py +++ b/maxapi/types/message.py @@ -1,7 +1,9 @@ from __future__ import annotations from pydantic import BaseModel, Field -from typing import Any, Optional, List, Union, TYPE_CHECKING +from typing import Annotated, Any, Optional, List, Union, TYPE_CHECKING + +from ..types.attachments.contact import Contact from ..enums.text_style import TextStyle from ..enums.parse_mode import ParseMode @@ -24,6 +26,19 @@ from .users import User if TYPE_CHECKING: from ..bot import Bot from ..types.input_media import InputMedia, InputMediaBuffer + + +Attachments = Annotated[Union[ + Audio, + Video, + File, + Image, + Sticker, + Share, + Location, + AttachmentButton, + Contact +], Field(discriminator='type')] class MarkupElement(BaseModel): @@ -91,18 +106,7 @@ class MessageBody(BaseModel): seq: int text: Optional[str] = None attachments: Optional[ - List[ - Union[ - AttachmentButton, - Audio, - Video, - File, - Image, - Sticker, - Share, - Location - ] - ] + List[Attachments] ] = Field(default_factory=list) # type: ignore markup: Optional[