Module: ImmosquareSlack::Channel

Extended by:
SharedMethods
Defined in:
lib/immosquare-slack/channel.rb

Class Method Summary collapse

Class Method Details

.list_channelsObject

##

Pour récupérer la liste des channels

##


9
10
11
12
13
14
15
16
17
# File 'lib/immosquare-slack/channel.rb', line 9

def list_channels
  @list_channels ||= begin
    extra_params = {
      :types            => ["public_channel", "private_channel"].join(","),
      :exclude_archived => false
    }
    fetch_paginated_data("https://slack.com/api/conversations.list", "channels", extra_params)
  end
end

.post_message(channel_name, text, notify: nil, notify_text: nil, bot_name: nil, notify_general_if_invalid_channel: true) ⇒ Object

##

Pour poster un message dans un channel

##


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/immosquare-slack/channel.rb', line 22

def post_message(channel_name, text, notify: nil, notify_text: nil, bot_name: nil, notify_general_if_invalid_channel: true)
  channel_id = get_channel_id_by_name(channel_name)

  if channel_id.nil?
    text = "immosquare-slack missing channel *#{channel_name}*\nmessage:\n#{text}"
    return post_message("general", text, :notify => :channel, :notify_text => "", :bot_name => bot_name, :notify_general_if_invalid_channel => false) if channel_name != "general" && notify_general_if_invalid_channel

    raise("channel '#{channel_name}' not found on slack")
  end

  url               = "https://slack.com/api/chat.postMessage"
  notification_text = notify ? build_notification_text(channel_id, notify, *notify_text) : nil
  text              = "#{notification_text}#{text}"

  body = {
    :channel => channel_id,
    :text    => text
  }

  body[:username] = bot_name if bot_name

  make_slack_api_call(url, :method => :post, :body => body)
end