OneSignal and push notifications are not designed explicitly for real-time communication. They are best used as a fallback when both users are not active on your app.For real-time communication, consider dedicated live chat solutions such as:
Social activity notifications
Trigger a push notification when a user is involved in social actions.Common social actions
Action | Example message |
---|---|
Like | “Anna liked your post.” |
Mention | “Leo mentioned you in a comment.” |
Tag | “Sara tagged you in a photo.” |
Invite | “Ben invited you to the event.” |
Comment | “Maya replied: ‘Looks awesome!’” |
Follow | “James started following you.” |
Share | “Alex shared ‘Hawaii Album’ with you.” |
Requirements
- A backend or CRM that tracks user activity and relationships.
- External IDs set in OneSignal to identify users.
- Using our Create Notification API.
Setup
1. Map users with External ID
Use Aliases & External ID to uniquely identify users in OneSignal.2. Detect the social action
In your backend, track who performed the action and who it affects.json
3. Send a push notification
Use the OneSignal API to notify the recipient:Add-ons
- Use Message Personalization to insert custom data like usernames, post titles, images, and more!
- Display a history of social alerts using an Activity Feed.
Direct (user-to-user) messages
Let users know they have a new message and optionally include message content or a deep link to the chat. Push notifications are best used as a fallback when both users are not actively chatting in the app.
Setup
1. Map users with External ID
Use Aliases & External ID to uniquely identify users in OneSignal.2. Trigger a notification on message send
From your backend, send a push to the recipient using the Create Notification API with theinclude_aliases
field:
Best practices
- Avoid spamming: Don’t send a notification for every single message. Use batching or only alert after X minutes of inactivity.
- Respect user settings: Let users mute or disable message notifications if needed.
- Use routing logic in your app to open the conversation. See Deep Linking for more information.