// app/novu/workflows/trial-ending.js
import { workflow } from "@novu/framework";
import { renderTrialEmail } from "../emails/trial-ending";
export const trialEndingWorkflow = workflow(
"trial-ending",
async ({ step, payload }) => {
const isLastDay = payload.daysLeft === 0;
const daysMessage = isLastDay
? "ends today"
: `ends in ${payload.daysLeft} days`;
// Push notification if enabled
await step.push("push", async () => ({
subject: "Trial Ending Soon",
body: `${payload.subscriptionName} trial ${daysMessage}`,
}));
// Email notification with HTML template
await step.email("send-email", async (inputs) => ({
subject: `Your ${payload.subscriptionName} Trial is Ending Soon`,
body: renderTrialEmail({ ...payload, ...inputs }),
}));
}
);