消息类中,有两个固定属性:
attr:消息属性,即消息的来源属性
type:消息类型,即消息的内容属性
而self和friend又可以跟消息类型所组合,所以所有消息类别如下:
自己发送的消息SelfMessage | 对方发来的消息FriendMessage | |
|---|---|---|
文本消息TextMessage | SelfTextMessage | FriendTextMessage |
引用消息QuoteMessage | SelfQuoteMessage | FriendQuoteMessage |
语音消息VoiceMessage | SelfVoiceMessage | FriendVoiceMessage |
图片消息ImageMessage | SelfImageMessage | FriendImageMessage |
视频消息VideoMessage | SelfVideoMessage | FriendVideoMessage |
文件消息FileMessage | SelfFileMessage | FriendFileMessage |
✨位置消息LocationMessage | SelfLocationMessage | FriendLocationMessage |
✨链接消息LinkMessage | SelfLinkMessage | FriendLinkMessage |
✨表情消息EmotionMessage | SelfEmotionMessage | FriendEmotionMessage |
✨合并消息MergeMessage | SelfMergeMessage | FriendMergeMessage |
✨名片消息PersonalCardMessage | SelfPersonalCardMessage | FriendPersonalCardMessage |
✨笔记消息NoteMessage | SelfNoteMessage | FriendNoteMessage |
其他消息OtherMessage | SelfOtherMessage | FriendOtherMessage |
简单的使用示例:
消息基类,所有消息类型都继承自该类
属性(所有消息类型都包含以下属性):
| 属性名 | 类型 | 描述 |
|---|---|---|
| type | str | 消息内容类型 |
| attr | str | 消息来源类型 |
| info | Dict | 消息的详细信息 |
| id | str | 消息UI ID(不重复,切换UI后会变) |
| ✨hash | str | 消息hash值(可能重复,切换UI后不变) |
| sender | str | 消息发送者 |
| content | str | 消息内容 |
获取该消息所属聊天窗口的信息
返回值:
dict获取消息中所有文本内容
返回值:
将消息滚动到视野内
系统消息,没有特殊用法
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| attr | str | system | 消息属性 |
拍一拍消息,继承自SystemMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| attr | str | tickle | 消息属性 |
特有属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| tickle_list | str | 拍一拍消息列表 |
时间消息
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| attr | str | time | 消息属性 |
特有属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| time | str | 时间 YYYY-MM-DD HH:MM:SS |
人发送的消息,即自己或好友、群友发送的消息
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| attr | str | friend | 消息属性 |
特有属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| sender_remark | str | 群消息中,该消息发送人自己设置的“我在本群的昵称” |
点击该消息,一般特殊消息才会有作用,比如图片消息、视频消息等
右键该消息,弹出右键菜单,并选择指定选项
返回值:
WxResponse引用该消息,并回复
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| text | str | 无 | 引用内容 |
| at | Union[List[str], str] | 无 | @用户列表 |
| timeout | int | 3 | 超时时间,单位为秒 |
返回值:
WxResponse转发该消息
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| targets | Union[List[str], str] | 无 | 转发对象名称 |
| ✨message | str | None | 要附加的消息(仅✨Plus版本支持该参数) |
| timeout | int | 3 | 超时时间,单位为秒 |
返回值:
WxResponse拍一拍该消息发送人
返回值:
WxResponse删除该消息
返回值:
WxResponse下载该消息发送人的头像
返回值:
好友、群友发送的消息,即聊天页面中,左侧人员发送的消息。继承自HumanMessage
获取发送人信息
返回值:
@该消息发送人
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| content | str | 必填 | 要发送的内容 |
| quote | bool | False | 是否引用该消息 |
返回值:
WxResponse添加该消息的发送人为好友
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| addmsg | str | None | 添加好友时的附加消息,默认为None |
| remark | str | None | 添加好友后的备注,默认为None |
| tags | list | None | 添加好友后的标签,默认为None |
| permission | Literal['朋友圈', '仅聊天'] | '朋友圈' | 添加好友后的权限,默认为'朋友圈' |
| timeout | int | 3 | 搜索好友的超时时间,默认为3秒 |
返回值:
WxResponse{{< cards >}} {{< card link="/docs/example/#8-合并转发消息" title="👉查看合并转发消息示例" tag="点击跳转" tagType="info" >}} {{< /cards >}}
多选该消息,仅作合并转发使用,如果不进行合并转发,请勿调用该方法
参数:无
返回值:无
自己发送的消息,即聊天页面中,右侧自己发送的消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| attr | str | self | 消息属性 |
文本消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | text | 消息属性 |
引用消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | quote | 消息属性 |
特有属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| quote_content | str | 引用消息内容 | 引用消息内容 |
下载引用消息中的图片,返回图片路径
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| dir_path | str | None | 下载路径,默认为None |
| timeout | int | 10 | 超时时间,默认为10秒 |
返回值: Path: 视频路径,成功时返回该类型
点击引用框体
参数:无
返回值:无
图片消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | image | 消息属性 |
下载图片,返回图片路径
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| dir_path | Union[str, Path] | None | 下载图片的目录,不填则默认WxParam.DEFAULT_SAVE_PATH |
| timeout | int | 10 | 下载超时时间 |
返回值:
WxResponse: 下载结果,失败时返回该类型视频消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | video | 消息属性 |
下载视频,返回视频路径
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| dir_path | Union[str, Path] | None | 下载视频的目录,不填则默认WxParam.DEFAULT_SAVE_PATH |
| timeout | int | 10 | 下载超时时间 |
返回值:
WxResponse: 下载结果,失败时返回该类型语音消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | voice | 消息属性 |
将语音消息转换为文本,返回文本内容
文件消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | file | 消息属性 |
下载文件,返回文件路径
参数:
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| dir_path | Union[str, Path] | None | 下载文件的目录,不填则默认WxParam.DEFAULT_SAVE_PATH |
| force_click | bool | False | 是否强制点击文件消息(当自动下载不可用时指定,否则会打开该文件) |
| timeout | int | 10 | 下载超时时间 |
返回值:
WxResponse: 下载结果,失败时返回该类型位置消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | location | 消息属性 |
特有属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| ✨address | str | 地址信息 | 该消息卡片的地址信息 |
链接消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | link | 消息属性 |
获取链接地址
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| timeout | int | 10 | 下载超时时间 |
返回值:
表情消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | emotion | 消息属性 |
合并消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | merge | 消息属性 |
获取合并消息中的所有消息
返回值:
名片消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | personal_card | 消息属性 |
添加好友
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| addmsg | str | None | 添加好友时的附加消息 |
| remark | str | None | 添加好友后的备注 |
| tags | List[str] | None | 添加好友后的标签 |
| permission | Literal['朋友圈', '仅聊天'] | '朋友圈' | 添加好友后的权限 |
| timeout | int | 3 | 搜索好友的超时时间 |
返回值:
WxResponse: 是否添加成功笔记消息。继承自HumanMessage
固定属性:
| 属性名 | 类型 | 属性值 | 描述 |
|---|---|---|---|
| type | str | note | 消息属性 |
获取笔记内容
保存笔记中的文件
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| dir_path | Union[str, Path] | None | 保存路径 |
返回值:
WxResponse: 是否保存成功,若成功则data为保存的文件路径列表将笔记转换为Markdown格式
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| dir_path | Union[str, Path] | None | 保存路径 |
返回值:
其他暂未支持解析的消息类型