Intro

Invoices and receipts require custom fields such as the order number, billing details, and objects purchased which must be dynamically fetched from the database. The use of step controls and the payload schema simplifies the fetching of that unique data.

Explore the source code on GitHub

Preview

Code Example

import { workflow } from '@novu/framework';
import { renderAppleReceiptEmail } from '../emails/apple-receipt';
import { zodControlSchema, jsonSchema, zodPayloadSchema } from './schemas';

/**
 * Apple Receipt Workflow
 */
export const appleReceipt = workflow(
  "Apple Receipt",
  async ({ step, payload }) => {
    await step.email(
      "send-email",
      async (controls) => {
        return {
          subject: controls.receiptSubject,
          body: renderAppleReceiptEmail(controls, payload),
        };
      },
      {
        controlSchema: zodControlSchema
      },
    );
  },
  { 
    payloadSchema: zodPayloadSchema
  }
);