From 95cc0eeaae85d238eaeb2748ff3614a684afc6d9 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Wed, 20 Dec 2023 18:48:10 +0530 Subject: [PATCH] fix: only use event type's webhooks (#12894) * fix: only use event type's webhooks * chore: improve code --- .../instant-meeting/handleInstantMeeting.ts | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/features/instant-meeting/handleInstantMeeting.ts b/packages/features/instant-meeting/handleInstantMeeting.ts index 62c482b0d8..f73b918dc8 100644 --- a/packages/features/instant-meeting/handleInstantMeeting.ts +++ b/packages/features/instant-meeting/handleInstantMeeting.ts @@ -13,8 +13,6 @@ import { getCustomInputsResponses, } from "@calcom/features/bookings/lib/handleNewBooking"; import { getFullName } from "@calcom/features/form-builder/utils"; -import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks"; -import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks"; import { sendGenericWebhookPayload } from "@calcom/features/webhooks/lib/sendPayload"; import { isPrismaObjOrUndefined } from "@calcom/lib"; import { WEBAPP_URL } from "@calcom/lib/constants"; @@ -24,12 +22,31 @@ import prisma from "@calcom/prisma"; import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums"; const handleInstantMeetingWebhookTrigger = async (args: { - subscriberOptions: GetSubscriberOptions; + eventTypeId: number; webhookData: Record; }) => { try { const eventTrigger = WebhookTriggerEvents.INSTANT_MEETING; - const subscribers = await getWebhooks(args.subscriberOptions); + + const subscribers = await prisma.webhook.findMany({ + where: { + AND: { + eventTypeId: args.eventTypeId, + eventTriggers: { + has: eventTrigger, + }, + active: true, + }, + }, + select: { + id: true, + subscriberUrl: true, + payloadTemplate: true, + appId: true, + secret: true, + }, + }); + const { webhookData } = args; const promises = subscribers.map((sub) => { @@ -178,12 +195,6 @@ async function handler(req: NextApiRequest) { }); // Trigger Webhook - const subscriberOptions: GetSubscriberOptions = { - userId: null, - eventTypeId: eventType.id, - triggerEvent: WebhookTriggerEvents.INSTANT_MEETING, - teamId: eventType.team.id, - }; const webhookData = { triggerEvent: WebhookTriggerEvents.INSTANT_MEETING, @@ -196,7 +207,7 @@ async function handler(req: NextApiRequest) { }; await handleInstantMeetingWebhookTrigger({ - subscriberOptions, + eventTypeId: eventType.id, webhookData, });