Última actividad 1730299949

Novu-2.ts Sin formato
1import { workflow, CronExpression } from '@novu/framework';
2import { z } from 'zod';
3import { render } from '@react-email/render';
4
5const commentWorkflow = workflow('comment-workflow', async (event) => {
6 const digest = await event.step.digest('digest-comments', (controls) => ({
7 cron: controls.schedule
8 }), { controlSchema: z.object({ schedule: z.nativeEnum(CronExpression) }) });
9
10 await event.step.email('digest-email', async (controls) => ({
11 subject: controls.subject,
12 body: render(<WeeklyDigestEmail { ...controls } events = { digest.events } />)
13 }), {
14 skip: () => !digest.events.length,
15 controlSchema: z.object({
16 subject: z.string().default('Hi {{subscriber.firstName}} - Acme Comments'),
17 openAiModel: z.enum(['gpt-3.5-turbo', 'gpt-4o']).default('gpt-4o'),
18 aiPrompt: z.string().default('Produce a concise comment digest'),
19 })
20 });
21}, { payloadSchema: z.object({ name: z.string(), comment: z.string() }) });
22
23await commentWorkflow.trigger({
24 payload: { name: 'John', comment: 'Are you free to give me a call?' },
25 to: 'jane@acme.com'
26});