winzik/tools/notify-commands.sh

37 lines
1.9 KiB
Shell

# shellcheck shell=bash
# Push notifications, the owner's side (docs/notifications.md, extension jumphp/notification). Sourced by bin/jumphp:
# notify:login <app> asks the token jnt_… (not echoed), keeps it in ~/.jumphp/notify/tokens.json (0600), never in the repository
# notify <app> --all|--user U|--group G "Title" "Text" [--url /play/] [--tag T] [--ttl S] [--dry-run]
# notify:stats <app> [--from D] [--to D], notify:history <app> [--limit N], notify:logout <app>
# notify:mcp MCP server on stdio for Claude Code: claude mcp add jumphp-notify -- bin/jumphp notify:mcp
# JUMPHP_NOTIFY_TOKEN / JUMPHP_NOTIFY_URL (environment) win over the saved token. PHP runs in the desktop runtime image (tools/notify.php).
notify_php() {
local home="${HOME}/.jumphp/notify"
mkdir -p "$home" && chmod 700 "$home"
# -e NAME without a value: docker takes it from this environment (the token never appears on a command line)
php_run . -v "$home:/jumphp-notify" -e JUMPHP_NOTIFY_HOME=/jumphp-notify \
${JUMPHP_NOTIFY_TOKEN:+-e JUMPHP_NOTIFY_TOKEN} ${JUMPHP_NOTIFY_URL:+-e JUMPHP_NOTIFY_URL} \
-- php /workspace/tools/notify.php "$@"
}
cmd_notify_login() {
local app="${1:-}" token=""
[[ "$app" =~ ^[a-z0-9][a-z0-9-]*$ ]] || die "usage: bin/jumphp notify:login <app> [--url https://jumphp.net]"
[ -r /dev/tty ] || die "notify:login needs a terminal (or set JUMPHP_NOTIFY_TOKEN)"
printf 'Notification token of %s (studio: project > Notifications, starts with jnt_): ' "$app" >/dev/tty
IFS= read -rs token </dev/tty
printf '\n' >/dev/tty
[ -n "$token" ] || die "no token given"
printf '%s\n' "$token" | notify_php login "$@"
}
cmd_notify() {
[ -n "${1:-}" ] || die "usage: bin/jumphp notify <app> --all|--user U|--group G \"Title\" \"Text\" [--url /play/] [--dry-run]"
notify_php send "$@"
}
cmd_notify_mcp() {
ensure_desktop_image >&2 # stdout is the MCP channel: nothing else may be written there
notify_php mcp
}