feat(feishu): extract embedded video/media from post (rich text) messages (#21786)

* feat(feishu): extract embedded video/media from post (rich text) messages

Previously, parsePostContent() only extracted embedded images (img tags)
from rich text posts, ignoring embedded video/audio (media tags). Users
sending post messages with embedded videos would not have the media
downloaded or forwarded to the agent.

Changes:
- Extend parsePostContent() to also collect media tags with file_key
- Return new mediaKeys array alongside existing imageKeys
- Update resolveFeishuMediaList() to download embedded media files
  from post messages using the messageResource API
- Add appropriate logging for embedded media discovery and download

* Feishu: keep embedded post media payloads type-safe

* Feishu: format post parser after media tag extraction

---------

Co-authored-by: laopuhuluwa <laopuhuluwa@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
laopuhuluwa
2026-02-28 13:39:24 +08:00
committed by GitHub
parent b0a8909a73
commit 53a2e72fcb
4 changed files with 123 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ const MARKDOWN_SPECIAL_CHARS = /([\\`*_{}\[\]()#+\-!|>~])/g;
type PostParseResult = {
textContent: string;
imageKeys: string[];
mediaKeys: Array<{ fileKey: string; fileName?: string }>;
mentionedOpenIds: string[];
};
@@ -125,7 +126,12 @@ function renderCodeBlockElement(element: Record<string, unknown>): string {
return `\`\`\`${language}\n${code}${trailingNewline}\`\`\``;
}
function renderElement(element: unknown, imageKeys: string[], mentionedOpenIds: string[]): string {
function renderElement(
element: unknown,
imageKeys: string[],
mediaKeys: Array<{ fileKey: string; fileName?: string }>,
mentionedOpenIds: string[],
): string {
if (!isRecord(element)) {
return escapeMarkdownText(toStringOrEmpty(element));
}
@@ -152,6 +158,14 @@ function renderElement(element: unknown, imageKeys: string[], mentionedOpenIds:
}
return "![image]";
}
case "media": {
const fileKey = normalizeFeishuExternalKey(toStringOrEmpty(element.file_key));
if (fileKey) {
const fileName = toStringOrEmpty(element.file_name) || undefined;
mediaKeys.push({ fileKey, fileName });
}
return "[media]";
}
case "emotion":
return renderEmotionElement(element);
case "br":
@@ -220,10 +234,16 @@ export function parsePostContent(content: string): PostParseResult {
const parsed = JSON.parse(content);
const payload = resolvePostPayload(parsed);
if (!payload) {
return { textContent: FALLBACK_POST_TEXT, imageKeys: [], mentionedOpenIds: [] };
return {
textContent: FALLBACK_POST_TEXT,
imageKeys: [],
mediaKeys: [],
mentionedOpenIds: [],
};
}
const imageKeys: string[] = [];
const mediaKeys: Array<{ fileKey: string; fileName?: string }> = [];
const mentionedOpenIds: string[] = [];
const paragraphs: string[] = [];
@@ -233,7 +253,7 @@ export function parsePostContent(content: string): PostParseResult {
}
let renderedParagraph = "";
for (const element of paragraph) {
renderedParagraph += renderElement(element, imageKeys, mentionedOpenIds);
renderedParagraph += renderElement(element, imageKeys, mediaKeys, mentionedOpenIds);
}
paragraphs.push(renderedParagraph);
}
@@ -245,9 +265,10 @@ export function parsePostContent(content: string): PostParseResult {
return {
textContent: textContent || FALLBACK_POST_TEXT,
imageKeys,
mediaKeys,
mentionedOpenIds,
};
} catch {
return { textContent: FALLBACK_POST_TEXT, imageKeys: [], mentionedOpenIds: [] };
return { textContent: FALLBACK_POST_TEXT, imageKeys: [], mediaKeys: [], mentionedOpenIds: [] };
}
}