Skip to content
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

fix: schedule no show webhooks for requires confirmation event #17089

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/features/bookings/lib/handleConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Prisma } from "@prisma/client";

import type { EventManagerUser } from "@calcom/core/EventManager";
import EventManager from "@calcom/core/EventManager";
import dayjs from "@calcom/dayjs";
import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";
import { sendScheduledEmailsAndSMS } from "@calcom/emails";
import {
Expand All @@ -10,6 +11,7 @@ import {
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
import type { Workflow } from "@calcom/features/ee/workflows/lib/types";
import tasker from "@calcom/features/tasker";
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
import { scheduleTrigger } from "@calcom/features/webhooks/lib/scheduleTrigger";
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
Expand All @@ -36,6 +38,8 @@ export async function handleConfirmation(args: {
prisma: PrismaClient;
bookingId: number;
booking: {
startTime: Date;
id: number;
eventType: {
currency: string;
description: string | null;
Expand Down Expand Up @@ -364,6 +368,22 @@ export async function handleConfirmation(args: {
orgId,
});

const subscribersHostsNoShowStarted = await getWebhooks({
userId,
eventTypeId: booking.eventTypeId,
triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW,
teamId,
orgId,
});

const subscribersGuestsNoShowStarted = await getWebhooks({
userId,
eventTypeId: booking.eventTypeId,
triggerEvent: WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW,
teamId,
orgId,
});

const scheduleTriggerPromises: Promise<unknown>[] = [];

subscribersMeetingStarted.forEach((subscriber) => {
Expand Down Expand Up @@ -391,6 +411,50 @@ export async function handleConfirmation(args: {
});
});

scheduleTriggerPromises.push(
...subscribersHostsNoShowStarted.map((webhook) => {
if (booking?.startTime && webhook.time && webhook.timeUnit) {
const scheduledAt = dayjs(booking.startTime)
.add(webhook.time, webhook.timeUnit.toLowerCase() as dayjs.ManipulateType)
.toDate();
return tasker.create(
"triggerHostNoShowWebhook",
{
triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW,
bookingId: booking.id,
// Prevents null values from being serialized
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit },
},
{ scheduledAt }
);
}
return Promise.resolve();
Comment on lines +420 to +431
Copy link
Contributor Author

Choose a reason for hiding this comment

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

create task for triggerHostNoShowWebhook and triggerGuestNoShowWebhook

})
);

scheduleTriggerPromises.push(
...subscribersGuestsNoShowStarted.map((webhook) => {
if (booking?.startTime && webhook.time && webhook.timeUnit) {
const scheduledAt = dayjs(booking.startTime)
.add(webhook.time, webhook.timeUnit.toLowerCase() as dayjs.ManipulateType)
.toDate();

return tasker.create(
"triggerGuestNoShowWebhook",
{
triggerEvent: WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW,
bookingId: booking.id,
// Prevents null values from being serialized
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit },
},
{ scheduledAt }
);
}

return Promise.resolve();
})
);

await Promise.all(scheduleTriggerPromises);

const eventTypeInfo: EventTypeInfo = {
Expand Down
Loading