12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- # vim:fenc=utf-8
- from enum import Enum, auto
- from typing import Optional
- from pydantic import BaseModel
- class MessageType(Enum):
- DEFAULT = (-1, "未分类的消息")
- TEXT = (1, "文本")
- VOICE = (2, "语音")
- GIF = (3, "GIF")
- IMAGE_GW = (4, "个微图片")
- IMAGE_QW = (5, "企微图片")
- MINI_PROGRAM = (6, "小程序")
- LINK = (7, "链接")
- SHI_PIN_HAO = (8, "视频号")
- NAME_CARD = (9, "名片")
- POSITION = (10, "位置")
- RED_PACKET = (11, "红包")
- FILE_GW = (12, "个微文件")
- FILE_QW = (13, "企微文件")
- VIDEO_GW = (14, "个微视频")
- VIDEO_QW = (15, "企微视频")
- AGGREGATION_MSG = (16, "聚合消息")
- ACTIVE_TRIGGER = (101, "主动触发器")
- AGGREGATION_TRIGGER = (102, "消息聚合触发器")
- def __init__(self, code, description):
- self.code = code
- self.description = description
- def __repr__(self):
- return f"{self.__class__.__name__}.{self.name}"
- class MessageChannel(Enum):
- CORP_WECHAT = (1, "企业微信")
- MINI_PROGRAM = (2, "小程序")
- SYSTEM = (101, "系统内部")
- def __init__(self, code, description):
- self.code = code
- self.description = description
- def __repr__(self):
- return f"{self.__class__.__name__}.{self.name}"
- class Message(BaseModel):
- id: int
- type: MessageType
- channel: MessageChannel
- sender: Optional[str] = None
- receiver: str
- content: Optional[str] = None
- timestamp: int
- ref_msg_id: Optional[int] = None
- @staticmethod
- def build(type, channel, sender, receiver, content, timestamp):
- return Message(
- id=0,
- type=type,
- channel=channel,
- sender=sender,
- receiver=receiver,
- content=content,
- timestamp=timestamp
- )
|