Subscribers
Subscribers are the entities designed to receive notifications. Each subscriber is unique and identified by a unique subscriberId. Learn how to manage subscribers in Novu.
In Novu, we call the entities designed to receive notifications as Subscribers
. Each subscriber is unique and identified by a unique subscriberId.
We recommend using the internal unique id your application uses for a specific user as the
subscriberId
.
Each subscriber has the following data points:
- User Data - Data stored in the subscriber object that you can easily access in your notification templates. This contains basic info such as first name, last name, avatar, locale, email, and phone. This data is fixed and structured.
- Custom Data - Apart from the above fixed structured user data, any unstructured custom data such as user's address, nationality, height, etc can also be stored in the
data
field using key-value pairs. - Channel Specific Credentials -
deviceTokens
required to send push notifications andwebhookUrl
for chat channel providers can also be stored.
Subscriber attributes
Prop | Type | Default |
---|---|---|
subscriberId? | string | - |
firstName? | string | - |
lastName? | string | - |
email? | string | - |
phone? | string | - |
locale? | string | - |
avatar? | string | - |
data? | object | {} |
Creating a subscriber
We support creating new subscriber using two ways, Just-in-time
means sending complete subscriber data in to
field while triggering or Ahead of Trigger
means adding subscribers before triggering notification.
Just-in-time
A non-existing subscriber can be added by sending subscriber data in to
field of the trigger method. If any subscriber with provided subscriberId
does not exists, a new subscriber will be created. In this case, subscriber will be created first and then the trigger will be executed synchronously.
When triggering the workflow, you must specify all required to
fields per the channels in the workflow. For example, if an email step is included in the workflow, then the to.email
field must be specified. Similarly if an SMS step is included, the to.phone
field must be specified.
Hydrating users data from database
If you are defining workflows with code using @novu/framework, you can use the subscriberId
to hydrate subscriber data directly from your database or other sources during workflow execution. This is useful when you don't want to store all the subscriber data in Novu.
Learn more about @novu/framework and how to use it to define workflows with code.
For example, you may have a welcome onboarding email that you trigger immediately after a user signs up, with the email only sent 1 hour after signup:
Then, when you trigger the workflow, you can pass the subscriberId
and the workflow will fetch the user data from your database in real-time:
It is possible for two subscribers to have the same email address in our system as subscriberId
is the unique identifier that distinguishes one subscriber from another.
Ahead of Trigger
Create the subscriber and then trigger the notification to this subscriber. Here subscriberId
is the required field and other fields are optional.
Novu will create a subscriber if one does not exist and will update the existing subscriber. You can call this function during registration or signup to make sure the subscriber data is up-to-date, if you wish to save additional attributes with a subscriber, you can pass additional custom data in the data field as key-value pairs.
Bulk subscriber creation
You can create subscribers in bulk (up to 500 at once) via the SDKs or API.
Manage subscribers from dashboard
Subscribers can be managed from the dashboard by navigating to the Subscribers
page.
