Slackblocks (slackblocks v2.8.0)

View Source

Constructs and validates Slack Block Kit values without sending HTTP requests.

Use model constructors for text conveniences and to_map/1 for a complete validated Slack payload. Every output boundary rechecks edited structs.

Examples

iex> Slackblocks.Blocks.Divider.new!() |> Slackblocks.to_map!()
%{"type" => "divider"}

iex> {:error, error} = Slackblocks.Blocks.Section.new([])
iex> error.category
:missing_required

Summary

Functions

Returns a Block Kit Builder URL without making network requests.

Decodes JSON without atomizing keys; rejects duplicate keys and lossy numbers.

Like decode/2, raising on failure.

Validates before encoding. Direct Jason encoding may raise ValidationError.

Like encode/1, raising on failure.

Reconstructs a known model or role from wire maps; optional defaults stay omitted.

Like from_map/2, raising on failure.

The shared Slack Block Kit contract version implemented by this package.

Returns a validated wire map with string keys and omitted optional nil fields.

Like to_map/1, raising on invalid values.

Checks the complete value, including receiving context and payload totals.

The version of the installed package.

Functions

block_kit_builder_url(value, options \\ [])

@spec block_kit_builder_url(
  struct() | list() | map(),
  keyword()
) :: {:ok, binary()} | {:error, Slackblocks.ValidationError.t()}

Returns a Block Kit Builder URL without making network requests.

Accepts a block, list of blocks, message/view payload, or explicit string-keyed JSON map. Blocks are wrapped in blocks; maps are validated as JSON data only. Optional team_id is encoded as one URL path segment. The fragment preserves list order and Unicode; JSON object key order is unspecified.

block_kit_builder_url!(value, options \\ [])

@spec block_kit_builder_url!(
  struct() | list() | map(),
  keyword()
) :: binary()

Like block_kit_builder_url/2, raising on invalid input.

decode(selector, json)

@spec decode(module() | atom(), binary()) :: {:ok, struct()} | {:error, Exception.t()}

Decodes JSON without atomizing keys; rejects duplicate keys and lossy numbers.

An application that compiled Jason before installing Decimal must run mix deps.compile jason --force in each build environment, then rebuild its release. Missing compile-time Decimal support returns an actionable ArgumentError in the tagged result; decode!/2 raises it.

decode!(selector, json)

@spec decode!(module() | atom(), binary()) :: struct()

Like decode/2, raising on failure.

encode(value)

@spec encode(struct()) :: {:ok, binary()} | {:error, Exception.t()}

Validates before encoding. Direct Jason encoding may raise ValidationError.

encode!(value)

@spec encode!(struct()) :: binary()

Like encode/1, raising on failure.

from_map(selector, wire)

@spec from_map(module() | atom(), map()) ::
  {:ok, struct()} | {:error, Slackblocks.ValidationError.t()}

Reconstructs a known model or role from wire maps; optional defaults stay omitted.

from_map!(selector, wire)

@spec from_map!(module() | atom(), map()) :: struct()

Like from_map/2, raising on failure.

spec_version()

@spec spec_version() :: String.t()

The shared Slack Block Kit contract version implemented by this package.

to_map(value)

@spec to_map(struct()) :: {:ok, map()} | {:error, Slackblocks.ValidationError.t()}

Returns a validated wire map with string keys and omitted optional nil fields.

to_map!(value)

@spec to_map!(struct()) :: map()

Like to_map/1, raising on invalid values.

validate(value)

@spec validate(struct()) :: :ok | {:error, Slackblocks.ValidationError.t()}

Checks the complete value, including receiving context and payload totals.

version()

@spec version() :: String.t()

The version of the installed package.