The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix the Resend webhooks
Kiran K13db299be43f
diff --git a/apps/web/app/api/resend/webhook/email-bounced.ts b/apps/web/app/api/resend/webhook/email-bounced.tsindex c8dbdef2e3..09384e1709 100644--- a/apps/web/app/api/resend/webhook/email-bounced.ts+++ b/apps/web/app/api/resend/webhook/email-bounced.ts@@ -1,4 +1,4 @@-const NOTIFICATION_EMAIL_SUBJECT_KEYWORDS = ["bounty", "message"];+import { prisma } from "@dub/prisma";export async function emailBounced({email_id: emailId,@@ -9,5 +9,36 @@ export async function emailBounced({subject?: string;tags?: Record<string, string>;}) {- //+ if (tags?.type !== "notification-email") {+ console.log(+ `Ignoring email.bounced webhook for email ${emailId} because it's not a notification email...`,+ );+ return;+ }++ const notificationEmail = await prisma.notificationEmail.findUnique({+ where: {+ emailId,+ },+ });++ if (!notificationEmail) {+ console.log(+ `notificationEmail ${emailId} not found for email.bounced webhook.`,+ );+ return;+ }++ if (notificationEmail.bouncedAt) {+ return;+ }++ await prisma.notificationEmail.update({+ where: {+ emailId,+ },+ data: {+ bouncedAt: new Date(),+ },+ });}diff --git a/apps/web/app/api/resend/webhook/email-delivered.ts b/apps/web/app/api/resend/webhook/email-delivered.tsindex b298387a7c..78eb63f0af 100644--- a/apps/web/app/api/resend/webhook/email-delivered.ts+++ b/apps/web/app/api/resend/webhook/email-delivered.ts@@ -1,4 +1,4 @@-const NOTIFICATION_EMAIL_SUBJECT_KEYWORDS = ["bounty", "message"];+import { prisma } from "@dub/prisma";export async function emailDelivered({email_id: emailId,@@ -9,5 +9,36 @@ export async function emailDelivered({subject?: string;tags?: Record<string, string>;}) {- //+ if (tags?.type !== "notification-email") {+ console.log(+ `Ignoring email.delivered webhook for email ${emailId} because it's not a notification email...`,+ );+ return;+ }++ const notificationEmail = await prisma.notificationEmail.findUnique({+ where: {+ emailId,+ },+ });++ if (!notificationEmail) {+ console.log(+ `notificationEmail ${emailId} not found for email.delivered webhook.`,+ );+ return;+ }++ if (notificationEmail.deliveredAt) {+ return;+ }++ await prisma.notificationEmail.update({+ where: {+ emailId,+ },+ data: {+ deliveredAt: new Date(),+ },+ });}diff --git a/apps/web/app/api/resend/webhook/email-opened.ts b/apps/web/app/api/resend/webhook/email-opened.tsindex d020d7107a..ff686188d9 100644--- a/apps/web/app/api/resend/webhook/email-opened.ts+++ b/apps/web/app/api/resend/webhook/email-opened.ts@@ -11,8 +11,6 @@ export async function emailOpened({tags?: Record<string, string>;subject?: string;}) {- console.log({ emailId, tags, subject });-// 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)