|
|
@@ -789,21 +789,21 @@ The JSON message format closely mirrors the format of the message you can consum
|
|
|
(see [JSON message format](subscribe/api.md#json-message-format) for details), but is not exactly identical. Here's an overview of
|
|
|
all the supported fields:
|
|
|
|
|
|
-| Field | Required | Type | Example | Description |
|
|
|
-|------------|----------|----------------------------------|---------------------------------------|-----------------------------------------------------------------------|
|
|
|
-| `topic` | ✔️ | *string* | `topic1` | Target topic name |
|
|
|
-| `message` | - | *string* | `Some message` | Message body; set to `triggered` if empty or not passed |
|
|
|
-| `title` | - | *string* | `Some title` | Message [title](#message-title) |
|
|
|
-| `tags` | - | *string array* | `["tag1","tag2"]` | List of [tags](#tags-emojis) that may or not map to emojis |
|
|
|
-| `priority` | - | *int (one of: 1, 2, 3, 4, or 5)* | `4` | Message [priority](#message-priority) with 1=min, 3=default and 5=max |
|
|
|
-| `actions` | - | *JSON array* | *(see [user actions](#user-actions))* | Custom [user action buttons](#user-actions) for notifications |
|
|
|
-| `click` | - | *URL* | `https://example.com` | Website opened when notification is [clicked](#click-action) |
|
|
|
-| `attach` | - | *URL* | `https://example.com/file.jpg` | URL of an attachment, see [attach via URL](#attach-file-from-url) |
|
|
|
-| `filename` | - | *string* | `file.jpg` | File name of the attachment |
|
|
|
-| `delay` | - | *string* | `30min`, `9am` | Timestamp or duration for delayed delivery |
|
|
|
-| `email` | - | *e-mail address* | `phil@example.com` | E-mail address for e-mail notifications |
|
|
|
-
|
|
|
-## User actions
|
|
|
+| Field | Required | Type | Example | Description |
|
|
|
+|------------|----------|----------------------------------|-------------------------------------------|-----------------------------------------------------------------------|
|
|
|
+| `topic` | ✔️ | *string* | `topic1` | Target topic name |
|
|
|
+| `message` | - | *string* | `Some message` | Message body; set to `triggered` if empty or not passed |
|
|
|
+| `title` | - | *string* | `Some title` | Message [title](#message-title) |
|
|
|
+| `tags` | - | *string array* | `["tag1","tag2"]` | List of [tags](#tags-emojis) that may or not map to emojis |
|
|
|
+| `priority` | - | *int (one of: 1, 2, 3, 4, or 5)* | `4` | Message [priority](#message-priority) with 1=min, 3=default and 5=max |
|
|
|
+| `actions` | - | *JSON array* | *(see [actiom buttons](#action-buttons))* | Custom [user action buttons](#action-buttons) for notifications |
|
|
|
+| `click` | - | *URL* | `https://example.com` | Website opened when notification is [clicked](#click-action) |
|
|
|
+| `attach` | - | *URL* | `https://example.com/file.jpg` | URL of an attachment, see [attach via URL](#attach-file-from-url) |
|
|
|
+| `filename` | - | *string* | `file.jpg` | File name of the attachment |
|
|
|
+| `delay` | - | *string* | `30min`, `9am` | Timestamp or duration for delayed delivery |
|
|
|
+| `email` | - | *e-mail address* | `phil@example.com` | E-mail address for e-mail notifications |
|
|
|
+
|
|
|
+## Action buttons
|
|
|
You can add action buttons to notifications to allow yourself to react to a notification directly. This is incredibly
|
|
|
useful and has countless applications. As of today, the following actions are supported:
|
|
|
|
|
|
@@ -812,6 +812,9 @@ useful and has countless applications. As of today, the following actions are su
|
|
|
when the action button is tapped
|
|
|
* [`http`](#send-http-request): Sends HTTP POST/GET/PUT request when the action button is tapped
|
|
|
|
|
|
+To define the user actions, you can either pass the `actions` field as part of the JSON body (if you're
|
|
|
+[publishing via JSON](#publish-as-json)), or use the `X-Actions` header (or any of its aliases: `Actions`, `Action`).
|
|
|
+
|
|
|
Here's an example of what that a notification with actions can look like:
|
|
|
|
|
|
<figure markdown>
|
|
|
@@ -819,12 +822,91 @@ Here's an example of what that a notification with actions can look like:
|
|
|
<figcaption>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</figcaption>
|
|
|
</figure>
|
|
|
|
|
|
+Using the `X-Actions` header and the **simple format** (details see below), you can create the above notification like
|
|
|
+this. This format is much easier to write, but less powerful:
|
|
|
+
|
|
|
+=== "Command line (curl)"
|
|
|
+ ```
|
|
|
+ curl \
|
|
|
+ -d "You left the house. Turn down the A/C?" \
|
|
|
+ -H "Actions: view, Open portal, https://home.nest.com/; \
|
|
|
+ http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65" \
|
|
|
+ ntfy.sh/myhome
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "ntfy CLI"
|
|
|
+ ```
|
|
|
+ ntfy publish \
|
|
|
+ --actions="view, Open portal, https://home.nest.com/; \
|
|
|
+ http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65" \
|
|
|
+ myhome \
|
|
|
+ "You left the house. Turn down the A/C?"
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "HTTP"
|
|
|
+ ``` http
|
|
|
+ POST /myhome HTTP/1.1
|
|
|
+ Host: ntfy.sh
|
|
|
+ Actions: view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65
|
|
|
+
|
|
|
+ You left the house. Turn down the A/C?
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "JavaScript"
|
|
|
+ ``` javascript
|
|
|
+ fetch('https://ntfy.sh/myhome', {
|
|
|
+ method: 'POST',
|
|
|
+ body: 'You left the house. Turn down the A/C?',
|
|
|
+ headers: {
|
|
|
+ 'Actions': 'view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "Go"
|
|
|
+ ``` go
|
|
|
+ req, _ := http.NewRequest("POST", "https://ntfy.sh/myhome", strings.NewReader("You left the house. Turn down the A/C?"))
|
|
|
+ req.Header.Set("Actions", "view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65")
|
|
|
+ http.DefaultClient.Do(req)
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "PowerShell"
|
|
|
+ ``` powershell
|
|
|
+ $uri = "https://ntfy.sh/myhome"
|
|
|
+ $headers = @{ Actions="view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65" }
|
|
|
+ $body = "You left the house. Turn down the A/C?"
|
|
|
+ Invoke-RestMethod -Method 'Post' -Uri $uri -Headers $headers -Body $body -UseBasicParsing
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "Python"
|
|
|
+ ``` python
|
|
|
+ requests.post("https://ntfy.sh/myhome",
|
|
|
+ data="You left the house. Turn down the A/C?",
|
|
|
+ headers={ "Actions": "view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65" })
|
|
|
+ ```
|
|
|
+
|
|
|
+=== "PHP"
|
|
|
+ ``` php-inline
|
|
|
+ file_get_contents('https://ntfy.sh/reddit_alerts', false, stream_context_create([
|
|
|
+ 'http' => [
|
|
|
+ 'method' => 'POST',
|
|
|
+ 'header' =>
|
|
|
+ "Content-Type: text/plain\r\n" .
|
|
|
+ "Actions: view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65",
|
|
|
+ 'content' => 'You left the house. Turn down the A/C?'
|
|
|
+ ]
|
|
|
+ ]));
|
|
|
+ ```
|
|
|
+
|
|
|
+Alternatively, you can define actions as **JSON array** (details see below), and pass them as part of the JSON body
|
|
|
+(see [publish as JSON](#publish-as-json)):
|
|
|
+
|
|
|
=== "Command line (curl)"
|
|
|
```
|
|
|
curl ntfy.sh \
|
|
|
-d '{
|
|
|
"topic": "myhome",
|
|
|
- "message": "You seem to have left the house. Want to turn down the A/C?",
|
|
|
+ "message": "You left the house. Turn down the A/C?",
|
|
|
"actions": [
|
|
|
{
|
|
|
"action": "view",
|
|
|
@@ -834,39 +916,54 @@ Here's an example of what that a notification with actions can look like:
|
|
|
{
|
|
|
"action": "http",
|
|
|
"label": "Turn down",
|
|
|
- "method": "POST",
|
|
|
- "url": "https://developer-api.nest.com/devices/thermostats/XZA124D",
|
|
|
- "headers": {
|
|
|
- "Authorization": "Bearer ...",
|
|
|
- "Content-Type": "application/json"
|
|
|
- },
|
|
|
- "body": "{\"target_temperature_f\": 65}"
|
|
|
- },
|
|
|
- {
|
|
|
- "action": "broadcast",
|
|
|
- "label": "Enter deep sleep 💤",
|
|
|
- "extras": {
|
|
|
- "command": "deepsleep"
|
|
|
- }
|
|
|
+ "url": "https://api.nest.com/device/XZ1D2",
|
|
|
+ "body": "target_temp_f=65"
|
|
|
}
|
|
|
]
|
|
|
}'
|
|
|
```
|
|
|
|
|
|
+=== "ntfy CLI"
|
|
|
+ ```
|
|
|
+ ntfy publish \
|
|
|
+ --actions '[
|
|
|
+ {
|
|
|
+ "action": "view",
|
|
|
+ "label": "Open portal",
|
|
|
+ "url": "https://home.nest.com/"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "action": "http",
|
|
|
+ "label": "Turn down",
|
|
|
+ "url": "https://api.nest.com/device/XZ1D2",
|
|
|
+ "body": "target_temp_f=65"
|
|
|
+ }
|
|
|
+ ]' \
|
|
|
+ myhome \
|
|
|
+ "You left the house. Turn down the A/C?"
|
|
|
+ ```
|
|
|
+
|
|
|
=== "HTTP"
|
|
|
``` http
|
|
|
POST / HTTP/1.1
|
|
|
Host: ntfy.sh
|
|
|
|
|
|
{
|
|
|
- "topic": "mytopic",
|
|
|
- "message": "Disk space is low at 5.1 GB",
|
|
|
- "title": "Low disk space alert",
|
|
|
- "tags": ["warning","cd"],
|
|
|
- "priority": 4,
|
|
|
- "attach": "https://filesrv.lan/space.jpg",
|
|
|
- "filename": "diskspace.jpg",
|
|
|
- "click": "https://homecamera.lan/xasds1h2xsSsa/"
|
|
|
+ "topic": "myhome",
|
|
|
+ "message": "You left the house. Turn down the A/C?",
|
|
|
+ "actions": [
|
|
|
+ {
|
|
|
+ "action": "view",
|
|
|
+ "label": "Open portal",
|
|
|
+ "url": "https://home.nest.com/"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "action": "http",
|
|
|
+ "label": "Turn down",
|
|
|
+ "url": "https://api.nest.com/device/XZ1D2",
|
|
|
+ "body": "target_temp_f=65"
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
```
|
|
|
|
|
|
@@ -875,14 +972,21 @@ Here's an example of what that a notification with actions can look like:
|
|
|
fetch('https://ntfy.sh', {
|
|
|
method: 'POST',
|
|
|
body: JSON.stringify({
|
|
|
- "topic": "mytopic",
|
|
|
- "message": "Disk space is low at 5.1 GB",
|
|
|
- "title": "Low disk space alert",
|
|
|
- "tags": ["warning","cd"],
|
|
|
- "priority": 4,
|
|
|
- "attach": "https://filesrv.lan/space.jpg",
|
|
|
- "filename": "diskspace.jpg",
|
|
|
- "click": "https://homecamera.lan/xasds1h2xsSsa/"
|
|
|
+ topic: "myhome",
|
|
|
+ message": "You left the house. Turn down the A/C?",
|
|
|
+ actions: [
|
|
|
+ {
|
|
|
+ action: "view",
|
|
|
+ label: "Open portal",
|
|
|
+ url: "https://home.nest.com/"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ action: "http",
|
|
|
+ label: "Turn down",
|
|
|
+ url: "https://api.nest.com/device/XZ1D2",
|
|
|
+ body: "target_temp_f=65"
|
|
|
+ }
|
|
|
+ ]
|
|
|
})
|
|
|
})
|
|
|
```
|
|
|
@@ -890,18 +994,24 @@ Here's an example of what that a notification with actions can look like:
|
|
|
=== "Go"
|
|
|
``` go
|
|
|
// You should probably use json.Marshal() instead and make a proper struct,
|
|
|
- // or even just use req.Header.Set() like in the other examples, but for the
|
|
|
- // sake of the example, this is easier.
|
|
|
+ // but for the sake of the example, this is easier.
|
|
|
|
|
|
body := `{
|
|
|
- "topic": "mytopic",
|
|
|
- "message": "Disk space is low at 5.1 GB",
|
|
|
- "title": "Low disk space alert",
|
|
|
- "tags": ["warning","cd"],
|
|
|
- "priority": 4,
|
|
|
- "attach": "https://filesrv.lan/space.jpg",
|
|
|
- "filename": "diskspace.jpg",
|
|
|
- "click": "https://homecamera.lan/xasds1h2xsSsa/"
|
|
|
+ "topic": "myhome",
|
|
|
+ "message": "You left the house. Turn down the A/C?",
|
|
|
+ "actions": [
|
|
|
+ {
|
|
|
+ "action": "view",
|
|
|
+ "label": "Open portal",
|
|
|
+ "url": "https://home.nest.com/"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "action": "http",
|
|
|
+ "label": "Turn down",
|
|
|
+ "url": "https://api.nest.com/device/XZ1D2",
|
|
|
+ "body": "target_temp_f=65"
|
|
|
+ }
|
|
|
+ ]
|
|
|
}`
|
|
|
req, _ := http.NewRequest("POST", "https://ntfy.sh/", strings.NewReader(body))
|
|
|
http.DefaultClient.Do(req)
|
|
|
@@ -911,15 +1021,22 @@ Here's an example of what that a notification with actions can look like:
|
|
|
``` powershell
|
|
|
$uri = "https://ntfy.sh"
|
|
|
$body = @{
|
|
|
- "topic"="powershell"
|
|
|
- "title"="Low disk space alert"
|
|
|
- "message"="Disk space is low at 5.1 GB"
|
|
|
- "priority"=4
|
|
|
- "attach"="https://filesrv.lan/space.jpg"
|
|
|
- "filename"="diskspace.jpg"
|
|
|
- "tags"=@("warning","cd")
|
|
|
- "click"= "https://homecamera.lan/xasds1h2xsSsa/"
|
|
|
- } | ConvertTo-Json
|
|
|
+ "topic"="myhome"
|
|
|
+ "message"="You left the house. Turn down the A/C?"
|
|
|
+ "actions"=@(
|
|
|
+ @{
|
|
|
+ "action"="view"
|
|
|
+ "label"="Open portal"
|
|
|
+ "url"="https://home.nest.com/"
|
|
|
+ },
|
|
|
+ @{
|
|
|
+ "action"="http",
|
|
|
+ "label"="Turn down"
|
|
|
+ "url"="https://api.nest.com/device/XZ1D2"
|
|
|
+ "body"="target_temp_f=65"
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } | ConvertTo-Json
|
|
|
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
|
|
```
|
|
|
|
|
|
@@ -927,14 +1044,21 @@ Here's an example of what that a notification with actions can look like:
|
|
|
``` python
|
|
|
requests.post("https://ntfy.sh/",
|
|
|
data=json.dumps({
|
|
|
- "topic": "mytopic",
|
|
|
- "message": "Disk space is low at 5.1 GB",
|
|
|
- "title": "Low disk space alert",
|
|
|
- "tags": ["warning","cd"],
|
|
|
- "priority": 4,
|
|
|
- "attach": "https://filesrv.lan/space.jpg",
|
|
|
- "filename": "diskspace.jpg",
|
|
|
- "click": "https://homecamera.lan/xasds1h2xsSsa/"
|
|
|
+ "topic": "myhome",
|
|
|
+ "message": "You left the house. Turn down the A/C?",
|
|
|
+ "actions": [
|
|
|
+ {
|
|
|
+ "action": "view",
|
|
|
+ "label": "Open portal",
|
|
|
+ "url": "https://home.nest.com/"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "action": "http",
|
|
|
+ "label": "Turn down",
|
|
|
+ "url": "https://api.nest.com/device/XZ1D2",
|
|
|
+ "body": "target_temp_f=65"
|
|
|
+ }
|
|
|
+ ]
|
|
|
})
|
|
|
)
|
|
|
```
|
|
|
@@ -946,31 +1070,57 @@ Here's an example of what that a notification with actions can look like:
|
|
|
'method' => 'POST',
|
|
|
'header' => "Content-Type: application/json",
|
|
|
'content' => json_encode([
|
|
|
- "topic": "mytopic",
|
|
|
- "message": "Disk space is low at 5.1 GB",
|
|
|
- "title": "Low disk space alert",
|
|
|
- "tags": ["warning","cd"],
|
|
|
- "priority": 4,
|
|
|
- "attach": "https://filesrv.lan/space.jpg",
|
|
|
- "filename": "diskspace.jpg",
|
|
|
- "click": "https://homecamera.lan/xasds1h2xsSsa/"
|
|
|
+ "topic": "myhome",
|
|
|
+ "message": "You left the house. Turn down the A/C?",
|
|
|
+ "actions": [
|
|
|
+ [
|
|
|
+ "action": "view",
|
|
|
+ "label": "Open portal",
|
|
|
+ "url": "https://home.nest.com/"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "action": "http",
|
|
|
+ "label": "Turn down",
|
|
|
+ "url": "https://api.nest.com/device/XZ1D2",
|
|
|
+ "headers": [
|
|
|
+ "Authorization": "Bearer ..."
|
|
|
+ ],
|
|
|
+ "body": "target_temp_f=65"
|
|
|
+ ]
|
|
|
+ ]
|
|
|
])
|
|
|
]
|
|
|
]));
|
|
|
```
|
|
|
|
|
|
+**Simple format syntax:**
|
|
|
+
|
|
|
+Generally, the `X-Actions` header is formatted like this:
|
|
|
+```
|
|
|
+Actions: <action>, <label>, <params, ...>
|
|
|
+```
|
|
|
+or:
|
|
|
+```
|
|
|
+Actions: action=<action>, label=<label>, param1=..., param2=..., ...
|
|
|
+```
|
|
|
+
|
|
|
+An `action` is either [`view`](#open-websiteapp), [`broadcast`](#send-android-broadcast), or [`http`](#send-http-request),
|
|
|
+and the `label` defines the button text. The other parameters depend on the action itself.
|
|
|
|
|
|
| Field | Required | Type | Example | Description |
|
|
|
|----------|----------|----------------------------|-----------------|------------------------------------------------|
|
|
|
| `action` | ✔️ | *view, broadcast, or http* | `view` | Action type |
|
|
|
| `label` | ✔️ | *string* | `Turn on light` | Label of the action button in the notification |
|
|
|
-
|
|
|
+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx
|
|
|
|
|
|
|
|
|
### Open website/app
|
|
|
The `view` action opens a website or app when the action button is tapped, e.g. a browser, a Google Maps location, or
|
|
|
even a deep link into Twitter or a show ntfy topic.
|
|
|
|
|
|
+XXXXXXXXXXXXXXXXXXx
|
|
|
+
|
|
|
+
|
|
|
### Send Android broadcast
|
|
|
The `broadcast` action sends an [Android broadcast](https://developer.android.com/guide/components/broadcasts) intent
|
|
|
when the action button is tapped. This allows integration into automation apps such as [MacroDroid](https://play.google.com/store/apps/details?id=com.arlosoft.macrodroid)
|
|
|
@@ -978,10 +1128,15 @@ or [Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.
|
|
|
you can do everything your phone is capable of. Examples include taking pictures, launching/killing apps, change device
|
|
|
settings, write/read files, etc.
|
|
|
|
|
|
+XXXXXXXXXXXXXXxx
|
|
|
+
|
|
|
+
|
|
|
### Send HTTP request
|
|
|
The `http` action sends a HTTP POST/GET/PUT request when the action button is tapped. You can use this to trigger REST APIs
|
|
|
for whatever systems you have, e.g. opening the garage door, or turning on/off lights.
|
|
|
|
|
|
+XXXXXXXXXXXXXXXXXXXXx
|
|
|
+
|
|
|
=== "`view` action"
|
|
|
``` json
|
|
|
{
|
|
|
@@ -1079,6 +1234,18 @@ You can define which URL to open when a notification is clicked. This may be use
|
|
|
to a Zabbix alert or a transaction that you'd like to provide the deep-link for. Tapping the notification will open
|
|
|
the web browser (or the app) and open the website.
|
|
|
|
|
|
+To define a click action for the notification, pass a URL as the value of the `X-Click` header (or its aliase `Click`).
|
|
|
+If you pass a website URL (`http://` or `https://`) the web browser will open. If you pass another URI that can be handled
|
|
|
+by another app, the responsible app may open.
|
|
|
+
|
|
|
+Examples:
|
|
|
+
|
|
|
+* `http://` or `https://` will open your browser (or an app if it registered for a URL)
|
|
|
+* `mailto:` links will open your mail app
|
|
|
+* `geo:` links will open Google Maps (or your maps application)
|
|
|
+* `ntfy://` links will open ntfy (see [ntfy:// links](subscribe/phone.md#ntfy-links))
|
|
|
+* ...
|
|
|
+
|
|
|
Here's an example that will open Reddit when the notification is clicked:
|
|
|
|
|
|
=== "Command line (curl)"
|
|
|
@@ -1751,7 +1918,7 @@ and can be passed as **HTTP headers** or **query parameters in the URL**. They a
|
|
|
| `X-Priority` | `Priority`, `prio`, `p` | [Message priority](#message-priority) |
|
|
|
| `X-Tags` | `Tags`, `Tag`, `ta` | [Tags and emojis](#tags-emojis) |
|
|
|
| `X-Delay` | `Delay`, `X-At`, `At`, `X-In`, `In` | Timestamp or duration for [delayed delivery](#scheduled-delivery) |
|
|
|
-| `X-Actions` | `Actions`, `Action` | JSON array or short format of [user actions](#user-actions) |
|
|
|
+| `X-Actions` | `Actions`, `Action` | JSON array or short format of [user actions](#action-buttons) |
|
|
|
| `X-Click` | `Click` | URL to open when [notification is clicked](#click-action) |
|
|
|
| `X-Attach` | `Attach`, `a` | URL to send as an [attachment](#attachments), as an alternative to PUT/POST-ing an attachment |
|
|
|
| `X-Filename` | `Filename`, `file`, `f` | Optional [attachment](#attachments) filename, as it appears in the client |
|