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";
6
const supabaseManagement = new SupabaseManagement({
7
id: "supabase-management",
10
const db = supabaseManagement.db<Database>(
12
process.env.SUPABASE_REFERENCE_ID!
15
const resend = new Resend({
17
apiKey: process.env.RESEND_API_KEY!,
22
id: "welcome-email-campaign",
23
name: "Welcome Email Campaign",
25
trigger: db.onUpdated({
33
email_confirmed_at: [{ $isNull: true }],
36
email_confirmed_at: [{ $isNull: false }],
43
run: async (payload, io, ctx) => {
44
if (!payload.record.email) {
49
ctx.run.isTest || ctx.environment.type === "DEVELOPMENT";
52
await io.wait("wait-1", isTestOrDev ? 10 : 60 * 60);
54
const email1 = await io.resend.sendEmail("email-1", {
55
to: payload.record.email,
56
subject: `Thanks for joining Acme Inc`,
57
text: `Hi there, welcome to our community! This is the first email we send you to help you get started.`,
58
from: process.env.RESEND_FROM_EMAIL!,
61
await io.wait("wait-2", isTestOrDev ? 10 : 60 * 60 * 12);
63
const email2 = await io.resend.sendEmail("email-2", {
64
to: payload.record.email,
65
subject: `Here are some tips to get started`,
66
text: `Hi there, welcome to our community! This is the second email we send you to help you get started.`,
67
from: process.env.RESEND_FROM_EMAIL!,
70
await io.wait("wait-3", isTestOrDev ? 10 : 60 * 60 * 24);
72
const email3 = await io.resend.sendEmail("email-3", {
73
to: payload.record.email,
74
subject: "Do you have any questions?",
75
text: `Hi there, welcome to our community! This is the third email we send you to help you get started.`,
76
from: process.env.RESEND_FROM_EMAIL!,