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

@@ -1272,6 +1272,13 @@ class MessageChain(ChainBase):
)
elif audio_ref.startswith("wxbot://voice"):
continue
elif audio_ref.startswith("feishu://file/"):
content = self.run_module(
"download_feishu_file_bytes", file_ref=audio_ref, source=source
)
filename = self._guess_audio_filename(
audio_ref, default="input.opus"
)
elif audio_ref.startswith("http"):
resp = RequestUtils(timeout=30).get_res(audio_ref)
content = resp.content if resp and resp.content else None
@@ -1339,11 +1346,11 @@ class MessageChain(ChainBase):
"""
下载可直接提供给 LLM 的附件内容,并统一转换为 data URL。
"""
attachments = CommingMessage.MessageImage.normalize_list(attachments)
if not attachments:
normalized_attachments = CommingMessage.MessageImage.normalize_list(attachments) or []
if not normalized_attachments:
return None
data_urls = []
for attachment in attachments:
for attachment in normalized_attachments:
attachment_ref = attachment.ref
try:
before_count = len(data_urls)

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,
)
]