Skip to content

Commit d46fb39

Browse files
committed
Support an array of channels.
1 parent 7b5652f commit d46fb39

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

.rubocop_todo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-02-08 14:45:33 UTC using RuboCop version 1.26.1.
3+
# on 2025-02-08 14:50:37 UTC using RuboCop version 1.26.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -47,7 +47,7 @@ Lint/RedundantCopDisableDirective:
4747
# Offense count: 13
4848
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
4949
Metrics/AbcSize:
50-
Max: 38
50+
Max: 42
5151

5252
# Offense count: 5
5353
# Configuration parameters: IgnoredMethods.

README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messagin
5454
- [Verifying the Request Signature](#verifying-the-request-signature)
5555
- [Message Handling](#message-handling)
5656
- [Formatting Messages](#formatting-messages)
57-
- [Date and time formatting](#date-and-time-formatting)
58-
- [Channel ID formatting](#channel-id-formatting)
59-
- [User ID formatting](#user-id-formatting)
60-
- [URL formatting](#url-formatting)
61-
- [Markdown formatting](#markdown-formatting)
57+
- [Date and Time Formatting](#date-and-time-formatting)
58+
- [Channel ID Formatting](#channel-id-formatting)
59+
- [User ID Formatting](#user-id-formatting)
60+
- [URL Formatting](#url-formatting)
61+
- [Markdown Formatting](#markdown-formatting)
6262
- [Parsing Messages](#parsing-messages)
63-
- [Unescaping message content](#unescaping-message-content)
64-
- [Escaping message content](#escaping-message-content)
63+
- [Unescaping Message Content](#unescaping-message-content)
64+
- [Escaping Message Content](#escaping-message-content)
6565
- [Command-Line Client](#command-line-client)
6666
- [Authenticate with Slack](#authenticate-with-slack)
6767
- [Send a Message](#send-a-message)
@@ -189,6 +189,9 @@ client.files_upload_v2(
189189
thread_ts: '1738331487.481469' # specifies a thread to add this file to
190190
)
191191
```
192+
193+
You can use all of channel ID, an array of channel IDs, or a channel name (prefixed with `#`) in `files_upload_v2`. Lookup by name is not supported by the Slack API and this method called invokes `conversations_list` in order to locate the channel ID. This invocation can have a cost if you have many Slack channels and is only recommended when you intend to list channels anyway.
194+
192195
Note: This library includes a `files_upload` method that uses a deprecated endpoint `files.upload` that will [no longer be supported on 3/11/2025](https://api.slack.com/methods/files.upload#markdown).
193196

194197
```ruby
@@ -613,15 +616,15 @@ The `verify!` call may raise `Slack::Events::Request::MissingSigningSecret`, `Sl
613616

614617
### Message Handling
615618

616-
All text in Slack uses the same [system of formatting and escaping](https://api.slack.com/docs/formatting): chat messages, direct messages, file comments, etc. [Slack::Messages::Formatting](lib/slack/messages/formatting.rb) provides convenience methods to format and parse messages.
619+
All text in Slack uses the same [system of Formatting and escaping](https://api.slack.com/docs/formatting): chat messages, direct messages, file comments, etc. [Slack::Messages::Formatting](lib/slack/messages/formatting.rb) provides convenience methods to format and parse messages.
617620

618621
#### Formatting Messages
619622

620-
`Slack::Messages::Formatting` provides a number of methods for formatting objects that you can then embed in outgoing messages.
623+
`Slack::Messages::Formatting` provides a number of methods for Formatting objects that you can then embed in outgoing messages.
621624

622-
##### Date and time formatting
625+
##### Date and Time Formatting
623626

624-
You can embed a pre-formatted date in a message as a string like any other text, but using Slack's date formatting allows you to display dates based on user preferences for dates and times, incorporating users' local time zones, and optionally using relative values like "yesterday", "today", or "tomorrow" when appropriate.
627+
You can embed a pre-formatted date in a message as a string like any other text, but using Slack's date Formatting allows you to display dates based on user preferences for dates and times, incorporating users' local time zones, and optionally using relative values like "yesterday", "today", or "tomorrow" when appropriate.
625628

626629
```ruby
627630
date = Time.now
@@ -644,7 +647,7 @@ Slack::Messages::Formatting.date(date, text: 'party time!')
644647
# => "<!date^1688150386^{date_num} {time_secs}|party time!>"
645648
```
646649

647-
##### Channel ID formatting
650+
##### Channel ID Formatting
648651

649652
If you already know the channel name you can just embed it in the message as `#some-channel`, but if you only have the ID you can embed it using special syntax which Slack will display as the channel name (while respecting channel visibility).
650653

@@ -654,7 +657,7 @@ Slack::Messages::Formatting.channel_link(channel_id)
654657
# => "<#C0000000001>"
655658
```
656659

657-
##### User ID formatting
660+
##### User ID Formatting
658661

659662
If you already know the user name you can just embed it in the message as `@some_username`, but if you only have the ID you can embed it using special syntax which Slack will display as the user name.
660663

@@ -664,9 +667,9 @@ Slack::Messages::Formatting.user_link(user_id)
664667
# => "<@U0000000001>"
665668
```
666669

667-
##### URL formatting
670+
##### URL Formatting
668671

669-
Slack will automatically parse fully qualified URLs in messages, but you need special formatting to embed a link with different text.
672+
Slack will automatically parse fully qualified URLs in messages, but you need special Formatting to embed a link with different text.
670673

671674
```ruby
672675
text = 'party time'
@@ -675,9 +678,9 @@ Slack::Messages::Formatting.url_link(text, url)
675678
# => "<https://media.giphy.com/media/AcfTF7tyikWyroP0x7/giphy.gif|party time>"
676679
```
677680

678-
##### Markdown formatting
681+
##### Markdown Formatting
679682

680-
Slack uses a mishmash of regular markdown formatting with its own syntax. Some features like headings aren't supported and will be left as-is, but others like bold, strikethrough, and links are converted.
683+
Slack uses a mishmash of regular markdown Formatting with its own syntax. Some features like headings aren't supported and will be left as-is, but others like bold, strikethrough, and links are converted.
681684

682685
```ruby
683686
text = """
@@ -703,7 +706,7 @@ Slack::Messages::Formatting.markdown(text)
703706

704707
`Slack::Messages::Formatting` also provides ways to escape or unescape messages. This comes handy, for example, you want to treat all input to a real time bot as plain text.
705708

706-
##### Unescaping message content
709+
##### Unescaping Message Content
707710

708711
```ruby
709712
Slack::Messages::Formatting.unescape('Hello &amp; &lt;world&gt;')
@@ -728,7 +731,7 @@ Slack::Messages::Formatting.unescape('‘hello’')
728731
# => "'hello'"
729732
```
730733

731-
##### Escaping message content
734+
##### Escaping Message Content
732735

733736
```ruby
734737
Slack::Messages::Formatting.escape('Hello & <world>')

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def files_upload_v2(params = {})
3232
raise ArgumentError, "Required argument :#{param} missing" if params[param].nil?
3333
end
3434

35-
channel = conversations_id(channel: params[:channels])['channel']['id']
35+
channels = Array(params[:channels]).map do |channel|
36+
conversations_id(channel: channel)['channel']['id']
37+
end.uniq.join(',')
38+
3639
content = params[:content]
3740
title = params[:title] || params[:filename]
3841

@@ -57,7 +60,7 @@ def files_upload_v2(params = {})
5760

5861
# Complete the upload.
5962
complete_upload_request_params = params.slice(:initial_comment, :thread_ts)
60-
complete_upload_request_params[:channels] = channel
63+
complete_upload_request_params[:channels] = channels
6164
complete_upload_request_params[:files] = [{ id: file_id, title: title }].to_json
6265

6366
files_completeUploadExternal(complete_upload_request_params)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,25 @@
8080
).files.size).to eq 1
8181
end
8282
end
83+
84+
context 'with an array of channels', vcr: { cassette_name: 'web/files_upload_v2_with_channels_list' } do
85+
before do
86+
allow(client).to receive(:conversations_list).and_yield(
87+
Slack::Messages::Message.new(
88+
'channels' => [{
89+
'id' => 'C08BHPZBZ8A',
90+
'name' => 'general'
91+
}]
92+
)
93+
)
94+
end
95+
96+
it 'completes the upload' do
97+
expect(client.files_upload_v2(
98+
filename: 'test.txt',
99+
content: 'Test File Contents',
100+
channels: ['C08AZ76CA4V', '#general']
101+
).files.size).to eq 1
102+
end
103+
end
83104
end

0 commit comments

Comments
 (0)