Slackbox.Store (Slackbox v0.1.0)

Copy Markdown View Source

In-memory store of Slack messages for the fake-Slack dev UI.

A GenServer that keeps an ordered list of entries (insertion order). Each entry is a map: %{ts:, channel:, message:, raw:, at:}. On every put/1 and clear/0 it broadcasts {:slackbox_store, op, entry_or_nil} on the "slackbox" topic of the Slackbox.PubSub server — but only when that PubSub server is actually running, so the store stays usable in plain tests.

Summary

Functions

Apply a Slack response payload to the message a token points at.

Returns a specification to start this module under a supervisor.

Drop every stored message.

Close the modal identified by view_id, broadcasting {:slackbox_store, :view_close, view_id}.

List every channel that has at least one message, in insertion order.

List the entries for a channel, in insertion order.

List the currently open modal views, in insertion order (newest last).

Open a modal view for trigger_id. Generates a view_id, appends a view entry, broadcasts {:slackbox_store, :view_open, entry}, and returns %{view_id: view_id} — mirroring Slack's views.open response.

Store a message. Assigns a ts if the message has none, computes the raw Slack payload, appends an entry, and returns %{ts:, channel:}.

Register a response_url callback token for the entry identified by {channel, ts}. Returns an opaque random token; a later apply_response/2 with that token updates the corresponding message. Mirrors Slack's response_url mechanism for the inbound simulation loop.

Start the store (registered under its module name by default).

Types

entry()

@type entry() :: %{
  ts: String.t(),
  channel: String.t() | nil,
  message: Slackbox.Message.t(),
  raw: map(),
  at: integer()
}

view()

@type view() :: %{view_id: String.t(), trigger_id: String.t(), view: map()}

Functions

apply_response(token, response_map)

@spec apply_response(String.t(), map()) :: :ok | {:error, :not_found}

Apply a Slack response payload to the message a token points at.

response_map["text"] overrides the message text when present and response_map["blocks"] overrides the blocks when present; the raw payload is recomputed and a {:slackbox_store, :update, entry} broadcast is emitted. Returns {:error, :not_found} for an unknown token.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Drop every stored message.

close_view(view_id)

@spec close_view(String.t()) :: :ok

Close the modal identified by view_id, broadcasting {:slackbox_store, :view_close, view_id}.

list_channels()

@spec list_channels() :: [String.t()]

List every channel that has at least one message, in insertion order.

list_messages(channel)

@spec list_messages(String.t() | nil) :: [entry()]

List the entries for a channel, in insertion order.

list_views()

@spec list_views() :: [view()]

List the currently open modal views, in insertion order (newest last).

open_view(trigger_id, view)

@spec open_view(String.t(), map()) :: %{view_id: String.t()}

Open a modal view for trigger_id. Generates a view_id, appends a view entry, broadcasts {:slackbox_store, :view_open, entry}, and returns %{view_id: view_id} — mirroring Slack's views.open response.

put(message)

@spec put(Slackbox.Message.t()) :: %{ts: String.t(), channel: String.t() | nil}

Store a message. Assigns a ts if the message has none, computes the raw Slack payload, appends an entry, and returns %{ts:, channel:}.

register_response(channel, ts)

@spec register_response(String.t() | nil, String.t()) :: String.t()

Register a response_url callback token for the entry identified by {channel, ts}. Returns an opaque random token; a later apply_response/2 with that token updates the corresponding message. Mirrors Slack's response_url mechanism for the inbound simulation loop.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the store (registered under its module name by default).