Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only use event type's webhooks #12894

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions packages/features/instant-meeting/handleInstantMeeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<string, unknown>;
}) => {
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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -196,7 +207,7 @@ async function handler(req: NextApiRequest) {
};

await handleInstantMeetingWebhookTrigger({
subscriberOptions,
eventTypeId: eventType.id,
webhookData,
});

Expand Down
Loading