Class: Slk::Api::Bots

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/api/bots.rb

Overview

Wrapper for Slack bots.info API endpoint

Instance Method Summary collapse

Constructor Details

#initialize(api_client, workspace, on_debug: nil) ⇒ Bots

Returns a new instance of Bots.



7
8
9
10
11
# File 'lib/slk/api/bots.rb', line 7

def initialize(api_client, workspace, on_debug: nil)
  @api = api_client
  @workspace = workspace
  @on_debug = on_debug
end

Instance Method Details

#get_name(bot_id) ⇒ String?

Get bot name by ID

Parameters:

  • bot_id (String)

    Bot ID starting with “B”

Returns:

  • (String, nil)

    Bot name or nil if not found



27
28
29
30
# File 'lib/slk/api/bots.rb', line 27

def get_name(bot_id)
  bot = info(bot_id)
  bot&.dig('name')
end

#info(bot_id) ⇒ Hash?

Look up bot information by ID

Parameters:

  • bot_id (String)

    Bot ID starting with “B”

Returns:

  • (Hash, nil)

    Bot info hash or nil if not found



16
17
18
19
20
21
22
# File 'lib/slk/api/bots.rb', line 16

def info(bot_id)
  response = @api.post_form(@workspace, 'bots.info', { bot: bot_id })
  response['bot'] if response['ok']
rescue ApiError => e
  @on_debug&.call("Bot lookup failed for #{bot_id}: #{e.message}")
  nil
end