Skip to main content

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.

Getting Started

1
Install Novu’s SDK in our project:
2
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:
  1. 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.
  2. 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 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 sending 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 Inngest’s 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 Inngest task. It also supports optional fields like phone and avatar.

Implementation Example

This example assumes:
  1. You have an event named video/uploaded that is being sent to Inngest when a user uploads a video.
  2. This event’s data payload includes at least videoUrl, videoId, userId, email, and userName.
  3. You have external services/functions mocked or implemented: deepgram.transcribe, llm.createCompletion, createSummaryPrompt, and db.videoSummaries.upsert.
  4. You have a Novu account, API Key (NOVU_SECRET_KEY environment variable), and a Novu workflow created with the ID video-processed-notification. This workflow should expect variables like userName, videoId, and potentially summarySnippet in its payload.
The Novu trigger call inside the implementation example maps to these SDK equivalents:

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.