How to send push notifications using OneSignal
In this guide we'll walk through how to configure a OneSignal provider in Knock to send push notifications. This guide assumes that you've already created a OneSignal channel in the Knock dashboard.
Your OneSignal channel expects that you are using Knock to author Push notification templates. Those templates are then passed to OneSignal as content.
How to configure OneSignal Push with Knock
To setup OneSignal Push with Knock you will need:
- Your OneSignal App ID
- Your OneSignal API Key for sending notifications
- To select a mode of operation between using
external_ids
(recommended) orplayer_ids
(deprecated by OneSignal).
Using OneSignal Push with Knock
external_id
(recommended)
Using If you’re using an external id to reference your OneSignal users within Knock, you do not need to supply any additional data to initiate a request. We will automatically pass your Knock user id to OneSignal as the external_id
.
player_id
Using When using player_ids you will need to store the player_id for a user within Knock as ChannelData for the OneSignal Push channel. This ensures that Knock has the correct value to pass to send a notification to a recipient when a workflow is triggered.
You can retrieve the player_id from OneSignal once a user has been registered, either by using the OneSignal mobile SDK, or by using a Webhook from OneSignal.
Data passed to OneSignal
When sending a push notification to OneSignal, we will automatically pass the following into the attachments data:
Property | Type | Description |
---|---|---|
knock_message_id* | string | The message ID of the corresponding Knock message |
data * | string | Any key/value data passed through in your trigger call |
Silent/background notifications
When selecting to send as a silent/background notification, Knock will passthrough the content_available=true option to OneSignal. You can enable this per push notification template by clicking "Manage template settings" in the header of the template editor.
Channel data requirements
When your OneSignal push channel is configured to use player_ids
you must supply ChannelData per-recipient that contains one or more player_ids for a user.