Skip to content

Commit d73e6c4

Browse files
feat: Add support for 'blocks' in 'files_upload_v2'
1 parent 676dd87 commit d73e6c4

File tree

5 files changed

+260
-4
lines changed

5 files changed

+260
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 3.0.1 (Next)
22

33
* Your contribution here.
4+
* [#576](https://github.com/slack-ruby/slack-ruby-client/pull/576): Add support for `blocks` in `files_upload_v2` - [@childish-sambino](https://github.com/childish-sambino).
45

56
### 3.0.0 (2025/09/22)
67

examples/oauth_v2/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Obtain a user OAuth token from Slack.
22

3-
Create a Slack app [here](https://api.slack.com/tutorials/tracks/getting-a-token).
3+
Create a Slack app [here](https://api.slack.com/tutorials/tracks/getting-a-token).
44

55
The new app has a pre-configured User OAuth Token which you can use for most of the examples.
66
However you may want to obtain a token for a different user, which can be accomplished as follows.
77

8-
To test locally use [ngrok](https://ngrok.com/) to expose your local server to the internet.
8+
To test locally use [ngrok](https://ngrok.com/) to expose your local server to the internet.
99

1010
```sh
1111
ngrok http 4242
@@ -27,7 +27,7 @@ Run the example.
2727

2828
```sh
2929
bundle install
30-
bundle exec dotenv ruby oauth_v2.rb
30+
bundle exec dotenv ruby oauth_v2.rb
3131
```
3232

3333
A browser window will open to complete the OAuth flow.

lib/slack/web/api/helpers/files.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module Files
2929
# Comma-separated string of channel IDs where the file will be shared. If not specified the file will be private.
3030
# @option params [string] :initial_comment
3131
# The message text introducing the file in specified channels.
32+
# @option params [string] :blocks
33+
# A JSON-based array of structured rich text blocks, presented as a URL-encoded string. If the initial_comment field is provided, the blocks field is ignored.
3234
# @option params [string] :thread_ts
3335
# Provide another message's ts value to upload this file as a reply.
3436
# Never use a reply's ts value; use its parent instead.
@@ -49,7 +51,7 @@ def files_upload_v2(params = {})
4951
channel_params = %i[channel channels channel_id].map { |param| params[param] }.compact
5052
raise ArgumentError, 'Only one of :channel, :channels, or :channel_id is required' if channel_params.size > 1
5153

52-
complete_upload_request_params = params.slice(:initial_comment, :thread_ts)
54+
complete_upload_request_params = params.slice(:initial_comment, :blocks, :thread_ts)
5355

5456
if params[:channels]
5557
complete_upload_request_params[:channels] = Array(params[:channels]).map do |channel|

spec/fixtures/slack/web/files_upload_v2_with_blocks.yml

Lines changed: 232 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/slack/web/api/endpoints/custom/files_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@
121121
end
122122
end
123123

124+
context 'when blocks parameter is specified', vcr: { cassette_name: 'web/files_upload_v2_with_blocks' } do
125+
it 'completes the upload with blocks' do
126+
blocks = [
127+
{
128+
type: 'section',
129+
text: {
130+
type: 'mrkdwn',
131+
text: 'This is a test file upload with blocks'
132+
}
133+
}
134+
]
135+
136+
expect(client.files_upload_v2(
137+
filename: 'test.txt',
138+
content: 'Test File Contents',
139+
channel_id: 'C07GQLY5Q3Z',
140+
blocks: blocks
141+
).files.size).to eq 1
142+
end
143+
end
144+
124145
context 'with an array of channels', vcr: { cassette_name: 'web/files_upload_v2_with_channels_list' } do
125146
before do
126147
allow(client).to receive(:conversations_list).and_yield(

0 commit comments

Comments
 (0)