Sha256: 04143925c0aa4848b87eb1ee2f15d2cd515cde8494319d6e104e3f0745612e30

Contents?: true

Size: 900 Bytes

Versions: 10

Compression:

Stored size: 900 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
  raise '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

10 entries across 10 versions & 1 rubygems

Version Path
slack-ruby-client-0.14.4 examples/hi_real_time/hi.rb
slack-ruby-client-0.14.3 examples/hi_real_time/hi.rb
slack-ruby-client-0.14.2 examples/hi_real_time/hi.rb
slack-ruby-client-0.14.1 examples/hi_real_time/hi.rb
slack-ruby-client-0.14.0 examples/hi_real_time/hi.rb
slack-ruby-client-0.13.1 examples/hi_real_time/hi.rb
slack-ruby-client-0.13.0 examples/hi_real_time/hi.rb
slack-ruby-client-0.12.0 examples/hi_real_time/hi.rb
slack-ruby-client-0.11.1 examples/hi_real_time/hi.rb
slack-ruby-client-0.11.0 examples/hi_real_time/hi.rb