ForcePilot/backend/package/yuxi/channel/extensions/bluebubbles/targets.py
Kris b018e3eda4 feat(bluebubbles): 新增BlueBubbles(iMessage)渠道插件完整实现
该提交新增了完整的BlueBubbles渠道插件,支持通过BlueBubbles Server集成iMessage功能,包含以下核心能力:
1.  支持私聊和群聊会话管理,自动区分会话类型
2.  完整的消息收发支持,包括文本、图片、语音、文件、视频消息
3.  支持消息反应、已读回执、消息编辑与撤回
4.  内置去重、防抖处理机制
5.  支持Webhook和WebSocket两种事件接收方式
6.  完善的权限与安全校验机制
7.  历史消息同步与抓包功能
8.  TTS语音合成与发送支持
9.  群组管理能力,包括重命名、修改头像、增减成员等
2026-05-21 10:40:33 +08:00

59 lines
1.7 KiB
Python

import re
def normalize_handle(handle: str) -> str:
handle = handle.strip()
if handle.startswith("bluebubbles:"):
handle = handle[len("bluebubbles:") :]
return handle
def extract_handle_from_chat_guid(chat_guid: str) -> str:
parts = chat_guid.split(";")
if len(parts) >= 3:
return parts[2]
return chat_guid
def is_dm_chat_guid(chat_guid: str) -> bool:
return ";-;" in chat_guid
def is_group_chat_guid(chat_guid: str) -> bool:
return ";+;" in chat_guid
def parse_target(raw: str) -> dict:
if not raw:
return {"type": "unknown", "value": "", "is_group": False}
if raw.startswith("chat_guid:"):
guid = raw[len("chat_guid:") :]
is_group = is_group_chat_guid(guid)
return {"type": "chat_guid", "value": guid, "is_group": is_group}
if raw.startswith("chat_id:"):
return {"type": "chat_id", "value": raw[len("chat_id:") :], "is_group": True}
if raw.startswith("chat_identifier:"):
return {"type": "chat_identifier", "value": raw[len("chat_identifier:") :], "is_group": True}
if raw.startswith("group:"):
return {"type": "group", "value": raw[len("group:") :], "is_group": True}
return {"type": "handle", "value": normalize_handle(raw), "is_group": False}
def resolve_chat_guid_from_data(data: dict) -> str | None:
for key in ("chatGuid", "chat_guid", "chat_id", "chatIdentifier"):
if data.get(key):
return data[key]
return None
def normalize_phone_lookup_key(value: str) -> str | None:
digits = re.sub(r"\D", "", value)
if len(digits) == 11 and digits.startswith("1"):
digits = digits[1:]
return digits if len(digits) >= 7 else None