import { workflow, CronExpression } from '@novu/framework'; import { z } from 'zod'; import { render } from '@react-email/render'; const commentWorkflow = workflow('comment-workflow', async (event) => { const digest = await event.step.digest('digest-comments', (controls) => ({ cron: controls.schedule }), { controlSchema: z.object({ schedule: z.nativeEnum(CronExpression) }) }); await event.step.email('digest-email', async (controls) => ({ subject: controls.subject, body: render() }), { skip: () => !digest.events.length, controlSchema: z.object({ subject: z.string().default('Hi {{subscriber.firstName}} - Acme Comments'), openAiModel: z.enum(['gpt-3.5-turbo', 'gpt-4o']).default('gpt-4o'), aiPrompt: z.string().default('Produce a concise comment digest'), }) }); }, { payloadSchema: z.object({ name: z.string(), comment: z.string() }) }); await commentWorkflow.trigger({ payload: { name: 'John', comment: 'Are you free to give me a call?' }, to: 'jane@acme.com' });