calcom / cal.com

Scheduling infrastructure for absolutely everyone.
https://cal.com
Other
32.61k stars 8.07k forks source link

Zoom links not being added to bookings requiring confirmation? #15473

Open thomaspoe opened 5 months ago

thomaspoe commented 5 months ago

Issue Summary

Hello everyone,

I am currently building a backend that will accept or deny bookings based on credits on a user account elsewhere. Currently, I have the cal.com embed on the dashboard & that works perfectly. There is some weird behavior depending on how the booking is accepted. If I go on cal.com & sign in to manually accept through the 'Bookings' tab, it seems to work perfectly - the booking is confirmed & accepted, the confirmation is sent via email INCLUDING THE ZOOM DETAILS.

The problem arises when I try to confirm bookings via my custom backend. In the docs, it says I can make a PATCH request & pass 'ACCEPTED' as the status. When I do that, it does accept the booking & but doesn't send an email or show zoom details in the cal.com dashboard.

Am I doing something wrong or is this a bug?

Steps to Reproduce

  1. Create booking that needs confirmation with Zoom App as the location
  2. Accept via a PATCH request passing 'ACCEPTED' as the status

Actual Results

Expected Results

Technical details

Here is my early implementation:

const url = `https://api.cal.com/v1/bookings/${data.payload.bookingId}?apiKey=${calAPIKey}`;

const body = JSON.stringify({
          status: "ACCEPTED",
        });

fetch(url, {
          method: "PATCH",
          headers: {
            "Content-Type":         "application/json",
          },
          body: body,
        })
          .then(async (response) => {
            // whatever
          .catch((err) => {
            console.log(err);
          });

Evidence

The one with the zoom details was manually accepted in the dashboard, the one without was accepted via the implementation above.

Screenshot 2024-06-18 at 02 57 34
dosubot[bot] commented 5 months ago

Hello @thomaspoe! I'm here to help you with any bugs, questions, or contributions. Let's work together to solve this issue.

The issue you're experiencing is due to the difference in how the booking acceptance process is handled between the manual acceptance through the 'Bookings' tab and the PATCH request via your custom backend.

When you manually accept a booking through the 'Bookings' tab, the handleConfirmation function is triggered. This function includes comprehensive logic for sending emails, scheduling reminders, and integrating video call details like Zoom. However, the PATCH request handler (patchHandler) you are using does not include this logic; it only updates the booking status in the database.

Here is the relevant part of the patchHandler code:

export async function patchHandler(req: NextApiRequest) {
  const { query, body } = req;
  const { id } = schemaQueryIdParseInt.parse(query);
  const data = schemaBookingEditBodyParams.parse(body);
  await checkPermissions(req, data);
  const booking = await prisma.booking.update({ where: { id }, data });
  return { booking: schemaBookingReadPublic.parse(booking) };
}

This function updates the booking status but does not handle sending emails or adding Zoom details.

To achieve the same result as the manual acceptance, you need to trigger the handleConfirmation function after updating the booking status via the PATCH request. Alternatively, you can configure a webhook to trigger on booking acceptance events to handle the sending of emails and integration of Zoom details. The WebhookTriggerEvents enum includes several events that can be used for this purpose, such as BOOKING_RESCHEDULED, BOOKING_CREATED, and INSTANT_MEETING [1][2][3].

By implementing one of these solutions, you can ensure that the booking acceptance process via your custom backend includes all necessary steps, such as sending confirmation emails and integrating Zoom details.

To continue talking to Dosu, mention @dosu.

thomaspoe commented 5 months ago

Also worth noting, this is not self hosted, this is using cal.com embeds & API. I am sure there might be other things happening when accepting via the cal.com dashboard like dosubot mentions, but there is currently no documented way to have the same flow happen via the API. I have also reviewed some of the code base & based on what I can tell, the code mentioned above by dosubot is supposed to already happen when a PATCH request is made regardless, but that doesn't seem to be happening though I could be wrong.

kmaity-9563 commented 5 months ago

where is the custom backend file ? @thomaspoe

kmaity-9563 commented 5 months ago

Hello @thomaspoe! I'm here to help you with any bugs, questions, or contributions. Let's work together to solve this issue.

The issue you're experiencing is due to the difference in how the booking acceptance process is handled between the manual acceptance through the 'Bookings' tab and the PATCH request via your custom backend.

When you manually accept a booking through the 'Bookings' tab, the handleConfirmation function is triggered. This function includes comprehensive logic for sending emails, scheduling reminders, and integrating video call details like Zoom. However, the PATCH request handler (patchHandler) you are using does not include this logic; it only updates the booking status in the database.

Here is the relevant part of the patchHandler code:

export async function patchHandler(req: NextApiRequest) {
  const { query, body } = req;
  const { id } = schemaQueryIdParseInt.parse(query);
  const data = schemaBookingEditBodyParams.parse(body);
  await checkPermissions(req, data);
  const booking = await prisma.booking.update({ where: { id }, data });
  return { booking: schemaBookingReadPublic.parse(booking) };
}

This function updates the booking status but does not handle sending emails or adding Zoom details.

To achieve the same result as the manual acceptance, you need to trigger the handleConfirmation function after updating the booking status via the PATCH request. Alternatively, you can configure a webhook to trigger on booking acceptance events to handle the sending of emails and integration of Zoom details. The WebhookTriggerEvents enum includes several events that can be used for this purpose, such as BOOKING_RESCHEDULED, BOOKING_CREATED, and INSTANT_MEETING [1][2][3].

By implementing one of these solutions, you can ensure that the booking acceptance process via your custom backend includes all necessary steps, such as sending confirmation emails and integrating Zoom details.

To continue talking to Dosu, mention @dosu.

hey is this really a high priority issue ? then assign me and tel me where is this custom backend

asadath1395 commented 3 weeks ago

@keithwillcode Is anyone working on v2 endpoint for updating a booking? I don't see any endpoint for that. If someone's working, then i think this issue will be closed once implemented, if not i would love to work on it. Or do you want me to update the v1 endpoint to work as how its working in platform app?

ThyMinimalDev commented 1 week ago

hey @asadath1395, for v2 endpoints we want to have a more granular approach to manipulating booking data, through action endpoints, similar to /cancel, /confirm, etc... these endpoints will make sure to update the data and trigger the relevant side effects depending on the actions