Block Kit builders and limit validation. Builders return plain maps (atom keys)
ready for Noizu.Slack.Chat.post_message/4's :blocks.
alias Noizu.Slack.Blocks
blocks = [
Blocks.header("Deploy finished"),
Blocks.section("*api* rolled out", fields: ["*Env*\nprod", "*SHA*\n`abc123`"]),
Blocks.divider(),
Blocks.context(["triggered by <@U123>"]),
Blocks.actions([Blocks.button("Open", "open_run", url: "https://example.com")])
]
{:ok, blocks} = Blocks.validate(blocks)Limits enforced by validate/1
- at most 50 blocks per message — exceeding is an error;
- section
text≤ 3000 chars, each section field ≤ 2000 chars, header text ≤ 150 chars — overlong text is truncated with a…(truncated)marker; - at most 10 fields per section — exceeding is an error.
Summary
Functions
An actions block of interactive elements.
A button element. Options: :value, :url, :style ("primary" / "danger").
A context block; strings become mrkdwn elements, maps pass through.
A divider block.
A list of mrkdwn text objects for a section's :fields.
A header block (plain text).
An image block.
Block limit per message (50).
Section text limit (3000 chars).
A mrkdwn text object.
A plain_text text object (emoji enabled).
A section block. text may be a string (mrkdwn) or a text object. Options:
:fields (strings or text objects), :accessory (an element, e.g. button/3),
:block_id.
Truncates text to max characters (graphemes), ending with the marker when cut.
Truncation marker appended to overlong text.
Validates (and normalizes) a block list against Slack's limits. Overlong text is
truncated with the marker; structural violations return
{:error, %Error{tag: :blocks}}. Works on atom- or string-keyed blocks.
Types
Functions
An actions block of interactive elements.
A button element. Options: :value, :url, :style ("primary" / "danger").
A context block; strings become mrkdwn elements, maps pass through.
@spec divider() :: block()
A divider block.
A list of mrkdwn text objects for a section's :fields.
A header block (plain text).
An image block.
Block limit per message (50).
Section text limit (3000 chars).
@spec mrkdwn(String.t()) :: text_object()
A mrkdwn text object.
A plain_text text object (emoji enabled).
A section block. text may be a string (mrkdwn) or a text object. Options:
:fields (strings or text objects), :accessory (an element, e.g. button/3),
:block_id.
@spec truncate(String.t(), pos_integer()) :: String.t()
Truncates text to max characters (graphemes), ending with the marker when cut.
Truncation marker appended to overlong text.
@spec validate([block()]) :: {:ok, [block()]} | {:error, Noizu.Slack.Error.t()}
Validates (and normalizes) a block list against Slack's limits. Overlong text is
truncated with the marker; structural violations return
{:error, %Error{tag: :blocks}}. Works on atom- or string-keyed blocks.