Skip to content

Commit 3c2cda6

Browse files
committed
Fix: do not attempt to resolve channel name for APIs that support it.
1 parent 91a639f commit 3c2cda6

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

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)