新增腾讯短信(Tencent SMS)渠道扩展,支持在 Yuxi 平台中集成腾讯云短信渠道。 包含以下功能模块: - client: 腾讯云短信 API 客户端封装 - plugin: 渠道插件核心 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - security: 安全校验 - dedupe: 消息去重 - delivery: 送达状态回调 - compliance: 合规管理 - frequency: 频率控制 - templates: 短信模板 - agent_prompt: Agent 提示词 - types: 类型定义
35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from .types import SmsScene, SmsTemplateConfig
|
|
|
|
|
|
class SmsTemplateRegistry:
|
|
def __init__(self):
|
|
self._bindings: dict[str, dict[SmsScene, SmsTemplateConfig]] = {}
|
|
|
|
def register(self, account_id: str, template: SmsTemplateConfig):
|
|
scene_bindings = self._bindings.setdefault(account_id, {})
|
|
scene_bindings[template.scene] = template
|
|
|
|
def resolve(self, account_id: str, scene: SmsScene) -> SmsTemplateConfig | None:
|
|
return self._bindings.get(account_id, {}).get(scene)
|
|
|
|
def list_all(self, account_id: str) -> list[SmsTemplateConfig]:
|
|
return list(self._bindings.get(account_id, {}).values())
|
|
|
|
def build_agent_prompt(self, account_id: str) -> str:
|
|
templates = self.list_all(account_id)
|
|
if not templates:
|
|
return "\u5f53\u524d\u65e0\u53ef\u7528\u7684\u77ed\u4fe1\u6a21\u677f\u3002"
|
|
lines = []
|
|
for t in templates:
|
|
lines.append(
|
|
f"- \u573a\u666f:{t.scene.value} | \u6a21\u677fID:{t.template_id} | "
|
|
f"\u7b7e\u540d:\u3010{t.sign_name}\u3011| \u53d8\u91cf\u6570:{t.param_count} | {t.description or ''}"
|
|
)
|
|
return (
|
|
"\u53ef\u7528\u77ed\u4fe1\u6a21\u677f\uff1a\n"
|
|
+ "\n".join(lines)
|
|
+ "\n\n\u53d1\u9001\u77ed\u4fe1\u65f6\u8bf7\u9009\u62e9\u5bf9\u5e94\u573a\u666f\uff0c\u4e25\u683c\u6309\u53d8\u91cf\u4e2a\u6570\u586b\u5145 TemplateParamSet\u3002"
|
|
)
|