Class: ChatNotifier::ThreadStore::SlackMetadata

Inherits:
ChatNotifier::ThreadStore show all
Defined in:
lib/chat_notifier/thread_store/slack_metadata.rb

Overview

Uses the Slack channel itself as the store: parents are posted with message metadata carrying the thread key; find scans recent history.

Constant Summary collapse

EVENT_TYPE =
"chat_notifier_thread"
HISTORY_URL =
"https://slack.com/api/conversations.history"
HISTORY_LIMIT =
200

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chatter:) ⇒ SlackMetadata

Returns a new instance of SlackMetadata.



12
13
14
# File 'lib/chat_notifier/thread_store/slack_metadata.rb', line 12

def initialize(chatter:)
  @chatter = chatter
end

Instance Attribute Details

#chatterObject (readonly)

Returns the value of attribute chatter.



16
17
18
# File 'lib/chat_notifier/thread_store/slack_metadata.rb', line 16

def chatter
  @chatter
end

Instance Method Details

#find(key, process: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chat_notifier/thread_store/slack_metadata.rb', line 18

def find(key, process: nil)
  response = fetch_history(process)
  unless response["ok"]
    ChatNotifier.logger.error(
      "ChatNotifier: thread lookup failed: #{response.fetch("error", "unrecognized response")}"
    )
    return nil
  end
  message = matching_message(response, key)
  return nil unless message

  ThreadRef.new(ts: message["ts"], status: message.dig("metadata", "event_payload", "status"))
rescue => error
  # A failed lookup must never abort posting the notification itself.
  ChatNotifier.logger.error("ChatNotifier: thread lookup failed: #{error.message}")
  nil
end

#record(key, ref) ⇒ Object

Posting the parent with metadata is the record; nothing separate to do.



37
# File 'lib/chat_notifier/thread_store/slack_metadata.rb', line 37

def record(key, ref) = nil