- Description:
- sm is a minimal binary to send a message to a Slack channel.
- Owner:
- Murilo Ijanc'
- Last Change:
- Clone URL:
ssh://anon@ijanc.org/got.sm
Commit Briefs
Use vendored http library for HTTPS. (main)
- replace the libtls Conn, the ffi module, and the inline HTTP formatter with http::post - slack_post is six lines; parse_ok takes &str because http:: decodes Content-Length and Transfer-Encoding internally - drop -C link-arg=-ltls; vendor/http.rs carries #[link(name = "tls")] which propagates to dependents - vendor http at ssh://ijanc@ijanc.org/http commit ebd3a89
Auto-detect Block Kit payloads and post as blocks.
If the message parses as a non-empty JSON array whose first element is an object with a string "type" field, send it as a "blocks" payload with a static fallback "text" for push and legacy notifications. Any other input, including messages that happen to be valid JSON but do not match that shape, is sent verbatim as text.
Use vendored jackson library for request and response JSON.
Drop the hand-rolled json_escape() and the substring-based response scanner in favor of jackson's json_struct! macro. PostMessage and PostResponse capture the wire format as plain Rust structs and the generated ToJson/FromJson impls handle (de)serialisation, including escapes and optional fields via Option<T>. jackson lives under vendor/ as a single file and is built as a separate rlib linked via --extern, so sm.rs is still one rustc invocation away from a binary. vendor/VENDOR records the upstream commit so updates are a straightforward re-copy.
Document the Slack mrkdwn formatting that is handled server-side.
sm transmits the message body verbatim and Slack renders it using its own mrkdwn variant, which is similar to but not identical to CommonMark. Add a matching FORMATTING section to README.md and sm.1 pointing at the upstream reference so callers do not assume CommonMark syntax. Also exclude the local channels scratch file from the working tree.
Initial import of sm, a minimal Slack message CLI.
sm posts a single message to a Slack channel through the chat.postMessage API. TLS is provided by libtls over a raw TCP stream, and JSON is generated and parsed inline so there are no crate dependencies beyond the Rust standard library. The channel id and the message come from argv; a message of "-" is read from standard input. The token is taken from the SLACK_USER_TOKEN environment variable. sm exits 0 on success; on failure it exits non-zero and writes a diagnostic to standard error, distinguishing input, transport, and API errors.
Branches
Tree
| .gitignore | commits | blame |
| .rustfmt.toml | commits | blame |
| LICENSE | commits | blame |
| Makefile | commits | blame |
| README.md | commits | blame |
| sm.1 | commits | blame |
| sm.rs | commits | blame |
| vendor/ | |
README.md
sm - Slack Message
==================
sm is a minimal binary to send a message to a Slack channel.
Requirements
------------
In order to build sm you need rustc and libtls (LibreSSL).
Installation
------------
Edit Makefile to match your local setup (sm is installed into
the /usr/local/bin namespace by default).
Afterwards enter the following command to build and install sm:
make clean install
Running sm
----------
sm takes the channel id and the message, in this order, and posts
the message to that channel as the owner of SLACK_USER_TOKEN.
Exit status is 0 on success and non-zero on failure.
sm C03DEET2M18 "hello from sm"
The message may also be read from standard input by passing "-":
date | sm C03DEET2M18 -
Print the version:
sm -V
Formatting
----------
sm sends the message bytes verbatim. Slack renders the text as
its own mrkdwn flavor on the server side; the syntax is similar
to but not identical to CommonMark (e.g. `*bold*` instead of
`**bold**`). See the Slack formatting reference for the full
list:
https://api.slack.com/reference/surfaces/formatting
Block Kit
---------
If the message parses as JSON and is a non-empty array whose
first element is an object with a string "type" field, sm posts
it as a Block Kit "blocks" payload instead of plain text. A
static fallback "text" is sent alongside the blocks so push and
legacy notifications have something to display. Anything else,
including messages that happen to be valid JSON but do not match
that shape, is sent verbatim as text.
cat blocks.json | sm C03DEET2M18 -
See the Block Kit reference:
https://api.slack.com/reference/block-kit/blocks
Configuration
-------------
sm reads a single environment variable:
SLACK_USER_TOKEN Slack user token, e.g. xoxp-...
The token must have the chat:write scope for the target channel.
Download
--------
got clone ssh://ijanc@ijanc.org/sm
License
-------
ISC — see LICENSE.
