Sha256: e109664a3e1ca2b83db497e7cbeb3b068aaec423832f3603d046b4800171cb12

Contents?: true

Size: 899 Bytes

Versions: 13

Compression:

Stored size: 899 Bytes

Contents

require 'slack-ruby-client'

Slack.configure do |config|
  config.token = ENV['SLACK_API_TOKEN']
  config.logger = Logger.new(STDOUT)
  config.logger.level = Logger::INFO
  fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
end

client = Slack::RealTime::Client.new

client.on :hello do
  puts "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
end

client.on :message do |data|
  puts data

  client.typing channel: data.channel

  case data.text
  when 'bot hi' then
    client.message channel: data.channel, text: "Hi <@#{data.user}>!"
  when /^bot/ then
    client.message channel: data.channel, text: "Sorry <@#{data.user}>, what?"
  end
end

client.on :close do |_data|
  puts 'Connection closing, exiting.'
end

client.on :closed do |_data|
  puts 'Connection has been disconnected.'
end

client.start!

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
slack-ruby-client-0.10.0 examples/hi_real_time/hi.rb
slack-ruby-client-0.9.1 examples/hi_real_time/hi.rb
slack-ruby-client-0.9.0 examples/hi_real_time/hi.rb
slack-ruby-client-0.8.1 examples/hi_real_time/hi.rb
slack-ruby-client-0.8.0 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.9 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.8 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.7 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.6 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.5 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.4 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.3 examples/hi_real_time/hi.rb
slack-ruby-client-0.7.2 examples/hi_real_time/hi.rb