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

57 lines
1.6 KiB
Python

from __future__ import annotations
from typing import Any
from pydantic import BaseModel
class BlueBubblesAccountConfig(BaseModel):
account_id: str = "default"
name: str = ""
server_url: str = "http://localhost:1234"
password: str = ""
enabled: bool = True
dm_policy: str = "pairing"
group_policy: str = "allowlist"
dm_allow_from: list[str] = []
group_allow_chats: list[str] = []
require_mention: bool = False
tapback_enabled: bool = True
default_account: bool = False
@property
def display_name(self) -> str:
return self.name or self.account_id
def parse_accounts_config(raw: dict[str, Any]) -> dict[str, BlueBubblesAccountConfig]:
accounts: dict[str, BlueBubblesAccountConfig] = {}
for key, value in raw.items():
if not isinstance(value, dict):
continue
try:
accounts[key] = BlueBubblesAccountConfig(**value)
except Exception:
continue
return accounts
def get_default_account(accounts: dict[str, BlueBubblesAccountConfig]) -> BlueBubblesAccountConfig | None:
for account in accounts.values():
if account.default_account and account.enabled:
return account
for account in accounts.values():
if account.enabled:
return account
return None
def normalize_account_id(raw_id: str) -> str:
return raw_id.strip().lower().replace(" ", "_")
def get_account_display_name(account_id: str, accounts: dict[str, BlueBubblesAccountConfig]) -> str:
if account_id in accounts:
return accounts[account_id].display_name
return account_id