The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update email webhooks
Steven Teyb7127a22c701
diff --git a/apps/web/app/api/resend/webhook/email-bounced.ts b/apps/web/app/api/resend/webhook/email-bounced.tsindex 549084b84c..a7764b3b29 100644--- a/apps/web/app/api/resend/webhook/email-bounced.ts+++ b/apps/web/app/api/resend/webhook/email-bounced.ts@@ -31,7 +31,7 @@ export async function emailBounced({return;}- await prisma.notificationEmail.update({+ const res = await prisma.notificationEmail.update({where: {emailId,},@@ -39,4 +39,8 @@ export async function emailBounced({bouncedAt: new Date(),},});++ console.log(+ `Updated notification email ${res.id} with Resend email id ${emailId} to bouncedAt: ${res.bouncedAt}`,+ );}diff --git a/apps/web/app/api/resend/webhook/email-delivered.ts b/apps/web/app/api/resend/webhook/email-delivered.tsindex 4faeaa551f..6cc127bd85 100644--- a/apps/web/app/api/resend/webhook/email-delivered.ts+++ b/apps/web/app/api/resend/webhook/email-delivered.ts@@ -31,7 +31,7 @@ export async function emailDelivered({return;}- await prisma.notificationEmail.update({+ const res = await prisma.notificationEmail.update({where: {emailId,},@@ -39,4 +39,8 @@ export async function emailDelivered({deliveredAt: new Date(),},});++ console.log(+ `Updated notification email ${res.id} with Resend email id ${emailId} to deliveredAt: ${res.deliveredAt}`,+ );}diff --git a/apps/web/app/api/resend/webhook/email-opened.ts b/apps/web/app/api/resend/webhook/email-opened.tsindex ff686188d9..22bcaf43e6 100644--- a/apps/web/app/api/resend/webhook/email-opened.ts+++ b/apps/web/app/api/resend/webhook/email-opened.ts@@ -1,7 +1,5 @@import { prisma } from "@dub/prisma";-const NOTIFICATION_EMAIL_SUBJECT_KEYWORDS = ["bounty", "message"];-export async function emailOpened({email_id: emailId,tags,@@ -11,18 +9,7 @@ export async function emailOpened({tags?: Record<string, string>;subject?: string;}) {- // if none of the following conditions are met, ignore the email- // 1. the tags include "type" with the value "notification-email"- // 2. the subject contains one of the keywords (TODO remove this soon)- if (- !(- tags?.type === "notification-email" ||- (subject &&- NOTIFICATION_EMAIL_SUBJECT_KEYWORDS.some((keyword) =>- subject.includes(keyword),- ))- )- ) {+ if (tags?.type !== "notification-email") {console.log(`Ignoring email.opened webhook for email ${emailId} because it's not a notification email...`,);@@ -64,10 +51,14 @@ export async function emailOpened({});console.log(- `Updated notification email ${notificationEmail.id} with Resend email id ${emailId} to opened at ${new Date()}`,+ `Updated notification email ${notificationEmail.id} with Resend email id ${emailId} to openedAt: ${notificationEmail.openedAt}`,);- if (!notificationEmail.programId || !notificationEmail.partnerId) {+ if (+ !notificationEmail.programId ||+ !notificationEmail.partnerId ||+ !notificationEmail.messageId+ ) {return notificationEmail;}