Class: Slk::Api::Search

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

Overview

Wrapper for Slack search.* API endpoints Note: search.messages requires user tokens (xoxc/xoxs), NOT bot tokens (xoxb)

Instance Method Summary collapse

Constructor Details

#initialize(api_client, workspace) ⇒ Search

Returns a new instance of Search.



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

def initialize(api_client, workspace)
  @api = api_client
  @workspace = workspace
end

Instance Method Details

#messages(query:, count: 20, page: 1, sort: 'timestamp', sort_dir: 'desc') ⇒ Hash

Search for messages across channels and DMs

Parameters:

  • query (String)

    Search query with optional modifiers (in:, from:, before:, after:, etc.)

  • count (Integer) (defaults to: 20)

    Number of results per page (max 100)

  • page (Integer) (defaults to: 1)

    Page number (1-indexed)

  • sort (String) (defaults to: 'timestamp')

    Sort field: ‘score’ or ‘timestamp’

  • sort_dir (String) (defaults to: 'desc')

    Sort direction: ‘asc’ or ‘desc’

Returns:

  • (Hash)

    API response with messages.matches array



20
21
22
23
24
25
26
27
28
# File 'lib/slk/api/search.rb', line 20

def messages(query:, count: 20, page: 1, sort: 'timestamp', sort_dir: 'desc')
  @api.get(@workspace, 'search.messages', {
             query: query,
             count: [count, 100].min,
             page: page,
             sort: sort,
             sort_dir: sort_dir
           })
end