Class: Socrates::Bots::SlackBot
- Inherits:
-
Object
- Object
- Socrates::Bots::SlackBot
- Defined in:
- lib/socrates/bots/slack_bot.rb
Instance Method Summary collapse
-
#initialize(state_factory:) ⇒ SlackBot
constructor
A new instance of SlackBot.
- #start ⇒ Object
Constructor Details
#initialize(state_factory:) ⇒ SlackBot
Returns a new instance of SlackBot.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/socrates/bots/slack_bot.rb', line 6 def initialize(state_factory:) Slack.configure do |config| config.token = ENV["SLACK_API_TOKEN"] config.logger = Logger.new(STDOUT) config.logger.level = Logger::INFO raise "Missing ENV['SLACK_API_TOKEN']!" unless config.token end @slack_client = Slack::RealTime::Client.new @adapter = SlackAdapter.new(@slack_client) @dispatcher = Core::Dispatcher.new(adapter: @adapter, state_factory: state_factory) end |
Instance Method Details
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/socrates/bots/slack_bot.rb', line 20 def start @slack_client.on :message do |data| # puts "> #{data}" # When first connecting, Slack may resend the last message. Ignore it... next if data.reply_to.present? @dispatcher.dispatch(message: data.text, context: data) end @slack_client.start! end |