@novu/echo
TypeScript icon, indicating that this package has built-in type declarations

0.24.3-alpha.0 • Public • Published

Code-First Notifications Workflow SDK

Version Downloads

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

Package Sidebar

Install

npm i @novu/echo

Weekly Downloads

535

Version

0.24.3-alpha.0

License

MIT

Unpacked Size

1.13 MB

Total Files

278

Last publish

Collaborators

  • sokratis
  • letitrock
  • scopsy