scorpiox-bot-plugin-ntfy
←README.mdmarkdown
151 lines · 8 KBHEAD
BlameDownload

ntfy — SCORPIOX BOT Push & Pub/Sub Channel Connector

plugin_ntfy (scorpiox-bot-plugin-oss-ntfy) is a clean-room, zero-dependency,

pure C99 connector for ntfy — the pub/sub-over-HTTP push

notification tool. It is one static binary with five modes, following the

SCORPIOX BOT plugin_<name> convention:

Mode Trigger What it does
Discovery --meta / SX_PLUGIN_META=1 one line of JSON: {"name":"ntfy","desc":"Push channel", "kind":"hybrid","mcp":true,"daemon":true,...}
Setup UI GET (CGI) dark/light Setup & Topic Pairing panel (bot theme tokens, sx-theme handoff, zero external assets)
Control API ?action=… / POST JSON config, test/send, pending/approve/deny, start/stop, status, logs — all behind require_node_auth()
MCP tool --mcp stdio JSON-RPC 2.0 MCP server exposing `ntfy_send` so the agent can push alerts and "task finished" pings to your phone
Channel gateway --daemon subscribes to <server>/<topic>/json (NDJSON), bridges approved inbound messages to the node's POST /inbox, and publishes the agent's newest assistant reply back to the publish topic

What it is for

  • Agent → phone: give your agent a ntfy_send tool. Alerts, build results,

"the long job is done" — delivered as a normal ntfy push (title, priority 1–5,

emoji tags, self-hosted server or https://ntfy.sh).

  • Phone → agent: point any ntfy client (the phone app, `curl -d hi

ntfy.sh/mytopic`, a script) at your subscribe topic. Messages from senders

you approved are injected into a SCORPIOX BOT session through the loopback

/inbox API; the agent's reply is published back to your publish topic and

arrives as a push. It is a two-way chat channel carried by plain HTTP.

Security model (read this)

  • ntfy has no sender identity. The user field is the publisher's own

claim and tags are free text. The connector therefore derives an opaque

identity — sha256("v1|<topic>|<user>|<tags lowercased>") — and treats it

as a name to approve, never as authentication.

  • Default-deny pairing. The first message from an unknown sender is

never forwarded to /inbox. The sender is held in a pending queue and

gets a challenge on the publish topic: open the plugin UI and approve it, or

have the sender publish exactly PAIR <8-char code> on the subscribe topic.

  • Anti-self-loop. Everything this plugin publishes carries a fixed tag

(scorpiox), an X-Source-Id, and its message id is remembered. ntfy

echoes your own publishes back on the subscription — the bridge ignores

them, so the channel cannot talk to itself.

  • Secrets are write-only. The ntfy bearer_token and the node

bot_password are stored at mode 0600 and never returned by any API

response — only has_bearer / has_bot_password booleans. A blank token

field means "leave it"; __clear__ wipes it.

  • TLS fails closed. HTTPS is verified against a bundled root store

(src/ca_bundle_pem.h) with hostname checking. A private-CA relay needs an

explicit ca_file or an explicit SPKI pin (allowed_pins, hex SHA-256 of

the leaf's SubjectPublicKeyInfo). The only no-verification mode is the

environment variable NTFY_TLS_INSECURE=1 — never a stored value, never an

HTTP parameter. Plain http:// is refused for non-loopback servers (a

bearer token would travel in the clear).

  • The node bridge is loopback-only. bot_api_url must be

http://127.0.0.1:… or http://localhost:…; the node password never

leaves the machine.

  • State lives in ~/.scorpiox/connectors/plugin_ntfy/

(/workspace/.scorpiox/connectors/… on BotCloud,

%LOCALAPPDATA%\scorpiox\connectors\… on Windows), all files mode 0600:

config.json, pairing.json-equivalents (pending.json, approved.json,

sent.json), status.json, daemon.log, daemon.pid. Override with

SX_CONNECTORS_DIR=/path (the suite uses this).

Configuration

Open the plugin from SCORPIOX BOT (Settings → Plugins → ntfy, or the node at

/plugin_ntfy). Fields:

Field Meaning
server_url ntfy server, default https://ntfy.sh; self-hosted http(s)://… also fine
topic subscribe topic — where humans/scripts send messages to the agent
publish_topic where the bot publishes from (defaults to topic)
target_session SCORPIOX BOT session id that receives approved messages
bot_api_url node API, loopback only (default http://127.0.0.1:8150)
bot_password node password for X-Bot-Password (write-only)
bearer_token optional Bearer … / Basic … value for a protected ntfy server (write-only)
priority, tags, title_prefix, reply_prefix, markdown how replies look as pushes
allow_all off by default — on, it skips pairing (anyone who knows the topic can talk to your agent; don't)
pairing_code_enabled allow senders to self-pair with PAIR <code>
ca_file, allowed_pins private-CA / pin support

The Setup tab also exposes the test-notification button, and the Pairing tab

lists every held sender with its sample message and code so approval is a

click, not a hex-entry.

The MCP tool

--mcp speaks line-delimited JSON-RPC 2.0 over stdio (what scorpiox-mcp /

sx-connector-mcp speak):

--> {"jsonrpc":"2.0","id":2,"method":"tools/list"}
<-- {"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"ntfy_send", ...}]}}

--> {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"ntfy_send",
     "arguments":{"message":"nightly build green","title":"CI","priority":4,"tags":"white_check_mark"}}}
<-- {"jsonrpc":"2.0","id":3,"result":{"content":[{"type":"text",
     "text":"published to mytopic (id abc123, priority 4)"}],"isError":false}}

ntfy_send(message, title?, priority?, tags?, topic?). Register it as a

single server (the sx-connector-mcp aggregator reads mcp_plugins.json) —

never one MCP server per plugin.

Building

make            # native  -> ./plugin_ntfy
make musl       # static linux-x86_64-musl
make arm64      # static linux-arm64-musl (aarch64-linux-gnu-gcc)
make win64      # static windows-x86_64 (x86_64-w64-mingw32)
make macos      # on a Mac (Apple clang), universal-friendly
make asan       # ASan+UBSan build under tests/asan/
make fortify    # -D_FORTIFY_SOURCE=2 build under tests/fortify/
make test       # offline suite (tests/run.sh, loopback only)
make e2e        # Playwright viewport checks + docs/ screenshots

All third-party code is vendored and statically linked:

vendor/yyjson.c (MIT, ibireme) and Mbed TLS 3.6.6 under vendor/mbedtls

(Apache-2.0, client config pinned in src/sx_ntfy_mbedtls_config.h; public

headers under src/mbedtls + src/psa so the dist builder's fixed

-I src -I vendor resolves them). No libcurl, no OpenSSL, no runtime .so

or .dll on any of the six dist targets.

Environment

Variable Effect
NTFY_SERVER_URL, NTFY_TOPIC, NTFY_PUBLISH_TOPIC, NTFY_TOKEN, NTFY_TARGET_SESSION, NTFY_BOT_API_URL, NTFY_TAGS, NTFY_REPLY_PREFIX, NTFY_TITLE_PREFIX, NTFY_CA_FILE, NTFY_TLS_PIN, NTFY_MARKDOWN, NTFY_PRIORITY, NTFY_ALLOW_ALL, NTFY_PAIRING_CODE, NTFY_REPLY_POLL_MS, NTFY_IDLE_TIMEOUT_MS first-run / overlay config (applied on top of config.json)
NTFY_TLS_INSECURE=1 explicit, loud, in-memory-only certificate bypass (status UI shows tls: verification OFF)
BOT_PASSWORD node password used by require_node_auth()
SX_CONNECTORS_DIR relocate the state directory (tests)
SX_PLUGIN_META=1 equivalent to --meta

Testing

tests/run.sh is fully offline: tests/mockd.py is one loopback process that

is simultaneously a mock ntfy server (publish capture + the NDJSON stream,

including our own publishes echoed back, exactly like the real server), a

mock node API (/inbox + /conversation with a scripted assistant reply),

and a control API the suite drives (/__inject, /__publishes, /__inbox,

/__reset, /__stats). It proves the pairing gate, the bridge, the reply

loop, the no-self-echo rule, the 401 paths, the secret write-only-ness, the

page hygiene (no <script src=, no CDN, no emoji) and a git-history secret

audit. tests/e2e.py drives the real page with Playwright at 1440/1024/390

in dark and light and writes docs/ui-*.png.

License

MIT. Clean-room implementation against the public ntfy HTTP protocol; not

affiliated with the ntfy project.