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.
@@ -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 = list[SendAttachment] | None
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:`edit`, :meth:`pin`, :meth:`delete`,
96
- :meth:`read`, :meth:`react`, :meth:`unreact` и :meth:`get_reactions`.
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 attachment: Одно новое вложение.
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
 
@@ -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: str | None = None
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)