How to send push notifications using Expo
In this guide we'll walk through how to configure an Expo provider in Knock to send push notifications. This guide assumes that you've already created an Expo channel in the Knock dashboard and that your React Native application is already setup to support Push notifications.
If you're new to setting up push in your Expo enabled React Native project, you can follow the excellent setup guide in the Expo documentation.
To configure Expo with Knock, you'll need your Expo project name (sometimes referred to as an
experience_id) and if you've enabled enhanced push security, you'll also need an auth token. You can read more about Enhanced Push Security in the Expo docs.
You can get both of these by logging into the Expo console. Once you have them, go back to the environment configuration for your Expo channel, complete the configuration, and you're good to go.
In order to use Expo with Knock you'll need to synchronize your users device tokens retrieved from the Expo SDK in either Android, iOS, or on the Web to Knock by setting channel data for your recipient.
You can follow the appropriate quickstart guide for your platform on Expo to see how to get the device token.
Knock makes no assumptions about managing your device tokens for you. Meaning if a recipient opts-out of receiving notifications on a device, or the token expires, it is up to you to remove the token from the recipients channel data. This behavior is subject to change in the future.
When sending a notification to Expo, we also pass through the following attributes:
|knock_message_id*||string||The message ID of the corresponding Knock message|
|data *||string||Any key/value data passed through in your trigger call|
We support sending Expo notifications as "silent", data-only notifications within Knock. You can enable this per push notification template under the 3-dot menu in the header of the template editor.
When silent push is enabled, we'll no longer pass through the content payload and your message will be sent with the
content-available: true flag as expected by Expo. All properties in the data payload described above will be sent with your notification.
We have full support for overriding the payload sent to Expo for adding things like badge counts, extra data properties, and sound files. You can set the push overrides under the 3 dot menu in "Manage settings > Push overrides". Push overrides support liquid for injecting data properties and referencing attributes on your recipients.
The overrides set are merged into the notification payload sent to Expo. See the Expo documentation for details.
In order to use a configured Expo channel you must store a list of one or more device tokens for the user or the object that you wish to deliver a notification to. You can retrieve a device token by following the guide on the Expo developer documentation.
|tokens*||string||One or more device tokens|