chorus/bot/chorus_bot/backend_client.py
pyr0ball 669bb3456a feat(bot): add modality map, config loader, and backend client
Implements core bot infrastructure:
- modality_map: channel name to modality string mapping (personal_text, voice, fb_messenger, nd_messenger)
- config: Config dataclass with env-driven configuration loading for Discord, backend, and email IMAP credentials
- backend_client: async HTTP client for posting items to backend /items endpoint

All modality_map tests passing (3/3)
2026-07-13 13:48:39 -07:00

28 lines
830 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,
) -> dict:
payload = {
"modality": modality,
"raw_content": raw_content,
"captured_at": captured_at.isoformat(),
"discord_message_id": discord_message_id,
"sender_id": sender_id,
}
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()