feat: add multi-chat routing and bill-specific dashboard countdown
This commit is contained in:
@@ -17,7 +17,7 @@ class ExternalServiceError(RuntimeError):
|
||||
|
||||
|
||||
class Notifier(Protocol):
|
||||
def send(self, text: str) -> None: ...
|
||||
def send(self, chat_id: str, text: str) -> None: ...
|
||||
|
||||
|
||||
class SaapaClient:
|
||||
@@ -88,35 +88,40 @@ class EitaaClient:
|
||||
def __init__(
|
||||
self,
|
||||
token: str,
|
||||
chat_id: str,
|
||||
*,
|
||||
timeout: float,
|
||||
session: requests.Session | None = None,
|
||||
) -> None:
|
||||
self._url = f"{EITAAYAR_BASE_URL}/{token}/sendMessage"
|
||||
self._chat_id = chat_id
|
||||
self._timeout = timeout
|
||||
self._session = session or _retrying_session({"GET"})
|
||||
|
||||
def send(self, text: str) -> None:
|
||||
def send(self, chat_id: str, text: str) -> None:
|
||||
try:
|
||||
response = self._session.get(
|
||||
self._url,
|
||||
params={"chat_id": self._chat_id, "text": text},
|
||||
params={"chat_id": chat_id, "text": text},
|
||||
timeout=self._timeout,
|
||||
)
|
||||
except requests.RequestException as error:
|
||||
raise ExternalServiceError(f"Eitaa request failed: {error}") from error
|
||||
raise ExternalServiceError(
|
||||
f"Eitaa request failed for chat {chat_id}: {error}"
|
||||
) from error
|
||||
if not response.ok:
|
||||
raise ExternalServiceError(f"Eitaa returned HTTP {response.status_code}")
|
||||
raise ExternalServiceError(
|
||||
f"Eitaa returned HTTP {response.status_code} for chat {chat_id}"
|
||||
)
|
||||
try:
|
||||
body = response.json()
|
||||
except requests.JSONDecodeError as error:
|
||||
raise ExternalServiceError("Eitaa returned invalid JSON") from error
|
||||
raise ExternalServiceError(
|
||||
f"Eitaa returned invalid JSON for chat {chat_id}"
|
||||
) from error
|
||||
if not isinstance(body, dict) or body.get("ok") is not True:
|
||||
description = body.get("description") if isinstance(body, dict) else None
|
||||
raise ExternalServiceError(
|
||||
f"Eitaa rejected the message: {description or 'unknown error'}"
|
||||
f"Eitaa rejected the message for chat {chat_id}: "
|
||||
f"{description or 'unknown error'}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user