30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
from typing import Dict, Any, Optional
|
|
from ..client import AvitoClient
|
|
|
|
class MessengerService:
|
|
"""Service to handle Avito Messenger (Chats)."""
|
|
|
|
def __init__(self, client: AvitoClient):
|
|
self.client = client
|
|
|
|
def get_chats(self, user_id: str, limit: int = 100, offset: int = 0) -> Dict[str, Any]:
|
|
"""
|
|
Get list of active chats for a user.
|
|
Endpoint: /messenger/v2/accounts/{user_id}/chats
|
|
"""
|
|
params = {"limit": limit, "offset": offset}
|
|
return self.client.get(f"/messenger/v2/accounts/{user_id}/chats", params=params)
|
|
|
|
def send_message(self, user_id: str, chat_id: str, text: str) -> Dict[str, Any]:
|
|
"""
|
|
Send a text message to a specific chat.
|
|
Endpoint: /messenger/v1/accounts/{user_id}/chats/{chat_id}/messages
|
|
"""
|
|
payload = {
|
|
"message": {
|
|
"text": text
|
|
},
|
|
"type": "text"
|
|
}
|
|
return self.client.post(f"/messenger/v1/accounts/{user_id}/chats/{chat_id}/messages", data=payload)
|