The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add new webhook handler
Kiran Kcec3802b9ce4
diff --git a/apps/web/app/api/resend/webhook/email-bounced.ts b/apps/web/app/api/resend/webhook/email-bounced.tsnew file mode 100644index 0000000000..c8dbdef2e3--- /dev/null+++ b/apps/web/app/api/resend/webhook/email-bounced.ts@@ -0,0 +1,13 @@+const NOTIFICATION_EMAIL_SUBJECT_KEYWORDS = ["bounty", "message"];++export async function emailBounced({+ email_id: emailId,+ subject,+ tags,+}: {+ email_id: string;+ subject?: string;+ tags?: Record<string, string>;+}) {+ //+}diff --git a/apps/web/app/api/resend/webhook/email-delivered.ts b/apps/web/app/api/resend/webhook/email-delivered.tsnew file mode 100644index 0000000000..b298387a7c--- /dev/null+++ b/apps/web/app/api/resend/webhook/email-delivered.ts@@ -0,0 +1,13 @@+const NOTIFICATION_EMAIL_SUBJECT_KEYWORDS = ["bounty", "message"];++export async function emailDelivered({+ email_id: emailId,+ subject,+ tags,+}: {+ email_id: string;+ subject?: string;+ tags?: Record<string, string>;+}) {+ //+}diff --git a/apps/web/app/api/resend/webhook/route.ts b/apps/web/app/api/resend/webhook/route.tsindex 514637d831..67fe259fbc 100644--- a/apps/web/app/api/resend/webhook/route.ts+++ b/apps/web/app/api/resend/webhook/route.ts@@ -1,16 +1,19 @@import { NextResponse } from "next/server";import { Webhook } from "svix";import { contactUpdated } from "./contact-updated";+import { emailBounced } from "./email-bounced";+import { emailDelivered } from "./email-delivered";import { emailOpened } from "./email-opened";+const webhookSecret = process.env.RESEND_WEBHOOK_SECRET!;+// POST /api/resend/webhook – listen to Resend webhooksexport const POST = async (req: Request) => {const rawBody = await req.text();- const secret = process.env.RESEND_WEBHOOK_SECRET!;+ const webhook = new Webhook(webhookSecret);- const wh = new Webhook(secret);// Throws on error, returns the verified content on success- wh.verify(rawBody, {+ webhook.verify(rawBody, {"svix-id": req.headers.get("svix-id")!,"svix-timestamp": req.headers.get("svix-timestamp")!,"svix-signature": req.headers.get("svix-signature")!,@@ -25,6 +28,12 @@ export const POST = async (req: Request) => {case "email.opened":await emailOpened(data);break;+ case "email.delivered":+ await emailDelivered(data);+ break;+ case "email.bounced":+ await emailBounced(data);+ break;}return NextResponse.json({ message: "Webhook processed." });diff --git a/packages/prisma/schema/notification.prisma b/packages/prisma/schema/notification.prismaindex bc3050976c..6182c36f8e 100644--- a/packages/prisma/schema/notification.prisma+++ b/packages/prisma/schema/notification.prisma@@ -16,8 +16,10 @@ model NotificationEmail {partnerId String?recipientUserId String?- openedAt DateTime?- createdAt DateTime @default(now())+ deliveredAt DateTime?+ openedAt DateTime?+ bouncedAt DateTime?+ createdAt DateTime @default(now())message Message? @relation(fields: [messageId], references: [id], onDelete: Cascade)bounty Bounty? @relation(fields: [bountyId], references: [id], onDelete: Cascade)