Slink.BlockKit (Slink v0.6.0)

Copy Markdown View Source

Plain functions that build Block Kit maps — no DSL, no macros.

Hand-writing block maps is the most verbose part of any bot. These builders return exactly the maps Slack expects, so they mix freely with hand-written ones and drop straight into reply/3's blocks: or a modal view:

import Slink.BlockKit

reply(context, "Ready to deploy?",
  blocks: [
    header("Deploy"),
    section("*prod* is 3 commits behind — ship it?"),
    actions([
      button("Deploy", action_id: "deploy", value: "prod", style: "primary"),
      button("Diff", action_id: "diff")
    ])
  ])

A modal for open_modal/2:

modal("Settings", [
  input("Email", plain_text_input(action_id: "email")),
  input("Plan", static_select("Choose…", [option("Free", "free"), option("Pro", "pro")],
    action_id: "plan"))
], submit: "Save", callback_id: "settings")

Text defaults to mrkdwn where Slack allows it (sections, context) and plain_text where Slack requires it (headers, buttons, titles). Every builder takes only the common options; anything more exotic, write the map — they compose.

Summary

Functions

An actions block holding interactive elements (buttons, selects…).

A button element. text is plain text.

A context block: small, muted text/images under a message.

A divider block.

A header block. text is plain text (Slack requires it here).

An image block. Options: title: (plain text), block_id:.

An input block (for modals): a labelled form element.

A mrkdwn text object: %{type: "mrkdwn", text: text}.

An option for a select menu: option("Pro plan", "pro").

A plain_text text object. Option: emoji: (default true).

A plain_text_input element (for input/3 blocks in modals).

A section block. text is mrkdwn (pass a text object to override).

A static_select menu. Build options with option/2.

Functions

actions(elements)

An actions block holding interactive elements (buttons, selects…).

button(text, opts \\ [])

A button element. text is plain text.

Options: action_id: (how the click arrives at your handler — see Slink.Event.action_id/1), value: (rides along with the click), style: ("primary" / "danger"), url:.

context(elements)

A context block: small, muted text/images under a message.

elements is a list of strings (each becomes mrkdwn) or element maps.

divider()

A divider block.

header(text)

A header block. text is plain text (Slack requires it here).

image(url, alt_text, opts \\ [])

An image block. Options: title: (plain text), block_id:.

input(label, element, opts \\ [])

An input block (for modals): a labelled form element.

Options: optional: (default false), hint: (plain text), block_id:.

modal(title, blocks, opts \\ [])

A modal view for Slink.open_modal/2 / Slink.API.open_view/3.

Options: submit: and close: (button labels, plain text), callback_id: (how the submission arrives — see Slink.Event.callback_id/1), private_metadata:.

mrkdwn(text)

A mrkdwn text object: %{type: "mrkdwn", text: text}.

option(text, value)

An option for a select menu: option("Pro plan", "pro").

plain_text(text, opts \\ [])

A plain_text text object. Option: emoji: (default true).

plain_text_input(opts \\ [])

A plain_text_input element (for input/3 blocks in modals).

Options: action_id:, multiline:, placeholder: (plain text), initial_value:.

section(text, opts \\ [])

A section block. text is mrkdwn (pass a text object to override).

Options: fields: (a list of strings — each becomes mrkdwn — or text objects), accessory: (an element, e.g. a button/2), block_id:.

static_select(placeholder, options, opts \\ [])

A static_select menu. Build options with option/2.

Options: action_id:, initial_option:.