Skip to content

Commit 063028b

Browse files
committed
Fix: do not resolve channel name for chat_postMessage.
1 parent 91a639f commit 063028b

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
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)

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)