fix: 支持飞书语音消息识别

This commit is contained in:
jxxghp
2026-05-13 12:45:32 +08:00
parent b24127e66f
commit f8d096f476
5 changed files with 98 additions and 20 deletions

View File

@@ -301,11 +301,32 @@ class FeishuModule(_ModuleBase, _MessageBase[Feishu]):
client = self.get_instance(client_config.name)
if not client:
return None
parts = file_ref.replace("feishu://file/", "", 1).split("/", 1)
file_key = parts[0].strip() if parts else ""
parts = [
part.strip()
for part in file_ref.replace("feishu://file/", "", 1).split("/")
if part.strip()
]
file_key = ""
downloaded = None
if len(parts) >= 2 and parts[0].startswith("om_"):
message_id, file_key = parts[0], parts[1]
downloaded = client.download_message_resource_bytes(
message_id=message_id,
file_key=file_key,
resource_type="audio",
)
if not downloaded:
downloaded = client.download_message_resource_bytes(
message_id=message_id,
file_key=file_key,
resource_type="file",
)
else:
file_key = parts[0] if parts else ""
if not file_key:
return None
downloaded = client.download_file_bytes(file_key)
if not downloaded:
downloaded = client.download_file_bytes(file_key)
if not downloaded:
return None
content, _, _ = downloaded

View File

@@ -235,13 +235,16 @@ class Feishu:
elif message_type in {"audio", "media", "file"}:
file_key = str(content.get("file_key") or "").strip()
file_name = str(content.get("file_name") or "").strip() or None
message_id = str(getattr(message, "message_id", None) or "").strip()
if file_key:
if message_type == "audio":
audio_refs = [f"feishu://file/{file_key}/{file_name or 'audio.opus'}"]
resource_path = f"{message_id}/{file_key}" if message_id else file_key
audio_refs = [f"feishu://file/{resource_path}/{file_name or 'audio.opus'}"]
else:
resource_path = f"{message_id}/{file_key}" if message_id else file_key
files = [
CommingMessage.MessageAttachment(
ref=f"feishu://file/{file_key}/{file_name or 'attachment'}",
ref=f"feishu://file/{resource_path}/{file_name or 'attachment'}",
name=file_name,
)
]