Module: Slack::Web::Api::Mixins::Channels

Included in:
Endpoints
Defined in:
lib/slack/web/api/mixins/channels.id.rb

Instance Method Summary collapse

Instance Method Details

#channels_id(options = {}) ⇒ Object

This method returns a channel ID given a channel name.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    Channel to get ID for, prefixed with #.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/slack/web/api/mixins/channels.id.rb', line 11

def channels_id(options = {})
  name = options[:channel]
  throw ArgumentError.new('Required arguments :channel missing') if name.nil?
  return { 'ok' => true, 'channel' => { 'id' => name } } unless name[0] == '#'
  channels_list.tap do |list|
    list.channels.each do |channel|
      return Slack::Messages::Message.new('ok' => true, 'channel' => { 'id' => channel.id }) if channel.name == name[1..-1]
    end
  end
  fail Slack::Web::Api::Error, 'channel_not_found'
end