Novu and Trigger.dev integration guide
Learn how to integrate Novu with Trigger.dev to send notifications from background jobs. This guide covers setting up both services, managing subscribers, triggering notifications, and includes practical examples for AI content generation and video processing workflows.
This guide walks you through integrating Novu, the open-source notification infrastructure, with Trigger.dev, a powerful open-source background jobs framework for TypeScript.
By combining Novu's robust notification workflows with Trigger.Dev's event-driven background job system allows you to send notifications across multiple channels (in-app, email, SMS, push, etc.) in response to events or background tasks — all within a seamless developer experience.
Whether you're processing payments, handling user onboarding, or running scheduled tasks, Trigger.dev lets you define workflows with fine-grained control and real-time observability. Novu plugs into those workflows to manage notification content and delivery, ensuring your service / product-to-user communication has a standard.
What You'll Learn
In this guide, you'll learn how to:
- Set up both Novu and Trigger.dev in your project
- Create and update subscribers via Novu's API
- Trigger Novu notification workflows from a Trigger.dev job
- Pass dynamic payload data to power your notification templates
If you haven't used or are unfamiliar with Trigger.dev, we recommend following the quickstart guide in their docs. This guide assumes you are familiar with the fundamentals.
Getting Started
Install Novu's SDK in your project:
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 task for 2 common Novu actions:
- Trigger Notification Workflow
- Add New Subscriber
Triggering Notifications
Core Requirements
When calling Novu's trigger
method, you must provide the following information:
Workflow ID
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.
Recipient Information
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).
Note: If a subscriber with this subscriberId
doesn't already exist in Novu, Novu will automatically create one when the workflow is triggered. You can also pass other identifiers like email
, phone
, etc., within the to
object, depending on your workflow steps.
Basic Trigger Example
Here's a simple Trigger.dev task that triggers a Novu workflow when the task runs.
Working with Dynamic Content
Using Payloads
Often, you'll want your notifications to include dynamic data related to the event that triggered them. This is done using the payload
property in the novu.trigger
call.
Example Use Case
Imagine you want to send an email confirming a background job's completion:
Email Template Variables
- Subject:
Job {{ jobName }} Completed Successfully!
- Body:
Hi {{ userName }}, your job '{{ jobName }}' finished processing.
To achieve this, you would pass the userName
and jobName
in the payload
object when triggering the workflow.
Advanced Trigger Example
Key Points about Payloads
Trigger.dev Task Payload
This is the data your Trigger.dev task receives when it's invoked. It contains the context needed for the task to run.
Novu Trigger Payload
This is the data you specifically send to Novu via the payload
property in the novu.trigger()
call. It's used for populating variables in your notification templates.
Implementation Examples
AI Tasks
This example demonstrates how to build a reliable AI content generation system that keeps users informed throughout the process using Novu notifications.
Video processing
This example shows how to build a video transcription service that notifies users when their video has been transcribed or if an error occurs during processing.
Managing Subscribers
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.).
When to Create Subscribers
Create or update a subscriber in Novu when:
New User Registration
When a new user signs up or is added to your system
Notification Eligibility
When a user becomes eligible to receive notifications
Data Updates
When 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.
Subscriber Creation Example
Using Subscriber Data in Templates
Once you've added custom fields to a subscriber, you can use them in Novu templates using Handlebars:
{{subscriber.firstName}}
, welcome!