新增BlueBubbles适配器全套核心工具类与服务,包含会话管理、消息去重、Webhook验证、缓存系统、账号配置解析、聊天消息处理等完整功能模块,支持iMessage消息收发、群管理、反应特效、语音合成等能力,提供完善的健康检查与配置校验流程。
35 lines
1.0 KiB
Python
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
|