Class: Relax::Bot

Inherits:
Base
  • Object
show all
Defined in:
lib/relax/bot.rb

Class Method Summary collapse

Methods inherited from Base

redis

Class Method Details

.relax_bots_keyObject



27
28
29
# File 'lib/relax/bot.rb', line 27

def self.relax_bots_key
  ENV['RELAX_BOTS_KEY']
end

.relax_bots_pubsubObject



23
24
25
# File 'lib/relax/bot.rb', line 23

def self.relax_bots_pubsub
  ENV['RELAX_BOTS_PUBSUB']
end

.start!(team_uid, token) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/relax/bot.rb', line 6

def self.start!(team_uid, token)
  if relax_bots_key.nil? || relax_bots_key == ""
    raise BotsKeyNotSetError, "Environment Variable RELAX_BOTS_KEY is not set"
  end

  if relax_bots_pubsub.nil? || relax_bots_pubsub == ""
    raise BotsPubsubNotSetError, "Environment Variable RELAX_BOTS_PUBSUB is not set"
  end

  redis.with do |conn|
    conn.multi do
      conn.hset(relax_bots_key, team_uid, {team_id: team_uid, token: token}.to_json)
      conn.publish(relax_bots_pubsub, {type: 'team_added', team_id: team_uid}.to_json)
    end
  end
end