Novu-2.ts
· 1.1 KiB · TypeScript
Eredeti
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(<WeeklyDigestEmail { ...controls } events = { digest.events } />)
}), {
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'
});
1 | import { workflow, CronExpression } from '@novu/framework'; |
2 | import { z } from 'zod'; |
3 | import { render } from '@react-email/render'; |
4 | |
5 | const 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 | |
23 | await commentWorkflow.trigger({ |
24 | payload: { name: 'John', comment: 'Are you free to give me a call?' }, |
25 | to: 'jane@acme.com' |
26 | }); |