From 6779d9dd1fd69eba98c06ec8519eab781cd74254 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Thu, 23 Dec 2021 00:16:28 +0100 Subject: [PATCH] Add NTFY_RAW --- client/client.yml | 19 ++++++++++--------- cmd/subscribe.go | 20 +++++++++++--------- docs/subscribe/api.md | 2 +- docs/subscribe/cli.md | 21 +++++++++++---------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/client/client.yml b/client/client.yml index 74be0f70..9f62990a 100644 --- a/client/client.yml +++ b/client/client.yml @@ -18,15 +18,16 @@ # priority: high,urgent # # Variables: -# Variable Aliases Description -# --------------- --------------- ----------------------------------- -# $NTFY_ID $id Unique message ID -# $NTFY_TIME $time Unix timestamp of the message delivery -# $NTFY_TOPIC $topic Topic name -# $NTFY_MESSAGE $message, $m Message body -# $NTFY_TITLE $title, $t Message title -# $NTFY_PRIORITY $priority, $p Message priority (1=min, 5=max) -# $NTFY_TAGS $tags, $ta Message tags (comma separated list) +# Variable Aliases Description +# --------------- --------------------- ----------------------------------- +# $NTFY_ID $id Unique message ID +# $NTFY_TIME $time Unix timestamp of the message delivery +# $NTFY_TOPIC $topic Topic name +# $NTFY_MESSAGE $message, $m Message body +# $NTFY_TITLE $title, $t Message title +# $NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max) +# $NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list) +# $NTFY_RAW $raw Raw JSON message # # Filters ('if:'): # You can filter 'message', 'title', 'priority' (comma-separated list, logical OR) diff --git a/cmd/subscribe.go b/cmd/subscribe.go index 0c9447c2..09e9deef 100644 --- a/cmd/subscribe.go +++ b/cmd/subscribe.go @@ -44,15 +44,16 @@ ntfy subscribe TOPIC COMMAND This executes COMMAND for every incoming messages. The message fields are passed to the command as environment variables: - Variable Aliases Description - --------------- --------------- ----------------------------------- - $NTFY_ID $id Unique message ID - $NTFY_TIME $time Unix timestamp of the message delivery - $NTFY_TOPIC $topic Topic name - $NTFY_MESSAGE $message, $m Message body - $NTFY_TITLE $title, $t Message title - $NTFY_PRIORITY $priority, $p Message priority (1=min, 5=max) - $NTFY_TAGS $tags, $ta Message tags (comma separated list) + Variable Aliases Description + --------------- --------------------- ----------------------------------- + $NTFY_ID $id Unique message ID + $NTFY_TIME $time Unix timestamp of the message delivery + $NTFY_TOPIC $topic Topic name + $NTFY_MESSAGE $message, $m Message body + $NTFY_TITLE $title, $t Message title + $NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max) + $NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list) + $NTFY_RAW $raw Raw JSON message Examples: ntfy sub mytopic 'notify-send "$m"' # Execute command for incoming messages @@ -207,6 +208,7 @@ func envVars(m *client.Message) []string { env = append(env, envVar(m.Title, "NTFY_TITLE", "title", "t")...) env = append(env, envVar(fmt.Sprintf("%d", m.Priority), "NTFY_PRIORITY", "priority", "prio", "p")...) env = append(env, envVar(strings.Join(m.Tags, ","), "NTFY_TAGS", "tags", "tag", "ta")...) + env = append(env, envVar(m.Raw, "NTFY_RAW", "raw")...) return env } diff --git a/docs/subscribe/api.md b/docs/subscribe/api.md index 5cf25ae7..0a4d6908 100644 --- a/docs/subscribe/api.md +++ b/docs/subscribe/api.md @@ -231,7 +231,7 @@ Available filters (all case-insensitive): | Filter variable | Alias | Example | Description | |---|---|---|---| -| `message` | `X-Message`, `m` | `ntfy.sh/mytopic?some_message` | Only return messages that match this exact message string | +| `message` | `X-Message`, `m` | `ntfy.sh/mytopic?message=lalala` | Only return messages that match this exact message string | | `title` | `X-Title`, `t` | `ntfy.sh/mytopic?title=some+title` | Only return messages that match this exact title string | | `priority` | `X-Priority`, `prio`, `p` | `ntfy.sh/mytopic?p=high,urgent` | Only return messages that match *any priority listed* (comma-separated) | | `tags` | `X-Tags`, `tag`, `ta` | `ntfy.sh/mytopic?tags=error,alert` | Only return messages that match *all listed tags* (comma-separated) | diff --git a/docs/subscribe/cli.md b/docs/subscribe/cli.md index 28892730..488398b9 100644 --- a/docs/subscribe/cli.md +++ b/docs/subscribe/cli.md @@ -112,6 +112,7 @@ in double-quotes, you should be fine: | `$NTFY_TITLE` | `$title`, `$t` | Message title | | `$NTFY_PRIORITY` | `$priority`, `$prio`, `$p` | Message priority (1=min, 5=max) | | `$NTFY_TAGS` | `$tags`, `$tag`, `$ta` | Message tags (comma separated list) | +| `$NTFY_RAW` | `$raw` | Raw JSON message | ### Subscribe to multiple topics ``` @@ -127,14 +128,14 @@ Here's an example config file that subscribes to three different topics, executi subscribe: - topic: echo-this command: 'echo "Message received: $message"' - - topic: alerts - command: notify-send -i /usr/share/ntfy/logo.png "Important" "$m" - if: - priority: high,urgent - - topic: calc - command: 'gnome-calculator 2>/dev/null &' - - topic: print-temp - command: | + - topic: alerts + command: notify-send -i /usr/share/ntfy/logo.png "Important" "$m" + if: + priority: high,urgent + - topic: calc + command: 'gnome-calculator 2>/dev/null &' + - topic: print-temp + command: | echo "You can easily run inline scripts, too." temp="$(sensors | awk '/Pack/ { print substr($4,2,2) }')" if [ $temp -gt 80 ]; then @@ -142,12 +143,12 @@ Here's an example config file that subscribes to three different topics, executi else echo "CPU temperature is $temp. That's alright." fi - ``` + ``` In this example, when `ntfy subscribe --from-config` is executed: * Messages to `echo-this` simply echos to standard out -* Messages to `alerts` display as desktop notification for high priority messages using `notify-send` +* Messages to `alerts` display as desktop notification for high priority messages using [notify-send](https://manpages.ubuntu.com/manpages/focal/man1/notify-send.1.html) * Messages to `calc` open the gnome calculator 😀 (*because, why not*) * Messages to `print-temp` execute an inline script and print the CPU temperature