Notification plugin/extension for Strapi

Hi, I’m in the proces of adding a push notification feature to my Strapi app (frontend Nuxt.js) where users can view notifications when someone else comments on their post or @mentions them. Being the beginner that I am, I’m not so sure how to go about doing it, so I’m doing some research and looking for good references to e.g. public Github repos to look at example code.

Has anyone implemented a notification system for Strapi here? Would love to take a look for learning… TIA!

1 Like

You can take a look at onesignal for push notifications:

3 Likes

Thanks as always Sunny!

I realised I must have used the wrong term. Just notifications, not push notifications. The kind like in Facebook, where we get when someone comments on our post.

Yes, that was the wrong term.

For notifications you should do the following:

Integrate Websockets (to get real time notifications, you can take a look at socket.io), if you don’t mind to get notifications only during refresh then use the Rest API. You can also use Rest API to get periodically new notifications, like every 30seconds.

Create a collection type called Notifications (with fields: Type [Enumeration: Mention, Reply], Relation with User [User has many Notifications], Read [Boolean])

When someone replies to the author’s post, then you create a new entry in notification with Relation to the user and with Type: Reply. Now you can use Websockets to emit a new event to the user, so it will get the new notification in realtime, or you can fetch them Periodically with RestAPI. Now you count all the user’s notifications with Read:false and display a badge with the count in frontend. When user clicks on a notifications you make a call to API and set Read: true, if the call was successful then you subtract -1 from counts in the frontend.

I hope that helps you a bit to understand what to do.

9 Likes

THANK YOU SOOO MUCH, @sunnyson ! You’re a life saver! I was over-thinking it in terms of lifecycle hooks, installing plugins, web sockets etc, but your explanation about just using a REST API like the other Strapi endpoints just clicked in my head, that I didn’t need it to be so complicated. Much grateful :pray:

3 Likes

It seem quite easy and charm, thanks!

1 Like

Thanks @sunnyson that’s brilliant. What if I want to inform users through notification when a new post is created? in this case would it be appropriate to make a relationship with Notification collection with post and populate Notification whenever a post is created. Moreover add title of the post as Notification title when a new post is created. OR any other way??

Regards

It seems strange to answer my own query but I thought it would be helpful for some new like me who comes on this forum and looking for the same solution. I discovered that Webhooks in Strapi can do this for me for more details please read this article Webhooks? in Strapi

Hi, i am new to strapi, i have created a webhook named user-notification

Requirement: anytime a new entry is made in notification collection trigger an event and show that content on next js website.

How do we access the notified data on next js website? Do we need to have any api endpoint?

2 Likes

I tried to get information about it and there is no API for notifications.

There is one plugin for integrating SocketIO but I could not make it work.

Finally, I opted for using Firebase Messages to handle it.