WardrikSlack.API (wardrik_slack v0.1.0-rc.1)

Copy Markdown

Calls Slack's Web API.

Each call merges in the channel's :req_options, so tests can point it at Req.Test. Rate-limited, 5xx and dropped requests are retried up to five times, with backoff or as long as Slack says to wait.

Summary

Functions

Calls method with Req options.

Calls method with body as JSON. Returns Slack's reply, or its error.

Like post/4, with the bot token and :req_options of workspace.

Calls method with params as a form, as Slack's read methods expect. Drops nil params.

Like read/4, with the bot token and :req_options of workspace.

Returns the channel's :req_options. [] unless set.

Posts reply to a button press's response_url.

Functions

call(method, options)

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

Calls method with Req options.

Returns {:ok, reply} when Slack answers "ok": true, {:error, error} with Slack's error, {:error, {:status, status}} for any other status, or Req's error.

post(method, token, body, req_options \\ [])

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

Calls method with body as JSON. Returns Slack's reply, or its error.

post_in(workspace, method, body)

@spec post_in(WardrikChannel.Workspace.t(), String.t(), map()) ::
  {:ok, map()} | {:error, term()}

Like post/4, with the bot token and :req_options of workspace.

read(method, token, params, req_options \\ [])

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

Calls method with params as a form, as Slack's read methods expect. Drops nil params.

read_in(workspace, method, params)

@spec read_in(WardrikChannel.Workspace.t(), String.t(), map()) ::
  {:ok, map()} | {:error, term()}

Like read/4, with the bot token and :req_options of workspace.

req_options(channel)

@spec req_options(WardrikChannel.Channel.t()) :: keyword()

Returns the channel's :req_options. [] unless set.

respond(url, reply, req_options)

@spec respond(String.t() | nil, map(), keyword()) :: :ok

Posts reply to a button press's response_url.

The reply replaces the message, or is shown only to the person who pressed. Always returns :ok. A failure is logged, since the press was already acted on.