Skip to content

fix: Make BOOKING_CANCELLED` webhook payload consistent for regular cancellation and request-reschedule flow#22

Open
tomerqodo wants to merge 3 commits intocoderabbit_combined_20260121_augment_sentry_coderabbit_1_base_fix_make_booking_cancelled_webhook_payload_consistent_for_regular_cancellation_and_request-reschedule_flow_pr694from
coderabbit_combined_20260121_augment_sentry_coderabbit_1_head_fix_make_booking_cancelled_webhook_payload_consistent_for_regular_cancellation_and_request-reschedule_flow_pr694
Open

fix: Make BOOKING_CANCELLED` webhook payload consistent for regular cancellation and request-reschedule flow#22
tomerqodo wants to merge 3 commits intocoderabbit_combined_20260121_augment_sentry_coderabbit_1_base_fix_make_booking_cancelled_webhook_payload_consistent_for_regular_cancellation_and_request-reschedule_flow_pr694from
coderabbit_combined_20260121_augment_sentry_coderabbit_1_head_fix_make_booking_cancelled_webhook_payload_consistent_for_regular_cancellation_and_request-reschedule_flow_pr694

Conversation

@tomerqodo
Copy link

@tomerqodo tomerqodo commented Jan 22, 2026

Benchmark PR from qodo-benchmark#694

Summary by CodeRabbit

  • New Features

    • Webhook payloads for booking cancellations now include a requestReschedule flag indicating if a reschedule was requested.
    • Added iCalSequence field to webhook payloads for better calendar synchronization.
    • Introduced webhook dispatch gating via feature flag configuration.
  • Documentation

    • Updated webhook payload documentation with new fields.
  • Tests

    • Updated test expectations to reflect new webhook payload structure.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

Walkthrough

This PR adds a requestReschedule boolean field and iCalSequence property to booking cancellation webhooks throughout the payload pipeline. Feature flag gating is introduced for webhook dispatches, and database queries are expanded to fetch additional event type fields (title, length, iCalSequence).

Changes

Cohort / File(s) Summary
Documentation
docs/developing/guides/automation/webhooks.mdx
Updated BOOKING_CANCELLED example payload to include requestReschedule: false field in root payload object.
Webhook Type System
packages/features/webhooks/lib/dto/types.ts, packages/features/webhooks/lib/types/params.ts, packages/features/webhooks/lib/sendPayload.ts
Added optional requestReschedule?: boolean field to BookingCancelledDTO, BookingCancelledParams, and EventPayloadType. Added optional iCalSequence?: number | null field to BookingCancelledDTO.booking and BookingCancelledParams.booking.
Webhook Payload Builders
packages/features/webhooks/lib/factory/base/BaseBookingPayloadBuilder.ts, packages/features/webhooks/lib/factory/versioned/v2021-10-20/BookingPayloadBuilder.ts
Extended BookingExtraDataMap[BOOKING_CANCELLED] to include requestReschedule?: boolean. Updated v2021-10-20 payload builder to add requestReschedule field defaulting to true.
Webhook Service & Factory
packages/features/webhooks/lib/service/BookingWebhookService.ts, packages/lib/server/service/BookingWebhookFactory.ts, packages/lib/server/service/__tests__/BookingWebhookFactory.test.ts
Enhanced BookingWebhookService to pass requestReschedule from params. Extended CancelledEventPayload interface with eventTypeId, length, iCalSequence, eventTitle, and requestReschedule fields. Updated tests to expect new payload fields.
Booking Handlers & Cancellation
packages/features/bookings/lib/handleCancelBooking.ts, packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts
Added feature flag check (ENABLE_WEBHOOKS) to gate webhook dispatch in handleCancelBooking. Added requestReschedule: false to main cancellation payload and requestReschedule: true to seat attendee cancellation payload.
Database & Repository Layer
packages/features/bookings/repositories/BookingRepository.ts
Added title and length fields to eventType select in findByUidIncludeEventTypeAndReferences and findByIdIncludeEventTypeAndReferences. Added iCalSequence to booking selection in findByUidIncludeEventTypeAndReferences.
Request Reschedule Handler
packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts
Enhanced cancelled event payload with eventTypeId, length, iCalSequence (incremented by 1), eventTitle, and requestReschedule flag set to true. Simplified event initialization with nullish-coalescing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Webhooks now reschedule with grace,
With sequence and fields in their place,
A flag gates the flow,
Through layers they go,
From bookings to payloads—what pace!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset: making the BOOKING_CANCELLED webhook payload consistent across different cancellation flows.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@packages/features/webhooks/lib/factory/versioned/v2021-10-20/BookingPayloadBuilder.ts`:
- Around line 45-50: The extra.requestReschedule field in
BookingPayloadBuilder.ts is defaulting to true (requestReschedule:
dto.requestReschedule ?? true) causing cancellations to be treated as reschedule
requests when unset; change the default to false by using dto.requestReschedule
?? false so that only explicit true values indicate a reschedule; update the
occurrence in BookingPayloadBuilder (the extra: { cancelledBy,
cancellationReason, requestReschedule } block) to use the corrected default.
🧹 Nitpick comments (1)
packages/lib/server/service/__tests__/BookingWebhookFactory.test.ts (1)

88-116: Consider adding explicit assertions for the new fields' default values.

The test correctly expects the new keys to exist but doesn't verify their values. Since the factory defaults these fields when not provided (eventTypeId: null, length: null, iCalSequence: null, eventTitle: null, requestReschedule: false), consider adding explicit assertions to catch regressions:

💡 Suggested improvement
       expect(payload.cancelledBy).toBe("test@example.com");
+      
+      // Verify new fields default to expected values when not provided
+      expect(payload.eventTypeId).toBeNull();
+      expect(payload.length).toBeNull();
+      expect(payload.iCalSequence).toBeNull();
+      expect(payload.eventTitle).toBeNull();
+      expect(payload.requestReschedule).toBe(false);
+      expect(payload.status).toBe("CANCELLED");

       // Verify no extra properties exist
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad9482 and b2acc84.

📒 Files selected for processing (13)
  • docs/developing/guides/automation/webhooks.mdx
  • packages/features/bookings/lib/handleCancelBooking.ts
  • packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts
  • packages/features/bookings/repositories/BookingRepository.ts
  • packages/features/webhooks/lib/dto/types.ts
  • packages/features/webhooks/lib/factory/base/BaseBookingPayloadBuilder.ts
  • packages/features/webhooks/lib/factory/versioned/v2021-10-20/BookingPayloadBuilder.ts
  • packages/features/webhooks/lib/sendPayload.ts
  • packages/features/webhooks/lib/service/BookingWebhookService.ts
  • packages/features/webhooks/lib/types/params.ts
  • packages/lib/server/service/BookingWebhookFactory.ts
  • packages/lib/server/service/__tests__/BookingWebhookFactory.test.ts
  • packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts
🧰 Additional context used
🧬 Code graph analysis (2)
packages/features/webhooks/lib/factory/base/BaseBookingPayloadBuilder.ts (1)
packages/platform/libraries/index.ts (1)
  • WebhookTriggerEvents (36-36)
packages/features/bookings/lib/handleCancelBooking.ts (2)
packages/features/booking-audit/lib/makeActor.ts (2)
  • buildActorEmail (84-86)
  • getUniqueIdentifier (88-90)
packages/features/webhooks/lib/WebhookService.ts (1)
  • sendPayload (21-37)
🔇 Additional comments (19)
packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts (1)

162-168: LGTM - requestReschedule: true correctly identifies seat cancellations during reschedule flow.

The hardcoded true value is appropriate here since cancelAttendeeSeat is invoked as part of the reschedule workflow, allowing downstream webhook consumers to distinguish this from a regular cancellation.

docs/developing/guides/automation/webhooks.mdx (1)

314-316: Documentation correctly shows requestReschedule: false for standard cancellation.

The example payload accurately reflects that regular cancellations will have requestReschedule: false, helping API consumers understand how to distinguish between standard cancellations and reschedule-triggered cancellations.

packages/features/webhooks/lib/sendPayload.ts (1)

82-100: LGTM - Type extension for requestReschedule is correctly defined.

The optional boolean field is appropriately added to EventPayloadType, maintaining backward compatibility while enabling the new cancellation distinction feature.

packages/features/webhooks/lib/service/BookingWebhookService.ts (1)

117-120: LGTM - Properly passes requestReschedule from params to DTO.

The service layer correctly passes through the requestReschedule value without transformation, consistent with how other cancellation-related fields are handled.

packages/features/webhooks/lib/factory/base/BaseBookingPayloadBuilder.ts (1)

14-18: LGTM - Type definition correctly extended with requestReschedule.

The BookingExtraDataMap type for BOOKING_CANCELLED is properly extended with the new optional boolean field, providing type safety for the payload builders.

packages/features/webhooks/lib/types/params.ts (1)

40-66: LGTM!

The type additions are well-placed and consistent with the PR objectives. iCalSequence correctly belongs in the booking object as booking-specific data, while requestReschedule as a top-level boolean appropriately indicates the flow type.

packages/features/bookings/lib/handleCancelBooking.ts (2)

413-431: Feature flag gating and requestReschedule: false look correct.

The implementation correctly:

  1. Gates webhook dispatch behind ENABLE_WEBHOOKS environment variable (enabled by default)
  2. Sets requestReschedule: false for regular cancellation flow, distinguishing it from the reschedule flow

However, consider extracting the feature flag check to a shared utility for consistency across the codebase, especially since other webhook dispatch locations may need the same check.


110-121: LGTM!

The refactored function calls using object parameters improve readability and make the intent clearer (e.g., actorType: "guest" vs positional arguments).

packages/lib/server/service/BookingWebhookFactory.ts (2)

49-57: LGTM!

The interface extension is well-designed with appropriate optional types that align with the PR objectives for making the cancellation payload consistent.


126-137: LGTM!

Good use of nullish coalescing with sensible defaults: null for optional data fields and false for the requestReschedule boolean. The "CANCELLED" as const provides proper type narrowing for consumers.

packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts (2)

274-279: LGTM!

The new payload fields are correctly populated:

  • requestReschedule: true properly distinguishes this flow from regular cancellation
  • iCalSequence is incremented consistently with the cancellation flow (using ?? 0 as a safe default before incrementing)
  • Optional fields use appropriate ?? null fallbacks

106-106: LGTM!

The nullish coalescing assignment bookingToReschedule.eventType ?? {} is cleaner and functionally equivalent to the previous guarded initialization.

packages/features/webhooks/lib/dto/types.ts (2)

42-58: LGTM!

The DTO type extensions are consistent with the rest of the type system. iCalSequence in the booking object and requestReschedule at the root level align perfectly with BookingCancelledParams in params.ts.


571-588: LGTM!

Adding requestReschedule?: boolean to EventPayloadType ensures the field can flow through the entire webhook pipeline consistently.

packages/features/bookings/repositories/BookingRepository.ts (5)

140-179: LGTM — RR filters look consistent with no‑show and routing constraints.

The added noShowHost, timestamp‑basis, and routing‑form filters align with the intended RR selection behavior.


328-328: LGTM — constructor formatting change only.


659-672: LGTM — PENDING confirmation query is clear and scoped.


1658-1688: LGTM — event type and iCal fields are now included in the select.

This matches the expanded webhook payload shape for cancellations/reschedules.


1919-1925: LGTM — signature formatting only.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines 45 to 50
extra: {
cancelledBy: dto.cancelledBy,
cancellationReason: dto.cancellationReason,
requestReschedule: dto.requestReschedule ?? true,
},
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Default value for requestReschedule should be false, not true.

The default ?? true means that if a caller forgets to set requestReschedule, the webhook will incorrectly indicate a reschedule request. Based on the PR's semantic intent and the documentation example (which shows false), regular cancellations should default to false, with only explicit reschedule flows setting true.

🐛 Proposed fix
       extra: {
         cancelledBy: dto.cancelledBy,
         cancellationReason: dto.cancellationReason,
-        requestReschedule: dto.requestReschedule ?? true,
+        requestReschedule: dto.requestReschedule ?? false,
       },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
extra: {
cancelledBy: dto.cancelledBy,
cancellationReason: dto.cancellationReason,
requestReschedule: dto.requestReschedule ?? true,
},
});
extra: {
cancelledBy: dto.cancelledBy,
cancellationReason: dto.cancellationReason,
requestReschedule: dto.requestReschedule ?? false,
},
});
🤖 Prompt for AI Agents
In
`@packages/features/webhooks/lib/factory/versioned/v2021-10-20/BookingPayloadBuilder.ts`
around lines 45 - 50, The extra.requestReschedule field in
BookingPayloadBuilder.ts is defaulting to true (requestReschedule:
dto.requestReschedule ?? true) causing cancellations to be treated as reschedule
requests when unset; change the default to false by using dto.requestReschedule
?? false so that only explicit true values indicate a reschedule; update the
occurrence in BookingPayloadBuilder (the extra: { cancelledBy,
cancellationReason, requestReschedule } block) to use the corrected default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants