Skip to content
Jennifer Programming Language

slack API reference

Post messages to a Slack channel through an Incoming Webhook, on top of the http client - a sibling of gotify / discord. send(webhookUrl, text) posts a plain message; the message builder assembles a richer payload from Slack Block Kit blocks (section / header / divider) and sendMessage posts it. Needs the default jennifer binary (uses net via http). The webhook URL is a secret belonging to the caller - read it from the environment or a config file; never commit it.

Import with import "slack.j" as slack;. See the slack guide for prose and examples.

Functions

slack.actionsBlock(m as Message, buttons as list of string)

Add an actions block from one or more buttons (built with button). Returns a fresh message.

Parameters

  • m {Message} - the message
  • buttons {list of string} - pre-rendered button fragments (see button)

Returns {Message} - a message with the actions block appended

slack.button(text as string, url as string)

Build a single URL button element for an actions block. Returns the pre-rendered button JSON fragment; pass a list of these to actionsBlock.

Parameters

  • text {string} - the button label (plain text)
  • url {string} - the URL the button opens

Returns {string} - the button JSON fragment

slack.contextBlock(m as Message, text as string)

Add a context block (small, muted helper text in mrkdwn). Returns a fresh message.

Parameters

  • m {Message} - the message
  • text {string} - the context text (mrkdwn)

Returns {Message} - a message with the context block appended

slack.divider(m as Message)

Add a divider block (a horizontal rule). Returns a fresh message.

Parameters

  • m {Message} - the message

Returns {Message} - a message with the divider appended

slack.fieldsSection(m as Message, fields as list of string)

Add a section block laid out as two-column fields (each entry rendered as mrkdwn). Slack packs the fields into a two-column grid. Returns a fresh message.

Parameters

  • m {Message} - the message
  • fields {list of string} - the field texts (mrkdwn), in order

Returns {Message} - a message with the fields section appended

slack.header(m as Message, heading as string)

Add a header block (plain text, bold and large). Returns a fresh message.

Parameters

  • m {Message} - the message
  • heading {string} - the header text (plain text)

Returns {Message} - a message with the header appended

slack.message()

Start an empty rich message (no fallback text, no blocks).

Returns {Message} - a fresh message

slack.render(m as Message)

Render a message to its JSON payload string.

Parameters

  • m {Message} - the message

Returns {string} - the JSON payload Slack expects

slack.section(m as Message, markdown as string)

Add a section block (Slack mrkdwn). Returns a fresh message.

Parameters

  • m {Message} - the message
  • markdown {string} - the section body (mrkdwn)

Returns {Message} - a message with the section appended

slack.send(webhookUrl as string, text as string)

Post a plain-text message to a Slack Incoming Webhook.

Parameters

  • webhookUrl {string} - the Incoming Webhook URL
  • text {string} - the message text (Slack mrkdwn)

Returns {http.Response} - Slack answers 200 with body "ok" on success

slack.sendMessage(webhookUrl as string, m as Message)

Post a built rich message to a Slack Incoming Webhook.

Parameters

  • webhookUrl {string} - the Incoming Webhook URL
  • m {Message} - the message to send

Returns {http.Response} - Slack answers 200 with body "ok" on success

slack.text(m as Message, text as string)

Set the top-level fallback text (shown in notifications and by clients that do not render blocks). Returns a fresh message.

Parameters

  • m {Message} - the message
  • text {string} - the fallback text

Returns {Message} - a message with the fallback text set

Structs

slack.Message

A rich message under construction: a fallback text (shown in notifications) plus a list of pre-rendered Block Kit block JSON fragments.

FieldTypeDescription
textstringthe top-level fallback / notification text ("" to omit)
blockslist of stringpre-rendered block JSON fragments