|
| 1 | +from collections.abc import AsyncGenerator |
| 2 | +from contextlib import asynccontextmanager |
1 | 3 | from typing import Any, Literal |
2 | 4 |
|
3 | 5 | from pymax.exceptions import Error, ResponseError, ResponseStructureError |
|
7 | 9 | ContactPresencePayload, |
8 | 10 | FetchContactsPayload, |
9 | 11 | SearchByPhonePayload, |
| 12 | + SetTypingPayload, |
10 | 13 | ) |
11 | 14 | from pymax.protocols import ClientProtocol |
12 | | -from pymax.static.enum import ContactAction, Opcode |
| 15 | +from pymax.static.enum import ContactAction, Opcode, TypingType |
13 | 16 | from pymax.types import Contact, Presence, Session, User |
14 | 17 | from pymax.utils import MixinsUtils |
15 | 18 |
|
@@ -267,3 +270,28 @@ async def get_contact_presence(self, contact_ids: list[int]) -> list[Presence]: |
267 | 270 | Presence(user_id=int(contact_id), last_seen=info.get("seen")) |
268 | 271 | for contact_id, info in presence.items() |
269 | 272 | ] |
| 273 | + |
| 274 | + @asynccontextmanager |
| 275 | + async def typing( |
| 276 | + self, chat_id: int, typing_type: TypingType = TypingType.TEXT |
| 277 | + ) -> AsyncGenerator[None, Any]: |
| 278 | + """ |
| 279 | + Устанавливает состояние "печатает" для указанного чата. |
| 280 | +
|
| 281 | + :param chat_id: ID чата. |
| 282 | + :type chat_id: int |
| 283 | + :param typing_type: Тип состояния "печатает". |
| 284 | + :type typing_type: TypingType |
| 285 | + :yields: None |
| 286 | + :rtype: None |
| 287 | + """ |
| 288 | + self.logger.debug("Set typing for chat %s", chat_id) |
| 289 | + |
| 290 | + payload = SetTypingPayload( |
| 291 | + chat_id=chat_id, |
| 292 | + type=typing_type, |
| 293 | + ).model_dump(by_alias=True) |
| 294 | + await self._send_only(opcode=Opcode.MSG_TYPING, payload=payload) |
| 295 | + self.logger.debug("Set typing for chat %s success (maybe?)", chat_id) |
| 296 | + yield |
| 297 | + self.logger.debug("Set typing for chat %s done", chat_id) |
0 commit comments