ForcePilot/backend/package/yuxi/channel/extensions/nostr/outbound.py
Kris 16455cb303 feat(channel): 添加 Nostr 渠道扩展
新增 Nostr 渠道扩展,支持在 Yuxi 平台中集成 Nostr 去中心化社交协议。

包含以下功能模块:
- bus: 事件总线与中继通信
- account: 账户管理
- key_utils: 密钥工具
- gateway: SSE/WebSocket 网关接入
- outbound: 外发消息管理
- gift_wrap: Gift Wrap 加密
- nip44: NIP-44 加密协议
- config_schema: 配置模式
- defaults: 默认配置
- profile_core: 用户资料核心
- profile_publisher: 资料发布
- event_utils: 事件工具
- deletion: 事件删除
- reactions: 表情反应
- metrics: 指标监控
- seen_tracker: 已读追踪
- session_route: 会话路由
- state_store: 状态存储
2026-05-21 11:31:51 +08:00

31 lines
1.3 KiB
Python

from .gateway import NostrGateway, NostrGatewayError
from .key_utils import normalize_pubkey
class NostrOutboundAdapter:
delivery_mode = "direct"
text_chunk_limit = 4000
def __init__(self, gateway: NostrGateway):
self.gateway = gateway
async def send_text(self, to: str, text: str, *, reply_to_id: str | None = None, account_id: str = "default"):
bus = self.gateway.get_bus(account_id)
if not bus:
raise NostrGatewayError(f"No active Nostr bus for account '{account_id}'")
to_pk = normalize_pubkey(to)
return await bus.send_dm(to_pk, text, reply_to_event_id=reply_to_id)
async def send_reaction(self, to: str, target_event_id: str, reaction: str = "+", *, account_id: str = "default"):
bus = self.gateway.get_bus(account_id)
if not bus:
raise NostrGatewayError(f"No active Nostr bus for account '{account_id}'")
to_pk = normalize_pubkey(to)
return await bus.send_reaction(target_event_id, reaction, target_pubkey=to_pk)
async def send_deletion(self, event_ids: list[str], reason: str = "", *, account_id: str = "default"):
bus = self.gateway.get_bus(account_id)
if not bus:
raise NostrGatewayError(f"No active Nostr bus for account '{account_id}'")
return await bus.send_deletion(event_ids, reason)