@novu/echo
v0.24.3-alpha.4
Published
The Code-First Notifications Workflow SDK.
Downloads
1,242
Readme
Code-First Notifications Workflow SDK
Novu Echo SDK 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 Echo 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/echo
Quickstart
import { Echo } from '@novu/echo';
const echo = new Echo();
const commentWorkflow = echo.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
});