rtm-class-ai / src /agent /callback.py
nbintang
initialize projects
62516b8
Raw
History Blame Contribute Delete
949 Bytes
from __future__ import annotations
from src.config import settings
class WebhookCallbackClient:
def __init__(self) -> None:
self._client = None
async def initialize(self) -> None:
if self._client is not None:
return
try:
import httpx
except ImportError as exc:
raise RuntimeError("httpx package is required for webhook callback.") from exc
self._client = httpx.AsyncClient(
timeout=settings.webhook_callback_timeout_seconds,
)
async def shutdown(self) -> None:
if self._client is None:
return
await self._client.aclose()
self._client = None
async def send_json(self, *, callback_url: str, payload: dict) -> None:
await self.initialize()
assert self._client is not None
response = await self._client.post(callback_url, json=payload)
response.raise_for_status()