Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
npm install @sirenapp/js-sdk
yarn add @sirenapp/js-sdk
<script src="https://siren-js.sirenapp.io/siren-js-umd-sdk.js"></script>
import Siren from "@sirenapp/js-sdk"; const sirenInstance = new Siren({ token: "your-user-token", recipientId: "your-recipient-id", onError: (error) => { console.error("Siren Error:", error); }, actionCallbacks: { onEventReceive: (response, eventType) => { console.log("Event received:", eventType, response); } } });
token
recipientId
onError
actionCallbacks
const { unviewedCount } = await sirenInstance.fetchUnviewedNotificationsCount(); console.log("Unviewed notifications:", unviewedCount);
const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '2024-01-01T00:00:00.000Z', end: '2024-12-31T23:59:59.999Z', isRead: false, category: 'updates' });
page
size
start
end
isRead
category
interface Notification { id: string; createdAt?: string; message: { channel: string; header: string; subHeader: string; body: string; actionUrl: string; avatar: { imageUrl: string; actionUrl: string | null; }; additionalData: string; }; requestId: string; isRead: boolean; }
// For notifications sirenInstance.startRealTimeFetch({ eventType: 'NOTIFICATIONS', params: { page: 0, size: 15, start: '2024-01-01T00:00:00.000Z', end: '2024-12-31T23:59:59.999Z', isRead: false, category: 'updates' } }); // For unviewed count sirenInstance.startRealTimeFetch({ eventType: 'UNVIEWED_COUNT' });
// Stop notifications updates sirenInstance.stopRealTimeFetch('NOTIFICATIONS'); // Stop unviewed count updates sirenInstance.stopRealTimeFetch('UNVIEWED_COUNT');
await sirenInstance.markAsReadById("notification-id-123");
await sirenInstance.markAsReadByDate({ startDate: "2024-01-01T00:00:00.000Z", category: "updates" // Optional });
await sirenInstance.deleteById("notification-id-123");
await sirenInstance.deleteByDate({ startDate: "2024-01-01T00:00:00.000Z", isRead: true, // Optional category: "updates" // Optional });
await sirenInstance.markAllAsViewed("2024-01-01T00:00:00.000Z");
import Siren from "@sirenapp/js-sdk"; // Initialize const siren = new Siren({ token: "your-user-token", recipientId: "your-recipient-id", onError: (error) => { console.error("Siren Error:", error); }, actionCallbacks: { onEventReceive: (response, eventType) => { if (eventType === 'NOTIFICATIONS') { console.log("New notifications:", response); } else if (eventType === 'UNVIEWED_COUNT') { console.log("Unviewed count:", response.unviewedCount); } } } }); // Fetch initial data async function initialize() { try { // Get unread count const { unviewedCount } = await siren.fetchUnviewedNotificationsCount(); console.log("Initial unread count:", unviewedCount); // Get notifications const notifications = await siren.fetchAllNotifications({ page: 0, size: 10, isRead: false }); console.log("Initial notifications:", notifications); // Start real-time updates siren.startRealTimeFetch({ eventType: 'NOTIFICATIONS' }); siren.startRealTimeFetch({ eventType: 'UNVIEWED_COUNT' }); } catch (error) { console.error("Initialization failed:", error); } } // Mark all as read async function markAllAsRead() { try { await siren.markAsReadByDate({ startDate: new Date().toISOString() }); console.log("All notifications marked as read"); } catch (error) { console.error("Failed to mark as read:", error); } } // Clean up function cleanup() { siren.stopRealTimeFetch('NOTIFICATIONS'); siren.stopRealTimeFetch('UNVIEWED_COUNT'); } // Initialize the app initialize(); // Clean up on unmount window.addEventListener('beforeunload', cleanup);
Was this page helpful?