Notifications

Push notification token management

Overview

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

Register a push token

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

Unregister a token

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

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:

// Get notification feed
const { data: items } = await r.inbox.list({ limit: 20 });
for (const item of items) {
console.log(`${item.title}${item.status}`); // "unread" or "read"
}
// Mark as read
await r.inbox.markRead(item.id);

Platform setup

Expo (React Native)

import * as Notifications from 'expo-notifications';
// Get the push token
const { data: token } = await Notifications.getExpoPushTokenAsync();
// Register with Recursiv
await r.notifications.registerToken({
token: token,
platform: Platform.OS, // 'ios' or 'android'
});

Web Push

// Get browser push subscription
const registration = await navigator.serviceWorker.ready;
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: vapidPublicKey,
});
await r.notifications.registerToken({
token: JSON.stringify(subscription),
platform: 'web',
});