Closed remon-nashid closed 1 year ago
I like the idea, and I vaguely remember looking into this a while ago. I don't quite know why I didn't pursue it further. I'll investigate it eventually.
current limitation of the UI client, that needs to remain open to receive events.
To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.
To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.
With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing.
@binwiederhier would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow? Thanks!
Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams.
With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing.
I am on Ubuntu, so I can't verify that. Can you maybe post a screenshot?
would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow?
This is tricky. I don't know anything about the server side implementation for the Push API. I don't know if it's based on HTTP/WebSockets/grpc/etc. I tried to look for libraries, but there are no popular libraries for Go, and the Push API seems like a more or less abandoned (or at least not widely used) standard, at least that's what it seemed in my 2min research.
As for where to plug it in: https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L185-L215 -- My assumption is that it's another server on a different port. I honestly don't know though, because I can't for the life of me find out what protocol it uses.
Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams.
Yeah I understand :-D
Okay I read parts of the Web Push API spec, and it looks like I was wrong. Apparently the browsers provide a push service, so Firefox/Mozilla would provide https://updates.push.services.mozilla.com/wpush
for instance, and the ntfy server would just have to forward the push to that.
So there is no additional server running that the browser has to connect to. It's all through Mozilla or Google's servers basically. I think in that case it's more similar to Firebase, in that we simply forward messages to the push service (see https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L421). The crypto of the Web Push API is quite complex, which is why I really would want to use a library for it.
I think I may do this because it's fun. But I'm not guaranteeing any timelines.
https://github.com/SherClockHolmes/webpush-go/ is a pretty good and popular library for this. I think the main obstacle (iirc the last time I looked at the firebase code for ntfy), would be that right now, Firebase keeps track of which device is subscribed to which topic, whereas with WebPush, ntfy would have to keep track of endpoint->topic mappings.
Another advantage of implementing this would be that in addition to ntfy-over-firebase, ntfy-over-unifiedpush would become possible (since WebPush and UnifiedPush are compatible). Self-hosted servers could also have push using some gateways.
current limitation of the UI client, that needs to remain open to receive events.
To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.
Could you point me to how to do this? If I understand you correctly it'll keep me notified if something happens without needing a tab with ntfy open?
Right click on the tab -> Pin tab
This does need the tab open though, but the tab is pinned, so it's just the small icon. There is no way to receive notifications without an open tab, unless you use the ntfy CLI: https://ntfy.sh/docs/subscribe/cli/#subscribe-to-topics
Gotcha, hopefully push can help with it.
VAPID, which stands for Voluntary Application Server Identity, is a new way to send and receive website push notifications. Your VAPID keys allow you to send web push campaigns without having to send them through a service like Firebase Cloud Messaging (or FCM)
Any news on this? I looked into how this would be implemened but wasn't able to find any simple tutorials of how to do this in go. i've seen more and more web pages sending these notifications, any hints on how you would add this? If it's not a huge task I might consider preparing a PR
@pinpox I just started working on this in #751, there are still some open questions about the UX around subscribing to background notifications.
There's also some technical stuff left - handling syncing from accounts and handling re-subscribing if the subscription is broken for whatever reason, and more testing on iOS (notifications work, the PWA needs to be tested more).
I've been testing the web push from #751 for a bit now, and it's been working great for me and the few other people that use my server. I was hoping this feature would be implemented soon, so big thanks to you for your work on it @nimbleghost!
@nimbleghost This would be fantastic if it works on iOS. How can I create a Docker image with your patch?
@helmut72 I also added #754, so you can simply checkout the branch run it from there.
e.g. locally: https://docs.ntfy.sh/develop/#build-a-docker-image-only-for-linux
or if using it in a compose file:
ntfy:
build:
context: ../path-to-checked-out-ntfy/
dockerfile: Dockerfile-build
command:
- serve
Please be aware that it's a WIP and I've already changed the db schema without migrations since it isn't released yet, so if you run it you may have to delete your web-push-subscriptions-file
database when pulling in updates. Service workers / application caching is also being worked on, which may result in odd behaviour and need a manual unregistration if something breaks (though so far hasn't been a problem).
@nimbleghost thanks, I have just used your repo: https://github.com/nimbleghost/ntfy
But webpush doesn't work. Added my webapp to home screen, check if notifications are enabled for this webapp, but I see the message "notification won't be supported"
@helmut72 are you using the correct branch? It's this one: https://github.com/nimbleghost/ntfy/tree/pwa
but if you are you also need to be serving the web app over https, and have the right config values set (see https://github.com/nimbleghost/ntfy/blob/pwa/docs/config.md#config-options and look for the web push options)
@nimbleghost Thanks, I've overseen that required config options. Great, now it works. I just miss that sound/beep and in the notification menu, ntfy is there twice. One entry with, other without sound.
@helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?
I am interest to have such features on web push
@mmojadad you've got the wrong tool here. ntfy is a privacy focused push notification service. Not a marketing platform. We will not add features to collect gps data or any user data, or support for campaigns.
@ binwiederhier Thanks for your clearifications.
@helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?
I have played with a commit from today lunch time. Now I've build it about 30min ago. Deleted everything and ntfy isn't there twice in the notification settings. In this single setting there is now no sound entry:
From the menu in the ntfy webapp, where I can choose the sound, sound now plays on my iPhone (and iPad):
But this feels more like a very small sound stream (like from Youtube) and not like a notification sound, because it's also there in the global player of iOS:
@helmut72 Ah you meant for the notification - as far as I can see iOS doesn't support sounds for web push whatsoever at the moment.
@nimbleghost Ok, I was unaware of this. Thanks for the info. Then it looks good for me.
I am closing this in favor of #346, which is (essentially) a duplicate. @nimbleghost is working on this right now.
This is a very neat tool. It's however missing a single feature that would make it a complete alternative for AWS/Azure notification solutions, and that is Push API support https://developer.mozilla.org/en-US/docs/Web/API/Push_API.
Any plans on enabling the server to push events to web clients? The goal is to get around the current limitation of the UI client, that needs to remain open to receive events.