Skip to content

Commit de56085

Browse files
committed
fix: include metadata in the BOOKING_CANCELLED webhook payload
1 parent 9172fe6 commit de56085

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/features/bookings/lib/handleCancelBooking.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
423423
isPlatformManagedUserBooking: bookingToDelete.user.isPlatformManaged,
424424
} satisfies HandleCancelBookingResponse;
425425

426+
const parsedMetadata = bookingMetadataSchema.safeParse(bookingToDelete.metadata || {});
427+
426428
const promises = webhooks.map((webhook) =>
427429
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, {
428430
...evt,
@@ -431,6 +433,7 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
431433
smsReminderNumber: bookingToDelete.smsReminderNumber || undefined,
432434
cancelledBy: cancelledBy,
433435
requestReschedule: false,
436+
...(parsedMetadata.success && parsedMetadata.data ? { metadata: parsedMetadata.data } : {}),
434437
}).catch((e) => {
435438
logger.error(
436439
`Error executing webhook for event: ${eventTrigger}, URL: ${webhook.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
@@ -441,7 +444,6 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
441444
await Promise.all(promises);
442445

443446
const workflows = await getAllWorkflowsFromEventType(bookingToDelete.eventType, bookingToDelete.userId);
444-
const parsedMetadata = bookingMetadataSchema.safeParse(bookingToDelete.metadata || {});
445447

446448
const creditService = new CreditService();
447449

packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ describe("Cancel Booking", () => {
141141
organizer,
142142
location: BookingLocations.CalVideo,
143143
subscriberUrl: "http://my-webhook.example.com",
144+
metadata: {
145+
videoCallUrl: "https://existing-daily-video-call-url.example.com",
146+
},
144147
payload: {
145148
cancelledBy: organizer.email,
146149
organizer: {
@@ -271,6 +274,9 @@ describe("Cancel Booking", () => {
271274
organizer,
272275
location: BookingLocations.CalVideo,
273276
subscriberUrl: "http://my-webhook.example.com",
277+
metadata: {
278+
videoCallUrl: "https://existing-daily-video-call-url.example.com",
279+
},
274280
payload: {
275281
cancelledBy: organizer.email,
276282
organizer: {
@@ -375,6 +381,9 @@ describe("Cancel Booking", () => {
375381
status: BookingStatus.ACCEPTED,
376382
startTime: `${plus1DateString}T05:00:00.000Z`,
377383
endTime: `${plus1DateString}T05:30:00.000Z`,
384+
metadata: {
385+
myCustomKey: "myCustomValue",
386+
},
378387
attendees: [
379388
{
380389
email: hostAttendee.email,
@@ -423,6 +432,9 @@ describe("Cancel Booking", () => {
423432
organizer,
424433
location: BookingLocations.CalVideo,
425434
subscriberUrl: "http://my-webhook.example.com",
435+
metadata: {
436+
myCustomKey: "myCustomValue",
437+
},
426438
payload: {
427439
cancelledBy: organizer.email,
428440
organizer: {
@@ -1180,6 +1192,9 @@ describe("Cancel Booking", () => {
11801192
},
11811193
location: BookingLocations.CalVideo,
11821194
subscriberUrl: "http://my-webhook.example.com",
1195+
metadata: {
1196+
videoCallUrl: "https://existing-daily-video-call-url.example.com",
1197+
},
11831198
payload: {
11841199
cancelledBy: organizer.email,
11851200
organizer: {

packages/testing/src/lib/bookingScenario/expects.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,12 +1152,14 @@ export function expectBookingCancelledWebhookToHaveBeenFired({
11521152
location,
11531153
subscriberUrl,
11541154
payload,
1155+
metadata,
11551156
}: {
11561157
organizer: { email: string; name: string; username?: string; usernameInOrg?: string };
11571158
booker: { email: string; name: string };
11581159
subscriberUrl: string;
11591160
location: string;
11601161
payload?: Record<string, unknown>;
1162+
metadata?: Record<string, unknown> | null;
11611163
}) {
11621164
const organizerPayload = {
11631165
username: organizer.username,
@@ -1169,7 +1171,7 @@ export function expectBookingCancelledWebhookToHaveBeenFired({
11691171
payload: {
11701172
...payload,
11711173
organizer: organizerPayload,
1172-
metadata: null,
1174+
...(metadata !== undefined ? { metadata } : {}),
11731175
responses: {
11741176
name: {
11751177
label: "name",

0 commit comments

Comments
 (0)