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";
11
const resend = new Resend({
13
apiKey: process.env.RESEND_API_KEY!,
18
id: "resend-drip-campaign",
19
name: "Resend: email drip campaign",
21
trigger: eventTrigger({
22
name: "send.drip.campaign",
33
run: async (payload, io, ctx) => {
35
text: `Hi there, welcome to our community! This is the first email we send you to help you get started.`,
39
await io.resend.sendEmail("email-1", {
42
subject: `Thanks for joining Acme Inc`,
44
react: <FirstEmail name={payload.name} text={email1.text} />,
47
await io.wait("wait-1-day", delay(60 * 60 * 24 * 1, ctx));
50
text: `Hi there, welcome to our community! This is the second email we send you to help you get started.`,
54
await io.resend.sendEmail("email-2", {
57
subject: `Here are some tips to get started`,
59
react: <SecondEmail name={payload.name} text={email2.text} />,
62
await io.wait("wait-4-days", delay(60 * 60 * 24 * 4, ctx));
65
text: `Hi there, welcome to our community! This is the third email we send you to help you get started.`,
69
await io.resend.sendEmail("email-3", {
72
subject: `Do you have any questions?`,
74
react: <ThirdEmail name={payload.name} text={email3.text} />,
77
await io.wait("wait-26-days", delay(60 * 60 * 24 * 26, ctx));
80
text: `This is the fourth email designed to re-engage your users after a month.`,
84
await io.resend.sendEmail("email-4", {
87
subject: `How are you getting on with Acme Inc.?`,
89
react: <MonthLaterEmail name={payload.name} text={email4.text} />,
94
function delay(seconds: number, context: TriggerContext) {
95
if (context.environment.type === "DEVELOPMENT" || context.run.isTest) {