Slackbox.Simulator (Slackbox v0.1.0)

Copy Markdown View Source

Turns a UI button click in the fake-Slack dashboard into a realistic inbound Slack interaction.

When a user clicks a Block Kit button, Slack POSTs a block_actions interaction payload to your app's interactivity request URL (as application/x-www-form-urlencoded with a single payload field). Your app replies out-of-band by POSTing to the interaction's response_url.

click/3 reproduces that exact flow over real HTTP against a configured endpoint, wiring in a response_url that routes back into Slackbox.Store (see Slackbox.ResponsePlug) so the message can be updated live.

Summary

Functions

Build the Slack block_actions interaction payload for action on entry.

Wrap event in a Slack event_callback envelope (Events API). Exposed for testing.

Build a Slack view_closed interaction payload. opts carries :user. Exposed for testing.

Build a Slack view_submission interaction payload.

Simulate a click on action for entry, POSTing a block_actions interaction to config.interactivity_url over real HTTP.

Simulate closing a modal, POSTing a view_closed interaction to config.interactivity_url. Signed when config.signing_secret is set.

Deliver event to the app's Events API URL (config.events_url) as a JSON body. Signed over the raw JSON body when config.signing_secret is set.

Simulate a modal submission, POSTing a view_submission interaction to config.interactivity_url. Signed when config.signing_secret is set.

Functions

build_block_actions(entry, action, opts)

@spec build_block_actions(map(), map(), map()) :: map()

Build the Slack block_actions interaction payload for action on entry.

action is a map with "action_id" and optional "value". opts carries :user and :response_url. Exposed for testing.

build_event_callback(event)

@spec build_event_callback(map()) :: map()

Wrap event in a Slack event_callback envelope (Events API). Exposed for testing.

build_view_closed(view_id, view, opts)

@spec build_view_closed(String.t(), map(), map()) :: map()

Build a Slack view_closed interaction payload. opts carries :user. Exposed for testing.

build_view_submission(view_id, view, state, opts)

@spec build_view_submission(String.t(), map(), map(), map()) :: map()

Build a Slack view_submission interaction payload.

Merges view_id and the collected state (Block Kit state.values) into view. opts carries :user. Exposed for testing.

click(entry, action, config)

@spec click(map(), map(), map()) :: {:ok, integer()} | {:error, term()}

Simulate a click on action for entry, POSTing a block_actions interaction to config.interactivity_url over real HTTP.

config keys: :interactivity_url, :response_base, :signing_secret (nil = unsigned), :user (default "U_DEMO"). Returns {:ok, status} on a completed request or {:error, reason} — it never raises into the caller.

close_view(view_id, view, config)

@spec close_view(String.t(), map(), map()) :: {:ok, integer()} | {:error, term()}

Simulate closing a modal, POSTing a view_closed interaction to config.interactivity_url. Signed when config.signing_secret is set.

send_event(event, config)

@spec send_event(map(), map()) :: {:ok, integer()} | {:error, term()}

Deliver event to the app's Events API URL (config.events_url) as a JSON body. Signed over the raw JSON body when config.signing_secret is set.

submit_view(view_id, view, state, config)

@spec submit_view(String.t(), map(), map(), map()) ::
  {:ok, integer()} | {:error, term()}

Simulate a modal submission, POSTing a view_submission interaction to config.interactivity_url. Signed when config.signing_secret is set.