ForcePilot/backend/package/yuxi/channels/adapters/wechat/template_adapter.py

38 lines
1.5 KiB
Python
Raw Normal View History

from __future__ import annotations
from typing import Any
DEFAULT_WELCOME_TEMPLATE = "你好!我是 AI 助手,有什么可以帮你的?"
DEFAULT_PAIRING_TEMPLATE = "收到你的访问请求,请输入配对码: {code}"
DEFAULT_APPROVED_TEMPLATE = "你的访问请求已获批准!"
DEFAULT_REJECTED_TEMPLATE = "你的访问请求已被拒绝。"
DEFAULT_ERROR_TEMPLATE = "抱歉,处理你的消息时出错: {error}"
class WeChatTemplateAdapter:
@staticmethod
def render_welcome(config: dict[str, Any], context: dict[str, Any] | None = None) -> str:
return config.get("welcome_message", DEFAULT_WELCOME_TEMPLATE)
@staticmethod
def render_pairing(config: dict[str, Any], code: str) -> str:
template = config.get("pairing_message", DEFAULT_PAIRING_TEMPLATE)
return template.format(code=code)
@staticmethod
def render_approved(config: dict[str, Any], context: dict[str, Any] | None = None) -> str:
return config.get("approved_message", DEFAULT_APPROVED_TEMPLATE)
@staticmethod
def render_rejected(config: dict[str, Any], context: dict[str, Any] | None = None) -> str:
return config.get("rejected_message", DEFAULT_REJECTED_TEMPLATE)
@staticmethod
def render_error(config: dict[str, Any], error: str) -> str:
template = config.get("error_message", DEFAULT_ERROR_TEMPLATE)
return template.format(error=error)
@staticmethod
def render_system_notice(config: dict[str, Any], notice: str) -> str:
return notice