新增腾讯短信(Tencent SMS)渠道扩展,支持在 Yuxi 平台中集成腾讯云短信渠道。 包含以下功能模块: - client: 腾讯云短信 API 客户端封装 - plugin: 渠道插件核心 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - security: 安全校验 - dedupe: 消息去重 - delivery: 送达状态回调 - compliance: 合规管理 - frequency: 频率控制 - templates: 短信模板 - agent_prompt: Agent 提示词 - types: 类型定义
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from .dedupe import TencentSmsDeduplicator
|
|
from .types import DeliveryStatus
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SmsDeliveryTracker:
|
|
def __init__(self):
|
|
self._dedupe = TencentSmsDeduplicator(max_size=50000, ttl_seconds=86400)
|
|
self._store: dict[str, DeliveryStatus] = {}
|
|
|
|
def handle_status_callback(self, item: dict) -> bool:
|
|
serial_no = item.get("SerialNo", "")
|
|
report_status = item.get("ReportStatus", "")
|
|
key = f"status:{serial_no}:{report_status}"
|
|
if self._dedupe.is_duplicate(key):
|
|
return False
|
|
|
|
status = DeliveryStatus(
|
|
serial_no=serial_no,
|
|
phone_number=item.get("PhoneNumber", ""),
|
|
report_status=report_status,
|
|
description=item.get("Description", ""),
|
|
report_time=item.get("ReportTime", ""),
|
|
session_context=item.get("SessionContext", ""),
|
|
)
|
|
self._store[serial_no] = status
|
|
logger.info(
|
|
"\u9001\u8fbe\u72b6\u6001\u66f4\u65b0: serial=%s, status=%s, phone=%s",
|
|
serial_no,
|
|
report_status,
|
|
status.phone_number,
|
|
)
|
|
return True
|
|
|
|
def get_status(self, serial_no: str) -> DeliveryStatus | None:
|
|
return self._store.get(serial_no)
|