Skip to content

Commit 308a3aa

Browse files
authored
Merge pull request #538 from dblock/translate-channels-file-upload
Translate channel names and support an array of channels in file upload.
2 parents aa4d1e4 + fafddf3 commit 308a3aa

File tree

7 files changed

+298
-23
lines changed

7 files changed

+298
-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-05 16:58:54 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: 34
50+
Max: 42
5151

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

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#528](https://github.com/slack-ruby/slack-ruby-client/pull/528): Don't treat asterisks in list items as italic in markdown - [@rspeicher](https://github.com/rspeicher).
66
* [#530](https://github.com/slack-ruby/slack-ruby-client/pull/530): Specify dependency on `logger` - [@rwstauner](https://github.com/rwstauner).
77
* [#533](https://github.com/slack-ruby/slack-ruby-client/pull/533), [#536](https://github.com/slack-ruby/slack-ruby-client/pull/536): Added `files_upload_v2` - [@gregsaab](https://github.com/gregsaab).
8+
* [#538](https://github.com/slack-ruby/slack-ruby-client/pull/538): Translate channel names and support an array of channels in `files_upload_v2` - [@dblock](https://github.com/dblock).
89
* Your contribution here.
910

1011
### 2.4.0 (2024/07/14)

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def files_upload_v2(params = {})
3232
raise ArgumentError, "Required argument :#{param} missing" if params[param].nil?
3333
end
3434

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

@@ -55,7 +59,8 @@ def files_upload_v2(params = {})
5559
end
5660

5761
# Complete the upload.
58-
complete_upload_request_params = params.slice(:channels, :initial_comment, :thread_ts)
62+
complete_upload_request_params = params.slice(:initial_comment, :thread_ts)
63+
complete_upload_request_params[:channels] = channels
5964
complete_upload_request_params[:files] = [{ id: file_id, title: title }].to_json
6065

6166
files_completeUploadExternal(complete_upload_request_params)

spec/fixtures/slack/web/files_upload_v2_with_channel_name.yml

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

0 commit comments

Comments
 (0)