Skip to content

Commit

Permalink
Implement unsubscribe functionality for Zapier webhooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
devkiran committed Jan 15, 2025
1 parent d5b8c8c commit 6ecb9a2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/web/app/api/webhooks/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ export const POST = async (req: Request) => {
const response = Buffer.from(body, "base64").toString("utf-8");
const isFailed = status >= 400;

// Unsubscribe Zapier webhook
if (
webhook.receiver === "zapier" &&
webhook.installationId &&
status === 410
) {
await prisma.webhook.delete({
where: {
id: webhookId,
},
});

return new Response(`Unsubscribed Zapier webhook ${webhookId}`);
}

await Promise.all([
// Record the webhook event
recordWebhookEvent({
Expand All @@ -63,5 +78,5 @@ export const POST = async (req: Request) => {
: []),
]);

return new Response("OK");
return new Response(`Webhook ${webhookId} processed`);
};

0 comments on commit 6ecb9a2

Please sign in to comment.