Files
cal.diy/packages/features/bookings/lib/getWebhookPayloadForBooking.ts
T
3a7122d613 fix: revert assignmentReason breaking change in webhook payloads (#27891)
* fix: revert assignmentReason breaking change in webhook payloads

Remove the new { category, details } format from EventPayloadType to
maintain backward compatibility for webhook consumers. The new format
is stripped at all webhook payload construction sites by destructuring
assignmentReason out of CalendarEvent before spreading into the payload.

A sanitizeAssignmentReasonForWebhook function provides an additional
safety net in sendPayload itself. Emails and booking single view
continue to use the new format via CalendarEvent.

Co-Authored-By: [email protected] <[email protected]>

* fix: strip assignmentReason from handlePaymentSuccess webhook payload

Co-Authored-By: [email protected] <[email protected]>

* fix: strip assignmentReason from triggerWebhooks and handleSeats webhook payloads

Co-Authored-By: [email protected] <[email protected]>

* refactor: use zod safeParse instead of type assertion in sanitizeAssignmentReasonForWebhook

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-02-16 21:55:10 -03:00

42 lines
1.1 KiB
TypeScript

import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
import type { CalendarEvent } from "@calcom/types/Calendar";
export const getWebhookPayloadForBooking = ({
booking,
evt,
}: {
booking: {
eventType: {
title: string;
description: string | null;
requiresConfirmation: boolean;
price: number;
currency: string;
length: number;
id: number;
} | null;
id: number;
eventTypeId: number | null;
userId: number | null;
};
evt: CalendarEvent;
}) => {
const eventTypeInfo: EventTypeInfo = {
eventTitle: booking.eventType?.title,
eventDescription: booking.eventType?.description,
requiresConfirmation: booking.eventType?.requiresConfirmation || null,
price: booking.eventType?.price,
currency: booking.eventType?.currency,
length: booking.eventType?.length,
};
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
const payload: EventPayloadType = {
...evtWithoutAssignmentReason,
...eventTypeInfo,
bookingId: booking.id,
};
return payload;
};