Notifications

Push notification token management

Overview

The notifications resource manages push notification tokens for mobile and web push.

Register a push token

1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv();
4
5// Register a push notification token (e.g., from Expo or Firebase)
6await r.notifications.registerToken({
7 token: 'ExponentPushToken[xxxxxxxxxxxx]',
8 platform: 'ios', // 'ios' | 'android' | 'web'
9});

Unregister a token

1// Remove a push token when the user logs out or disables notifications
2await r.notifications.unregisterToken({
3 token: 'ExponentPushToken[xxxxxxxxxxxx]',
4});

Methods

MethodDescription
r.notifications.registerToken({ token, platform })Register a push notification token
r.notifications.unregisterToken({ token })Remove a push notification token

In-app notifications

For in-app notification feeds, use the inbox resource:

1// Get notification feed
2const { data: items } = await r.inbox.list({ limit: 20 });
3
4for (const item of items) {
5 console.log(`${item.title} — ${item.status}`); // "unread" or "read"
6}
7
8// Mark as read
9await r.inbox.markRead(item.id);

Platform setup

Expo (React Native)

1import * as Notifications from 'expo-notifications';
2
3// Get the push token
4const { data: token } = await Notifications.getExpoPushTokenAsync();
5
6// Register with Recursiv
7await r.notifications.registerToken({
8 token: token,
9 platform: Platform.OS, // 'ios' or 'android'
10});

Web Push

1// Get browser push subscription
2const registration = await navigator.serviceWorker.ready;
3const subscription = await registration.pushManager.subscribe({
4 userVisibleOnly: true,
5 applicationServerKey: vapidPublicKey,
6});
7
8await r.notifications.registerToken({
9 token: JSON.stringify(subscription),
10 platform: 'web',
11});