Skip to main content

Novu#

The Novu client provides methods to interact with notifications, preferences, and real-time events.

Constructor Options#

PropertyTypeDescription
backendUrlstring
applicationIdentifierstring
subscriberHashstring
contextHashstring
apiUrlstring
socketUrlstring
socketOptionsNovuSocketOptionsCustom socket configuration options. These options will be merged with the default socket configuration. Use socketType to explicitly select the socket implementation: 'cloud' for PartySocket or 'self-hosted' for socket.io. For socket.io-client connections, supports all socket.io-client options (e.g., path, reconnectionDelay, timeout, etc.). For PartySocket connections, options are applied to the WebSocket instance.
useCacheboolean
defaultScheduleDefaultSchedule
contextPartial<Record<string, ContextValue>>
subscriberIdstring
subscriberstring | Subscriber

Usage#

Notifications#

Methods#

list#

Fetches a list of notifications based on provided filters.

PropertyTypeDescription
tagsTagsFilter
readboolean
archivedboolean
snoozedboolean
seenboolean
dataRecord<string, unknown>
severitySeverityLevelEnum | SeverityLevelEnum[]
createdGtenumber
createdLtenumber

The response will be of type:

PropertyTypeDescription
notificationsNotification[]
hasMoreboolean
filterNotificationFilter

count#

Fetches the count of notifications based on filters.

PropertyTypeDescription
tagsTagsFilter
readboolean
archivedboolean
snoozedboolean
seenboolean
dataRecord<string, unknown>
severitySeverityLevelEnum | SeverityLevelEnum[]
createdGtenumber
createdLtenumber

read#

Marks a notification as read.

unread#

Marks a notification as unread.

seen#

Marks a notification as seen.

Note

Seen vs Read: Notifications can be “seen” (automatically tracked when visible) or “read” (explicitly marked by user interaction). The Inbox component automatically marks notifications as seen when they’re visible for 1+ seconds using the browser’s IntersectionObserver API. This automatic tracking batches requests for performance and works seamlessly with infinite scroll and pagination, while read status requires explicit user action.

Why no unseen method? Unlike read/unread which can be toggled, seen is designed as a one-way operation. Once a notification has been seen by a user, it remains seen. This reflects the natural user experience where visibility cannot be “undone”. Use filtering with seen: false to get unseen notifications instead.

seenAll#

Marks notifications as seen. You can filter them by notification IDs, tags, or data attributes.

archive#

Archives a notification.

unarchive#

Unarchives a notification.

readAll#

Marks all notifications as read. You can filter them by tags.

archiveAll#

Archives all notifications. You can filter them by tags.

archiveAllRead#

Archives all read notifications. You can filter them by tags.

delete#

Deletes a single notification permanently.

deleteAll#

Deletes multiple notifications permanently. You can filter them by tags or data attributes.

snooze#

Snoozes a notification for a specified duration. Here snoozeUntil is ISO 8601 formatted string timestamp, representing the date and time the notification is un-snoozed, it should be a future date and time.

unsnooze#

Unsnoozes a notification.

completePrimary#

Marks primary action of a notification as completed.

completeSecondary#

Marks secondary action of a notification as completed.

revertPrimary#

Reverts primary action of a notification to pending.

revertSecondary#

Reverts secondary action of a notification to pending.

Notification#

Individual notification instances have their own methods for marking as seen, read, archived, etc. These methods are available directly on each notification object.

Methods#

  • seen() - Marks the notification as seen
  • read() - Marks the notification as read
  • unread() - Marks the notification as unread
  • archive() - Archives the notification
  • unarchive() - Unarchives the notification
  • delete() - Deletes the notification
  • snooze() - Snoozes the notification
  • unsnooze() - Unsnoozes the notification
  • completePrimary() - Marks primary action as completed
  • completeSecondary() - Marks secondary action as completed
  • revertPrimary() - Reverts primary action to pending
  • revertSecondary() - Reverts secondary action to pending
Note
The seen() method is only available on individual notification instances, not on the novu.notifications object. Use novu.notifications.seenAll() for bulk operations.

Usage#

Preferences#

Methods#

list#

Fetches the subscriber’s notification preferences.

update#

update method is available with each preference object.

The response will be of type:

PropertyTypeDescription
levelPreferenceLevel
enabledboolean
conditionRulesLogic
subscriptionIdstring
channelsChannelPreference
overridesIPreferenceOverride[]
workflowWorkflow
schedule{ isEnabled: boolean; weeklySchedule?: WeeklySchedule; }

bulkUpdate#

Updates multiple workflow’s channel preferences at once.

Schedule#

The preferences.schedule submodule lets you fetch and update a subscriber’s delivery schedule.

get#

Fetches the subscriber’s schedule.

update#

Updates the subscriber’s schedule. You can update the entire weekly schedule or only specific days.

Schedule Class#

A Schedule instance is returned when fetching or updating a schedule.

PropertyTypeDescription
isEnabledboolean
weeklyScheduleWeeklySchedule
update(args: UpdateScheduleArgs) => Result<Schedule>

Events#

The Novu client provides real-time event handling through WebSocket connections.

Available Events#

  • notifications.notification_received: Triggered when a new notification is received.
  • notifications.unread_count_changed: Triggered when the unread count changes.
  • notifications.unseen_count_changed: Triggered when the unseen count changes.
  • preferences.schedule.get.pending: Triggered when fetching a schedule starts.
  • preferences.schedule.get.resolved: Triggered when fetching a schedule succeeds.
  • preferences.schedule.update.pending: Triggered when updating a schedule starts.
  • preferences.schedule.update.resolved: Triggered when updating a schedule succeeds.
  • subscriptions.list.pending: Triggered when loading subscriptions starts.
  • subscriptions.list.resolved: Triggered when subscriptions are loaded.
  • subscriptions.get.pending: Triggered when fetching a subscription starts.
  • subscriptions.get.resolved: Triggered when a specific subscription is fetched.
  • subscriptions.create.pending: Triggered when creating a subscription starts.
  • subscriptions.create.resolved: Triggered when a subscription is created.
  • subscriptions.update.pending: Triggered when updating a subscription starts.
  • subscriptions.update.resolved: Triggered when a subscription is updated.
  • subscriptions.delete.pending: Triggered when deleting a subscription start.
  • subscriptions.delete.resolved: Triggered when a subscription is deleted.

Connection events#

The client also emits socket lifecycle events so you can surface real-time connection state (for example, a “reconnecting” banner). Each payload carries the socketUrl in its args.

  • socket.connect.pending: Triggered when the real-time socket starts connecting.
  • socket.connect.resolved: Triggered when a connection attempt finishes, whether it succeeds or fails. On failure, the payload includes an error.
  • socket.disconnect.resolved: Triggered when the real-time socket drops or disconnect() is called. Use it to show a connection-lost state.

Usage#

Subscriptions#

The Subscriptions module lets you manage a subscriber’s subscriptions to topics. A subscription represents a subscriber’s opt-in to a topic and defines which workflows within that topic they receive notifications from.

It supports creating conditional subscriptions where users only receive notifications when the trigger payload matches a JSON Logic rule (for example, payload.tier is premium). Subscriber profile, Context data, and step results are not available in subscription conditions. Use step conditions for those cases.

Manage subscriptions at two levels:

  • Module-level methods on novu.subscriptions
  • Instance-level methods on a TopicSubscription object

Methods#

List#

Fetches all subscriptions for a specific topic.

PropertyTypeDescription
topicKeystring

The response items are TopicSubscription instances.

get#

Fetch a single subscription by topic and identifier.

PropertyTypeDescription
topicKeystring
identifierstring
workflowIdsstring[]
tagsstring[]

create#

Create a new subscription to a topic. You can pass a list of preferences to filter specific workflows or tags.

PropertyTypeDescription
topicKeystring
topicNamestring
identifierstring
namestring
preferencesPreferenceFilter[]

update#

Updates an existing subscription.

PropertyTypeDescription
namestring
preferencesPreferenceFilter[]

delete#

Delete a subscription by topic and subscription ID.

TopicSubscription#

A TopicSubscription instance represents a single subscription and provides methods for updating or deleting it, as well as managing its preferences.

PropertyTypeDescription
idstring
identifierstring
topicKeystring
preferencesSubscriptionPreference[]
update{ (args: BaseUpdateSubscriptionArgs): Result<TopicSubscription>; (args: InstanceUpdateSubscriptionArgs): Result<TopicSubscription>; }
updatePreference{ (args: BaseSubscriptionPreferenceArgs): Result<SubscriptionPreference>; (args: InstanceSubscriptionPreferenceArgs): Result<SubscriptionPreference>; }
bulkUpdatePreferences{ (args: Array<BaseSubscriptionPreferenceArgs>): Result<SubscriptionPreference[]>; (args: Array<InstanceSubscriptionPreferenceArgs>): Result<SubscriptionPreference[]>; }
delete() => Result<void>

Update a subscription#

Update subscription metadata or replace its preferences list. Use this method when updating the subscription as a whole. For granular preference updates, use preference-level methods instead.

Update SubscriptionPreference#

Each subscription contains a list of SubscriptionPreference objects that you can update individually.

PropertyTypeDescription
subscriptionIdstring
workflowWorkflow
enabledboolean
conditionRulesLogic
update(args: { value: boolean | RulesLogic; }) => Result<SubscriptionPreference>

Delete a subscription (instance method)#

Web Chat#

Two-way in-app chat with an agent. Call loadWebChat(novu) before novu.webChat.conversation(). React apps use useWebChat, which loads Web Chat automatically.

See Web Chat.

conversation()#

conversation() returns a runtime for one conversation. If you pass conversationId, later calls with the same agentId and conversationId reuse that runtime. If you omit conversationId, each call creates a new runtime and a new socket. Keep the returned object. When the chat unmounts, call dispose().

Do not call novu.webChat.subscribe() from UI code. The runtime owns the socket.

ArgumentTypeDescription
agentIdstringPublic agent identifier from the dashboard.
conversationIdstringResume this conversation. Omit this argument to start a new chat.
agentHashstringHMAC of agentId. Required when Web Chat HMAC is on.

Runtime methods#

MethodDescription
getSnapshot()Current immutable snapshot.
subscribe(listener)Call listener on every snapshot. Returns a stop function.
sendMessage(input)Send a user message. input is a string, or { text, metadata }. Creates a conversation when conversationId is omitted.
retryMessage(messageId)Resend a message whose status is failed. Reuses the original idempotency key.
respondToAction({ approvalId, decision })Resolve a pending approval. Pass approvalId from pendingActions or message parts.
sendAction({ actionId, sourceMessageId, value })Click a Card button. Do not use this for tool approval.
fetchMore()Load the next older history page.
load()Reload the newest history page. Runs on resume when conversationId is set.
dispose()Stop listeners and release the socket.

Snapshot fields#

FieldDescription
messagesConversation timeline.
pendingActionsTool approvals and MCP connect items that are still pending.
conversationIdServer id after create or resume.
run.isRunning / run.typingAgent-turn snapshot.
conversationStatus'active' or 'resolved'. This is not a loading flag.
statusHistory load: 'ready', 'loading', or 'fetching'.
pagination.hasMore / pagination.statusOlder history pages. Call fetchMore().
isRecovering / catchUpErrorReconnect recovery. The runtime reconnects on its own.
errorLast load, send, retry, or action error.

See Messages.

Types#

Notification#

PropertyTypeDescription
idstring
transactionIdstring
subjectstring
bodystring
toSubscriber
isReadboolean
isSeenboolean
isArchivedboolean
isSnoozedboolean
snoozedUntilstring
deliveredAtstring[]
createdAtstring
readAtstring
firstSeenAtstring
archivedAtstring
avatarstring
primaryActionAction
secondaryActionAction
channelTypeChannelType
tagsstring[]
redirectRedirect
dataNotificationData
workflowWorkflow
severitySeverityLevelEnum
read() => Result<Notification>
unread() => Result<Notification>
seen() => Result<Notification>
archive() => Result<Notification>
unarchive() => Result<Notification>
delete() => Result<void>
snooze(snoozeUntil: string) => Result<Notification>
unsnooze() => Result<Notification>
completePrimary() => Result<Notification>
completeSecondary() => Result<Notification>
revertPrimary() => Result<Notification>
revertSecondary() => Result<Notification>
on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => () => void
off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => void

Subscriber#

PropertyTypeDescription
idstring
subscriberIdstring
firstNamestring
lastNamestring
emailstring
phonestring
avatarstring
localestring
dataRecord<string, unknown>
timezonestring