Sha256: 3353b83690423a3bedd96d41bae653de145757e54494bf5e500d8f6c143ee5e6

Contents?: true

Size: 885 Bytes

Versions: 26

Compression:

Stored size: 885 Bytes

Contents

require 'slack-ruby-client'

fail 'Missing ENV[SLACK_API_TOKENS]!' unless ENV.key?('SLACK_API_TOKENS')

$stdout.sync = true
logger = Logger.new($stdout)
logger.level = Logger::DEBUG

ENV['SLACK_API_TOKENS'].split.each do |token|
  logger.info "Starting #{token[0..12]} ..."

  client = Slack::RealTime::Client.new(token: token)

  client.on :hello do
    logger.info "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|
    logger.info 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.start_async
end

loop do
  Thread.pass
end

Version data entries

26 entries across 13 versions & 1 rubygems

Version Path
slack-ruby-client-0.10.0 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.10.0 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.9.1 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.9.1 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.9.0 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.9.0 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.8.1 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.8.1 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.8.0 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.8.0 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.7.9 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.7.9 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.7.8 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.7.8 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.7.7 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.7.7 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.7.6 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.7.6 examples/hi_real_time_async_eventmachine/hi.rb
slack-ruby-client-0.7.5 examples/hi_real_time_async_celluloid/hi.rb
slack-ruby-client-0.7.5 examples/hi_real_time_async_eventmachine/hi.rb