Skip to content

Commit de05a5e

Browse files
committed
Добавил класс ContactAttach для обработки контактов и обновил Message для поддержки новых типов вложений
1 parent c6ab809 commit de05a5e

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/pymax/static/enum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class AttachType(str, Enum):
196196
STICKER = "STICKER"
197197
AUDIO = "AUDIO"
198198
CONTROL = "CONTROL"
199+
CONTACT = "CONTACT"
199200

200201

201202
class FormattingType(str, Enum):

src/pymax/types.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,36 @@ def from_dict(cls, data: dict[str, Any]) -> Self:
630630
)
631631

632632

633+
class ContactAttach:
634+
def __init__(
635+
self, contact_id: int, first_name: str, last_name: str, name: str, photo_url: str
636+
) -> None:
637+
self.contact_id = contact_id
638+
self.first_name = first_name
639+
self.last_name = last_name
640+
self.name = name
641+
self.photo_url = photo_url
642+
self.type = AttachType.CONTACT
643+
644+
@classmethod
645+
def from_dict(cls, data: dict[str, Any]) -> Self:
646+
return cls(
647+
contact_id=data["contactId"],
648+
first_name=data["firstName"],
649+
last_name=data["lastName"],
650+
name=data["name"],
651+
photo_url=data["photoUrl"],
652+
)
653+
654+
@override
655+
def __repr__(self) -> str:
656+
return f"ContactAttach(contact_id={self.contact_id!r}, first_name={self.first_name!r}, last_name={self.last_name!r}, name={self.name!r}, photo_url={self.photo_url!r})"
657+
658+
@override
659+
def __str__(self) -> str:
660+
return f"ContactAttach: {self.name}"
661+
662+
633663
class Message:
634664
def __init__(
635665
self,
@@ -652,6 +682,7 @@ def __init__(
652682
| ControlAttach
653683
| StickerAttach
654684
| AudioAttach
685+
| ContactAttach
655686
]
656687
| None
657688
),
@@ -672,7 +703,15 @@ def __init__(
672703
@classmethod
673704
def from_dict(cls, data: dict[Any, Any]) -> Self:
674705
message = data["message"] if data.get("message") else data
675-
attaches: list[PhotoAttach | VideoAttach | FileAttach | ControlAttach | StickerAttach] = []
706+
attaches: list[
707+
PhotoAttach
708+
| VideoAttach
709+
| FileAttach
710+
| ControlAttach
711+
| StickerAttach
712+
| AudioAttach
713+
| ContactAttach
714+
] = []
676715
for a in message.get("attaches", []):
677716
if a["_type"] == AttachType.PHOTO:
678717
attaches.append(PhotoAttach.from_dict(a))
@@ -686,6 +725,8 @@ def from_dict(cls, data: dict[Any, Any]) -> Self:
686725
attaches.append(StickerAttach.from_dict(a))
687726
elif a["_type"] == AttachType.AUDIO:
688727
attaches.append(AudioAttach.from_dict(a))
728+
elif a["_type"] == AttachType.CONTACT:
729+
attaches.append(ContactAttach.from_dict(a))
689730
link_value = message.get("link")
690731
if isinstance(link_value, dict):
691732
link = MessageLink.from_dict(link_value)

0 commit comments

Comments
 (0)