From 7a736044e469f814893c153b75821367f2de7172 Mon Sep 17 00:00:00 2001 From: Kartik Saini Date: Mon, 16 Dec 2024 15:47:19 +0530 Subject: [PATCH 1/2] fix: wrong Meeting Ended payload in zapier --- .../bookings/lib/handleConfirmation.ts | 21 ++++++++++++++-- .../features/bookings/lib/handleNewBooking.ts | 12 +++++++-- .../features/webhooks/lib/scheduleTrigger.ts | 25 ++++++++++++++++++- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/packages/features/bookings/lib/handleConfirmation.ts b/packages/features/bookings/lib/handleConfirmation.ts index 2f28d265f92c65..cf7d4843f8bef2 100644 --- a/packages/features/bookings/lib/handleConfirmation.ts +++ b/packages/features/bookings/lib/handleConfirmation.ts @@ -28,6 +28,7 @@ import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util"; import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar"; +import { getCalEventResponses } from "./getCalEventResponses"; import { scheduleNoShowTriggers } from "./handleNewBooking/scheduleNoShowTriggers"; const log = logger.getSubLogger({ prefix: ["[handleConfirmation] book:user"] }); @@ -154,6 +155,8 @@ export async function handleConfirmation(args: { smsReminderNumber: string | null; metadata: Prisma.JsonValue | null; customInputs: Prisma.JsonValue; + title: string; + responses: Prisma.JsonValue; eventType: { bookingFields: Prisma.JsonValue | null; slug: string; @@ -230,7 +233,9 @@ export async function handleConfirmation(args: { }, description: true, attendees: true, + responses: true, location: true, + title: true, uid: true, startTime: true, metadata: true, @@ -290,6 +295,8 @@ export async function handleConfirmation(args: { }, uid: true, startTime: true, + responses: true, + title: true, metadata: true, endTime: true, smsReminderNumber: true, @@ -389,8 +396,18 @@ export async function handleConfirmation(args: { const scheduleTriggerPromises: Promise[] = []; + const updatedBookingsWithCalEventResponses = updatedBookings.map((booking) => { + return { + ...booking, + ...getCalEventResponses({ + bookingFields: booking.eventType?.bookingFields ?? null, + booking, + }), + }; + }); + subscribersMeetingStarted.forEach((subscriber) => { - updatedBookings.forEach((booking) => { + updatedBookingsWithCalEventResponses.forEach((booking) => { scheduleTriggerPromises.push( scheduleTrigger({ booking, @@ -402,7 +419,7 @@ export async function handleConfirmation(args: { }); }); subscribersMeetingEnded.forEach((subscriber) => { - updatedBookings.forEach((booking) => { + updatedBookingsWithCalEventResponses.forEach((booking) => { scheduleTriggerPromises.push( scheduleTrigger({ booking, diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 3ffa25123e9749..446c7bbe3af8f6 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -76,6 +76,7 @@ import type { EventPayloadType, EventTypeInfo } from "../../webhooks/lib/sendPay import { getAllCredentials } from "./getAllCredentialsForUsersOnEvent/getAllCredentials"; import { refreshCredentials } from "./getAllCredentialsForUsersOnEvent/refreshCredentials"; import getBookingDataSchema from "./getBookingDataSchema"; +import { getCalEventResponses } from "./getCalEventResponses"; import { addVideoCallDataToEvent } from "./handleNewBooking/addVideoCallDataToEvent"; import { checkBookingAndDurationLimits } from "./handleNewBooking/checkBookingAndDurationLimits"; import { checkIfBookerEmailIsBlocked } from "./handleNewBooking/checkIfBookerEmailIsBlocked"; @@ -1816,10 +1817,17 @@ async function handler( } if (booking && booking.status === BookingStatus.ACCEPTED) { + const bookingWithCalEventResponses = { + ...booking, + ...getCalEventResponses({ + bookingFields: eventType?.bookingFields ?? null, + booking, + }), + }; for (const subscriber of subscribersMeetingEnded) { scheduleTriggerPromises.push( scheduleTrigger({ - booking, + booking: bookingWithCalEventResponses, subscriberUrl: subscriber.subscriberUrl, subscriber, triggerEvent: WebhookTriggerEvents.MEETING_ENDED, @@ -1830,7 +1838,7 @@ async function handler( for (const subscriber of subscribersMeetingStarted) { scheduleTriggerPromises.push( scheduleTrigger({ - booking, + booking: bookingWithCalEventResponses, subscriberUrl: subscriber.subscriberUrl, subscriber, triggerEvent: WebhookTriggerEvents.MEETING_STARTED, diff --git a/packages/features/webhooks/lib/scheduleTrigger.ts b/packages/features/webhooks/lib/scheduleTrigger.ts index 6529e8e7994e90..4e1ed7d0e059e5 100644 --- a/packages/features/webhooks/lib/scheduleTrigger.ts +++ b/packages/features/webhooks/lib/scheduleTrigger.ts @@ -70,9 +70,32 @@ export async function addSubscription({ }, status: BookingStatus.ACCEPTED, }, + include: { + eventType: { + select: { + bookingFields: true, + }, + }, + attendees: { + select: { + name: true, + email: true, + }, + }, + }, + }); + + const bookingsWithCalEventResponses = bookings.map((booking) => { + return { + ...booking, + ...getCalEventResponses({ + bookingFields: booking.eventType?.bookingFields ?? null, + booking, + }), + }; }); - for (const booking of bookings) { + for (const booking of bookingsWithCalEventResponses) { scheduleTrigger({ booking, subscriberUrl: createSubscription.subscriberUrl, From c4f363baa3825b52725eedbf3b3086c89ee58ff6 Mon Sep 17 00:00:00 2001 From: Kartik Saini Date: Tue, 17 Dec 2024 13:49:53 +0530 Subject: [PATCH 2/2] fix --- packages/features/bookings/lib/handleNewBooking.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 446c7bbe3af8f6..89758aec90653d 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -76,7 +76,6 @@ import type { EventPayloadType, EventTypeInfo } from "../../webhooks/lib/sendPay import { getAllCredentials } from "./getAllCredentialsForUsersOnEvent/getAllCredentials"; import { refreshCredentials } from "./getAllCredentialsForUsersOnEvent/refreshCredentials"; import getBookingDataSchema from "./getBookingDataSchema"; -import { getCalEventResponses } from "./getCalEventResponses"; import { addVideoCallDataToEvent } from "./handleNewBooking/addVideoCallDataToEvent"; import { checkBookingAndDurationLimits } from "./handleNewBooking/checkBookingAndDurationLimits"; import { checkIfBookerEmailIsBlocked } from "./handleNewBooking/checkIfBookerEmailIsBlocked"; @@ -1819,10 +1818,7 @@ async function handler( if (booking && booking.status === BookingStatus.ACCEPTED) { const bookingWithCalEventResponses = { ...booking, - ...getCalEventResponses({ - bookingFields: eventType?.bookingFields ?? null, - booking, - }), + responses: reqBody.calEventResponses, }; for (const subscriber of subscribersMeetingEnded) { scheduleTriggerPromises.push(