from __future__ import annotations import json from typing import Any from yuxi.channels.adapters.bluebubbles.webhook_auth import ( extract_signature, verify_webhook_signature, ) from yuxi.utils.logging_config import logger class WebhookIngress: def __init__(self, webhook_secret: str = ""): self._secret = webhook_secret def validate(self, headers: dict[str, str], body: bytes) -> bool: if not self._secret: logger.warning("[BlueBubbles] Webhook received but no secret configured") return True signature = extract_signature(headers) if not signature: logger.warning("[BlueBubbles] Webhook received without signature") return False return verify_webhook_signature(self._secret, body, signature) def parse_event(self, body: bytes) -> dict[str, Any] | None: try: return json.loads(body) except json.JSONDecodeError: logger.warning("[BlueBubbles] Webhook: invalid JSON body") return None