Class: ActionMessenger::Base

Inherits:
AbstractController::Base
  • Object
show all
Includes:
AbstractController::Helpers, AbstractController::Logger, AbstractController::Rendering, Rescuable, ActionView::Layouts
Defined in:
lib/action_messenger/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rescuable

#handle_exceptions

Instance Attribute Details

#caller_method_nameObject (readonly)

Returns the value of attribute caller_method_name.



36
37
38
# File 'lib/action_messenger/base.rb', line 36

def caller_method_name
  @caller_method_name
end

Class Method Details

.loggerObject



15
16
17
# File 'lib/action_messenger/base.rb', line 15

def logger
  ActionMessenger.config.logger || (defined?(Rails) ? Rails.logger : nil)
end

Instance Method Details

#message_to_slack(channel:, options: {}) ⇒ Object

message to slack

ex. message_to_slack(channel: ‘#general’, options: ‘sample’)

Parameters:



46
47
48
49
50
51
52
53
54
# File 'lib/action_messenger/base.rb', line 46

def message_to_slack(channel:, options: {})
  @caller_method_name = caller[0][/`([^']*)'/, 1]
  options = apply_defaults(options)
  message = nil
  ActiveSupport::Notifications.instrument('message_to_slack.action_messenger', channel: channel, body: options[:text]) do
    message = slack_client.message(channel, options)
  end
  message
end

#upload_file_to_slack(channels:, file:, options: {}) ⇒ Object

upload file to slack

Parameters:

  • channels (String)

    slack channel ex. #general, #hoge

  • file (Faraday::UploadIO)

    upload file ex. Faraday::UploadIO.new(‘/path/to/sample.jpg’, ‘image/jpg’)

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


63
64
65
66
67
68
69
# File 'lib/action_messenger/base.rb', line 63

def upload_file_to_slack(channels: ,file: ,options: {})
  upload_file = nil
  ActiveSupport::Notifications.instrument('upload_file_to_slack.action_messenger', channels: channels) do
    upload_file = slack_client.upload_file(channels, file, options)
  end
  upload_file
end