30 lines
879 B
Python
30 lines
879 B
Python
from abc import ABC, abstractmethod
|
||
from core.schema import StandardMessage, StandardResponse
|
||
|
||
class BaseAdapter(ABC):
|
||
"""
|
||
消息适配器基类 (Interface)
|
||
所有的平台接口(千牛、微信等)都必须继承并实现这几个方法
|
||
"""
|
||
|
||
@abstractmethod
|
||
async def translate_inbound(self, raw_msg: any) -> StandardMessage:
|
||
"""
|
||
[接收]:把各个平台的原始 JSON 数据,格式化为大脑认的 StandardMessage
|
||
"""
|
||
pass
|
||
|
||
@abstractmethod
|
||
async def translate_outbound(self, response: StandardResponse, user_id: str):
|
||
"""
|
||
[发送]:把大脑生成的 StandardResponse,翻译回平台原生的接口发出去
|
||
"""
|
||
pass
|
||
|
||
@abstractmethod
|
||
def platform_id(self) -> str:
|
||
"""
|
||
标识当前平台名称 (如 'qianniu', 'wechat')
|
||
"""
|
||
pass
|