How can I trigger notification using socket.io?

How can I trigger notification using socket.io, so whenever there is new entry in database, it automatically shows notification?

1 Like

What kind of notifications are we talking about? Native push notifications? Some custom in-app notification?

Native push notification

You wouldn’t even need SocketIO for that. If you use Ionic Apps for your push notifications, here’s an example:

  1. User sends a message
  2. The request is sent to the backend
  3. The backend handles the request
  4. Before responding, the backend calls the Ionic Apps API to send the appropriate notification
  5. Backend responds to the client

Now if you need to do this on a user-basis, I’m not sure how that works on Ionic Apps. The functionality is there, I simply haven’t made it before. If it’s for something like news, so that everyone has to receive it, then it’s simple enough after you manage to get notifications setup properly.

So yeah, basically try to look into using Ionic Apps for notifications. Get it working using the site, try the API, then setup the backend.

https://docs.ionic.io/services/push/  
https://apps.ionic.io/
https://docs.ionic.io/api/http.html  
https://docs.ionic.io/api/endpoints/push.html  

Edit: About the user basis stuff, what you could do is save the token you get when registering the device with the user in your backend, then the backend would look up the token for a user when needed and send the notification to just that token.

1 Like