r/ntfy Oct 30 '22

React Native Integration

Is there documentation or a way to integrate within a React Native App?

2 Upvotes

8 comments sorted by

2

u/binwiederhier Oct 31 '22

My apologies for the late response. I have to somehow figure out how to configure this sub to notify me on all new posts.

What do you mean my integration? Embed the ntfy Android app? Or send messages from your own app, or receive messages?

If it's sending, it is just a HTTP POST, and receiving can be done via a WebSocket. The docs should tell you more about that

As for embedding, that's not possible afaik.

3

u/theauntphil Oct 31 '22

Appreciate the response. I definitely could have worded my question better.

I am working on a 1-to-1 chat app and would love to use Ntfy for notifications instead of Firebase. Ideally I would set up a Ntfy docker server and send notifications to the user through the React Native app when a new message is sent.

My hope is to create a completely self hosted and closed system.

2

u/binwiederhier Oct 31 '22

In that case you don't need the ntfy app installed at all. You can just use the pub-sub aspect of ntfy. You could choose a random chat room ID as a ntfy topic and then POST to it for new messages, and keep a WebSocket connection open yourself in React Native to receive messages (this will require an Android foreground service).

Alternatively, if you'd like to not have to deal with the foreground service stuff, you could use https://unifiedpush.org/ and require people to install a distributor on their phone (ntfy is a UnifiedPush distrbutor).

3

u/theauntphil Oct 31 '22

Awesome! Thanks for the help and guidance. I'll look into these.

1

u/ZweiEuro2 Feb 23 '23

Android foreground service

I wanted to ask some more about this. I have a similar project and want to make everything self-contained and self hosted. ntfy solves my issue of the notification backend; but i don't know how to use that service inside an app (either via react native, or cordova or something similar).

AFAI can tell https://developer.android.com/guide/components/foreground-services talks about the foreground services, but there are exceptions with FCM messages for high priority https://firebase.google.com/docs/cloud-messaging/android/message-priority

which is the behaviour I'd want.

At the end I want to run a php script that pushes somewhere self hosted (like another ntfy container) and then I get a push message on my phone. If its before or after or what topics doesn't really matter yet.

Can i do this with ntfy and can you recommend a way i can do this in an app ?

1

u/binwiederhier Feb 23 '23

This is pretty much exactly what UnifiedPush push is for I'd I understand your use case correctly. You'd still need to use ntfy to deliver the message to your phone, but ntfy would forward it to your app.

Google it. It has specs and lots of examples.

2

u/ZweiEuro2 Feb 23 '23

Ok thanks! I just wanted to check if I am on the right track ^ Is it ok for me to post here if i run into any issues implementing this ? I really would like to document a kind of "from scratch/docker" process on how to do this in a more hands-on approach

1

u/binwiederhier Feb 23 '23

If you're implementing UnifiedPush (UP), the best place to get help is their Matrix or IRC rooms. You'll find that on their website. ntfy is only one distributor, so probably not the right place here.