slack_download_file
Download files from Slack and save them locally using file ID and destination path.
Instructions
Download a file from Slack and save it to the specified path.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_id | Yes | The Slack file ID to download. | |
| save_path | Yes | Local file path where the file should be saved. |
Implementation Reference
- src/index.js:640-708 (handler)The handler logic for 'slack_download_file' which fetches the file from Slack and saves it to a local path.
case "slack_download_file": { const fileId = args.file_id; const savePath = args.save_path; // Get file info first const fileInfo = await slack.files.info({ file: fileId, }); const file = fileInfo.file; const downloadUrl = file.url_private_download || file.url_private; if (!downloadUrl) { return { content: [ { type: "text", text: "Error: No download URL available for this file.", }, ], }; } // Download the file using fetch with auth header const response = await fetch(downloadUrl, { headers: { Authorization: `Bearer ${SLACK_BOT_TOKEN}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Error downloading file: ${response.status} ${response.statusText}`, }, ], }; } // Write to file const fs = await import("fs/promises"); const path = await import("path"); // Ensure directory exists await fs.mkdir(path.dirname(savePath), { recursive: true }); const buffer = Buffer.from(await response.arrayBuffer()); await fs.writeFile(savePath, buffer); return { content: [ { type: "text", text: JSON.stringify( { success: true, file_name: file.name, saved_to: savePath, size: buffer.length, }, null, 2 ), }, ], }; } - src/index.js:208-224 (schema)The schema definition for the 'slack_download_file' tool.
{ name: "slack_download_file", description: "Download a file from Slack and save it to the specified path.", inputSchema: { type: "object", properties: { file_id: { type: "string", description: "The Slack file ID to download.", }, save_path: { type: "string", description: "Local file path where the file should be saved.", }, }, required: ["file_id", "save_path"],