Class: BotMob::Networks::Slack::Connection
- Inherits:
-
Connection
- Object
- Connection
- BotMob::Networks::Slack::Connection
- Defined in:
- lib/bot_mob/networks/slack/connection.rb
Overview
# BotMob::Networks::Slack::Connection
Handles all the connection details between a bot and Slack
Instance Attribute Summary collapse
-
#bot ⇒ Object
readonly
Returns the value of attribute bot.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Attributes inherited from Connection
Instance Method Summary collapse
- #client ⇒ Object
- #deliver(outbound_message, options = {}) ⇒ Object
-
#initialize(bot, options = {}) ⇒ Connection
constructor
A new instance of Connection.
Methods inherited from Connection
Constructor Details
#initialize(bot, options = {}) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 |
# File 'lib/bot_mob/networks/slack/connection.rb', line 10 def initialize(bot, = {}) @bot = bot @token = [:token] raise BotMob::NetworkConnectionError, 'Slack connection requires a :token parameter' if @token.nil? end |
Instance Attribute Details
#bot ⇒ Object (readonly)
Returns the value of attribute bot.
8 9 10 |
# File 'lib/bot_mob/networks/slack/connection.rb', line 8 def bot @bot end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/bot_mob/networks/slack/connection.rb', line 8 def token @token end |
Instance Method Details
#client ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/bot_mob/networks/slack/connection.rb', line 27 def client @client ||= begin client = ::Slack::Web::Client.new(token: token) client.auth_test client end end |
#deliver(outbound_message, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bot_mob/networks/slack/connection.rb', line 16 def deliver(, = {}) BotMob.logger.info(" Sending to Slack: \"#{options.inspect}\"\n") BotMob.logger.info(" Text: \"#{outbound_message.body.inspect}\"\n") client.chat_postMessage( channel: .channel, text: .body, as_user: true ) end |