Files
tw/core/schema.py
2026-03-06 13:23:32 +08:00

31 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pydantic import BaseModel, Field
from typing import List, Optional, Any
from datetime import datetime
class StandardMessage(BaseModel):
"""全平台通用的输入消息协议"""
platform: str = "qianniu" # 来源平台qianniu, wechat, feishu, console
msg_id: str # 消息唯一ID
user_id: str # 发送者唯一ID
user_name: str = "" # 发送者昵称
content: str # 消息文本内容
msg_type: int = 0 # 消息类型0 文本, 1 图片, 2 语音等
image_urls: List[str] = Field(default_factory=list) # 提取出来的图片链接
acc_id: str = "" # 商家/店铺账号ID
acc_type: str = "" # 平台类型标识
timestamp: datetime = Field(default_factory=datetime.now)
raw_data: Any = None # 原始消息体(仅供调试或特殊逻辑备查)
# 扩展字段:针对电商场景
goods_name: Optional[str] = None
goods_order: Optional[str] = None
class StandardResponse(BaseModel):
"""大脑给出的通用回复协议"""
reply_content: str # 回复文本或图片URL
msg_type: int = 0 # 0: 文本, 1: 图片, 2: 撤回, 9: 转人工
should_reply: bool = True # 是否需要发送
need_transfer: bool = False # 是否触发转人工
transfer_group: str = "" # 转人工的分组ID
metadata: dict = Field(default_factory=dict) # 额外元数据(如埋点、调试信息)