Skip to main content

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
Note

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.

Understanding Payloads

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 }}).

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.

Breakdown

The Key Components

  1. The AI Generation Task
Note

This task handles the actual AI content generation:

  • It creates text content using GPT-4
  • It creates an image using DALL-E 3
  • It has built-in retry logic (will try up to 3 times if it fails)

  1. The Two Notification Tasks

Completion Notification

Error Notification


  1. The Main Workflow Orchestrator
Note

This task:

  • Responds to the content generation event
  • Tries to generate content
  • Sends appropriate notifications based on success or failure

Notification Workflows You Would Need in Novu

  1. ai-generation-completed: Sent when content is successfully generated

Workflow payload variables: {{userName}}, {{theme}}, {{contentPreview}}, {{imageUrl}}, {{viewUrl}}

  1. ai-generation-error: Sent when content generation fails

Workflow payload variables: {{userName}}, {{theme}}, {{errorMessage}}, {{supportEmail}}

Novu trigger calls in the AI tasks example:

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.

Breakdown

How It Works

  • A user uploads a video for transcription
  • The system processes the video using Deepgram’s API
  • The user receives a notification when transcription is complete or if an error occurs

The Key Components

  1. Transcription Task

The core of this workflow is the transcribeVideo task that handles the actual transcription:

Tip

This task:

  • Downloads the video file from a URL
  • Extracts audio and converts it to WAV format
  • Sends the audio to Deepgram for transcription
  • Stores the results in a database

  1. Notification Tasks

There are two notification tasks:

Success Notification

Error Notification


  1. Main Workflow Orchestrator

Usage

  1. Create two notification workflows in Novu:
  • transcription-completed with payload variables: {{userName}}, {{videoName}}, {{wordCount}}, {{duration}}, {{viewUrl}}
  • transcription-error with payload variables: {{userName}}, {{videoName}}, {{errorMessage}}, {{supportEmail}}
  1. Trigger the workflow by sending an event:

Example Notifications

Success notification email:

Note

Subject: Your video “Weekly Team Meeting” has been transcribed

Hello John,

Good news! We’ve finished transcribing your video “Weekly Team Meeting”.

Details:

  • Duration: 32:15
  • Word count: 4,320

You can view and edit your transcription here: https://yourapp.com/transcriptions/transcript-789

Thanks for using our service!

Error notification email:

Note

Subject: Issue with transcribing “Weekly Team Meeting”

Hello John,

We encountered a problem while transcribing your video “Weekly Team Meeting”.

Error details: The audio quality was too low for accurate transcription.

Please try uploading your video again with improved audio, or contact support@yourapp.com if you need assistance.

We apologize for the inconvenience.

This workflow provides a complete solution for transcribing videos and keeping users informed about the process status, all while handling errors gracefully.

Novu trigger calls in the video processing example:

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

Note

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:

Hi {{subscriber.firstName}}, welcome!

Best Practices#

Data Management Best Practices

As a best practice, maintain consistent subscriber identification:

  • Use your internal userId as the subscriberId in Novu
  • Keep this mapping consistent across all integrations
  • Store notification preferences and settings in your user model
  • Consider adding a reference field in your user table: novuSubscriberId

Example user model:

This ensures reliable user tracking and simplifies debugging notification issues.

Proactive Data Synchronization

Keep subscriber data synchronized by:

  • Updating Novu whenever user contact info changes
  • Implementing webhooks to handle notification delivery status
  • Setting up retry mechanisms for failed updates
Enriching Subscriber Data

Enhance notifications with contextual data:

  • Store user preferences, roles, and settings
  • Include relevant business logic flags
  • Add metadata for analytics and tracking