Code-First Notifications Workflow SDK

Novu Framework allows you to write notification workflows in your codebase. Workflows are functions that execute business logic and use your preferred libraries for email, SMS, and chat generation. You can use Novu Framework with React.Email, MJML, or any other template generator.
Learn more about the Code-First Notifications Workflow SDK in our docs.
Installation
npm install @novu/framework
Quickstart
import { workflow } from '@novu/framework';
import { serve } from '@novu/framework/express';
const commentWorkflow = await workflow(
'comment-on-post',
async ({ payload, step }) => {
const inAppResponse = await step.inApp('notify-user', async () => ({
body: renderBody(payload.postId),
}));
const weeklyDigest = await step.digest('wait-1-week', () => ({
amount: 7,
unit: 'days',
}));
await step.email(
'weekly-comments',
async (inputs) => {
return {
subject: `Weekly post comments (${weeklyDigest.events.length + 1})`,
body: renderReactEmail(inputs, weeklyDigest.events),
};
},
{ skip: () => inAppResponse.seen }
);
},
{
payloadSchema: {
type: 'object',
properties: {
postId: {
title: 'Post ID',
type: 'string',
description: 'The ID of the post.',
default: '123',
},
},
required: ['postId'],
additionalProperties: false,
} as const,
}
);
serve({ workflows: [commentWorkflow] });