Slackbox.Message (Slackbox v0.1.0)

Copy Markdown View Source

A Slack message with composable pipe builders — the Slack analogue of Swoosh.Email. The struct alone fully determines what the fake Slack dev UI renders, so message content lives here (not in per-call options).

A raw Slack JSON map may be supplied via :raw as an escape hatch.

Summary

Functions

Collect every action_id from the message's actions blocks, in order.

A Block Kit actions block wrapping interactive elements.

Set the Block Kit blocks for this message.

A Block Kit button element. Supported opts: :action_id, :value. Nil opts are dropped so the payload matches Slack's shape.

Build a new message from keyword/map attrs.

A Block Kit section block with mrkdwn text.

Set the fallback/notification text.

Post this message as a threaded reply to parent_ts.

Set the destination channel (e.g. "#alerts" or a channel id).

Serialize to a Slack Web API payload map (drops nil/empty fields).

Target user for post_ephemeral.

Toggle Slack link unfurling for this message.

Types

t()

@type t() :: %Slackbox.Message{
  attachments: [map()],
  blocks: [map()],
  channel: String.t() | nil,
  icon: String.t() | nil,
  metadata: map(),
  raw: map() | nil,
  reply_broadcast: boolean() | nil,
  text: String.t() | nil,
  thread_ts: String.t() | nil,
  ts: String.t() | nil,
  unfurl_links: boolean() | nil,
  unfurl_media: boolean() | nil,
  user: String.t() | nil,
  username: String.t() | nil
}

Functions

action_ids(message)

@spec action_ids(t()) :: [String.t()]

Collect every action_id from the message's actions blocks, in order.

actions(elements)

@spec actions([map()]) :: map()

A Block Kit actions block wrapping interactive elements.

blocks(msg, blocks)

@spec blocks(t(), [map()]) :: t()

Set the Block Kit blocks for this message.

button(text, opts \\ [])

@spec button(
  String.t(),
  keyword()
) :: map()

A Block Kit button element. Supported opts: :action_id, :value. Nil opts are dropped so the payload matches Slack's shape.

new(attrs \\ [])

@spec new(keyword() | map()) :: t()

Build a new message from keyword/map attrs.

section(text)

@spec section(String.t()) :: map()

A Block Kit section block with mrkdwn text.

text(msg, text)

@spec text(t(), String.t()) :: t()

Set the fallback/notification text.

thread(msg, parent_ts)

@spec thread(t(), String.t()) :: t()

Post this message as a threaded reply to parent_ts.

to_channel(msg, channel)

@spec to_channel(t(), String.t()) :: t()

Set the destination channel (e.g. "#alerts" or a channel id).

to_payload(m)

@spec to_payload(t()) :: map()

Serialize to a Slack Web API payload map (drops nil/empty fields).

to_user(msg, user)

@spec to_user(t(), String.t()) :: t()

Target user for post_ephemeral.

unfurl_links(msg, bool)

@spec unfurl_links(t(), boolean()) :: t()

Toggle Slack link unfurling for this message.