Novu and Inngest integration guide
This guide walks you through integrating Inngest with Novu notifications
Why Use Novu with Inngest?
By combining these tools, you can:
- Trigger Smart Notifications: Send notifications across multiple channels (email, SMS, push, in-app) based on complex event triggers
- Build Reliable Workflows: Create robust notification pipelines with Inngest's state management and retry capabilities
- Scale Effortlessly: Handle high-volume notification workloads with Inngest's queue management
- Maintain Observability: Monitor your notification workflows in real-time through Inngest's dashboard
What You'll Learn
This guide teaches you how to:
- Configure Novu and Inngest in your project
- Manage notification subscribers via Novu's API
- Create event-driven notification workflows with Inngest
- Use dynamic data to personalize your notifications
New to Inngest? We recommend starting with their quickstart guide before continuing.
-
Install Novu's SDK in our project
-
Create a new task
You can also add this trigger to an existing one or multiple tasks
Import Novu's SDK and provide the credentials to initialize the Novu instance.
For the sake of this guide, we will create a new dedicated functions for 2 common Novu actions:
- Trigger Notification Workflow
- Add New Subscriber
Trigger Notification Workflow from an Inngest function
You can trigger Novu notification workflows directly from your Ingest function. This allows you to send notifications based on events or completions within your background jobs.
To trigger a Novu workflow, you'll use the Novu Node.js SDK within your Inngest's createFunction
method.
Core Requirements
When calling Novu's trigger
method, you must provide the following information:
workflowId
(string): This identifies the specific notification workflow you want to execute.- Note: Ensure this workflow ID corresponds to an existing, active workflow in your Novu dashboard.
to
(object): This object specifies the recipient of the notification. At a minimum, it requires:subscriberId
(string): A unique identifier for the notification recipient within your system (e.g., a user ID).
subscriberId
doesn't already exist in Novu, Novu will automatically create one when the workflow is triggered. You can also pass other identifiers likeemail
,phone
, etc., within theto
object, depending on your workflow steps.
Basic Trigger Example
Here's a simple Inngest function that triggers a Novu workflow when the function is being invoked. It assumes the function invoke receives a userId
and email
in its payload.
Adding Dynamic Content with payload
Often, you'll want your notifications to include dynamic data related to the event that triggered them (e.g., a user's name, an order number, job details).
This is done using the payload
property in the novu.trigger
call.
The payload
is an object containing key-value pairs that you can reference within your Novu notification templates using Handlebars syntax (e.g., {{ name }}
, {{ order.id }}
).
Use Case Example:
Imagine you want to send an email confirming a background job's completion:
- Subject:
Function {{ functionName }} Completed Successfully!
- Body:
Hi {{ userName }}, your function '{{ functionName }}' finished processing.
To achieve this, you would pass the userName
and functionName
in the payload
object when triggering the workflow.
Trigger Example with Payload
Let's modify the previous function to accept more data (like a user's name
) in its own payload and pass relevant parts to the Novu trigger
payload.
Add a New Subscriber to Novu
Before triggering notifications, Novu needs to know who to notify. That's where subscribers come in. A subscriber in Novu represents a user (or entity) that can receive notifications through one or more channels (in-app, email, SMS, etc.).
You can create a new subscriber programmatically from a Trigger.dev task using Novu's SDK.
When Should You Create Subscribers?
Create or update a subscriber in Novu when:
- A new user signs up or is added to your system
- A user becomes eligible to receive notifications
- You want to ensure subscriber metadata (name, phone, etc.) is up-to-date
If you trigger a workflow with a subscriberId
that doesn't exist, Novu will auto-create the subscriber. However, doing it explicitly ensures full control over subscriber data.
Create a Subscriber in a Task
Below is a task that creates a Novu subscriber using a Trigger.dev task. It also supports optional fields like phone
and avatar
.
Implementation Example
This example assumes:
- You have an event named
video/uploaded
that is being sent to Inngest when a user uploads a video. - This event's
data
payload includes at leastvideoUrl
,videoId
,userId
,email
, anduserName
. - You have external services/functions mocked or implemented:
deepgram.transcribe
,llm.createCompletion
,createSummaryPrompt
, anddb.videoSummaries.upsert
. - You have a Novu account, API Key (
NOVU_SECRET_KEY
environment variable), and a Novu workflow created with the IDvideo-processed-notification
. This workflow should expect variables likeuserName
,videoId
, and potentiallysummarySnippet
in its payload.
Template Usage Example
Once you've added custom fields (like firstName
, userName
, or phone
) to a subscriber, you can use them in Novu templates using Handlebars:
- Hi
{{subsciber.firstName}}
, welcome! - We'll reach you at
{{subsciber.phone}}
if needed. - Your account is set up under
{{subscriber.data.userName}}
.
Best Practices
- Store your Novu
subscriberId
as part of your user model — so you always have a reference. - Create/update subscribers proactively when user data changes (e.g., phone number updates).
- Use
data
to store additional info like roles, tags for more personalized notifications.