Skip to content

Commit

Permalink
fix: wrong Meeting Ended payload in zapier (#18202)
Browse files Browse the repository at this point in the history
* fix: wrong Meeting Ended payload in zapier

* fix
  • Loading branch information
kart1ka authored Jan 10, 2025
1 parent cec1c9e commit b652ae7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
21 changes: 19 additions & 2 deletions packages/features/bookings/lib/handleConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { EventTypeMetaDataSchema, eventTypeAppMetadataOptionalSchema } from "@ca
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"] });
Expand Down Expand Up @@ -155,6 +156,8 @@ export async function handleConfirmation(args: {
cancellationReason?: string | null;
metadata: Prisma.JsonValue | null;
customInputs: Prisma.JsonValue;
title: string;
responses: Prisma.JsonValue;
eventType: {
bookingFields: Prisma.JsonValue | null;
slug: string;
Expand Down Expand Up @@ -232,7 +235,9 @@ export async function handleConfirmation(args: {
description: true,
cancellationReason: true,
attendees: true,
responses: true,
location: true,
title: true,
uid: true,
startTime: true,
metadata: true,
Expand Down Expand Up @@ -292,6 +297,8 @@ export async function handleConfirmation(args: {
},
uid: true,
startTime: true,
responses: true,
title: true,
metadata: true,
cancellationReason: true,
endTime: true,
Expand Down Expand Up @@ -393,8 +400,18 @@ export async function handleConfirmation(args: {

const scheduleTriggerPromises: Promise<unknown>[] = [];

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,
Expand All @@ -406,7 +423,7 @@ export async function handleConfirmation(args: {
});
});
subscribersMeetingEnded.forEach((subscriber) => {
updatedBookings.forEach((booking) => {
updatedBookingsWithCalEventResponses.forEach((booking) => {
scheduleTriggerPromises.push(
scheduleTrigger({
booking,
Expand Down
8 changes: 6 additions & 2 deletions packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1852,10 +1852,14 @@ async function handler(
}

if (booking && booking.status === BookingStatus.ACCEPTED) {
const bookingWithCalEventResponses = {
...booking,
responses: reqBody.calEventResponses,
};
for (const subscriber of subscribersMeetingEnded) {
scheduleTriggerPromises.push(
scheduleTrigger({
booking,
booking: bookingWithCalEventResponses,
subscriberUrl: subscriber.subscriberUrl,
subscriber,
triggerEvent: WebhookTriggerEvents.MEETING_ENDED,
Expand All @@ -1867,7 +1871,7 @@ async function handler(
for (const subscriber of subscribersMeetingStarted) {
scheduleTriggerPromises.push(
scheduleTrigger({
booking,
booking: bookingWithCalEventResponses,
subscriberUrl: subscriber.subscriberUrl,
subscriber,
triggerEvent: WebhookTriggerEvents.MEETING_STARTED,
Expand Down
25 changes: 24 additions & 1 deletion packages/features/webhooks/lib/scheduleTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b652ae7

Please sign in to comment.