Class: Pechkin::Connector::Slack
- Defined in:
- lib/pechkin/connector/slack.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(bot_token, name) ⇒ Slack
constructor
A new instance of Slack.
- #send_message(channel, message, message_desc) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(bot_token, name) ⇒ Slack
Returns a new instance of Slack.
6 7 8 9 10 11 |
# File 'lib/pechkin/connector/slack.rb', line 6 def initialize(bot_token, name) super() @headers = { 'Authorization' => "Bearer #{bot_token}" } @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/pechkin/connector/slack.rb', line 4 def name @name end |
Instance Method Details
#send_message(channel, message, message_desc) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pechkin/connector/slack.rb', line 13 def (channel, , ) text = CGI.unescape_html() = ['slack_attachments'] || {} if text.strip.empty? && .empty? return { channel: channel, code: 400, response: '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: channel, code: response.code.to_i, response: response.body } end |