Launching a real-time Slack bot using the slack-ruby-client gem

require "slack-ruby-client"

Slack.configure do |config|
  config.token = "[your unique Slack token]"
end


client = Slack::RealTime::Client.new 

client.on :hello do
  puts 'Successfully connected.'
end

client.on :message do |data|
  # respond to messages
end

client.start!

To use a real-time Slack bot you must first create a bot from the Slack build section. There you will get an API token to launch a bot from your Ruby script.

The above code simply demonstrates logging into Slack as a bot which appears like any other team member who is online.

Resources