Sha256: 6c28d67838330b268621eed83eb4adaae987615614e28a50281263e0a1dd32cb

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

module SlackRubyBot
  class App < Server
    def initialize(options = {})
      SlackRubyBot.configure do |config|
        config.token = ENV['SLACK_API_TOKEN'] || raise("Missing ENV['SLACK_API_TOKEN'].")
        config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV['SLACK_RUBY_BOT_ALIASES']
      end
      Slack.configure do |config|
        config.token = SlackRubyBot.config.token
      end
      super
    end

    def config
      SlackRubyBot.config
    end

    def self.instance
      @instance ||= new
    end

    private

    def hello(client, _data)
      if client.team && client.self
        SlackRubyBot.configure do |config|
          config.url = "https://#{client.team.domain}.slack.com"
          config.team = client.team.name
          config.team_id = client.team.id
          config.user = client.self.name
          config.user_id = client.self.id
          logger.info "Welcome #{config.user} to the #{config.team} team."
        end
      end
      super
    end

    def reset!
      super
      SlackRubyBot.configure do |config|
        config.url = nil
        config.team = nil
        config.user = nil
        config.team_id = nil
        config.user_id = nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
slack-ruby-bot-0.12.0 lib/slack-ruby-bot/app.rb
slack-ruby-bot-0.11.2 lib/slack-ruby-bot/app.rb
slack-ruby-bot-0.11.1 lib/slack-ruby-bot/app.rb
slack-ruby-bot-0.11.0 lib/slack-ruby-bot/app.rb