Skip to content

fix: no show webhook triggers not updating #21345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

kart1ka
Copy link
Contributor

@kart1ka kart1ka commented May 15, 2025

What does this PR do?

The webhook triggers like Meeting Started and Meeting Ended are correctly updating for existing bookings when a webhook is created or updated. However, the No Show (Hosts/Guests) triggers were not being updated in the same way.
This PR fixes that issue.

Visual Demo (For contributors especially)

Could not reproduce the bug for webhook triggers such as Meeting started and Meeting ended.
https://www.loom.com/share/393185653d73437ca95523267b53f961?sid=363c0f88-42c2-4c84-874d-3dcbb342035f

No show webhook triggers fixed:
https://www.loom.com/share/73a5f001faa64b5099072ef4e3e63ea4?sid=de73daec-169c-4ff6-bbed-0836708c7967

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Summary by mrge

Fixed an issue where No Show webhook triggers were not updating for existing bookings when a webhook was created or updated.

  • Bug Fixes
    • No Show (Hosts/Guests) triggers now update correctly for existing bookings.
    • Canceling or rescheduling a booking now removes related No Show tasks.
    • Disabling a webhook now cancels all associated No Show tasks.

@kart1ka kart1ka requested a review from a team as a code owner May 15, 2025 19:06
Copy link

vercel bot commented May 15, 2025

@kart1ka is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label May 15, 2025
@graphite-app graphite-app bot requested a review from a team May 15, 2025 19:06
@github-actions github-actions bot added enterprise area: enterprise, audit log, organisation, SAML, SSO Medium priority Created by Linear-GitHub Sync webhooks area: webhooks, callback, webhook payload labels May 15, 2025
@dosubot dosubot bot added this to the v5.4 milestone May 15, 2025
@dosubot dosubot bot added the 🐛 bug Something isn't working label May 15, 2025
Copy link

graphite-app bot commented May 15, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (05/15/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (05/15/25)

1 label was added to this PR based on Keith Williams's automation.

Comment on lines +598 to +604
} else {
await prisma.task.deleteMany({
where: {
referenceUid: bookingUid,
},
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done in case a booking is cancelled/rescheduled and we need to delete both (guests and host no show tasks).

Comment on lines 608 to 615
await prisma.task.deleteMany({
where: {
payload: {
contains: shouldContain,
},
},
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be very slow in production environment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I had the same thought — but then I saw a similar pattern being used here so I went with that initially.

Anyway, I’ve updated the logic now to match how we handle it in updateTriggerForExistingBookings.

Copy link
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

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

Left comments

@kart1ka
Copy link
Contributor Author

kart1ka commented May 25, 2025

I have addressed the comments.

@keithwillcode keithwillcode added the community-interns The team responsible for reviewing, testing and shipping low/medium community PRs label Jun 9, 2025
@kart1ka kart1ka requested a review from Udit-takkar June 10, 2025 07:32
@dosubot dosubot bot modified the milestone: v5.4 Jun 17, 2025
@dosubot dosubot bot added this to the v5.5 milestone Jun 17, 2025
Copy link
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

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

LGTM

@CarinaWolli CarinaWolli modified the milestones: v5.5, v5.6 Jul 16, 2025
@dosubot dosubot bot modified the milestone: v5.6 Jul 16, 2025
Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

Walkthrough

The changes introduce and integrate logic for handling "no-show" webhook tasks throughout the booking lifecycle. This includes adding functions to schedule and cancel no-show webhook tasks, updating the relevant booking and webhook handler functions to invoke these new utilities, and ensuring the booking's unique identifier (uid) is consistently passed where needed. The webhook trigger management is refactored to distinctly handle both scheduling and no-show event types, with new helper functions for fetching bookings and managing tasks. Updates span booking confirmation, new booking creation, rescheduling, booking cancellation, and webhook deactivation scenarios.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Assessment against linked issues

Objective Addressed Explanation
Schedule webhook triggers for older bookings (#18955, CAL-5092)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

Possibly related PRs

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a5cb64 and e14b40e.

📒 Files selected for processing (1)
  • packages/features/bookings/lib/handleNewBooking.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/features/bookings/lib/handleNewBooking.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

♻️ Duplicate comments (3)
packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts (1)

66-67: Good fix! Added referenceUid to task creation.

The addition of referenceUid: booking.uid to both host and guest no-show task creation calls properly addresses the previous review comment and ensures tasks can be correctly associated with bookings for later cancellation.

Also applies to: 97-98

packages/features/webhooks/lib/scheduleTrigger.ts (2)

590-628: Consistent implementation with existing patterns.

The cancelNoShowTasksForBooking function properly handles task cancellation for both specific bookings (by uid) and bulk operations (by webhook). While bulk deletion could be slow with many bookings, the implementation follows the established pattern used in updateTriggerForExistingBookings.

The function correctly uses tasker.cancelWithReference for specific trigger types and falls back to direct database deletion for general cases.


630-671: Well-implemented no-show task scheduling!

The function properly:

  • Validates all required fields before proceeding
  • Correctly checks that the location is Cal Video (as no-show detection only works for Cal Video)
  • Uses dayjs for time calculations with proper type casting
  • Creates tasks with all necessary metadata including referenceUid for later cancellation

The trigger type validation logic is correct.

🧹 Nitpick comments (1)
packages/features/webhooks/lib/scheduleTrigger.ts (1)

377-470: Excellent refactoring! Extracted booking fetching logic.

The fetchBookingsFromWebhook helper function cleanly extracts the complex booking fetching logic, making it reusable and improving code maintainability. The function properly handles all webhook configurations including organization, team, and user-level webhooks.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37f5005 and 9a5cb64.

📒 Files selected for processing (8)
  • packages/features/bookings/lib/handleCancelBooking.ts (2 hunks)
  • packages/features/bookings/lib/handleConfirmation.ts (2 hunks)
  • packages/features/bookings/lib/handleNewBooking.ts (4 hunks)
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts (3 hunks)
  • packages/features/webhooks/lib/scheduleTrigger.ts (5 hunks)
  • packages/trpc/server/routers/loggedInViewer/connectAndJoin.handler.ts (1 hunks)
  • packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts (2 hunks)
  • packages/trpc/server/routers/viewer/webhook/edit.handler.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/trpc/server/routers/loggedInViewer/connectAndJoin.handler.ts
  • packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts
  • packages/features/bookings/lib/handleConfirmation.ts
  • packages/trpc/server/routers/viewer/webhook/edit.handler.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
  • packages/features/bookings/lib/handleNewBooking.ts
  • packages/features/webhooks/lib/scheduleTrigger.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/trpc/server/routers/loggedInViewer/connectAndJoin.handler.ts
  • packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts
  • packages/features/bookings/lib/handleConfirmation.ts
  • packages/trpc/server/routers/viewer/webhook/edit.handler.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
  • packages/features/bookings/lib/handleNewBooking.ts
  • packages/features/webhooks/lib/scheduleTrigger.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: vijayraghav-io
PR: calcom/cal.com#21072
File: packages/app-store/office365calendar/api/webhook.ts:120-123
Timestamp: 2025-07-18T17:57:16.395Z
Learning: The office365calendar webhook handler in packages/app-store/office365calendar/api/webhook.ts is specifically designed for Office365 calendar integration, not as a generic webhook handler. Therefore, it's safe to assume that fetchAvailabilityAndSetCache method will be implemented in the Office365CalendarService, making explicit validation checks unnecessary.
📚 Learning: in the failedbookingsbyfield component (packages/features/insights/components/failedbookingsbyfield....
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.389Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.

Applied to files:

  • packages/trpc/server/routers/loggedInViewer/connectAndJoin.handler.ts
  • packages/features/bookings/lib/handleConfirmation.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/features/bookings/lib/handleNewBooking.ts
  • packages/features/webhooks/lib/scheduleTrigger.ts
📚 Learning: the office365calendar webhook handler in packages/app-store/office365calendar/api/webhook.ts is spec...
Learnt from: vijayraghav-io
PR: calcom/cal.com#21072
File: packages/app-store/office365calendar/api/webhook.ts:120-123
Timestamp: 2025-07-18T17:57:16.395Z
Learning: The office365calendar webhook handler in packages/app-store/office365calendar/api/webhook.ts is specifically designed for Office365 calendar integration, not as a generic webhook handler. Therefore, it's safe to assume that fetchAvailabilityAndSetCache method will be implemented in the Office365CalendarService, making explicit validation checks unnecessary.

Applied to files:

  • packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts
  • packages/trpc/server/routers/viewer/webhook/edit.handler.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
  • packages/features/bookings/lib/handleNewBooking.ts
  • packages/features/webhooks/lib/scheduleTrigger.ts
📚 Learning: applies to **/*.{ts,tsx} : flag excessive day.js use in performance-critical code; prefer native dat...
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*.{ts,tsx} : Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js `.utc()` in hot paths like loops

Applied to files:

  • packages/features/webhooks/lib/scheduleTrigger.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (17)
packages/trpc/server/routers/loggedInViewer/connectAndJoin.handler.ts (1)

242-242: LGTM! Proper integration of booking UID for no-show triggers.

The addition of uid: updatedBooking.uid correctly provides the booking's unique identifier to the scheduleNoShowTriggers function, enabling proper no-show webhook trigger management.

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

9-12: LGTM! Proper import of no-show task cancellation function.

The import correctly includes cancelNoShowTasksForBooking alongside the existing deleteWebhookScheduledTriggers import, maintaining consistency in the import structure.


160-160: LGTM! Consistent cleanup of no-show tasks during reschedule.

The addition of cancelNoShowTasksForBooking properly ensures that no-show tasks are cancelled when a booking is rescheduled, maintaining consistency with the overall no-show trigger management system.

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

45-45: LGTM! Proper type extension for booking UID.

The addition of uid: string to the booking object type correctly extends the interface to include the booking's unique identifier, ensuring type safety for no-show trigger management.


448-448: LGTM! Consistent integration of booking UID for no-show triggers.

The addition of uid: booking.uid properly provides the booking's unique identifier to the scheduleNoShowTriggers function, enabling correct no-show webhook trigger scheduling.

packages/trpc/server/routers/viewer/webhook/edit.handler.ts (2)

4-4: LGTM! Proper import of no-show task cancellation function.

The import correctly includes cancelNoShowTasksForBooking alongside existing webhook trigger management functions, maintaining import organization consistency.


55-62: LGTM! Proper cleanup of no-show tasks on webhook deactivation.

The addition of cancelNoShowTasksForBooking correctly ensures that when a webhook is deactivated, associated no-show tasks are cancelled before deleting scheduled triggers. The webhook context object provides the necessary identifiers for proper task cleanup.

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

12-15: LGTM! Proper import of no-show task cancellation function.

The import correctly includes cancelNoShowTasksForBooking alongside deleteWebhookScheduledTriggers, maintaining consistency in the import structure for webhook-related cleanup functions.


516-516: LGTM! Consistent cleanup of no-show tasks during booking cancellation.

The addition of cancelNoShowTasksForBooking properly ensures that no-show tasks are cancelled when bookings are cancelled, maintaining consistency with the overall no-show trigger management system. The function is correctly added to the webhook trigger promises array.

packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts (1)

8-14: LGTM! Type update aligns with no-show trigger requirements.

The addition of the uid property to the booking type is necessary for uniquely identifying bookings when scheduling and canceling no-show tasks.

packages/features/bookings/lib/handleNewBooking.ts (4)

42-44: LGTM! Import added for no-show task cancellation.

The import of cancelNoShowTasksForBooking is correctly placed alongside related webhook trigger functions.


2081-2096: Good refactoring! Improved concurrent task handling.

The change from a single promise to an array of promises allows proper concurrent handling of both webhook trigger deletion and no-show task cancellation during booking rescheduling. This ensures comprehensive cleanup of all scheduled tasks.


2129-2136: Excellent error handling improvement!

Combining deletion and scheduling promises into a single Promise.all with proper error catching ensures all operations are attempted and errors are logged appropriately.


2239-2244: LGTM! Booking object properly includes uid.

The booking object now correctly includes the uid property required by the updated scheduleNoShowTriggers function signature.

packages/features/webhooks/lib/scheduleTrigger.ts (3)

1-8: LGTM! Imports properly organized for new functionality.

The imports are correctly updated to support the new no-show trigger functionality, including tasker for task management and proper type imports.


22-26: Good constant definition for no-show triggers.

The NO_SHOW_TRIGGERS array clearly defines the supported no-show webhook events, making the code more maintainable.


472-535: Well-structured refactoring for dual trigger support!

The refactored updateTriggerForExistingBookings function elegantly handles both scheduling and no-show triggers by:

  • Separating added/removed triggers for each type
  • Using the extracted fetchBookingsFromWebhook helper
  • Efficiently processing all operations with Promise.all

The early return optimization when no triggers change is a nice touch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working community Created by Linear-GitHub Sync community-interns The team responsible for reviewing, testing and shipping low/medium community PRs enterprise area: enterprise, audit log, organisation, SAML, SSO Medium priority Created by Linear-GitHub Sync webhooks area: webhooks, callback, webhook payload
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-5092] Schedule webhook triggers for older bookings
5 participants