Facebook Pixel
Chat Notifications for Offline Users Email and Push Notifications

How do I send notifications to offline chat users?

The answer

Maintain a Map of online users. When a message is sent, check if the receiver is online. If not, send an email notification with the sender's name, message preview, and a link to the chat. Rate-limit to 1 email per 10 minutes and respect user notification preferences.

More FAQs in Chat Notifications for Offline Users Email and Push Notifications

Request Notification.permission on first visit. When a message is received via Socket.io and the tab is hidden (document.hidden), create a new Notification with the sender's name, message text, and icon. Handle notificationclick to open the chat URL.

Check NotificationLog for a recent notification (within 10 minutes) before sending. If one exists, skip. Also respect user preferences (notificationPreferences.messageEmail). Don't send to bounced or complained emails. Log each notification sent.

Add a notificationPreferences object to the User model (messageEmail, messagePush, connectionEmail, dailyDigest, all booleans). Create a PATCH endpoint to update preferences. Check these flags before sending any notification.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.