OneSignal is not designed for real-time communication. Push notifications are best used as a fallback when users are not actively in the app. For real-time in-app messaging, use your app’s existing messaging layer and trigger OneSignal notifications only when the recipient is offline or inactive.
Social activity
Notify users when someone likes, comments, mentions, tags, or follows them.
Direct messages
Alert users to new incoming messages with debouncing and conversation deep links.
Gaming alerts
Send time-sensitive competitive events like base attacks, challenges, and guild activity.
Prerequisites
Before you begin, make sure you have:- The OneSignal SDK installed on your app. See Mobile SDK setup or Web SDK setup.
- An
external_idset for every user so you can target them by your own identifier. See Users & Aliases. - A backend that can detect social actions and call the OneSignal API. See REST API overview.
- Templates created in the dashboard if you plan to use
custom_datafor personalization. Atemplate_idis required to usecustom_data.
Social activity notifications
Send a push notification when a user is involved in a social action. Usecustom_data to inject the sender’s name, avatar, and relevant context into the message at send time. No data is stored in OneSignal.
Common social actions
| Action | Example notification |
|---|---|
| Like | ”Anna liked your photo.” |
| Comment | ”Leo replied: ‘Looks awesome!’” |
| Mention | ”Sara mentioned you in a comment.” |
| Tag | ”James tagged you in a post.” |
| Follow | ”Maya started following you.” |
| Invite | ”Ben invited you to the event.” |
| Share | ”Alex shared ‘Hawaii Album’ with you.” |
Setup
Detect the action on your backend
When a social action occurs, your backend identifies the sender and recipient, plus any relevant context like post ID or content:
JSON
Create a push template
In the dashboard, go to Messages > Templates > New Push Template. Use Liquid syntax to reference Message:Image (optional, displays the sender’s avatar):Save the template and note its
custom_data fields:Heading:Liquid
Liquid
Liquid
template_id.Call the Create Message API
From your backend, send the notification to the recipient:OneSignal renders the template at send time using the
JSON
custom_data values. The sender’s name and avatar appear in the notification without being stored in OneSignal.Optional: add email and SMS fallbacks
To reach users who have push disabled or whose notification went undelivered, see Email and SMS fallbacks below.
Throttle high-volume actions
A viral post can generate thousands oflike events per second. Don’t send a push for each one — that floods the recipient and gets your app muted or uninstalled. The pattern:
- Accumulate counts on your backend (e.g., a Redis counter keyed by recipient + post).
- After a quiet window (10 minutes is a reasonable default), send a single digest push: “12 people liked your post.”
- If more likes arrive after the digest, start a fresh window — don’t immediately push again.
Direct (user-to-user) messages
Notify a user when they receive a new direct message, and deep link them directly into the conversation.Only send a push when the recipient is not actively in the chat. Notifying someone who is already reading the conversation creates a poor experience. Use your app’s own logic to check whether the recipient is currently active before triggering a notification. OneSignal does not track whether a user is currently using your app.
Setup
Detect when a message is sent and check activity
When User A sends a message to User B, check whether User B is currently active in that conversation. If User B is offline or not in the conversation, proceed to send a push.
Avoid sending one push per message
If User A sends several messages in a row, wait a short period after the last message before triggering a notification. Here is how to do this in your backend:
- When the first message arrives, start a timer (for example, 60 seconds).
- If another message arrives before the timer runs out, reset it.
- When the timer runs out with no new messages, send a single push summarizing the unread count.
Send the push notification
Send a push to User B with a deep link to the conversation:Your app reads
JSON
data.conversation_id on notification open and navigates to the correct screen. See Deep linking for platform-specific setup.Optional: add email and SMS fallbacks
To reach users who have push disabled or whose notification went undelivered, see Email and SMS fallbacks below.
Gaming: competitive and social alerts
Competitive games benefit from time-sensitive alerts that create urgency. Usecustom_data to make these notifications feel specific and personal. A notification that names the attacker or shows exact resource counts is far more compelling than a generic alert.
Common competitive events
| Event | Example notification |
|---|---|
| Base attack | ”Your village is under attack! Orca is raiding your base.” |
| Challenge | ”DragonSlayer99 challenged you to a ranked duel. You have 24h to respond.” |
| Leaderboard | ”You’ve been knocked out of the top 10. Orca just passed you at #8.” |
| Guild event | ”Guild war starts in 30 minutes. BladeClan is counting on you!” |
| Clan invite | ”DragonSlayer99 invited you to join BladeClan.” |
| Resource ready | ”Your troops are trained and ready to deploy.” |
Setup
Detect the game event on your backend
When a competitive event occurs, your game backend identifies the affected player and captures relevant context:
JSON
Create a push template
In the dashboard, create a Push Template with Liquid references:Heading:Message:Save the template and note its
Liquid
Liquid
template_id.Send the notification
Call the Create Message API from your game backend:The
JSON
url deep links the player directly to the defend screen. The data object passes context to your app’s notification handler so it can load the correct battle state.Optional: add email and SMS fallbacks
To reach players who have push disabled or whose notification went undelivered, see Email and SMS fallbacks below.
More gaming alert examples
- Leaderboard overtake
- Guild event
- Challenge invite
Template message:API request:
Liquid
JSON
Email and SMS fallbacks
Add an email or SMS fallback to any notification type to reach users who have push disabled or whose notification was not delivered. Use the View Message API to check for a confirmed receipt or click. If none is recorded within your delay window, send a follow-up using the samecustom_data approach with an Email or SMS template.
- Email
- SMS
Social activityBest for high-value actions like mentions and direct replies.Email template example (subject):Direct messagesBest as a daily digest of unread conversations rather than per-message alerts.Email template example (subject):Email template example (body, iterating over the conversations array):See Personalize messages with API custom_data for the full array-iteration reference, including nested objects and conditional rendering.GamingBest for non-urgent recaps like weekly leaderboard summaries, guild war results, or milestone unlocks.Email template example (subject):
JSON
Liquid
JSON
Liquid
Liquid
JSON
Liquid
FAQ
Can OneSignal send notifications in real time, like a chat app?
No. Push notifications are delivered through Apple (APNs) and Google (FCM) infrastructure, which introduces variable delivery times and no delivery guarantees. Use your app’s existing messaging layer for real-time in-app communication and use OneSignal as a fallback when the recipient is not actively in the app.How do I avoid notifying a user who is already in the app?
OneSignal does not track whether a user is currently active in your app. Your own backend logic must determine whether to trigger the notification. Only call the OneSignal API when you’ve confirmed the recipient is offline or not in the relevant screen.How do I prevent multiple notifications from rapid message sequences?
Add a short delay in your backend before sending a notification. When the first message arrives, start a timer. If another message comes in before it runs out, reset it. When the timer runs out, send a single push with the unread count. OneSignal does not consolidate multiple API calls automatically, so if you call the API five times, five notifications are sent.Is custom_data saved to the user’s profile after the message sends?
No. custom_data is ephemeral and exists only during the API request, used to render the template at send time. It is not stored in OneSignal and cannot be reused in future messages or Journeys. For persistent user data, use Tags.
Can I target multiple recipients in one API call?
Yes. Pass multipleexternal_id values in the include_aliases array. If each recipient needs different personalized content (for example, different attacker names), use the bulk personalization pattern in custom_data. See Personalize messages with API custom_data for the full approach. The exact per-call recipient cap and rate limits are documented on the Create Message API reference — for very large audiences, segment-based targeting is more efficient than passing thousands of external_id values per call.
Do I need to localize messages for international users?
Yes for any audience that spans languages. Theheadings and contents fields accept multiple language codes (e.g., { "en": "...", "es": "...", "fr": "..." }) and OneSignal selects the right variant based on each subscription’s language. The same pattern applies to template fields. See Multi-language messaging for the full reference, including fallback language behavior.
Related pages
Personalize messages with API custom_data
Inject dynamic, message-specific data into templates using custom_data and Liquid syntax.
Message personalization
Overview of all personalization options in OneSignal, including Tags, user attributes, and segmentation.
Deep linking
Route users to a specific screen in your app when they tap a notification.
Create an Activity Feed
Display a history of social alerts inside your app using OneSignal’s notification inbox.
Templates
Create and manage reusable message templates for push, email, and SMS.
Create Message API
Complete API reference for sending messages with custom_data, targeting, and all available fields.