Skip to content

feat(slack): file.upload, share a file to a channel, DM or thread - #104

Open
Shanik1 wants to merge 1 commit into
shift-labs-ai:mainfrom
Shanik1:feat/slack-file-upload
Open

Shanik1 wants to merge 1 commit into
shift-labs-ai:mainfrom
Shanik1:feat/slack-file-upload

Conversation

@Shanik1

@Shanik1 Shanik1 commented Nov 23, 2026

Copy link
Copy Markdown

What

Adds slack.file.upload. Until now the Slack plugin could only read files (file.get, file.list), so an agent had no way to send a file to a channel or a DM.

await slack.file.upload({
  channel: "D0123456789",          // conversation ID, or a user ID → DM
  contentPath: "./report.csv",     // or contentBase64 / content
  initialComment: "Weekly report",
  threadTs: "1700000000.000100",   // optional: reply in a thread
});
// → [{ id: "F…", title: "report.csv" }]

How

It uses Slack's external upload flow, which replaced the retired files.upload method:

  1. files.getUploadURLExternal (form body) → upload_url, file_id
  2. POST the raw bytes to upload_url
  3. files.completeUploadExternal (form body) shares the file to channel_id / thread_ts with initial_comment

Details:

  • Content: exactly one of contentBase64, contentPath or content, following the naming used by googleDrive, gmail and microsoftMail. It reuses _shared/base64 and _shared/localFile. The filename defaults to contentPath's basename, else file.
  • Size: up to 64 MiB, which is how much one buffered request through the credential transport can carry (Slack itself accepts 1 GB).
  • DMs: channel takes a conversation ID, or a user ID that is opened with conversations.open (this needs im:write). Without channel the file stays private to the uploader.
  • Credential: a new upload target, https://files.slack.com/upload/v1/, POST only. The upload_url Slack returns is checked with pathWithin, so a URL outside Slack's file host is refused before any bytes or token are sent.
  • docs/bundled-plugins.md: slack action count 38 → 39.

Tests

packages/codemode/src/tests/slack-plugin.test.ts:

  • the three requests in order: bodies, form encoding, bearer token, bytes on the wire, channel_id, thread_ts, initial_comment
  • a user ID is opened as a DM, and the returned D… ID is used
  • contentPath is named after its basename and sent as-is, with no channel
  • an upload URL off files.slack.com is refused before the bytes are sent
  • ambiguous or missing content, invalid base64, and threadTs without channel are all refused before any request

bun run check, bun run typecheck, and bun --filter @shiftlabs/codemode test (2741 pass, 0 fail) all pass locally.

I also tested it against a real Slack workspace with a user token: a text file from contentPath was shared to a DM with an initial comment, and a 7853-byte PNG sent as contentBase64 arrived as a thread reply with the same size, recognized as image/png.

Uploads through Slack's external upload flow (files.getUploadURLExternal,
the bytes to the issued upload URL, files.completeUploadExternal), which
replaced the retired files.upload method.

- Content from contentBase64, contentPath or content (exactly one), up to
  64 MiB, the bound of one buffered request through the credential transport.
- channel takes a conversation ID, or a user ID that is opened as a DM
  (conversations.open, needs im:write). Without channel the file stays private.
- initialComment, threadTs, title, altText and snippetType pass through.
- A new 'upload' credential target, https://files.slack.com/upload/v1/,
  POST only. The upload URL Slack returns is held to it with pathWithin, so
  the token is never sent off Slack's file host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant