Class: ActionMessenger::Providers::Slack

Inherits:
Object
  • Object
show all
Defined in:
lib/action_messenger/providers/slack.rb

Constant Summary collapse

TokenError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSlack

Returns a new instance of Slack.

Raises:



11
12
13
14
15
16
17
# File 'lib/action_messenger/providers/slack.rb', line 11

def initialize
  raise(TokenError.new('slack api token is blank.')) if ActionMessenger.config.slack_api_token.blank?

  @client = ::Slack::Web::Client.new.tap do |client|
    client.token = ActionMessenger.config.slack_api_token
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/action_messenger/providers/slack.rb', line 9

def client
  @client
end

Instance Method Details

#message(channel, options) ⇒ Object

message to slack

Parameters:

  • channel (String)
  • options (Hash)


22
23
24
25
# File 'lib/action_messenger/providers/slack.rb', line 22

def message(channel, options)
  options = {channel: channel}.merge(message_option_to_api_hash(options))
  client.chat_postMessage(options)
end

#upload_file(channels, file, options) ⇒ Object

upload file to slack

Parameters:



33
34
35
36
# File 'lib/action_messenger/providers/slack.rb', line 33

def upload_file(channels, file, options)
  options = {channels: channels, file: file}.merge(upload_file_option_to_api_hash(options))
  client.files_upload(options)
end