Module: MosEisley::SlackWeb

Defined in:
lib/slack.rb

Constant Summary collapse

BASE_URL =
'https://slack.com/api/'.freeze

Class Method Summary collapse

Class Method Details

.auth_testObject



149
150
151
# File 'lib/slack.rb', line 149

def self.auth_test
  post_to_slack('auth.test', '')
end

.chat_memessage(channel:, text:) ⇒ Object



46
47
48
49
# File 'lib/slack.rb', line 46

def self.chat_memessage(channel:, text:)
  data = {channel: channel, text: text}
  post_to_slack('chat.meMessage', data)
end

.chat_postephemeral(channel:, blocks: nil, text: nil, thread_ts: nil) ⇒ Object



51
52
53
# File 'lib/slack.rb', line 51

def self.chat_postephemeral(channel:, blocks: nil, text: nil, thread_ts: nil)
  chat_send(:postEphemeral, channel, blocks, text, thread_ts)
end

.chat_postmessage(channel:, blocks: nil, text: nil, thread_ts: nil) ⇒ Object



55
56
57
# File 'lib/slack.rb', line 55

def self.chat_postmessage(channel:, blocks: nil, text: nil, thread_ts: nil)
  chat_send(:postMessage, channel, blocks, text, thread_ts)
end

.chat_schedulemessage(channel:, post_at:, blocks: nil, text: nil, thread_ts: nil) ⇒ Object



59
60
61
# File 'lib/slack.rb', line 59

def self.chat_schedulemessage(channel:, post_at:, blocks: nil, text: nil, thread_ts: nil)
  chat_send(:scheduleMessage, channel, blocks, text, thread_ts, post_at)
end

.chat_send(m, channel, blocks, text, thread_ts, post_at = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/slack.rb', line 63

def self.chat_send(m, channel, blocks, text, thread_ts, post_at = nil)
  data = {channel: channel}
  if m == :scheduleMessage
    post_at ? data[:post_at] = post_at : raise
  end
  if blocks
    data[:blocks] = blocks
    data[:text] = text if text
  else
    text ? data[:text] = text : raise
  end
  data[:thread_ts] = thread_ts if thread_ts
  post_to_slack("chat.#{m}", data)
end

.conversations_members(channel:, cursor: nil, limit: nil) ⇒ Object



123
124
125
126
127
128
# File 'lib/slack.rb', line 123

def self.conversations_members(channel:, cursor: nil, limit: nil)
  params = {channel: channel}
  params[:cursor] = cursor if cursor
  params[:limit] = limit if limit
  get_from_slack('conversations.members', params)
end

.post_log(blocks: nil, text: nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/slack.rb', line 82

def self.post_log(blocks: nil, text: nil)
  if c = ENV['SLACK_LOG_CHANNEL_ID']
    d = {channel: c}
    if blocks
      d[:blocks] = blocks
      if text
        d[:text] = text
      end
    else
      if text
        d[:text] = text
      else
        return nil
      end
    end
    chat_postmessage(d)
  else
    return nil
  end
end

.post_response_url(url, payload) ⇒ Object



78
79
80
# File 'lib/slack.rb', line 78

def self.post_response_url(url, payload)
  post_to_slack(nil, payload, url)
end

.users_info(user) ⇒ Object



130
131
132
# File 'lib/slack.rb', line 130

def self.users_info(user)
  get_from_slack('users.info', {user: user})
end

.users_list(cursor: nil, limit: nil) ⇒ Object



134
135
136
137
138
139
# File 'lib/slack.rb', line 134

def self.users_list(cursor: nil, limit: nil)
  params = {include_locale: true}
  params[:cursor] = cursor if cursor
  params[:limit] = limit if limit
  get_from_slack('users.list', params)
end

.users_lookupbyemail(email) ⇒ Object



141
142
143
# File 'lib/slack.rb', line 141

def self.users_lookupbyemail(email)
  get_from_slack('users.lookupByEmail', {email: email})
end

.users_profile_get(user) ⇒ Object



145
146
147
# File 'lib/slack.rb', line 145

def self.users_profile_get(user)
  get_from_slack('users.profile.get', {user: user})
end

.views_open(trigger_id:, view:) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/slack.rb', line 103

def self.views_open(trigger_id:, view:)
  data = {
    trigger_id: trigger_id,
    view: view,
  }
  post_to_slack('views.open', data)
end

.views_push(trigger_id:, view:) ⇒ Object



120
121
# File 'lib/slack.rb', line 120

def self.views_push(trigger_id:, view:)
end

.views_update(view_id:, view:, hash: nil) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/slack.rb', line 111

def self.views_update(view_id:, view:, hash: nil)
  data = {
    view_id: view_id,
    view: view,
  }
  data[:hash] if hash
  post_to_slack('views.update', data)
end