1
import { SupabaseManagement } from "@trigger.dev/supabase";
2
import { Database } from "./mocks/supabase-types";
3
import { Resend } from "@trigger.dev/resend";
4
import { TriggerClient } from "@trigger.dev/sdk";
7
const supabaseManagement = new SupabaseManagement({
8
id: "supabase-management",
11
const db = supabaseManagement.db<Database>(
13
process.env.SUPABASE_REFERENCE_ID!
16
const resend = new Resend({
18
apiKey: process.env.RESEND_API_KEY!,
23
id: "welcome-email-campaign",
24
name: "Welcome Email Campaign",
26
trigger: db.onUpdated({
34
email_confirmed_at: [{ $isNull: true }],
37
email_confirmed_at: [{ $isNull: false }],
44
run: async (payload, io, ctx) => {
45
if (!payload.record.email) {
50
ctx.run.isTest || ctx.environment.type === "DEVELOPMENT";
53
await io.wait("wait-1", isTestOrDev ? 10 : 60 * 60);
55
const email1 = await io.resend.sendEmail("email-1", {
56
to: payload.record.email,
57
subject: `Thanks for joining Acme Inc`,
58
text: `Hi there, welcome to our community! This is the first email we send you to help you get started.`,
59
from: process.env.RESEND_FROM_EMAIL!,
62
await io.wait("wait-2", isTestOrDev ? 10 : 60 * 60 * 12);
64
const email2 = await io.resend.sendEmail("email-2", {
65
to: payload.record.email,
66
subject: `Here are some tips to get started`,
67
text: `Hi there, welcome to our community! This is the second email we send you to help you get started.`,
68
from: process.env.RESEND_FROM_EMAIL!,
71
await io.wait("wait-3", isTestOrDev ? 10 : 60 * 60 * 24);
73
const email3 = await io.resend.sendEmail("email-3", {
74
to: payload.record.email,
75
subject: "Do you have any questions?",
76
text: `Hi there, welcome to our community! This is the third email we send you to help you get started.`,
77
from: process.env.RESEND_FROM_EMAIL!,