Skip to content

feat(web-api): include a blocks argument for file uploads#2261

Merged
zimeg merged 2 commits intomainfrom
zimeg-feat-webapi-filesuploadv2-blocks
Jun 13, 2025
Merged

feat(web-api): include a blocks argument for file uploads#2261
zimeg merged 2 commits intomainfrom
zimeg-feat-webapi-filesuploadv2-blocks

Conversation

@zimeg
Copy link
Copy Markdown
Member

@zimeg zimeg commented Jun 12, 2025

Summary

This PR includes a blocks argument for file uploads when using either the files.completeUploadExternal method or the filesUploadV2 function. Fixes #2208. 📠 ✨

Reviewers

Please feel free to upload multiple files or one file multiple times with blocks using the following examples! 🤖

A bot with the files:write scope added to a channel is required!

Blocks

const blocks = [
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "The uploaded file has finished processing!\n\n*Select an action or reaction:*"
    }
  },
  {
    "type": "divider"
  },
  {
    "type": "actions",
    "elements": [
      {
        "type": "button",
        "text": {
          "type": "plain_text",
          "text": "Delete",
          "emoji": true
        },
        "value": "delete"
      }
    ]
  }
];

Single file upload

const result = await web.files.uploadV2({
  channel_id: "C0123456789",
  blocks,
  file: "./index.js",
  filename: "code.js",
});

Multiple file upload

const result = await web.files.uploadV2({
  channel_id: "C0123456789",
  blocks,
  file_uploads: [
    {
      filename: "code.js",
      file: "./index.js",
    },
    {
      filename: "review.txt",
      content: "LGTM",
    },
  ],
});

Requirements

@zimeg zimeg added this to the [email protected] milestone Jun 12, 2025
@zimeg zimeg self-assigned this Jun 12, 2025
@zimeg zimeg added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` labels Jun 12, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.71%. Comparing base (ce6c9f6) to head (e23b066).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2261      +/-   ##
==========================================
+ Coverage   92.67%   92.71%   +0.03%     
==========================================
  Files          38       38              
  Lines       10554    10609      +55     
  Branches      682      683       +1     
==========================================
+ Hits         9781     9836      +55     
  Misses        761      761              
  Partials       12       12              
Flag Coverage Δ
cli-hooks 95.23% <ø> (ø)
cli-test 94.76% <ø> (ø)
oauth 77.39% <ø> (ø)
socket-mode 61.82% <ø> (ø)
web-api 97.97% <100.00%> (+0.01%) ⬆️
webhook 96.65% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together 🥇

Left one addressable comment around tests, but this PR is great quality

Comment thread packages/web-api/src/WebClient.spec.ts Outdated
Comment on lines +1193 to +1197
.post('/api/files.completeUploadExternal', {
blocks: '[{"type":"section","text":{"type":"plain_text","text":"Hello"}}]',
channel_id: 'C010101010',
files: '[{"id":"F0123456789","title":"test-txt.txt"}]',
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since blocks is optional should we leave this unit test as it is and move this to its own test? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamBergamin Super good call! It also gave us a chance to test content in a more complete unit with the e23b066 changes 🧪 ✨

Comment on lines +504 to +506
A posted message can be formatted with [Block Kit](https://docs.slack.dev/block-kit) using the `blocks` argument instead
of the `initial_comment` text.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 💯

const { blocks, channel_id, thread_ts, initial_comment, file_id, title } = upload;
if (file_id) {
const compareString = `:::${channel_id}:::${thread_ts}:::${initial_comment}`;
const compareString = `:::${channel_id}:::${thread_ts}:::${initial_comment}:::${JSON.stringify(blocks)}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch 🚀

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 😌

I'm sometimes thankful to use manual testing during development, but I also thinking improving tests according to an above comment could show this change too 🚀

file_uploads: ExcludeFromUnion<FileUploadV2, 'channel_id' | 'channels' | 'initial_comment' | 'thread_ts'>[];
file_uploads: ExcludeFromUnion<
FileUploadV2,
'blocks' | 'channel_id' | 'channels' | 'initial_comment' | 'thread_ts'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetical order 😮 🌟

@zimeg
Copy link
Copy Markdown
Member Author

zimeg commented Jun 13, 2025

@WilliamBergamin No problem at all! I think file uploading is a useful feature to have 🤖 ✨

Your testing suggestions are once more incredible for testing the right things and I'm feeling confident that these cases continue to work with actual tokens and channel IDs so I will merge this 🚢 💨

@zimeg zimeg merged commit 0e369c0 into main Jun 13, 2025
59 checks passed
@zimeg zimeg deleted the zimeg-feat-webapi-filesuploadv2-blocks branch June 13, 2025 04:45
@zimeg
Copy link
Copy Markdown
Member Author

zimeg commented Jun 13, 2025

📣 I do think a similar change is needed in the Python slack_sdk and Java com.slack.api.Slack which I'll soon plan to follow up with or at least create a tracking issue for the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type-check fail for blocks in web.files.completeUploadExternal

2 participants