30 lines
902 B
Python
30 lines
902 B
Python
from datetime import datetime
|
|
import httpx
|
|
|
|
|
|
class BackendClient:
|
|
def __init__(self, base_url: str):
|
|
self._base_url = base_url.rstrip("/")
|
|
|
|
async def create_item(
|
|
self,
|
|
*,
|
|
modality: str,
|
|
raw_content: str,
|
|
captured_at: datetime,
|
|
discord_message_id: str | None,
|
|
sender_id: str | None = None,
|
|
direction: str = "inbound",
|
|
) -> dict:
|
|
payload = {
|
|
"modality": modality,
|
|
"raw_content": raw_content,
|
|
"captured_at": captured_at.isoformat(),
|
|
"discord_message_id": discord_message_id,
|
|
"sender_id": sender_id,
|
|
"direction": direction,
|
|
}
|
|
async with httpx.AsyncClient() as client:
|
|
resp = await client.post(f"{self._base_url}/items", json=payload, timeout=10)
|
|
resp.raise_for_status()
|
|
return resp.json()
|