Skip to content

Commit

Permalink
Merge pull request #731 from novuhq/feature/docs-update-onesignal-and…
Browse files Browse the repository at this point in the history
…-sdk

feat: NV-4743, NV-4744, NV-4440, COM-253
  • Loading branch information
jainpawan21 authored Jan 15, 2025
2 parents 31f70b6 + 4827e9f commit d93b548
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 45 deletions.
2 changes: 2 additions & 0 deletions api-reference/subscribers/bulk-create-subscribers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import ApikeyWarning from "/snippets/apikey-warning.mdx";

<ApikeyWarning />

<Tip>This api upserts (updates the existing values) the subscribers</Tip>

<RequestExample>

```javascript Node.js
Expand Down
6 changes: 5 additions & 1 deletion framework/typescript/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ Build and define type safe controls to expose no-code editing capabilities to yo

## Explore the SDK

- Client
- [Client](/sdks/framework/typescript/client)
- [Workflow](/sdks/framework/typescript/workflow)
- [Steps](/sdks/framework/typescript/steps)

<Info>The `@novu/framework` SDK is compatible with Node.js version 20.0.0 and above.</Info>
10 changes: 9 additions & 1 deletion inbox/react/components/preferences.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ function Novu() {

### Filtering preferences

You can filter the preferences visible by the user by specifying the `preferenceFilter` on the `Inbox` component, learn more about it [here](/inbox/react/components/inbox#filter-visible-preferences)
You can filter the preferences visible by the user by specifying the `preferenceFilter` on the `Inbox` component, learn more about it [here](/inbox/react/components/inbox#filter-visible-preferences)

### Hide global preferences
Global subscriber preferences are shown by default, it can hidden by using below code in global css file
```css
.nv-workflowContainer:first-child {
display: none;
}
```
8 changes: 3 additions & 5 deletions integrations/providers/push/apns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You also need the following to connect to APNs:

The overrides field supports all [Notification payload](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification?language=objc) values, as shown below:

```jsx
```typescript
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
Expand Down Expand Up @@ -56,7 +56,7 @@ novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
});
```

```jsx
```typescript
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
Expand Down Expand Up @@ -102,9 +102,8 @@ import {
const novu = new Novu("<NOVU_SECRET_KEY>");

await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.APNS, {
deviceTokens: ['token1', 'token2'],
deviceTokens: ['token1', 'token2'],
});

```
</Tab>
<Tab title="cURL">
Expand All @@ -119,7 +118,6 @@ curl -L -X PUT 'https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials'
"integrationIdentifier": "apns-MnGLxp8uy"
}'
```

</Tab>
</Tabs>

Expand Down
5 changes: 2 additions & 3 deletions integrations/providers/push/expo-push.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To enable Expo Push integration, you need to create an [Expo Application Servic

The overrides field supports all [Message Request](https://docs.expo.dev/push-notifications/sending-notifications/#message-request-format) values. An example of the same follows:

```jsx
```typescript
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
Expand All @@ -36,9 +36,8 @@ import {
const novu = new Novu("<NOVU_SECRET_KEY>");

await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.EXPO, {
deviceTokens: ['token1', 'token2'],
deviceTokens: ['token1', 'token2'],
});

```
</Tab>
<Tab title="cURL">
Expand Down
14 changes: 7 additions & 7 deletions integrations/providers/push/fcm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ import {
const novu = new Novu("<NOVU_SECRET_KEY>");

await novu.subscribers.setCredentials(
'subscriberId',
PushProviderIdEnum.FCM,
{ deviceTokens: ['token1', 'token2'] },
'fcm-MnGLxp8uy'
'subscriberId',
PushProviderIdEnum.FCM, {
deviceTokens: ['token1', 'token2']
},
'fcm-MnGLxp8uy'
);

```
</Tab>

Expand Down Expand Up @@ -97,7 +97,7 @@ Checkout the [API reference](/api-reference/subscribers/update-subscriber-creden

## SDK Trigger Example

```jsx
```typescript
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
Expand Down Expand Up @@ -132,7 +132,7 @@ novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
});
```

Device/notification identifiers can be set by using [setCredentials](#set-device-token) or by using the `deviceIdentifiers` field in overrides.
Device/notification identifiers can be set by using [setCredentials](#set-device-token) 

<Info> Novu uses FCM version V1</Info>

Expand Down
25 changes: 15 additions & 10 deletions integrations/providers/push/onesignal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: "Learn how to use the Onesignal provider to send push notifications

To configure the OneSignal integration, you will need an active account which has credentials for APNs, FCM or both, and have access to the `OneSignal App ID` and `Rest API Key` available via your [application's settings page](https://documentation.onesignal.com/docs/keys-and-ids).

# Setting the Device Token
## Setting the Device Token

Once OneSignal has been configured with your credentials for APNs/FCM, and the OneSignal SDK has been [set up and configured](https://documentation.onesignal.com/docs/onboarding-with-onesignal#step-1-setup-onesignal-sdk) for your application, your users will begin to be automatically assigned a unique OneSignal [player_id](https://documentation.onesignal.com/docs/users#player-id) identifier by the SDK.

Expand All @@ -31,7 +31,6 @@ await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.OneSign
// Your user's unique 'player_id' from OneSignal
deviceTokens: ['ad0452ca-3ca7-43b5-bf9b-fa93fd322035'],
});

```
</Tab>
<Tab title="cURL">
Expand All @@ -52,21 +51,27 @@ curl -L -X PUT 'https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials'

Checkout the [API reference](/api-reference/subscribers/update-subscriber-credentials) for more details.

# SDK Trigger Example

```jsx
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
## SDK Trigger Example

```typescript
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: {
subtitle: "This is subtitle value",
mutableContent: "Mutable content value",
// for android notification categories
channelId: "category_id",
// for ios notification categories
categoryId: "Category id",
// same value is used for all sizes and browsers
icon: "https://image.com/icon.png",
// used for both android and ios
sound: "sound file url"
}
});
```

Device/notification identifiers can be set by using [setCredentials](https://docs.novu.co/channels/email/resend/#set-device-token) or by using the `deviceIdentifiers` field in overrides.
113 changes: 111 additions & 2 deletions integrations/providers/push/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: "Overview"
sidebarTitle: "Overview"
description: "Learn how to configure the Push channel"
---
import { MissingProvider } from "/snippets/missing-provider.mdx";

Push notifications are a powerful way to deliver real-time updates, reminders, and personalized messages to your users across mobile and web platforms.
Whether it's a promotional alert, a system notification, or a critical update, push notifications are key to enhancing engagement and retention.
Expand All @@ -17,7 +18,115 @@ Novu simplifies the process by offering a unified API that supports multiple pus
- **Device Management**: Keep subscriber device tokens in sync using just-in-time or manual updates

## Common Use Cases

- **Transactional Notifications**: Payment updates, delivery alerts, appointment reminders
- **Engagement Notifications**: Promotions, re-engagement campaigns, social media interactions
- **System Alerts**: Security warnings, downtime alerts, account activity updates
- **System Alerts**: Security warnings, downtime alerts, account activity updates


## How to send push notifications
To send a push notification to subscribers (users) using Novu:

- Add a push channel provider in integration store
- Add push channel as a step in existing or new workflow.
- Add static or dynamic content using variables in push step fields
- Store provider specific device tokens/identifiers in subscriber profile. Read provider specific documentation on how to obtain and store device tokens.
- Make sure all provider specific steps are configured properly before triggering workflow. Read provider related documentation for all required steps.
- Trigger the workflow.

## Supported providers

- [Firebase Cloud Messaging (FCM)](/channels-and-providers/push/fcm)
- [Expo Push](/channels-and-providers/push/expo-push)
- [Apple Push Notification Service](/channels-and-providers/push/apns)
- [OneSignal](/channels-and-providers/push/onesignal)
- [Pushpad](/channels-and-providers/push/pushpad)
- [Push Webhook](/channels-and-providers/push/push-webhook)

<Note>Novu supports multiple active providers for push channel.</Note>

## Managing push device tokens

To send push notifications to subscribers, you need to store device tokens or identifiers in subscriber profiles. These tokens are unique identifiers that help push notification providers deliver messages to the correct devices. Each provider has its own method for obtaining and storing device tokens.

Novu offers to ways of keeping your device tokens in sync with subscriber profiles:

- Just-in-time: Pass device tokens in the payload when triggering a workflow. Novu will automatically update subscriber profiles with the new device tokens.
- Manual: Update subscriber profiles with device tokens using the Novu Set Credentials API.

### Just-in-time

When triggering a workflow, you can pass the `channels` array on the subscriber object with the device tokens for the push provider of your choice. Here is an example with fcm:

```typescript
novu.trigger("workflow-id", {
to: {
subscriberId: "subscriber-id",
channels: [
{
providerId: "fcm",
credentials: {
deviceTokens: ["token-1", "token-2"],
},
},
],
},
payload: {},
});
```

### Manual

Use the Novu Set Credentials API to update subscriber profiles with device tokens. You can read more about the API in the [API Reference](/api-reference/subscribers/update-subscriber-credentials) or the [FCM Example](/integrations/providers/push/fcm#setting-device-token)

## Frequently Asked Questions

### How to remove one device token from subscriber credentials?

To remove a device token from subscriber credentials, you need to get the current device tokens from subscriber credentials, remove all deviceTokens, remove the token you want to remove and then update the subscriber credentials with new device tokens.

<Tabs>
<Tab title="Node.js">
```ts
import {
Novu,
PushProviderIdEnum
} from '@novu/node';

const novu = new Novu('<NOVU_SECRET_KEY>');

// fetch subscriber details
const subscriber = await novu.subscribers.get('subscriberId');

// get current device tokens from subscriber credentials for the provider
const currentDeviceTokens = subsciber.data.data.channels.find(
// _integrationId can also be checked in place of providerId ;
(channel) => channel.providerId === PushProviderIdEnum.FCM,
).credentials.deviceTokens;

// remove all device tokens
await this.novu.subscribers.setCredentials(
'subscriberId',
PushProviderIdEnum.FCM, {
deviceTokens: []
},
);

// remove the token you want to remove
const newDeviceTokens = currentDeviceTokens.filter(
(token) => token !== 'token-to-be-removed',
);

// update subscriber credentials with new device tokens
await this.novu.subscribers.setCredentials(
'subscriberId',
PushProviderIdEnum.FCM, {
deviceTokens: newDeviceTokens
},
);
```
</Tab>
</Tabs>

<Tip>
<MissingProvider channelName="PUSH" />
</Tip>
3 changes: 1 addition & 2 deletions integrations/providers/push/push-webhook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ const novu = new Novu("<NOVU_SECRET_KEY>");

// PushProviderIdEnum.PushWebhook = push-webhook
await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.PushWebhook, {
deviceTokens: ['ANY_RANDOM_STRING'],
deviceTokens: ['ANY_RANDOM_STRING'],
});

```
</Tab>
<Tab title="cURL">
Expand Down
11 changes: 5 additions & 6 deletions integrations/providers/push/pusher-beams.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: "Learn how to use the Pusher Beams provider to send push notificati

To enable Pusher Beams integration, you need to create a Pusher Beams Instance and use both `Instance ID` and `Secret Key` from the Instance [dashboard](https://dashboard.pusher.com/beams/).

# Setting the Device Token
## Setting the Device Token

Once Pusher Beams instance has been created, and the Pusher Beams SDK has been [set up and configured](https://pusher.com/docs/beams/reference/all-libraries/) for your application, you can associate users with their devices using [Authenticated Users](https://pusher.com/docs/beams/guides/publish-to-specific-user/web/).

Expand All @@ -28,10 +28,9 @@ import {
const novu = new Novu("<NOVU_SECRET_KEY>");

await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.PusherBeams, {
// Your user's unique 'userId' from Pusher Beams
deviceTokens: ['userId-from-pusher-beams'],
// Your user's unique 'userId' from Pusher Beams
deviceTokens: ['userId-from-pusher-beams'],
});

```
</Tab>
<Tab title="cURL">
Expand All @@ -52,9 +51,9 @@ curl -L -X PUT 'https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials'

Checkout the [API reference](/api-reference/subscribers/update-subscriber-credentials) for more details.

# SDK Trigger Example
## SDK Trigger Example

```jsx
```typescript
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
Expand Down
13 changes: 5 additions & 8 deletions integrations/providers/push/pushpad.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: "Learn how to use the Pushpad provider to send web push notificatio

To configure the Pushpad integration, you will need an active account and you need to have a `Pushpad Auth Token` (from the [account settings](https://pushpad.xyz/access_tokens)) and the `Pushpad Project ID` (from the project settings).

# Setting the Device Token
## Setting the Device Token

Once Pushpad has been configured with your credentials and the Pushpad SDK has been [set up and installed](https://pushpad.xyz/docs/pushpad_pro_getting_started) on your website, you can [assign a user ID (uid)](https://pushpad.xyz/docs/identifying_users) to the push subscriptions.

Expand All @@ -28,10 +28,9 @@ import {
const novu = new Novu("<NOVU_SECRET_KEY>");

await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.Pushpad, {
// the user ID (uid) that you used for Pushpad
deviceTokens: ['user123'],
// the user ID (uid) that you used for Pushpad
deviceTokens: ['user123'],
});

```
</Tab>
<Tab title="cURL">
Expand All @@ -54,7 +53,7 @@ Checkout the [API reference](/api-reference/subscribers/update-subscriber-creden

# SDK Trigger Example

```jsx
```typescript
import { Novu } from "@novu/node";

const novu = new Novu("<NOVU_SECRET_KEY>");
Expand All @@ -65,6 +64,4 @@ novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
},
payload: {},
});
```

The devices of the subscriber that should receive the notifications can be set by using `setCredentials` or by using the `deviceIdentifiers` field in overrides.
```

0 comments on commit d93b548

Please sign in to comment.