Design
Scope
The deck posts messages to a Slack™ channel through an Incoming Webhook: plain text with send, and rich messages built from Block Kit™ blocks (header, section, fieldsSection, contextBlock, actionsBlock with button, divider) starting from message and posted with sendMessage. render returns the JSON payload without sending it, and escape makes text from elsewhere safe for mrkdwn.
It is deliberately not a Slack client:
- No Web API. No bot or user tokens, no
chat.postMessage, no reading channels, no files, no threads. An Incoming Webhook is the smallest thing that lets a program notify a channel, and it needs no OAuth app install beyond creating the webhook. - No interactivity. Buttons are URL buttons only; handling block actions needs a request URL and a server, which is another program.
- Only the common blocks. Images, inputs, select menus and rich-text blocks are left out; the six blocks cover notifications.
- No client-side enforcement of Slack's limits (block count, text lengths). Slack answers an invalid payload with a
4xx, which reaches the caller as the response.
Decisions
- A deck, not a bundled module. A client for one vendor's service belongs in the deck ecosystem. The deck is one of the bundled modules that
jennifermoves out (M30.1 in its milestones, formerly M28.32). - Same surface as the module. The types and functions are those of the standard library's
slackmodule, so migrating changes only the import. Two additions differ:escape, and the webhook URL check. - The response is returned, not judged.
sendandsendMessagereturn thehttp.Response. Slack answers200with the bodyok; a revoked or unknown webhook is a4xxwith a body such asno_service, which the caller reads. A notifier usually logs a failure and carries on. - Immutable builder of pre-rendered blocks. A
Messageholds the fallbacktextand a list of block JSON fragments; every step returns a new message. Rendering each block when it is added keeps blocks of different shapes in one homogeneous list. Every string goes throughjson.encode. - Fallback text is optional but advised. Slack shows
textin notifications and in clients that do not render blocks;renderleaves out empty parts. - Escaping is explicit. Slack's mrkdwn turns
<...>into links and mentions (<!channel>,<@U123>) wherever the text came from.escapereplaces&,<and>with entities; it is a separate call so that a message meant to link or mention keeps working as it did in the module.
Errors
The deck throws Error{kind: "slack"} for one check of its own: a webhook URL that is not https://, or http:// to a loopback host, thrown before anything is sent, with the URL left out of the message.
Slack's answers are responses, not errors, so the deck has no error struct (as recorded for the @jennifer decks in M28.57). Transport failures come from http unchanged: "timeout", "closed", "limit", and on interpreters with transport error kinds (M28.65) a net.NetError of kind "net" for a refused connection, reset, failed lookup or TLS failure (older ones throw those as "runtime").
Security and limits
- The webhook URL is the credential. Anyone holding it can post to the channel. The docs tell callers to read it from the environment or a config file.
- No cleartext sends.
httpsends a plainhttp://URL to any host in the clear, so the deck refuses anything buthttps://.http://is allowed only to127.0.0.1,localhostand[::1], for a local test server. The host is taken from the authority after anyuser@part, sohttp://127.0.0.1@evil.example/is refused. - Untrusted text goes through
escapebefore it reaches a mrkdwn block; JSON encoding keeps it from changing the payload's structure. Button URLs are passed as given. - Response size, deadlines and redirects are
http's defaults; the deck adds no caps of its own and no retries.
Testing and validation
src/slack_test.j tests every block's rendered JSON (escaping included), escape, and sends through an httpd server on a loopback port that answers like a webhook: 200 ok on the expected path, 404 no_service otherwise. It also checks that every malformed or plain-http:// URL throws before a request goes out.
The tests never reach Slack. examples/post.j posts when SLACK_WEBHOOK_URL is set and only prints its payload otherwise, so CI runs it offline.
Known limitations and open questions
- Rate limits (
429withRetry-After) are left to the caller; the deck does not retry. - Webhooks cannot reply in threads or update messages; that needs the Web API, which is out of scope.
Dependencies on the interpreter
- The floor is
>=0.27.0, for the UTF-8 codec ofencoding.decodeandtesting.assertThrowsArgs. 0.26.0 deprecates the bundled module (M30.1) and itshttprefuses a URL without a valid scheme. httpneeds thenetcapability, so posting needs the defaultjenniferbinary; building and rendering messages also work onjennifer-tiny.- The tests use
httpdandtaskfor the loopback server.