maxapi-python 2.2.0__py3-none-any.whl → 2.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maxapi_python-2.2.0.dist-info → maxapi_python-2.3.1.dist-info}/METADATA +2 -1
- {maxapi_python-2.2.0.dist-info → maxapi_python-2.3.1.dist-info}/RECORD +28 -28
- pymax/__init__.py +1 -1
- pymax/api/chats/payloads.py +6 -0
- pymax/api/chats/service.py +18 -0
- pymax/api/messages/payloads.py +21 -1
- pymax/api/messages/service.py +42 -11
- pymax/api/users/payloads.py +22 -0
- pymax/api/users/service.py +14 -1
- pymax/app.py +26 -6
- pymax/base.py +48 -3
- pymax/dispatch/__init__.py +12 -1
- pymax/dispatch/dispatcher.py +134 -16
- pymax/dispatch/enums.py +1 -0
- pymax/dispatch/router.py +86 -4
- pymax/infra/chat.py +21 -0
- pymax/infra/message.py +29 -6
- pymax/infra/user.py +12 -1
- pymax/protocol/tcp/compression.py +18 -0
- pymax/protocol/tcp/payload.py +20 -4
- pymax/protocol/tcp/protocol.py +5 -1
- pymax/session/store.py +11 -0
- pymax/types/domain/__init__.py +1 -1
- pymax/types/domain/chat.py +21 -1
- pymax/types/domain/message.py +32 -9
- pymax/types/domain/user.py +14 -4
- {maxapi_python-2.2.0.dist-info → maxapi_python-2.3.1.dist-info}/WHEEL +0 -0
- {maxapi_python-2.2.0.dist-info → maxapi_python-2.3.1.dist-info}/licenses/LICENSE +0 -0
pymax/types/domain/message.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from collections.abc import Sequence
|
|
3
4
|
from typing import TYPE_CHECKING, Annotated, Any, TypeAlias
|
|
4
5
|
|
|
5
6
|
from pydantic import Field, PrivateAttr, model_validator
|
|
@@ -42,7 +43,7 @@ KnownAttachment: TypeAlias = Annotated[
|
|
|
42
43
|
]
|
|
43
44
|
Attachment: TypeAlias = KnownAttachment | UnknownAttachment
|
|
44
45
|
SendAttachment: TypeAlias = Photo | File | Video
|
|
45
|
-
SendAttachments: TypeAlias =
|
|
46
|
+
SendAttachments: TypeAlias = Sequence[SendAttachment] | None
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
class ReactionCounter(CamelModel):
|
|
@@ -92,8 +93,9 @@ class Message(CamelModel):
|
|
|
92
93
|
|
|
93
94
|
Сообщения, полученные через клиент, обычно уже привязаны к сервису
|
|
94
95
|
сообщений. После этого можно вызывать удобные методы объекта:
|
|
95
|
-
:meth:`reply`, :meth:`answer`, :meth:`
|
|
96
|
-
:meth:`read`, :meth:`react`, :meth:`unreact` и
|
|
96
|
+
:meth:`reply`, :meth:`answer`, :meth:`forward`, :meth:`edit`, :meth:`pin`,
|
|
97
|
+
:meth:`delete`, :meth:`read`, :meth:`react`, :meth:`unreact` и
|
|
98
|
+
:meth:`get_reactions`.
|
|
97
99
|
|
|
98
100
|
Используйте ``Message`` в обработчиках ``on_message`` и при работе с
|
|
99
101
|
историей. Некоторые поля могут быть ``None``, потому что Max присылает
|
|
@@ -243,6 +245,32 @@ class Message(CamelModel):
|
|
|
243
245
|
notify=notify,
|
|
244
246
|
)
|
|
245
247
|
|
|
248
|
+
async def forward(
|
|
249
|
+
self,
|
|
250
|
+
chat_id: int,
|
|
251
|
+
*,
|
|
252
|
+
notify: bool = True,
|
|
253
|
+
) -> Message | None:
|
|
254
|
+
"""Пересылает это сообщение в другой чат.
|
|
255
|
+
|
|
256
|
+
:param chat_id: ID целевого чата.
|
|
257
|
+
:type chat_id: int
|
|
258
|
+
:param notify: Отправить ли получателям push-уведомление.
|
|
259
|
+
:type notify: bool
|
|
260
|
+
:returns: Пересланное сообщение или ``None``, если сервер его не вернул.
|
|
261
|
+
:rtype: Message | None
|
|
262
|
+
:raises RuntimeError: Если сообщение не привязано к сервису или не
|
|
263
|
+
содержит ``chat_id``.
|
|
264
|
+
"""
|
|
265
|
+
actions, source_chat_id = self._bound()
|
|
266
|
+
|
|
267
|
+
return await actions.forward_message(
|
|
268
|
+
chat_id=chat_id,
|
|
269
|
+
message_id=self.id,
|
|
270
|
+
source_chat_id=source_chat_id,
|
|
271
|
+
notify=notify,
|
|
272
|
+
)
|
|
273
|
+
|
|
246
274
|
async def pin(self, notify_pin: bool = True) -> bool:
|
|
247
275
|
"""Закрепляет это сообщение в чате.
|
|
248
276
|
|
|
@@ -264,17 +292,13 @@ class Message(CamelModel):
|
|
|
264
292
|
async def edit(
|
|
265
293
|
self,
|
|
266
294
|
text: str,
|
|
267
|
-
attachment: SendAttachment | None = None,
|
|
268
295
|
attachments: SendAttachments = None,
|
|
269
296
|
) -> Message:
|
|
270
297
|
"""Редактирует текст и вложения этого сообщения.
|
|
271
298
|
|
|
272
299
|
:param text: Новый текст сообщения с поддержкой markdown.
|
|
273
300
|
:type text: str
|
|
274
|
-
:param
|
|
275
|
-
:type attachment: SendAttachment | None
|
|
276
|
-
:param attachments: Список новых вложений. Имеет приоритет над
|
|
277
|
-
``attachment``.
|
|
301
|
+
:param attachments: Новые файлы, фотографии или видео для сообщения.
|
|
278
302
|
:type attachments: SendAttachments
|
|
279
303
|
:returns: Отредактированное сообщение.
|
|
280
304
|
:rtype: Message
|
|
@@ -287,7 +311,6 @@ class Message(CamelModel):
|
|
|
287
311
|
chat_id=chat_id,
|
|
288
312
|
message_id=self.id,
|
|
289
313
|
text=text,
|
|
290
|
-
attachment=attachment,
|
|
291
314
|
attachments=attachments,
|
|
292
315
|
)
|
|
293
316
|
|
pymax/types/domain/user.py
CHANGED
|
@@ -11,6 +11,14 @@ if TYPE_CHECKING:
|
|
|
11
11
|
from pymax.api.users.service import UserService
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
class ContactInfo(CamelModel): # TODO: move to another file
|
|
15
|
+
"""Контакт телефонной книги для ``import_contacts``."""
|
|
16
|
+
|
|
17
|
+
phone: str
|
|
18
|
+
first_name: str
|
|
19
|
+
last_name: str | None = None
|
|
20
|
+
|
|
21
|
+
|
|
14
22
|
class User(CamelModel):
|
|
15
23
|
"""Контакт или пользователь Max.
|
|
16
24
|
|
|
@@ -41,11 +49,11 @@ class User(CamelModel):
|
|
|
41
49
|
:ivar description: Описание профиля.
|
|
42
50
|
:vartype description: str | None
|
|
43
51
|
:ivar gender: Пол пользователя.
|
|
44
|
-
:vartype gender: str | None
|
|
52
|
+
:vartype gender: str | int | None
|
|
45
53
|
:ivar link: Ссылка на профиль.
|
|
46
54
|
:vartype link: str | None
|
|
47
55
|
:ivar web_app: Данные связанного web-приложения, если есть.
|
|
48
|
-
:vartype web_app: dict[str, Any] | None
|
|
56
|
+
:vartype web_app: dict[str, Any] | str | None
|
|
49
57
|
:ivar menu_button: Данные кнопки меню профиля, если есть.
|
|
50
58
|
:vartype menu_button: dict[str, Any] | None
|
|
51
59
|
"""
|
|
@@ -63,9 +71,11 @@ class User(CamelModel):
|
|
|
63
71
|
phone: int | None = None
|
|
64
72
|
status: str | None = None
|
|
65
73
|
description: str | None = None
|
|
66
|
-
gender
|
|
74
|
+
# Bots may send ``gender`` as a numeric code and ``web_app`` as a URL
|
|
75
|
+
# string instead of an object; accept these so profile parsing won't fail.
|
|
76
|
+
gender: str | int | None = None
|
|
67
77
|
link: str | None = None
|
|
68
|
-
web_app: dict[str, Any] | None = None
|
|
78
|
+
web_app: dict[str, Any] | str | None = None
|
|
69
79
|
menu_button: dict[str, Any] | None = None
|
|
70
80
|
|
|
71
81
|
_actions: UserService | None = PrivateAttr(default=None)
|
|
File without changes
|
|
File without changes
|