1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-23 19:59:26 +01:00
ntfy/docs/index.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
3.3 KiB
Markdown
Raw Normal View History

2021-12-04 02:38:21 +01:00
# Getting started
2021-12-05 21:57:37 +01:00
ntfy lets you **send push notifications to your phone or desktop via scripts from any computer**, using simple HTTP PUT
or POST requests. I use it to notify myself when scripts fail, or long-running commands complete.
2021-12-02 05:08:12 +01:00
2021-12-05 21:57:37 +01:00
## Step 1: Get the app
2023-11-07 20:00:10 +01:00
<a href="https://play.google.com/store/apps/details?id=io.heckel.ntfy"><img src="static/img/badge-googleplay.png"></a>
<a href="https://f-droid.org/en/packages/io.heckel.ntfy/"><img src="static/img/badge-fdroid.png"></a>
<a href="https://apps.apple.com/us/app/ntfy/id1625396347"><img src="static/img/badge-appstore.png"></a>
2021-12-05 21:57:37 +01:00
To [receive notifications on your phone](subscribe/phone.md), install the app, either via Google Play or F-Droid.
Once installed, open it and subscribe to a topic of your choosing. Topics don't have to explicitly be created, so just
pick a name and use it later when you [publish a message](publish.md). Note that **topic names are public, so it's wise
to choose something that cannot be guessed easily.**
For this guide, we'll just use `mytopic` as our topic name:
<figure markdown>
![adding a topic](static/img/getting-started-add.png){ width=500 }
<figcaption>Creating/adding your first topic</figcaption>
</figure>
That's it. After you tap "Subscribe", the app is listening for new messages on that topic.
## Step 2: Send a message
2021-12-18 04:38:29 +01:00
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,
or with the [ntfy CLI](install.md). The message is in the request body. Here's an example showing how to publish a
simple message using a POST request:
2021-12-05 21:57:37 +01:00
=== "Command line (curl)"
```
curl -d "Backup successful 😀" ntfy.sh/mytopic
```
2021-12-18 04:38:29 +01:00
=== "ntfy CLI"
```
ntfy publish mytopic "Backup successful 😀"
```
2021-12-05 21:57:37 +01:00
=== "HTTP"
``` http
POST /mytopic HTTP/1.1
Host: ntfy.sh
Backup successful 😀
```
=== "JavaScript"
``` javascript
fetch('https://ntfy.sh/mytopic', {
method: 'POST', // PUT works too
body: 'Backup successful 😀'
})
```
=== "Go"
``` go
http.Post("https://ntfy.sh/mytopic", "text/plain",
strings.NewReader("Backup successful 😀"))
```
=== "Python"
``` python
requests.post("https://ntfy.sh/mytopic",
data="Backup successful 😀".encode(encoding='utf-8'))
```
2021-12-05 21:57:37 +01:00
=== "PHP"
``` php-inline
file_get_contents('https://ntfy.sh/mytopic', false, stream_context_create([
'http' => [
'method' => 'POST', // PUT also works
'header' => 'Content-Type: text/plain',
'content' => 'Backup successful 😀'
]
]));
```
This will create a notification that looks like this:
<figure markdown>
2021-12-12 20:26:24 +01:00
![basic notification](static/img/android-screenshot-basic-notification.png){ width=500 }
2021-12-05 21:57:37 +01:00
<figcaption>Android notification</figcaption>
</figure>
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
2022-05-26 22:22:47 +02:00
[publishing messages](publish.md), as well as the detailed page on the [Android/iOS app](subscribe/phone.md).
2021-12-05 21:57:37 +01:00
Here's another video showing the entire process:
2021-12-04 02:38:21 +01:00
<figure>
2021-12-12 20:26:24 +01:00
<video controls muted autoplay loop width="650" src="static/img/android-video-overview.mp4"></video>
2021-12-04 02:38:21 +01:00
<figcaption>Sending push notifications to your Android phone</figcaption>
</figure>
2021-12-02 05:08:12 +01:00