Slackblocks (slackblocks v2.8.0)
View SourceConstructs 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.
Like block_kit_builder_url/2, raising on invalid input.
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
@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.
Like block_kit_builder_url/2, raising on invalid input.
@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.
Like decode/2, raising on failure.
@spec encode(struct()) :: {:ok, binary()} | {:error, Exception.t()}
Validates before encoding. Direct Jason encoding may raise ValidationError.
Like encode/1, raising on failure.
@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.
Like from_map/2, raising on failure.
@spec spec_version() :: String.t()
The shared Slack Block Kit contract version implemented by this package.
@spec to_map(struct()) :: {:ok, map()} | {:error, Slackblocks.ValidationError.t()}
Returns a validated wire map with string keys and omitted optional nil fields.
Like to_map/1, raising on invalid values.
@spec validate(struct()) :: :ok | {:error, Slackblocks.ValidationError.t()}
Checks the complete value, including receiving context and payload totals.
@spec version() :: String.t()
The version of the installed package.