mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:52:43 +00:00
fix(slack): download all files in multi-image messages (#15447)
* fix(slack): download all files in multi-image messages resolveSlackMedia() previously returned after downloading the first file, causing multi-image Slack messages to lose all but the first attachment. This changes the function to collect all successfully downloaded files into an array, matching the pattern already used by Telegram, Line, Discord, and iMessage adapters. The prepare handler now populates MediaPaths, MediaUrls, and MediaTypes arrays so downstream media processing (vision, sandbox staging, media notes) works correctly with multiple attachments. Fixes #11892, #7536 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(slack): preserve MediaTypes index alignment with MediaPaths/MediaUrls The filter(Boolean) on MediaTypes removed entries with undefined contentType, shrinking the array and breaking index correlation with MediaPaths and MediaUrls. Downstream code (media-note.ts, attachments.ts) requires these arrays to have equal lengths for correct per-attachment MIME type lookup. Replace filter(Boolean) with a nullish coalescing fallback to "application/octet-stream". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(slack): align MediaType fallback and tests (#15447) (thanks @CommanderCrowCode) * fix: unblock plugin-sdk account-id typing (#15447) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -132,17 +132,28 @@ function resolveSlackMediaMimetype(
|
||||
return mime;
|
||||
}
|
||||
|
||||
export type SlackMediaResult = {
|
||||
path: string;
|
||||
contentType?: string;
|
||||
placeholder: string;
|
||||
};
|
||||
|
||||
const MAX_SLACK_MEDIA_FILES = 8;
|
||||
|
||||
/**
|
||||
* Downloads all files attached to a Slack message and returns them as an array.
|
||||
* Returns `null` when no files could be downloaded.
|
||||
*/
|
||||
export async function resolveSlackMedia(params: {
|
||||
files?: SlackFile[];
|
||||
token: string;
|
||||
maxBytes: number;
|
||||
}): Promise<{
|
||||
path: string;
|
||||
contentType?: string;
|
||||
placeholder: string;
|
||||
} | null> {
|
||||
}): Promise<SlackMediaResult[] | null> {
|
||||
const files = params.files ?? [];
|
||||
for (const file of files) {
|
||||
const limitedFiles =
|
||||
files.length > MAX_SLACK_MEDIA_FILES ? files.slice(0, MAX_SLACK_MEDIA_FILES) : files;
|
||||
const results: SlackMediaResult[] = [];
|
||||
for (const file of limitedFiles) {
|
||||
const url = file.url_private_download ?? file.url_private;
|
||||
if (!url) {
|
||||
continue;
|
||||
@@ -169,16 +180,16 @@ export async function resolveSlackMedia(params: {
|
||||
params.maxBytes,
|
||||
);
|
||||
const label = fetched.fileName ?? file.name;
|
||||
return {
|
||||
results.push({
|
||||
path: saved.path,
|
||||
contentType: effectiveMime ?? saved.contentType,
|
||||
placeholder: label ? `[Slack file: ${label}]` : "[Slack file]",
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
// Ignore download failures and fall through to the next file.
|
||||
// Ignore download failures and try the next file.
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return results.length > 0 ? results : null;
|
||||
}
|
||||
|
||||
export type SlackThreadStarter = {
|
||||
|
||||
Reference in New Issue
Block a user