Sha256: 0870515c3c83e640962041562e4ad9bbe0f1590a08d7ba754c40e7df68b4700c

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module SlackRubyBot
  class App < Server
    def config
      SlackRubyBot.config
    end

    def self.instance
      @instance ||= begin
        configure!
        new(token: SlackRubyBot.config.token)
      end
    end

    def self.configure!
      SlackRubyBot.configure do |config|
        config.token = ENV['SLACK_API_TOKEN'] if ENV.key?('SLACK_API_TOKEN')
        raise('Missing Slack API Token.') unless config.token.present?

        config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV.key?('SLACK_RUBY_BOT_ALIASES')
      end
      Slack.configure do |config|
        config.token = SlackRubyBot.config.token
      end
    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

3 entries across 3 versions & 1 rubygems

Version Path
slack-ruby-bot-0.16.1 lib/slack-ruby-bot/app.rb
slack-ruby-bot-0.16.0 lib/slack-ruby-bot/app.rb
slack-ruby-bot-0.15.0 lib/slack-ruby-bot/app.rb