ntfy.sh | PUT/POST push notifications to your phone
ntfy (pronounce: notify) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, entirely without signup, cost or setup. It's also open source if you want to run your own.
There are many ways to use it: Notify yourself when a build finishes, when an rsync is done or a backup fails, or know when somebody logs into your server. There are many more examples, endless possibilities 😀.
Publishing messages
Publishing messages can be done via PUT or POST. Topics are created on the fly by subscribing or publishing to them. Because there is no sign-up, the topic is essentially a password, so pick something that's not easily guessable.
Here's an example showing how to publish a message using a POST request (via curl -d):
curl -d "Backup successful 😀" ntfy.sh/mytopic
There are more features related to publishing messages: You can set a notification priority, a title, and tag messages. Here's an example using all of them:
curl \
-H "Title: Unauthorized access detected" \
-H "Priority: urgent" \
-H "Tags: warning,skull" \
-d "Remote access to $(hostname) detected. Act right away." \
ntfy.sh/mytopic
Subscribe to a topic
You can create and subscribe to a topic either in this web UI, or in your own app by subscribing to an EventSource, a JSON feed, or raw feed.
Subscribe in this Web UI
Subscribe to topics here and receive messages as desktop notification. Topics are not password-protected, so choose a name that's not easy to guess. Once subscribed, you can publish messages via PUT/POST.
Subscribe from your phone
You can use the Ntfy Android App to receive notifications directly on your phone. Just like the server, this app is also open source. Since I don't have an iPhone or a Mac, I didn't make an iOS app yet. I'd be awesome if someone else could help out.
Subscribe via your app, or via the CLI
Using EventSource in JS, you can consume notifications like this (see live example):
const eventSource = new EventSource('https://ntfy.sh/mytopic/sse');
eventSource.onmessage = (e) => {
// Do something with e.data
};
You can also use the same /sse endpoint via curl or any other HTTP library:
$ curl -s ntfy.sh/mytopic/sse
event: open
data: {"id":"weSj9RtNkj","time":1635528898,"event":"open","topic":"mytopic"}
data: {"id":"p0M5y6gcCY","time":1635528909,"event":"message","topic":"mytopic","message":"Hi!"}
event: keepalive
data: {"id":"VNxNIg5fpt","time":1635528928,"event":"keepalive","topic":"test"}
To consume JSON instead, use the /json endpoint, which prints one message per line:
$ curl -s ntfy.sh/mytopic/json
{"id":"SLiKI64DOt","time":1635528757,"event":"open","topic":"mytopic"}
{"id":"hwQ2YpKdmg","time":1635528741,"event":"message","topic":"mytopic","message":"Hi!"}
{"id":"DGUDShMCsc","time":1635528787,"event":"keepalive","topic":"mytopic"}
Or use the /raw endpoint if you need something super simple (empty lines are keepalive messages):
$ curl -s ntfy.sh/mytopic/raw
This is a notification
And another one with a smiley face 😀
Privacy policy
Neither the server nor the app record any personal information, or share any of the messages and topics with any outside service. All data is exclusively used to make the service function properly. The one exception is the Firebase Cloud Messaging (FCM) service, which is required to provide instant Android notifications (see FAQ for details).
The web server does not log or otherwise store request paths, remote IP addresses or even topics or messages, aside from a short on-disk cache (for {{.CacheDuration}}) to support service restarts.