Sha256: da6c26f2d146996cd401c61e9438eacfe48e37d783b6bd7b2ef36865d9c45ea7

Contents?: true

Size: 955 Bytes

Versions: 13

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true
require 'slack-ruby-client'
require 'async'

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

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

threads = []

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 /hi/
      client.message channel: data.channel, text: "Hi <@#{data.user}>!"
    else
      client.message channel: data.channel, text: "Sorry <@#{data.user}>, what?"
    end
  end

  threads << client.start_async
end

threads.each(&:join)

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
slack-ruby-client-2.4.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-2.3.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-2.2.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-2.1.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-2.0.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-1.1.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-1.0.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-0.17.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-0.16.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-0.15.1 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-0.15.0 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-0.14.6 examples/hi_real_time_async_async/hi.rb
slack-ruby-client-0.14.5 examples/hi_real_time_async_async/hi.rb