Class: Pechkin::SlackConnector
- Defined in:
- lib/pechkin/connector_slack.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(bot_token, name) ⇒ SlackConnector
constructor
A new instance of SlackConnector.
- #send_message(channel, message, message_desc) ⇒ Object
Methods inherited from Connector
Constructor Details
#initialize(bot_token, name) ⇒ SlackConnector
Returns a new instance of SlackConnector.
5 6 7 8 |
# File 'lib/pechkin/connector_slack.rb', line 5 def initialize(bot_token, name) @headers = { 'Authorization' => "Bearer #{bot_token}" } @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/pechkin/connector_slack.rb', line 3 def name @name end |
Instance Method Details
#send_message(channel, message, message_desc) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pechkin/connector_slack.rb', line 10 def (channel, , ) text = CGI.unescape_html() = ['slack_attachments'] || {} if text.strip.empty? && .empty? return [channel, 400, 'Internal error: message is empty'] end params = { channel: channel, text: text, attachments: } url = 'https://slack.com/api/chat.postMessage' response = post_data(url, params, headers: @headers) [channel, response.code.to_i, response.body] end |