新增 Twitter 和 Viber 两个渠道扩展。 Twitter 渠道扩展功能模块: - auth: OAuth 认证管理 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - tweets: 推文管理 - social: 社交互动 - reactions: 表情反应 - media: 媒体资源处理 Viber 渠道扩展功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - rate_limiter: 速率限制 - media: 媒体资源处理
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.security.pairing import PairingManager
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ViberPairingAdapter:
|
|
id_label = "viberUserId"
|
|
|
|
def __init__(self):
|
|
self._pairing = PairingManager()
|
|
|
|
async def generate_code(self, peer_id: str, account_id: str = "default") -> str:
|
|
request = await self._pairing.upsert_code("viber", peer_id, account_id)
|
|
return request.code
|
|
|
|
async def verify_code(self, peer_id: str, code: str, account_id: str = "default") -> bool:
|
|
return await self._pairing.verify("viber", peer_id, code, account_id)
|
|
|
|
async def approve(self, peer_id: str, account_id: str = "default") -> None:
|
|
await self._pairing.approve("viber", peer_id, account_id)
|
|
|
|
async def reject(self, peer_id: str, account_id: str = "default") -> None:
|
|
await self._pairing.reject("viber", peer_id, account_id)
|
|
|
|
def normalize_allow_entry(self, entry: str) -> str:
|
|
stripped = entry.strip()
|
|
if stripped.startswith("viber:user:"):
|
|
return stripped[11:]
|
|
if stripped.startswith("viber:"):
|
|
return stripped[6:]
|
|
return stripped
|
|
|
|
async def notify_approval(self, config: dict, peer_id: str, account_id: str | None = None) -> None:
|
|
logger.info("viber pairing approved for peer %s", peer_id)
|