53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
|
|
"""消息域模型:单条消息 / 消息拉取响应。"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from pydantic import BaseModel, Field
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------------------------
|
|||
|
|
# 消息接口(GET /api/messages/since)
|
|||
|
|
# ---------------------------------------------------------------------------
|
|||
|
|
class Message(BaseModel):
|
|||
|
|
"""单条微信消息。"""
|
|||
|
|
|
|||
|
|
msg_id: str = Field(description="消息 ID")
|
|||
|
|
talker: str = Field(description="会话对方 wxid(群消息为 chatroom id)")
|
|||
|
|
sender: str = Field(default="", description="实际发送者 wxid(群消息中为成员 wxid)")
|
|||
|
|
is_sender: bool = Field(default=False, description="是否为本机发送")
|
|||
|
|
type: int = Field(description="微信原始消息类型")
|
|||
|
|
render_type: str = Field(description="渲染类型:text/image/voice/video/file/system")
|
|||
|
|
content: str = Field(default="", description="消息内容文本")
|
|||
|
|
create_time: int = Field(description="消息时间戳(Unix 秒)")
|
|||
|
|
session_type: str = Field(description="会话类型:p2p / group")
|
|||
|
|
|
|||
|
|
|
|||
|
|
class MessagesResponse(BaseModel):
|
|||
|
|
"""消息拉取响应。"""
|
|||
|
|
|
|||
|
|
messages: list[Message] = Field(default_factory=list)
|
|||
|
|
next_cursor: int = Field(description="下次拉取应使用的 cursor")
|
|||
|
|
has_more: bool = Field(default=False, description="是否可能还有更多消息")
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------------------------
|
|||
|
|
# 按会话拉取(GET /api/messages/by_session)
|
|||
|
|
# ---------------------------------------------------------------------------
|
|||
|
|
class MessagesBySessionResponse(BaseModel):
|
|||
|
|
"""按会话拉取历史消息响应。"""
|
|||
|
|
|
|||
|
|
messages: list[Message] = Field(default_factory=list)
|
|||
|
|
next_cursor: int = Field(description="下次拉取应使用的 cursor")
|
|||
|
|
has_more: bool = Field(default=False, description="是否可能还有更多消息")
|
|||
|
|
talker: str = Field(description="本次查询的会话对方 wxid")
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------------------------
|
|||
|
|
# 消息搜索(GET /api/messages/search)
|
|||
|
|
# ---------------------------------------------------------------------------
|
|||
|
|
class MessageSearchResponse(BaseModel):
|
|||
|
|
"""消息搜索响应。"""
|
|||
|
|
|
|||
|
|
messages: list[Message] = Field(default_factory=list)
|
|||
|
|
total: int = Field(default=0, description="命中总数(可能大于返回条数)")
|