| 1 |
# Getting started |
| 2 |
ntfy lets you **send push notifications to your phone or desktop via scripts from any computer**, using simple HTTP PUT |
| 3 |
or POST requests. I use it to notify myself when scripts fail, or long-running commands complete. |
| 4 |
|
| 5 |
## Step 1: Get the app |
| 6 |
<a href="https://play.google.com/store/apps/details?id=io.heckel.ntfy"><img width="170" src="static/img/badge-googleplay.png"></a> |
| 7 |
<a href="https://f-droid.org/en/packages/io.heckel.ntfy/"><img width="170" src="static/img/badge-fdroid.svg"></a> |
| 8 |
<a href="https://apps.apple.com/us/app/ntfy/id1625396347"><img width="150" src="static/img/badge-appstore.png"></a> |
| 9 |
|
| 10 |
To [receive notifications on your phone](subscribe/phone.md), install the app, either via Google Play, App Store or F-Droid. |
| 11 |
Once installed, open it and subscribe to a topic of your choosing. Topics don't have to explicitly be created, so just |
| 12 |
pick a name and use it later when you [publish a message](publish.md). Note that **topic names are public, so it's wise |
| 13 |
to choose something that cannot be guessed easily.** |
| 14 |
|
| 15 |
For this guide, we'll just use `mytopic` as our topic name: |
| 16 |
|
| 17 |
<figure markdown> |
| 18 |
{ width=500 } |
| 19 |
<figcaption>Creating/adding your first topic</figcaption> |
| 20 |
</figure> |
| 21 |
|
| 22 |
That's it. After you tap "Subscribe", the app is listening for new messages on that topic. |
| 23 |
|
| 24 |
## Step 2: Send a message |
| 25 |
Now let's [send a message](publish.md) to our topic. It's easy in every language, since we're just using HTTP PUT/POST, |
| 26 |
or with the [ntfy CLI](install.md). The message is in the request body. Here's an example showing how to publish a |
| 27 |
simple message using a POST request: |
| 28 |
|
| 29 |
=== "Command line (curl)" |
| 30 |
``` |
| 31 |
curl -d "Backup successful 😀" ntfy.sh/mytopic |
| 32 |
``` |
| 33 |
|
| 34 |
=== "ntfy CLI" |
| 35 |
``` |
| 36 |
ntfy publish mytopic "Backup successful 😀" |
| 37 |
``` |
| 38 |
|
| 39 |
=== "HTTP" |
| 40 |
``` http |
| 41 |
POST /mytopic HTTP/1.1 |
| 42 |
Host: ntfy.sh |
| 43 |
|
| 44 |
Backup successful 😀 |
| 45 |
``` |
| 46 |
|
| 47 |
=== "JavaScript" |
| 48 |
``` javascript |
| 49 |
fetch('https://ntfy.sh/mytopic', { |
| 50 |
method: 'POST', // PUT works too |
| 51 |
body: 'Backup successful 😀' |
| 52 |
}) |
| 53 |
``` |
| 54 |
|
| 55 |
=== "Go" |
| 56 |
``` go |
| 57 |
http.Post("https://ntfy.sh/mytopic", "text/plain", |
| 58 |
strings.NewReader("Backup successful 😀")) |
| 59 |
``` |
| 60 |
|
| 61 |
=== "Python" |
| 62 |
``` python |
| 63 |
requests.post("https://ntfy.sh/mytopic", |
| 64 |
data="Backup successful 😀".encode(encoding='utf-8')) |
| 65 |
``` |
| 66 |
|
| 67 |
=== "PHP" |
| 68 |
``` php-inline |
| 69 |
file_get_contents('https://ntfy.sh/mytopic', false, stream_context_create([ |
| 70 |
'http' => [ |
| 71 |
'method' => 'POST', // PUT also works |
| 72 |
'header' => 'Content-Type: text/plain', |
| 73 |
'content' => 'Backup successful 😀' |
| 74 |
] |
| 75 |
])); |
| 76 |
``` |
| 77 |
|
| 78 |
This will create a notification that looks like this: |
| 79 |
|
| 80 |
<figure markdown> |
| 81 |
{ width=500 } |
| 82 |
<figcaption>Android notification</figcaption> |
| 83 |
</figure> |
| 84 |
|
| 85 |
That's it. You're all set. Go play and read the rest of the docs. I highly recommend reading at least the page on |
| 86 |
[publishing messages](publish.md), as well as the detailed page on the [Android/iOS app](subscribe/phone.md). |
| 87 |
|
| 88 |
Here's another video showing the entire process: |
| 89 |
|
| 90 |
<figure> |
| 91 |
<video controls muted autoplay loop width="650" src="static/img/android-video-overview.mp4"></video> |
| 92 |
<figcaption>Sending push notifications to your Android phone</figcaption> |
| 93 |
</figure> |
| 94 |
|
| 95 |
|