Building notification workflows with the Novu Framework
The Novu framework allows you to build and manage advanced notification workflows with code, and expose no-code controls for non-technical users to modify.
Workflows are the building blocks of your customer notification experience, they will define the what, when, how and where of your notifications.
Building blocks
Each Novu workflow is composed of 3 main components:
- Trigger - The event that will start the workflow
- Channel Steps - The delivery method of the notification with the content
- Action Steps - Actions that will happen before and after a given channel step is executed.
Let’s take a look at a simple example of a workflow that sends an email after one day:
Trigger
The trigger is the event that will start the workflow. In our current example the sample-workflow
identifier will be used as our trigger id.
Workflow identifiers should be unique to your application and should be descriptive of the workflow’s purpose.
Channel Steps
Channel Steps are the delivery methods of the notification. In our example, we have an email Channel Step that will send an email with the subject Welcome to Novu
and the body Hello, welcome to Novu!
.
Novu’s durable workflow execution engine will select the relevant delivery provider configured for this channel and send the notification with the specified content.
Novu supports a variety of common notification channels out-of-the-box, including email, SMS, push, inbox, and chat.
To read more about the full list of parameters, check out the full SDK reference.
Action Steps
Action Steps are purpose built functions that help you manage the flow of your workflow. In our example, we have a delay Acction Step that will pause the workflow for one day before sending the email.
You can also use Action Steps to perform other tasks such as fetching data from an external API, updating a database, or sending a notification to another channel.
Novu supported the following Action Steps: delay, custom and digest.
Create a Workflow
Here’s a bare-bones example of a Workflow to send a notification in response to a trigger:
We’ll build on top of this basic code block in the following examples below.
Just-in-time data fetching
You can add any custom logic needed into your steps. For example, you might want to fetch more information about your new user from a database during the Workflow execution. You can achieve this with the following changes:
We call this just-in-time notification data fetching. It allows you pull in data from the relevant sources during the Workflow execution, removing the need to store all of your subscriber data in Novu.
Multi-step workflow
What if you want to send another update to the same user in one week? But you don’t want to send the follow-up if the user opted out. We can add more steps to the Workflow to achieve this.
With this simple Workflow, we:
- Sent a new signup email
- Waited 1 week
- Sent a follow-up notification in-app
That’s the flexibility that Novu Framework offers.
Read the section on Controls next to learn how to expose Novu’s no-code editing capabilities to your peers.
Payload Schema
Payload schema defines the payload passed during the novu.trigger
method. This is useful for ensuring that the payload is correctly formatted and that the data is valid.
Tags
Tags are used to categorize the workflows. They also allow you to filter and group notifications for your Inbox tabs.
Passing Payload
Here is an example of the validated payload during trigger:
Was this page helpful?