Class: ConsoleAgent::SlackBot

Inherits:
Object
  • Object
show all
Defined in:
lib/console_agent/slack_bot.rb

Instance Method Summary collapse

Constructor Details

#initializeSlackBot

Returns a new instance of SlackBot.

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/console_agent/slack_bot.rb', line 13

def initialize
  @bot_token = ConsoleAgent.configuration.slack_bot_token || ENV['SLACK_BOT_TOKEN']
  @app_token = ConsoleAgent.configuration.slack_app_token || ENV['SLACK_APP_TOKEN']
  @channel_ids = resolve_channel_ids

  raise ConfigurationError, "SLACK_BOT_TOKEN is required" unless @bot_token
  raise ConfigurationError, "SLACK_APP_TOKEN is required (Socket Mode)" unless @app_token
  raise ConfigurationError, "slack_allowed_usernames must be configured (e.g. ['alice'] or 'ALL')" unless ConsoleAgent.configuration.slack_allowed_usernames

  @bot_user_id = nil
  @sessions = {}       # thread_ts → { channel:, engine:, thread: }
  @user_cache = {}     # slack user_id → display_name
  @mutex = Mutex.new
end

Instance Method Details

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/console_agent/slack_bot.rb', line 28

def start
  @bot_user_id = slack_api("auth.test", token: @bot_token).dig("user_id")
  log_startup

  loop do
    run_socket_mode
    puts "Reconnecting in 5s..."
    sleep 5
  end
rescue Interrupt
  puts "\nSlackBot shutting down."
end