1
import { TriggerClient, TriggerContext, eventTrigger } from "@trigger.dev/sdk";
7
} from "./mocks/reactEmails";
8
import { Resend } from "@trigger.dev/resend";
9
import { z } from "zod";
10
const resend = new Resend({
12
apiKey: process.env.RESEND_API_KEY!,
17
id: "resend-drip-campaign",
18
name: "Resend: email drip campaign",
20
trigger: eventTrigger({
21
name: "send.drip.campaign",
32
run: async (payload, io, ctx) => {
34
text: `Hi there, welcome to our community! This is the first email we send you to help you get started.`,
38
await io.resend.sendEmail("email-1", {
41
subject: `Thanks for joining Acme Inc`,
43
react: <FirstEmail name={payload.name} text={email1.text} />,
46
await io.wait("wait-1-day", delay(60 * 60 * 24 * 1, ctx));
49
text: `Hi there, welcome to our community! This is the second email we send you to help you get started.`,
53
await io.resend.sendEmail("email-2", {
56
subject: `Here are some tips to get started`,
58
react: <SecondEmail name={payload.name} text={email2.text} />,
61
await io.wait("wait-4-days", delay(60 * 60 * 24 * 4, ctx));
64
text: `Hi there, welcome to our community! This is the third email we send you to help you get started.`,
68
await io.resend.sendEmail("email-3", {
71
subject: `Do you have any questions?`,
73
react: <ThirdEmail name={payload.name} text={email3.text} />,
76
await io.wait("wait-26-days", delay(60 * 60 * 24 * 26, ctx));
79
text: `This is the fourth email designed to re-engage your users after a month.`,
83
await io.resend.sendEmail("email-4", {
86
subject: `How are you getting on with Acme Inc.?`,
88
react: <MonthLaterEmail name={payload.name} text={email4.text} />,
93
function delay(seconds: number, context: TriggerContext) {
94
if (context.environment.type === "DEVELOPMENT" || context.run.isTest) {