Apple Push Notification Service (opens in a new tab), as the name suggests, is a notification delivery service provided by Apple.
Apple provides two authentication methods to make a secure connection to APNs. The first is Certificate-Based Authentication (using a .p12 certificate). The second is Token-Based Authentication (using a .p8 key). We'll make use of the .p8 key.
To enable APNS integration, you need to create an Apple Developer (opens in a new tab) account with an Admin role (opens in a new tab).
To generate the p8 key for your account:
- Head over to Certificates, Identifiers & Profiles > Keys.
- Register a new key and give it a name.
- Enable the Apple Push Notifications service (APNs) checkbox by selecting it.
- Click the Continue button and on the next page, select Register.
- Download the .p8 key file.
You also need the following to connect to APNs:
- Key ID - This is a 10-character unique identifier for the authentication key. You can find it in the key details section of the newly created key in your Apple developer account.
- Team ID - This is available in your Apple developer account.
- Bundle ID - This is the ID of your app. You can find it in the app info section of your Apple developer account.
The overrides field supports all Notification payload (opens in a new tab) values, as shown below:
import { Wolfx } from '@novu/node';
const novu = new Wolfx("<WOLFX_API_KEY>");
novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>', {
to: {
subscriberId: '<SUBSCRIBER_ID>',
},
payload: {
abc: 'def', // If the notification is a data notification, the payload will be sent as the data
},
overrides: {
apns: {
payload: {
aps: {
notification: {
# Test,
body: 'Test push',
},
data: {
key: 'value',
},
},
},
},
},
});
import { Wolfx } from '@novu/node';
const novu = new Wolfx("<WOLFX_API_KEY>");
novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>', {
to: {
subscriberId: '<SUBSCRIBER_ID>',
},
payload: {
key1: 'val1',
key2: 'val2', // If the notification is a data notification, the payload will be sent as the data
},
overrides: {
type: 'data',
apns: {
headers: {
'apns-priority': '5',
},
payload: {
aps: {
alert: {
'loc-key': 'GAME_PLAY_REQUEST_FORMAT',
'loc-args': ['Shelly', 'Rick'],
},
sound: 'demo.wav',
},
},
},
},
});
Before triggering the notification to a subscriber(user) with push as a step in the workflow, make sure you have added the subscriber's device token as follows:
import {
Wolfx,
ChatProviderIdEnum
} from '@novu/node';
const novu = new Wolfx("<WOLFX_API_KEY>");
await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.APNS, {
deviceTokens: ['token1', 'token2'],
});
Checkout the API reference for more details.