NovuN
Novu2y ago
BrunoLM

How to send a weekly email with notifications using echo?

The following seems to only show the last notification and not all of the digested. How can I display all of them in the email?

import { Echo } from "@novu/echo";
import { Body, Container, Head, Html, Tailwind, render } from "@react-email/components";

import { env } from "@/env";

export const echo = new Echo({
  apiKey: env.NOVU_API_KEY,
  devModeBypassAuthentication: env.NODE_ENV === "development",
});

function ReactEmail(props: unknown) {
  return (
    <Html>
      <Head />
      <Tailwind>
        <Body className="bg-white my-auto mx-auto font-sans px-2">
          <Container className="border border-solid border-[#eaeaea] rounded my-[40px] mx-auto p-[20px] max-w-[465px]">
            <pre>{JSON.stringify(props, null, 2)}</pre>
          </Container>
        </Body>
      </Tailwind>
    </Html>
  );
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function renderEmail(input: any, payload: any) {
  return render(<ReactEmail {...input} {...payload} />);
}


void echo.workflow(
  "weekly-email",
  async ({ step, payload }) => {
    await step.digest("weekly", async () => {
      return {
        amount: 2,
        unit: "minutes",
      };
    });

    await step.email("email", async (inputs) => {
      return {
        subject: "New updates",
        body: renderEmail(inputs, payload),
      };
    });
  },
  {
    payloadSchema: {
      additionalProperties: true,
    },
  },
);
Was this page helpful?