Class: SlackSocketModeBot::Bot

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

Overview

Entry class for the gem, allows registering callbacks that will be triggered when the bot is mentioned

Instance Method Summary collapse

Constructor Details

#initialize(bot_token:, app_token:, logger: nil) ⇒ Bot

Returns a new instance of Bot.



9
10
11
12
13
14
15
16
17
18
# File 'lib/bot/bot.rb', line 9

def initialize(bot_token:, app_token:, logger: nil)
  @bot_token = bot_token
  @logger = logger || Logger.new($stdout)

  slack_web_client # init

  @socket_mode_client = Transport::SocketModeClient.new(
    app_token:, logger:, callback: method(:process_event)
  )
end

Instance Method Details

#on(match_regex, &block) ⇒ Object

Registers a callback for a matching regex



21
22
23
# File 'lib/bot/bot.rb', line 21

def on(match_regex, &block)
  (@handlers ||= []) << MentionHandler.new(match_regex, block)
end

#run!Object



25
26
27
# File 'lib/bot/bot.rb', line 25

def run!
  @socket_mode_client.run!
end