增强对JSON卡片消息的处理,支持群公告解析并构建相应文本

pull/69/head
墨梓柒 2025-12-11 15:26:25 +08:00
parent 96b6487ccc
commit 12f6d205e1
No known key found for this signature in database
GPG Key ID: 4A65B9DBA35F7635
1 changed files with 21 additions and 2 deletions

View File

@ -487,7 +487,7 @@ class MessageHandler:
async def handle_json_message(self, raw_message: dict) -> Seg | None: async def handle_json_message(self, raw_message: dict) -> Seg | None:
""" """
处理JSON卡片消息(小程序分享) 处理JSON卡片消息(小程序分享群公告)
Parameters: Parameters:
raw_message: dict: 原始消息 raw_message: dict: 原始消息
Returns: Returns:
@ -501,8 +501,27 @@ class MessageHandler:
return None return None
try: try:
# 尝试解析JSON获取prompt提示信息 # 尝试解析JSON获取详细信息
parsed_json = json.loads(json_data) parsed_json = json.loads(json_data)
app = parsed_json.get("app", "")
# 检查是否为群公告
if app == "com.tencent.mannounce":
meta = parsed_json.get("meta", {})
mannounce = meta.get("mannounce", {})
title = mannounce.get("title", "")
text = mannounce.get("text", "")
# 构建群公告文本
announce_text = "[群公告]"
if title:
announce_text += f"\n标题: {title}"
if text:
announce_text += f"\n内容: {text}"
return Seg(type="text", data=announce_text)
# 其他卡片消息使用prompt字段
prompt = parsed_json.get("prompt", "[卡片消息]") prompt = parsed_json.get("prompt", "[卡片消息]")
return Seg(type="text", data=prompt) return Seg(type="text", data=prompt)
except json.JSONDecodeError: except json.JSONDecodeError: