Class: Slk::Services::MessageResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/services/message_resolver.rb

Overview

Resolves and fetches individual messages by timestamp from channels Used by activity feed, saved items, and other features that need to fetch message content by ts.

Instance Method Summary collapse

Constructor Details

#initialize(conversations_api:, on_debug: nil) ⇒ MessageResolver

Returns a new instance of MessageResolver.



9
10
11
12
# File 'lib/slk/services/message_resolver.rb', line 9

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

Instance Method Details

#fetch_by_ts(channel_id, message_ts) ⇒ Hash?

Fetch a single message by its timestamp from a channel

Parameters:

  • channel_id (String)

    The channel ID

  • message_ts (String)

    The message timestamp

Returns:

  • (Hash, nil)

    The message data or nil if not found



18
19
20
21
22
23
24
25
26
# File 'lib/slk/services/message_resolver.rb', line 18

def fetch_by_ts(channel_id, message_ts)
  response = fetch_message_history(channel_id, message_ts)
  return nil unless response['ok'] && response['messages']&.any?

  response['messages'].find { |msg| msg['ts'] == message_ts }
rescue ApiError => e
  @on_debug&.call("Could not fetch message #{message_ts} from #{channel_id}: #{e.message}")
  nil
end