Show HN: A tool to send push notifications to your phone, written in Go
github.com
github.com
curl -d "hi there" ntfy.sh/mytopic
It's open source and easily self-hostable. It has tons of features (though I'm still working on many), and there's also an Android app.I'd love some feedback, and I'd love it even more if you started using it. I'm doing this for funsies, but I'm also running it as a real service/project, with uptime monitoring and all that.
1. Create a Telegram bot by using BotFather (/newbot), get its HTTP API access token.
2. Invite that bot to a group, make it as a administrator.
3. Invite @RawDataBot to that group. It will tell the group's chat_id.
4. Done. If we want to trigger the notification, just send HTTP GET to https :// api.telegram.org/botBOTTOKEN/sendMessage?chat_id=CHATID&text=URLENCODEDTEXT . Replace BOTTOKEN with your bot's HTTP API access token , CHATID with the group's chat_id, and URLENCODEDTEXT with the notification text body (url encoded).
Thank you for making this open source. At least, by using this, now i can self-host everything without having to rely to Telegram anymore.
The software in TFA can be self-hosted, for privacy.
P.S. Congratulations on the launch OP, I've been looking at gotify for a while and would try to use yours when the need arises.
[1] https://play.google.com/store/apps/details?id=in.dc297.mqttc...
[2] https://play.google.com/store/apps/details?id=net.dinglisch....
My alerting regime is also built on 'curl' commands that generate SMS via twilio.
For example:
curl -s -X POST -d "Body=$msg" -d "From=$from" -d "To=$to" "https://api.twilio.com/2010-04-01/Accounts/$accountsid/Messages" -u "$accountsid:$authtoken"
... and I am very happy with the ability to send SMS with both a configurable from and to number.However I am interested and open-minded - what are the benefits of using a push notification ?
If you are happy with SMS and twilio, then use it. Having many options is generally always awesome.
The main reason I made ntfy was because I mumbo jumbo (that's a technically term) on all sorts of servers for work and for fun, and I often do things in a tmux or screen that take forever, like rsync something (ha!) or reseed a MySQL replica. On many of those servers, I cannot or should not install anything, and I certainly don't want to leave an auth token in the bash history.
For those use cases, having a short command to ping me when something is done is FREAKING AWESOME. This has become muscle memory to me by now:
rsync -av bla root@myserver:/bla; curl -d "rsync done" ntfy.sh/philalerts
No auth token. No looong string of things. Just a simple curl.But again. If you're happy with SMS+twilio, then there's no reason to switch. Though I would love it if you could give it a shot.
I am merely an rsync lover like you.
In 2005 I named my company rsync.net because I thought it was descriptive of the service.
Prior to naming it that, I explicitly asked permission from both the original author of 'rsync' and the maintainers at the time. They said they had no problem with it.
I have not authored any piece of the rsync tool.
Some twisted soul could even put sending a message to you via cronrab every minute, and you don't seem to have any way to block it, or filter it from the rest.
I'd say that it's infinitely better to have an opaque an otherwise useless API token in your bash history than to have a URL of a bare and uncontrolled web service in the same bash history, and now on the open internet.
If I were to design a service like that, I'd have an URL like domain.api/username/${token}, where the token can be changed and / or retited, should it become a target of a spam attack. Exporting this token once in the beginning of a shell session should not be hard; SSH even allows you do it with SendEnv.
As for the retirable token, you are right. In the current approach this cannot be done. I have an open ticket for auth (optional) that I'll soon implement. I want to get it right, so if you have thoughts, I'd love input on it: https://github.com/binwiederhier/ntfy/issues/19
It's just like with passwords.
Edit: isn’t this super costly for personal use?
Not really ... I notice twilio deducting USD $9 every 10 or 12 days ? It's a business expense.
I also 'lookup' numbers to check if they are mobile or not:
curl -s -X GET "https://lookups.twilio.com/v1/PhoneNumbers/$number?Type=carrier&Type=caller-name" -u $accountsid:$authtoken | /usr/local/bin/jq '.'
... which is handy. Usually shows their name and carrier ID as well.As you can see, I pipe it through 'jq' because that's what all the cool kids do.
And if you're doing this before you try to SMS them, you can skip the lookup entirely, if it's a landline you'll just get an error back.
(I work at a company that uses Twilio heavily and it's full of this sort of microoptimization)
I have a group SMS with family where people are constantly sharing pictures etc and it is working fine.
It's also against the App Store rules to make an app which provides an OS limited service such as push notifications as an API.
It would be one abstraction away, but you're right, it would be pretty close.
> It's also against the App Store rules to make an app which provides an OS limited service such as push notifications as an API.
They don't seem to enforce those rules very consistently, given how many "push notification" services exist today.
I can see spammers creating schemes to obtain peoples notification URL/address and bombarding them with multimedia popup ads with no ability for the user to block them.
Tying notifications to apps at least means that there is some audit trail and ability for users to stop receiving notifications and ultimately for the developer/sender to be removed entirely.
For example, when one of my servers reboots, I have this in cron:
@reboot sleep 600 && echo "Server has rebooted" | mail -s "Alert - Reboot notification" 2125551212@smstext.com
curl -d "Server has rebooted" "ntfy.sh/mytopic?email=phil@example.com"SMS isn't secure and I can't send an iMessage from the command line. Push notification is the only way to get a message securely to my phone.
> I can see spammers creating schemes to obtain peoples notification URL/address and bombarding them with multimedia popup ads with no ability for the user to block them.
I addressed this in a sibling comment -- it would still go through Apple's servers and there is a lot they can do to mitigate that.
> Tying notifications to apps at least means that there is some audit trail and ability for users to stop receiving notifications and ultimately for the developer/sender to be removed entirely.
If apple ran the service, they would have all the same paper trails and mitigations.
What kind of use cases do you have in mind?
Since it would still go through apple servers, they could put mitigations in place, such as checking for repeated messages to multiple accounts, one IP pushing to multiple accounts, the actual content of the message, etc. They could also put an interface right on the phone that lets you mark it as spam. They could also give you an easy way to rotate the key.
> What kind of use cases do you have in mind?
- Set up a cron to trigger an push when I know we need to leave the house.
- Set up a cron to trigger a push at 7pm to all the phones in the house to remind the kids to come to dinner (and remind me it is dinner time).
- Use a weather API and the Nest API to determine when it is time to open or close the window and push that.
- Use my cameras to determine when the postman has arrived and then push that the mail has arrived.
- Basically any useful household information that can be gathered via API and pushed without anyone having to ask for it.
You can also send images captured from your camera in addition to just text notifications.
But the point is I want Apple to do it so I don't have to rely on a 3rd party. I already have to trust Apple with my private data and for the most part rely on their servers to be up.
I don't want to add another service to rely on.
ntfy is open by default, meaning no need to create accounts or set up anything. You can use it without having to remember a token or anything. That means you can use it easily on servers where you cannot install anything, e.g. at work.
It's also a pub-sub system and not just a notification system, so you can do stuff like collect data from multiple machines super easily with multiple publishers and one subscriber [1], and whatever else you can think of.
In terms of features, I'm lagging behind a little on some things (images, nice web UI) but I'm ahead on others (scheduled messages, tags/emojis, webhooks support, email notifications, publish via email, see more [2]). I've also got a CLI that can run commands on incoming messages which is pretty neat (see [3]). Plus, i think the docs are pretty neat too.
I suggest you give it a go and tell me what you think. It's pretty easy to install the app and uninstall if you don't like it.
Here's a summary from a while ago too [4].
[1] https://ntfy.sh/docs/examples/#collect-data-from-multiple-ma...
[2] https://ntfy.sh/docs/publish/
[3] https://ntfy.sh/docs/subscribe/cli/
[4] https://www.reddit.com/r/selfhosted/comments/qxlsm9/my_open_...
I shall setup and play with this, thanks!
Edit: It was exactly for things like `bash long-running-script.sh ; notify "done"` that I installed Gotify in the first place, but I've never actually used it like that. This I surely will!
Also, there are a few more examples here [3]
[1] https://github.com/binwiederhier/ntfy/issues
Unfortunately, Firebase requires Google services. UnifiedPush integration would be nice
2. I've just started work [3] on making ntfy a UnifiedPush (https://unifiedpush.org) distributor, meaning that other apps/services will be able to use ntfy.sh (or a self-hosted server) as a means to deliver notifications or messages. I'm super excited about this, and I don't think it'll take very long.
[1] https://f-droid.org/en/packages/io.heckel.ntfy/
[2] https://play.google.com/store/apps/details?id=io.heckel.ntfy
I detailed it a bit more here with links to the docs: https://news.ycombinator.com/item?id=29719493
Edit: If you want to use FCM for your selfhosted server, you can, but you have to build your own .APK file. Instructions are here:
Although I like seeing things attempt to compete with Google, this can't come close because of the restrictions of Android enacted by Google.
I have recently started work to make ntfy a UnifiedPush distributor [2].
Side note:
- you _can_ actually dismiss the foreground service notification, see [3] for a screenshot
- the battery impact is not as severe as I had thought initially. On my phone, it's about 4% battery over 17h "use" [4]. I'm planning on making "slow delivery" possible to counter this bahavior, see this ticket [5]
[2] https://github.com/binwiederhier/ntfy/issues/9
[3] https://ntfy.sh/docs/subscribe/phone/#instant-delivery
[4] https://ntfy.sh/docs/faq/#how-much-battery-does-the-android-...
I noticed UnifiedPush and your efforts there and I am curious. My summary after a brief glance is UnifiedPush will not achieve anything useful, for the same reasons: iOS and Android push notifications are locked down. For example, sure, Android is OSS, but most of the functionality is provided by proprietary apps or Google Play Services. This results is challenges today, but further challenges down the road (App Store rules/policies change, stronger enforcement).
About the battery usage, this is always a hard question to answer. 4% is very low, which seems good. But how could you measure that effectively? Perhaps if the connection is good, it might take 4% battery over 17h of "use". But could this be worse if network is intermittent (i.e. realistic conditions)? Or lots of data being used (or *abused*).
Additionally, supporting UnifiedPush (code and adoption by app devs) is supporting:
1. Non-google app stores (e.g. F-Droid with it's great selection of FOSS apps)
2. Google-free distributions of Android
3. Linux phones
The above amount to a small but non-trivial community, but imho supporting (or participating in) them ethically is something I like.
One battery saving idea: there is a ticket to let the user control the interval at which the topic is polled. Right now it's obviously a persistent connection. But likely polling every 5min may consume less battery.
I created a ticket to remind myself: https://github.com/binwiederhier/ntfy/issues/69
Feel free to add your hopes and dreams to the ticket. ;-)
Here's how you do it:
1. Install MacroDroid [1] on your phone
2. Set up an action in MacroDroid to publish a message to a ntfy topic via a HTTP GET (see [2])
3. On your computer, install the ntfy CLI and set up the ntfy-client systemd service (or use `ntfy subscribe mytopic 'echo $m'` or something similar); see instructions here: [3]
Here are some screenshots/videos of how to integrate MacroDroid and Tasker with ntfy [4]. Please note that the MacroDroid notes are a little out of date, since you can now use HTTP GET to publish messages, so you don't need to use the "Send intent" thing anymore, which means you don't need the ntfy app on your phone.
If you need more help, you can find me on Discord [4] and I'll help out.
[1] https://play.google.com/store/apps/details?id=com.arlosoft.m...
[2] https://ntfy.sh/docs/publish/#webhooks-send-via-get
[3] https://ntfy.sh/docs/subscribe/cli/#subscribe-to-multiple-to...
https://userbase.kde.org/KDE_Connect/Tutorials/Useful_comman...
That's literally what the ntfy API is, too. Long polling over https, either as JSON or SSE or RAW. Dead simple: https://ntfy.sh/docs/subscribe/api/
Another option is to use Caddy with the Exec module with a Webhook (https://caddyserver.com/docs/modules/exec), but you’d need to use an auth plugin as well.
Update: yes, still exists
e.g. curl -d "Visit my site spammer.com for your chance to win $100" ntfy.sh/{phil_alerts,controversial,topic3,topic4, etc...}
I have pretty rigorous rate limiting based on IP address [1]. If you have lots of IP addresses at your disposal, I may have a problem. So far it's been fine.
I run it in an LXD container and I use Caddy as proxy (for Let's Encrypt HTTPS). It works very well.
Happy to provide details if someone is interested.
If you think this is a good setup and many people will run it like that, we could add it to the docs as an example on the install page: https://ntfy.sh/docs/install/
I didn't write an app, however. I rely on the browser notification API which doesn't have the best support on mobile unfortunately. It works great on desktop.
My inspiration was the same though. I do most of my work over ssh, and wanted a local desktop notification when a slow command was finished running.
All of your examples include a "!", which is a special character in bash. Sure that works without quoting?
I last have a command line pastebin called pcopy, which I host on https://nopaste.net
Great minds, I'm telling ya, great minds.
I use it like this:
cat example.txt | push
pull > example.txt
Maybe we are long-lost brothers!I was reading some guides to understand how to configure Firebase and deploy all the the necessary parts on an Azure server. But now, thanks to this, I can get everything up and running in a matter of a few minutes. You have saved me a lot of time. Not to mention the ability to easily integrate it with the other command line tools I often use. This is huge. Thank you so much for this, I'm going to get a lot out of it.
./backup-server.sh; curl -d "backup done" ntfy.sh/shake_backups
[1] https://news.ycombinator.com/item?id=29719738FWIW for anyone else, 1Pass or similar can easily create a four short words style password that's DNS compliant.
Use case: basic server monitoring.
Given that I bought the domain and all that I'm kinda sticking with the name though.
That said, auth is on the list of things to add. It'll be optional and I will try to make it simple. There's a ticket for it here [1]
It does require signup, though.
Anyone familiar with something to achieve this? Preferably self hosted
Good: it took virtually no time to set up and it’s been running for years and years.
Bad: everything gets the IFTTT logo.
I was inspired by the docs of the fantastically awesome GoReleaser [1] tool, so half the credit goes to them :-D
You can find more info on the configuration page for a self hosted server [3].
You may want to check out this question in the FAQ too [4]
You can also turn off publishing to FCM for ntfy.sh on a per-message by message basis [5].
[1] https://play.google.com/store/apps/details?id=io.heckel.ntfy
[2] https://f-droid.org/en/packages/io.heckel.ntfy/
[3] https://ntfy.sh/docs/config/#firebase-fcm