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!

You can take a look at onesignal for push notifications:

1 Like

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.

3 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:

1 Like