protocol.py 635 B

1234567891011121314151617181920212223
  1. from pydantic import BaseModel
  2. from typing import Optional
  3. import uuid
  4. class IMMessage(BaseModel):
  5. msg_id: str = ""
  6. sender: str
  7. receiver: str
  8. content: str
  9. msg_type: str = "chat" # chat | image | video | system
  10. sender_chat_id: Optional[str] = None # 发送方窗口 ID
  11. receiver_chat_id: Optional[str] = None # 接收方窗口 ID(指定则定向,否则广播)
  12. def model_post_init(self, __context):
  13. if not self.msg_id:
  14. self.msg_id = uuid.uuid4().hex[:12]
  15. class IMResponse(BaseModel):
  16. status: str # "success" | "failed"
  17. msg_id: str
  18. error: Optional[str] = None