MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / extractSlackFiles

Method extractSlackFiles

src/runtime/adapters/slack.ts:814–853  ·  view source on GitHub ↗

* Extract file attachments from a Slack event. * Downloads files using the Bot Token for private URL access.

(
    event: any,
    channelId: string,
    _client: any,
  )

Source from the content-addressed store, hash-verified

812 * Downloads files using the Bot Token for private URL access.
813 */
814 private async extractSlackFiles(
815 event: any,
816 channelId: string,
817 _client: any,
818 ): Promise<ChannelAttachment[]> {
819 const files = event.files;
820 if (!Array.isArray(files) || files.length === 0) return [];
821
822 const attachments: ChannelAttachment[] = [];
823
824 for (const file of files) {
825 try {
826 const downloadUrl =
827 file.url_private_download || file.url_private;
828 if (!downloadUrl) {
829 console.warn(
830 `[Slack] No download URL for file: ${file.name || file.id}`,
831 );
832 continue;
833 }
834
835 const attachment = await downloadAndSaveAttachment(
836 this.rootDir,
837 channelId,
838 downloadUrl,
839 file.name || file.title || "file",
840 file.mimetype,
841 { Authorization: `Bearer ${this.options.botToken}` },
842 );
843 attachments.push(attachment);
844 } catch (err) {
845 console.error(
846 `[Slack] Failed to download file ${file.name || file.id}:`,
847 err,
848 );
849 }
850 }
851
852 return attachments;
853 }
854
855 /**
856 * Send a file to the Slack channel/thread.

Callers 2

handleDirectMessageMethod · 0.95
handleMentionMethod · 0.95

Calls 1

Tested by

no test coverage detected