Skip to content

Commit a1120c0

Browse files
authored
Merge pull request #544 from dblock/fix-resolve-name
Fix: do not attempt to resolve channel name for APIs that support it.
2 parents 91a639f + a35729e commit a1120c0

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

.rubocop_todo.yml

Lines changed: 7 additions & 6 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-09 15:51:54 UTC using RuboCop version 1.26.1.
3+
# on 2025-02-11 15:48:56 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
@@ -100,13 +100,13 @@ RSpec/ContextMethod:
100100
- 'spec/slack/messages/formatting_spec.rb'
101101
- 'spec/slack/web/api/mixins/users_spec.rb'
102102

103-
# Offense count: 83
103+
# Offense count: 84
104104
# Configuration parameters: Prefixes.
105105
# Prefixes: when, with, without
106106
RSpec/ContextWording:
107107
Enabled: false
108108

109-
# Offense count: 70
109+
# Offense count: 72
110110
# Configuration parameters: CountAsOne.
111111
RSpec/ExampleLength:
112112
Max: 18
@@ -117,13 +117,13 @@ RSpec/ExampleLength:
117117
RSpec/FilePath:
118118
Enabled: false
119119

120-
# Offense count: 70
120+
# Offense count: 74
121121
# Configuration parameters: .
122122
# SupportedStyles: have_received, receive
123123
RSpec/MessageSpies:
124124
EnforcedStyle: receive
125125

126-
# Offense count: 95
126+
# Offense count: 97
127127
RSpec/MultipleExpectations:
128128
Max: 5
129129

@@ -142,11 +142,12 @@ RSpec/NamedSubject:
142142
RSpec/NestedGroups:
143143
Max: 6
144144

145-
# Offense count: 5
145+
# Offense count: 6
146146
RSpec/StubbedMock:
147147
Exclude:
148148
- 'spec/slack/real_time/client_spec.rb'
149149
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
150+
- 'spec/slack/web/api/endpoints/custom/conversations_spec.rb'
150151
- 'spec/slack/web/api/pagination/cursor_spec.rb'
151152
- 'spec/slack/web/client_spec.rb'
152153

CHANGELOG.md

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

33
* [#542](https://github.com/slack-ruby/slack-ruby-client/pull/542): Add support for ruby 3.4 - [@dblock](https://github.com/dblock).
4+
* [#544](https://github.com/slack-ruby/slack-ruby-client/pull/544): Fix: do not resolve channel name for `chat_postMessage` - [@dblock](https://github.com/dblock).
45
* Your contribution here.
56

67
### 2.5.0 (2025/02/09)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,15 @@ The `verify!` call may raise `Slack::Events::Request::MissingSigningSecret`, `Sl
614614

615615
### Message Handling
616616

617-
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.
617+
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.
618618

619619
#### Formatting Messages
620620

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

623623
##### Date and Time Formatting
624624

625-
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.
625+
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.
626626

627627
```ruby
628628
date = Time.now
@@ -667,7 +667,7 @@ Slack::Messages::Formatting.user_link(user_id)
667667

668668
##### URL Formatting
669669

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

672672
```ruby
673673
text = 'party time'
@@ -678,7 +678,7 @@ Slack::Messages::Formatting.url_link(text, url)
678678

679679
##### Markdown Formatting
680680

681-
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.
681+
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.
682682

683683
```ruby
684684
text = """

lib/slack/web/api/endpoints/chat.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def chat_postEphemeral(options = {})
173173
def chat_postMessage(options = {})
174174
raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
175175
raise ArgumentError, 'At least one of :attachments, :blocks, :text is required' if options[:attachments].nil? && options[:blocks].nil? && options[:text].nil?
176-
options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
177176
options = encode_options_as_json(options, %i[attachments blocks metadata])
178177
post('chat.postMessage', options)
179178
end

lib/slack/web/api/templates/method.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Slack
4848
<% end %>
4949
<% if data['group'] == 'groups' && data['args']['channel'] && !data['args']['channel']['desc'].include?('Can be an encoded ID, or a name.') %>
5050
options = options.merge(channel: groups_id(options)['group']['id']) if options[:channel]
51-
<% elsif data['args']['channel'] && !data['args']['channel']['desc'].include?('Can be an encoded ID, or a name.') %>
51+
<% elsif data['args']['channel'] && ['Can be an encoded ID, or a name.', 'encoded ID or channel name'].none? { |desc| data['args']['channel']['desc'].include?(desc) } %>
5252
options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
5353
<% end %>
5454
<% if data['args']['user'] %>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@
9292
end
9393

9494
context 'chat_postMessage' do
95+
it 'does not convert channel name to channel ID' do
96+
expect(client).not_to receive(:conversations_id)
97+
expect(client).to receive(:post).with(
98+
'chat.postMessage',
99+
{
100+
channel: '#channel',
101+
text: 'text'
102+
}
103+
)
104+
client.chat_postMessage(channel: '#channel', text: 'text')
105+
end
106+
95107
it 'automatically converts attachments and blocks into JSON' do
96108
expect(client).to receive(:post).with(
97109
'chat.postMessage',

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,19 @@
1010
expect(json.channel.name).to eq 'mpdm-dblock--rubybot--player1-1'
1111
end
1212
end
13+
14+
context 'list' do
15+
it 'resolves channel and includes all arguments into http requests' do
16+
expect(client).to receive(:conversations_list).and_yield(
17+
Slack::Messages::Message.new(
18+
'channels' => [{
19+
'id' => 'CDEADBEEF',
20+
'name' => 'general'
21+
}]
22+
)
23+
)
24+
expect(client).to receive(:post).with('conversations.history', { channel: 'CDEADBEEF', limit: 10 })
25+
client.conversations_history(channel: '#general', limit: 10)
26+
end
27+
end
1328
end

0 commit comments

Comments
 (0)