ForcePilot/backend/package/yuxi/channels/adapters/bluebubbles/webhook_ingress.py
Kris 6aa1d52a8b feat(bluebubbles): 实现完整的BlueBubbles适配器基础组件
新增BlueBubbles适配器全套核心工具类与服务,包含会话管理、消息去重、Webhook验证、缓存系统、账号配置解析、聊天消息处理等完整功能模块,支持iMessage消息收发、群管理、反应特效、语音合成等能力,提供完善的健康检查与配置校验流程。
2026-05-12 00:42:57 +08:00

35 lines
1.0 KiB
Python

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