Slackbox.Adapters.Live (Slackbox v0.1.0)

Copy Markdown View Source

Live adapter. A thin, owned Req-based Slack Web API client — the SAME app code that renders in the fake dev UI (Local) actually posts to Slack when this adapter is configured.

# config/prod.exs
config :my_app, MyApp.Slack,
  adapter: Slackbox.Adapters.Live,
  token: System.get_env("SLACK_BOT_TOKEN")

Config keys

Read from the merged config keyword list (adapter config plus per-call opts):

  • :token — Slack bot token (xoxb-...). Required for Web API methods (post_message, post_ephemeral, update, delete, open_view); a missing token yields {:error, :missing_token}. Not needed for respond, which posts to a signed response_url.
  • :base_url — Slack Web API base. Defaults to "https://slack.com/api"; override it to point at a fake server.
  • :req_options — keyword list merged into every Req request. Handy for a test plug: stub, or for app-level timeouts/retries. Defaults to [].

Return shapes

  • post_message / update{:ok, %{ts: ..., channel: ...}}
  • open_view{:ok, %{view_id: ...}}
  • post_ephemeral{:ok, %{}} (with :message_ts when Slack returns one)
  • delete / respond{:ok, %{}}
  • Slack API failure → {:error, {:slack, reason}}
  • HTTP 429 → {:error, {:rate_limited, retry_after_seconds | nil}}

  • respond non-200 → {:error, {:http, status}}
  • transport error → {:error, exception}

Errors are always returned as tagged tuples; the adapter never raises into the caller.