fix: no show webhook triggers not updating (#21345)
* fix: no show webhook triggers not updating * fix: add missing booking uid * refactor: fetch bookings from webhook * use allSettled --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
8 files changed
+206
-41
No files matched your search
@@ -9,7 +9,10 @@ import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventR
|
|||||||
import { sendCancelledReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
|
import { sendCancelledReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
|
||||||
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import { deleteWebhookScheduledTriggers } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
import {
|
||||||
|
deleteWebhookScheduledTriggers,
|
||||||
|
cancelNoShowTasksForBooking,
|
||||||
|
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||||
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||||
import type { EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
import type { EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||||
import EventManager from "@calcom/lib/EventManager";
|
import EventManager from "@calcom/lib/EventManager";
|
||||||
@@ -517,6 +520,7 @@ async function handler(input: CancelBookingInput) {
|
|||||||
for (const booking of updatedBookings) {
|
for (const booking of updatedBookings) {
|
||||||
// delete scheduled webhook triggers of cancelled bookings
|
// delete scheduled webhook triggers of cancelled bookings
|
||||||
webhookTriggerPromises.push(deleteWebhookScheduledTriggers({ booking }));
|
webhookTriggerPromises.push(deleteWebhookScheduledTriggers({ booking }));
|
||||||
|
webhookTriggerPromises.push(cancelNoShowTasksForBooking({ bookingUid: booking.uid }));
|
||||||
|
|
||||||
//Workflows - cancel all reminders for cancelled bookings
|
//Workflows - cancel all reminders for cancelled bookings
|
||||||
workflowReminderPromises.push(WorkflowRepository.deleteAllWorkflowReminders(booking.workflowReminders));
|
workflowReminderPromises.push(WorkflowRepository.deleteAllWorkflowReminders(booking.workflowReminders));
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ export async function handleConfirmation(args: {
|
|||||||
booking: {
|
booking: {
|
||||||
startTime: Date;
|
startTime: Date;
|
||||||
id: number;
|
id: number;
|
||||||
|
uid: string;
|
||||||
eventType: {
|
eventType: {
|
||||||
currency: string;
|
currency: string;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
@@ -444,6 +445,7 @@ export async function handleConfirmation(args: {
|
|||||||
startTime: booking.startTime,
|
startTime: booking.startTime,
|
||||||
id: booking.id,
|
id: booking.id,
|
||||||
location: booking.location,
|
location: booking.location,
|
||||||
|
uid: booking.uid,
|
||||||
},
|
},
|
||||||
triggerForUser,
|
triggerForUser,
|
||||||
organizerUser: { id: booking.userId },
|
organizerUser: { id: booking.userId },
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebh
|
|||||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import {
|
import {
|
||||||
deleteWebhookScheduledTriggers,
|
deleteWebhookScheduledTriggers,
|
||||||
|
cancelNoShowTasksForBooking,
|
||||||
scheduleTrigger,
|
scheduleTrigger,
|
||||||
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||||
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
||||||
@@ -2261,15 +2262,22 @@ async function handler(
|
|||||||
const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);
|
const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);
|
||||||
const subscribersMeetingStarted = await getWebhooks(subscriberOptionsMeetingStarted);
|
const subscribersMeetingStarted = await getWebhooks(subscriberOptionsMeetingStarted);
|
||||||
|
|
||||||
let deleteWebhookScheduledTriggerPromise: Promise<unknown> = Promise.resolve();
|
const deleteWebhookScheduledTriggerPromises: Promise<unknown>[] = [];
|
||||||
const scheduleTriggerPromises = [];
|
const scheduleTriggerPromises = [];
|
||||||
|
|
||||||
if (rescheduleUid && originalRescheduledBooking) {
|
if (rescheduleUid && originalRescheduledBooking) {
|
||||||
//delete all scheduled triggers for meeting ended and meeting started of booking
|
//delete all scheduled triggers for meeting ended and meeting started of booking
|
||||||
deleteWebhookScheduledTriggerPromise = deleteWebhookScheduledTriggers({
|
deleteWebhookScheduledTriggerPromises.push(
|
||||||
booking: originalRescheduledBooking,
|
deleteWebhookScheduledTriggers({
|
||||||
isDryRun,
|
booking: originalRescheduledBooking,
|
||||||
});
|
isDryRun,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
deleteWebhookScheduledTriggerPromises.push(
|
||||||
|
cancelNoShowTasksForBooking({
|
||||||
|
bookingUid: originalRescheduledBooking.uid,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (booking && booking.status === BookingStatus.ACCEPTED) {
|
if (booking && booking.status === BookingStatus.ACCEPTED) {
|
||||||
@@ -2302,12 +2310,20 @@ async function handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([deleteWebhookScheduledTriggerPromise, ...scheduleTriggerPromises]).catch((error) => {
|
const scheduledTriggerResults = await Promise.allSettled([
|
||||||
|
...deleteWebhookScheduledTriggerPromises,
|
||||||
|
...scheduleTriggerPromises,
|
||||||
|
]);
|
||||||
|
const failures = scheduledTriggerResults.filter((result) => result.status === "rejected");
|
||||||
|
|
||||||
|
if (failures.length > 0) {
|
||||||
loggerWithEventDetails.error(
|
loggerWithEventDetails.error(
|
||||||
"Error while scheduling or canceling webhook triggers",
|
"Error while scheduling or canceling webhook triggers",
|
||||||
JSON.stringify({ error })
|
safeStringify({
|
||||||
|
errors: failures.map((f) => f.reason),
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
|
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
|
||||||
await handleWebhookTrigger({
|
await handleWebhookTrigger({
|
||||||
@@ -2410,7 +2426,12 @@ async function handler(
|
|||||||
try {
|
try {
|
||||||
if (isConfirmedByDefault) {
|
if (isConfirmedByDefault) {
|
||||||
await scheduleNoShowTriggers({
|
await scheduleNoShowTriggers({
|
||||||
booking: { startTime: booking.startTime, id: booking.id, location: booking.location },
|
booking: {
|
||||||
|
startTime: booking.startTime,
|
||||||
|
id: booking.id,
|
||||||
|
location: booking.location,
|
||||||
|
uid: booking.uid,
|
||||||
|
},
|
||||||
triggerForUser,
|
triggerForUser,
|
||||||
organizerUser: { id: organizerUser.id },
|
organizerUser: { id: organizerUser.id },
|
||||||
eventTypeId,
|
eventTypeId,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type ScheduleNoShowTriggersArgs = {
|
|||||||
startTime: Date;
|
startTime: Date;
|
||||||
id: number;
|
id: number;
|
||||||
location: string | null;
|
location: string | null;
|
||||||
|
uid: string;
|
||||||
};
|
};
|
||||||
triggerForUser?: number | true | null;
|
triggerForUser?: number | true | null;
|
||||||
organizerUser: { id: number | null };
|
organizerUser: { id: number | null };
|
||||||
@@ -62,7 +63,7 @@ const _scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => {
|
|||||||
// Prevents null values from being serialized
|
// Prevents null values from being serialized
|
||||||
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit },
|
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit },
|
||||||
},
|
},
|
||||||
{ scheduledAt }
|
{ scheduledAt, referenceUid: booking.uid }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -93,7 +94,7 @@ const _scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => {
|
|||||||
// Prevents null values from being serialized
|
// Prevents null values from being serialized
|
||||||
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit },
|
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit },
|
||||||
},
|
},
|
||||||
{ scheduledAt }
|
{ scheduledAt, referenceUid: booking.uid }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import type { Prisma, Webhook, Booking } from "@prisma/client";
|
import type { Booking, Prisma, Webhook } from "@prisma/client";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
|
||||||
import { selectOOOEntries } from "@calcom/app-store/zapier/api/subscriptions/listOOOEntries";
|
import { selectOOOEntries } from "@calcom/app-store/zapier/api/subscriptions/listOOOEntries";
|
||||||
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||||
import { getHumanReadableLocationValue } from "@calcom/lib/location";
|
import tasker from "@calcom/features/tasker";
|
||||||
|
import { DailyLocationType, getHumanReadableLocationValue } from "@calcom/lib/location";
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||||
@@ -17,6 +19,11 @@ const SCHEDULING_TRIGGER: WebhookTriggerEvents[] = [
|
|||||||
WebhookTriggerEvents.MEETING_STARTED,
|
WebhookTriggerEvents.MEETING_STARTED,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const NO_SHOW_TRIGGERS: WebhookTriggerEvents[] = [
|
||||||
|
WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW,
|
||||||
|
WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW,
|
||||||
|
];
|
||||||
|
|
||||||
const log = logger.getSubLogger({ prefix: ["[node-scheduler]"] });
|
const log = logger.getSubLogger({ prefix: ["[node-scheduler]"] });
|
||||||
|
|
||||||
export async function addSubscription({
|
export async function addSubscription({
|
||||||
@@ -367,20 +374,9 @@ export const deleteWebhookScheduledTriggers = withReporting(
|
|||||||
"deleteWebhookScheduledTriggers"
|
"deleteWebhookScheduledTriggers"
|
||||||
);
|
);
|
||||||
|
|
||||||
export async function updateTriggerForExistingBookings(
|
async function fetchBookingsFromWebhook(
|
||||||
webhook: Webhook,
|
webhook: Pick<Webhook, "id" | "userId" | "teamId" | "eventTypeId">
|
||||||
existingEventTriggers: WebhookTriggerEvents[],
|
): Promise<Booking[]> {
|
||||||
updatedEventTriggers: WebhookTriggerEvents[]
|
|
||||||
) {
|
|
||||||
const addedEventTriggers = updatedEventTriggers.filter(
|
|
||||||
(trigger) => !existingEventTriggers.includes(trigger) && SCHEDULING_TRIGGER.includes(trigger)
|
|
||||||
);
|
|
||||||
const removedEventTriggers = existingEventTriggers.filter(
|
|
||||||
(trigger) => !updatedEventTriggers.includes(trigger) && SCHEDULING_TRIGGER.includes(trigger)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (addedEventTriggers.length === 0 && removedEventTriggers.length === 0) return;
|
|
||||||
|
|
||||||
const currentTime = new Date();
|
const currentTime = new Date();
|
||||||
const where: Prisma.BookingWhereInput = {
|
const where: Prisma.BookingWhereInput = {
|
||||||
AND: [{ status: BookingStatus.ACCEPTED }],
|
AND: [{ status: BookingStatus.ACCEPTED }],
|
||||||
@@ -470,27 +466,71 @@ export async function updateTriggerForExistingBookings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return bookings;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateTriggerForExistingBookings(
|
||||||
|
webhook: Webhook,
|
||||||
|
existingEventTriggers: WebhookTriggerEvents[],
|
||||||
|
updatedEventTriggers: WebhookTriggerEvents[]
|
||||||
|
) {
|
||||||
|
const addedEventTriggers = updatedEventTriggers.filter(
|
||||||
|
(trigger) => !existingEventTriggers.includes(trigger) && SCHEDULING_TRIGGER.includes(trigger)
|
||||||
|
);
|
||||||
|
const removedEventTriggers = existingEventTriggers.filter(
|
||||||
|
(trigger) => !updatedEventTriggers.includes(trigger) && SCHEDULING_TRIGGER.includes(trigger)
|
||||||
|
);
|
||||||
|
|
||||||
|
const addedNoShowTriggers = updatedEventTriggers.filter(
|
||||||
|
(trigger) => !existingEventTriggers.includes(trigger) && NO_SHOW_TRIGGERS.includes(trigger)
|
||||||
|
);
|
||||||
|
const removedNoShowTriggers = existingEventTriggers.filter(
|
||||||
|
(trigger) => !updatedEventTriggers.includes(trigger) && NO_SHOW_TRIGGERS.includes(trigger)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
addedEventTriggers.length === 0 &&
|
||||||
|
removedEventTriggers.length === 0 &&
|
||||||
|
addedNoShowTriggers.length === 0 &&
|
||||||
|
removedNoShowTriggers.length === 0
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const bookings = await fetchBookingsFromWebhook(webhook);
|
||||||
|
|
||||||
if (bookings.length === 0) return;
|
if (bookings.length === 0) return;
|
||||||
|
|
||||||
if (addedEventTriggers.length > 0) {
|
if (addedEventTriggers.length > 0 || addedNoShowTriggers.length > 0 || removedNoShowTriggers.length > 0) {
|
||||||
const promise = bookings.map((booking) => {
|
const allPromises = bookings.flatMap((booking) => {
|
||||||
return addedEventTriggers.map((triggerEvent) => {
|
return [
|
||||||
if (
|
...addedEventTriggers.map(async (triggerEvent) => {
|
||||||
triggerEvent === WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW ||
|
if (NO_SHOW_TRIGGERS.includes(triggerEvent)) return;
|
||||||
triggerEvent === WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW
|
await scheduleTrigger({
|
||||||
)
|
booking,
|
||||||
return Promise.resolve();
|
subscriberUrl: webhook.subscriberUrl,
|
||||||
|
subscriber: webhook,
|
||||||
scheduleTrigger({ booking, subscriberUrl: webhook.subscriberUrl, subscriber: webhook, triggerEvent });
|
triggerEvent,
|
||||||
});
|
});
|
||||||
|
}),
|
||||||
|
...addedNoShowTriggers.map(async (triggerEvent) => {
|
||||||
|
await scheduleNoShowTaskForBooking(booking, webhook, triggerEvent);
|
||||||
|
}),
|
||||||
|
...removedNoShowTriggers.map((triggerEvent) =>
|
||||||
|
cancelNoShowTasksForBooking({
|
||||||
|
bookingUid: booking.uid,
|
||||||
|
triggerEvent,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(promise);
|
await Promise.all(allPromises);
|
||||||
}
|
}
|
||||||
|
|
||||||
const promise = removedEventTriggers.map((triggerEvent) =>
|
const promise = removedEventTriggers.map((triggerEvent) =>
|
||||||
deleteWebhookScheduledTriggers({ triggerEvent, webhookId: webhook.id })
|
deleteWebhookScheduledTriggers({ triggerEvent, webhookId: webhook.id })
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all(promise);
|
await Promise.all(promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,3 +586,86 @@ export async function listOOOEntries(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function cancelNoShowTasksForBooking({
|
||||||
|
bookingUid,
|
||||||
|
triggerEvent,
|
||||||
|
webhook,
|
||||||
|
}: {
|
||||||
|
bookingUid?: string;
|
||||||
|
triggerEvent?: WebhookTriggerEvents;
|
||||||
|
webhook?: Pick<Webhook, "id" | "userId" | "teamId" | "eventTypeId">;
|
||||||
|
}) {
|
||||||
|
if (bookingUid) {
|
||||||
|
if (triggerEvent && !NO_SHOW_TRIGGERS.includes(triggerEvent)) return;
|
||||||
|
|
||||||
|
if (triggerEvent === WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW) {
|
||||||
|
await tasker.cancelWithReference(bookingUid, "triggerHostNoShowWebhook");
|
||||||
|
} else if (triggerEvent === WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW) {
|
||||||
|
await tasker.cancelWithReference(bookingUid, "triggerGuestNoShowWebhook");
|
||||||
|
} else {
|
||||||
|
await prisma.task.deleteMany({
|
||||||
|
where: {
|
||||||
|
referenceUid: bookingUid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (webhook) {
|
||||||
|
const bookings = await fetchBookingsFromWebhook(webhook);
|
||||||
|
|
||||||
|
if (bookings.length === 0) return;
|
||||||
|
|
||||||
|
const promises = bookings.map(async (booking) => {
|
||||||
|
return await prisma.task.deleteMany({
|
||||||
|
where: {
|
||||||
|
referenceUid: booking.uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function scheduleNoShowTaskForBooking(
|
||||||
|
booking: { id: number; uid: string; startTime: Date; location: string | null },
|
||||||
|
webhook: Webhook,
|
||||||
|
triggerEvent: WebhookTriggerEvents
|
||||||
|
) {
|
||||||
|
if (!webhook.time || !webhook.timeUnit || !booking.startTime || !booking.location) return;
|
||||||
|
|
||||||
|
const isCalVideoLocation = booking.location === DailyLocationType || booking.location?.trim() === "";
|
||||||
|
if (!isCalVideoLocation) return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
triggerEvent !== WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW &&
|
||||||
|
triggerEvent !== WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const scheduledAt = dayjs(booking.startTime)
|
||||||
|
.add(webhook.time ?? 0, webhook.timeUnit?.toLowerCase() as dayjs.ManipulateType)
|
||||||
|
.toDate();
|
||||||
|
|
||||||
|
const taskType =
|
||||||
|
triggerEvent === WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW
|
||||||
|
? "triggerHostNoShowWebhook"
|
||||||
|
: "triggerGuestNoShowWebhook";
|
||||||
|
|
||||||
|
await tasker.create(
|
||||||
|
taskType,
|
||||||
|
{
|
||||||
|
triggerEvent,
|
||||||
|
bookingId: booking.id,
|
||||||
|
webhook: {
|
||||||
|
...webhook,
|
||||||
|
time: webhook.time ?? 0,
|
||||||
|
timeUnit: webhook.timeUnit ?? "HOUR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheduledAt,
|
||||||
|
referenceUid: booking.uid,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -239,6 +239,7 @@ export const Handler = async ({ ctx, input }: Options) => {
|
|||||||
startTime: updatedBooking.startTime,
|
startTime: updatedBooking.startTime,
|
||||||
id: updatedBooking.id,
|
id: updatedBooking.id,
|
||||||
location: updatedBooking.location,
|
location: updatedBooking.location,
|
||||||
|
uid: updatedBooking.uid,
|
||||||
},
|
},
|
||||||
triggerForUser: !eventType?.teamId || (eventType?.teamId && eventType?.parentId),
|
triggerForUser: !eventType?.teamId || (eventType?.teamId && eventType?.parentId),
|
||||||
organizerUser: { id: user.id },
|
organizerUser: { id: user.id },
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import dayjs from "@calcom/dayjs";
|
|||||||
import { sendRequestRescheduleEmailAndSMS } from "@calcom/emails";
|
import { sendRequestRescheduleEmailAndSMS } from "@calcom/emails";
|
||||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import { deleteWebhookScheduledTriggers } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
import {
|
||||||
|
deleteWebhookScheduledTriggers,
|
||||||
|
cancelNoShowTasksForBooking,
|
||||||
|
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||||
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||||
import { CalendarEventBuilder } from "@calcom/lib/builders/CalendarEvent/builder";
|
import { CalendarEventBuilder } from "@calcom/lib/builders/CalendarEvent/builder";
|
||||||
import { CalendarEventDirector } from "@calcom/lib/builders/CalendarEvent/director";
|
import { CalendarEventDirector } from "@calcom/lib/builders/CalendarEvent/director";
|
||||||
@@ -154,6 +157,7 @@ export const requestRescheduleHandler = async ({ ctx, input }: RequestReschedule
|
|||||||
// delete scheduled jobs of previous booking
|
// delete scheduled jobs of previous booking
|
||||||
const webhookPromises = [];
|
const webhookPromises = [];
|
||||||
webhookPromises.push(deleteWebhookScheduledTriggers({ booking: bookingToReschedule }));
|
webhookPromises.push(deleteWebhookScheduledTriggers({ booking: bookingToReschedule }));
|
||||||
|
webhookPromises.push(cancelNoShowTasksForBooking({ bookingUid: bookingToReschedule.uid }));
|
||||||
|
|
||||||
await Promise.all(webhookPromises).catch((error) => {
|
await Promise.all(webhookPromises).catch((error) => {
|
||||||
log.error("Error while deleting scheduled webhook triggers", JSON.stringify({ error }));
|
log.error("Error while deleting scheduled webhook triggers", JSON.stringify({ error }));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
updateTriggerForExistingBookings,
|
updateTriggerForExistingBookings,
|
||||||
deleteWebhookScheduledTriggers,
|
deleteWebhookScheduledTriggers,
|
||||||
|
cancelNoShowTasksForBooking,
|
||||||
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||||
@@ -51,6 +52,14 @@ export const editHandler = async ({ input, ctx }: EditOptions) => {
|
|||||||
const activeTriggersBefore = webhook.active ? webhook.eventTriggers : [];
|
const activeTriggersBefore = webhook.active ? webhook.eventTriggers : [];
|
||||||
await updateTriggerForExistingBookings(webhook, activeTriggersBefore, updatedWebhook.eventTriggers);
|
await updateTriggerForExistingBookings(webhook, activeTriggersBefore, updatedWebhook.eventTriggers);
|
||||||
} else if (!data.active && webhook.active) {
|
} else if (!data.active && webhook.active) {
|
||||||
|
await cancelNoShowTasksForBooking({
|
||||||
|
webhook: {
|
||||||
|
id: webhook.id,
|
||||||
|
userId: webhook.userId,
|
||||||
|
teamId: webhook.teamId,
|
||||||
|
eventTypeId: webhook.eventTypeId,
|
||||||
|
},
|
||||||
|
});
|
||||||
await deleteWebhookScheduledTriggers({ webhookId: webhook.id });
|
await deleteWebhookScheduledTriggers({ webhookId: webhook.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user