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

69 lines
1.9 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
from typing import Any
def render_card(
title: str | None = None,
body: str = "",
subtitle: str | None = None,
image_url: str | None = None,
footer: str | None = None,
accent_color: str = "#007AFF",
) -> str:
parts = []
if title:
parts.append(f"<b>{_escape_html(title)}</b>")
if subtitle:
parts.append(f"<i>{_escape_html(subtitle)}</i>")
if image_url:
parts.append(f'<img src="{_escape_html(image_url)}" alt="image" style="max-width:100%">')
if body:
parts.append(body)
if footer:
parts.append(f'<small style="color:#888888">{_escape_html(footer)}</small>')
return "\n".join(parts)
def render_notification(title: str, body: str = "", level: str = "info") -> str:
level_icons = {"info": "", "warning": "⚠️", "error": "", "success": ""}
icon = level_icons.get(level, "")
lines = [f"{icon} <b>{_escape_html(title)}</b>"]
if body:
lines.append(body)
return "\n".join(lines)
def render_items(items: list[dict[str, Any]], item_template: str = "{label}: {value}") -> str:
lines = []
for item in items:
line = item_template
for key, val in item.items():
line = line.replace(f"{{{key}}}", str(val))
lines.append(f"{line}")
return "\n".join(lines)
def render_button_row(buttons: list[dict[str, str]]) -> str:
if not buttons:
return ""
links = []
for btn in buttons:
label = btn.get("label", "")
url = btn.get("url", "")
if url:
links.append(f'<a href="{_escape_html(url)}">{_escape_html(label)}</a>')
else:
links.append(f"[{_escape_html(label)}]")
return " | ".join(links)
def _escape_html(text: str) -> str:
return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;")