Skip to content

Commit 6779d9d

Browse files
author
Philipp Heckel
committed
Add NTFY_RAW
1 parent 8593961 commit 6779d9d

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

client/client.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
# priority: high,urgent
1919
#
2020
# Variables:
21-
# Variable Aliases Description
22-
# --------------- --------------- -----------------------------------
23-
# $NTFY_ID $id Unique message ID
24-
# $NTFY_TIME $time Unix timestamp of the message delivery
25-
# $NTFY_TOPIC $topic Topic name
26-
# $NTFY_MESSAGE $message, $m Message body
27-
# $NTFY_TITLE $title, $t Message title
28-
# $NTFY_PRIORITY $priority, $p Message priority (1=min, 5=max)
29-
# $NTFY_TAGS $tags, $ta Message tags (comma separated list)
21+
# Variable Aliases Description
22+
# --------------- --------------------- -----------------------------------
23+
# $NTFY_ID $id Unique message ID
24+
# $NTFY_TIME $time Unix timestamp of the message delivery
25+
# $NTFY_TOPIC $topic Topic name
26+
# $NTFY_MESSAGE $message, $m Message body
27+
# $NTFY_TITLE $title, $t Message title
28+
# $NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max)
29+
# $NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list)
30+
# $NTFY_RAW $raw Raw JSON message
3031
#
3132
# Filters ('if:'):
3233
# You can filter 'message', 'title', 'priority' (comma-separated list, logical OR)

cmd/subscribe.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ ntfy subscribe TOPIC COMMAND
4444
This executes COMMAND for every incoming messages. The message fields are passed to the
4545
command as environment variables:
4646
47-
Variable Aliases Description
48-
--------------- --------------- -----------------------------------
49-
$NTFY_ID $id Unique message ID
50-
$NTFY_TIME $time Unix timestamp of the message delivery
51-
$NTFY_TOPIC $topic Topic name
52-
$NTFY_MESSAGE $message, $m Message body
53-
$NTFY_TITLE $title, $t Message title
54-
$NTFY_PRIORITY $priority, $p Message priority (1=min, 5=max)
55-
$NTFY_TAGS $tags, $ta Message tags (comma separated list)
47+
Variable Aliases Description
48+
--------------- --------------------- -----------------------------------
49+
$NTFY_ID $id Unique message ID
50+
$NTFY_TIME $time Unix timestamp of the message delivery
51+
$NTFY_TOPIC $topic Topic name
52+
$NTFY_MESSAGE $message, $m Message body
53+
$NTFY_TITLE $title, $t Message title
54+
$NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max)
55+
$NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list)
56+
$NTFY_RAW $raw Raw JSON message
5657
5758
Examples:
5859
ntfy sub mytopic 'notify-send "$m"' # Execute command for incoming messages
@@ -207,6 +208,7 @@ func envVars(m *client.Message) []string {
207208
env = append(env, envVar(m.Title, "NTFY_TITLE", "title", "t")...)
208209
env = append(env, envVar(fmt.Sprintf("%d", m.Priority), "NTFY_PRIORITY", "priority", "prio", "p")...)
209210
env = append(env, envVar(strings.Join(m.Tags, ","), "NTFY_TAGS", "tags", "tag", "ta")...)
211+
env = append(env, envVar(m.Raw, "NTFY_RAW", "raw")...)
210212
return env
211213
}
212214

docs/subscribe/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Available filters (all case-insensitive):
231231

232232
| Filter variable | Alias | Example | Description |
233233
|---|---|---|---|
234-
| `message` | `X-Message`, `m` | `ntfy.sh/mytopic?some_message` | Only return messages that match this exact message string |
234+
| `message` | `X-Message`, `m` | `ntfy.sh/mytopic?message=lalala` | Only return messages that match this exact message string |
235235
| `title` | `X-Title`, `t` | `ntfy.sh/mytopic?title=some+title` | Only return messages that match this exact title string |
236236
| `priority` | `X-Priority`, `prio`, `p` | `ntfy.sh/mytopic?p=high,urgent` | Only return messages that match *any priority listed* (comma-separated) |
237237
| `tags` | `X-Tags`, `tag`, `ta` | `ntfy.sh/mytopic?tags=error,alert` | Only return messages that match *all listed tags* (comma-separated) |

docs/subscribe/cli.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ in double-quotes, you should be fine:
112112
| `$NTFY_TITLE` | `$title`, `$t` | Message title |
113113
| `$NTFY_PRIORITY` | `$priority`, `$prio`, `$p` | Message priority (1=min, 5=max) |
114114
| `$NTFY_TAGS` | `$tags`, `$tag`, `$ta` | Message tags (comma separated list) |
115+
| `$NTFY_RAW` | `$raw` | Raw JSON message |
115116
116117
### Subscribe to multiple topics
117118
```
@@ -127,27 +128,27 @@ Here's an example config file that subscribes to three different topics, executi
127128
subscribe:
128129
- topic: echo-this
129130
command: 'echo "Message received: $message"'
130-
- topic: alerts
131-
command: notify-send -i /usr/share/ntfy/logo.png "Important" "$m"
132-
if:
133-
priority: high,urgent
134-
- topic: calc
135-
command: 'gnome-calculator 2>/dev/null &'
136-
- topic: print-temp
137-
command: |
131+
- topic: alerts
132+
command: notify-send -i /usr/share/ntfy/logo.png "Important" "$m"
133+
if:
134+
priority: high,urgent
135+
- topic: calc
136+
command: 'gnome-calculator 2>/dev/null &'
137+
- topic: print-temp
138+
command: |
138139
echo "You can easily run inline scripts, too."
139140
temp="$(sensors | awk '/Pack/ { print substr($4,2,2) }')"
140141
if [ $temp -gt 80 ]; then
141142
echo "Warning: CPU temperature is $temp. Too high."
142143
else
143144
echo "CPU temperature is $temp. That's alright."
144145
fi
145-
```
146+
```
146147
147148
In this example, when `ntfy subscribe --from-config` is executed:
148149
149150
* Messages to `echo-this` simply echos to standard out
150-
* Messages to `alerts` display as desktop notification for high priority messages using `notify-send`
151+
* 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)
151152
* Messages to `calc` open the gnome calculator 😀 (*because, why not*)
152153
* Messages to `print-temp` execute an inline script and print the CPU temperature
153154

0 commit comments

Comments
 (0)