* add reschedule link if event if type team * fix type errors * fix type errors * change team.name to team.slug * fix type_errors * fix type-errors * fix type-errors * fetch team from db * make rescheduleLink dynamic (temp_changes) * fix type-error * add org support * fix type errors * remove old org code * use /reschedule/uid instead * remove not needed changes * implement feedback * code clean up --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { sendAttendeeRequestEmail, sendOrganizerRequestEmail } from "@calcom/emails";
|
|
import { getWebhookPayloadForBooking } from "@calcom/features/bookings/lib/getWebhookPayloadForBooking";
|
|
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
|
import sendPayload from "@calcom/features/webhooks/lib/sendPayload";
|
|
import logger from "@calcom/lib/logger";
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
|
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
|
|
|
const log = logger.getSubLogger({ prefix: ["[handleBookingRequested] book:user"] });
|
|
|
|
/**
|
|
* Supposed to do whatever is needed when a booking is requested.
|
|
*/
|
|
export async function handleBookingRequested(args: {
|
|
evt: CalendarEvent;
|
|
booking: {
|
|
eventType: {
|
|
team?: {
|
|
parentId: number | null;
|
|
} | null;
|
|
currency: string;
|
|
description: string | null;
|
|
id: number;
|
|
length: number;
|
|
price: number;
|
|
requiresConfirmation: boolean;
|
|
title: string;
|
|
teamId?: number | null;
|
|
} | null;
|
|
eventTypeId: number | null;
|
|
userId: number | null;
|
|
id: number;
|
|
};
|
|
}) {
|
|
const { evt, booking } = args;
|
|
|
|
log.debug("Emails: Sending booking requested emails");
|
|
await sendOrganizerRequestEmail({ ...evt });
|
|
await sendAttendeeRequestEmail({ ...evt }, evt.attendees[0]);
|
|
|
|
try {
|
|
const subscribersBookingRequested = await getWebhooks({
|
|
userId: booking.userId,
|
|
eventTypeId: booking.eventTypeId,
|
|
triggerEvent: WebhookTriggerEvents.BOOKING_REQUESTED,
|
|
teamId: booking.eventType?.teamId,
|
|
});
|
|
|
|
const webhookPayload = getWebhookPayloadForBooking({
|
|
booking,
|
|
evt,
|
|
});
|
|
|
|
const promises = subscribersBookingRequested.map((sub) =>
|
|
sendPayload(
|
|
sub.secret,
|
|
WebhookTriggerEvents.BOOKING_REQUESTED,
|
|
new Date().toISOString(),
|
|
sub,
|
|
webhookPayload
|
|
).catch((e) => {
|
|
console.error(
|
|
`Error executing webhook for event: ${WebhookTriggerEvents.BOOKING_REQUESTED}, URL: ${sub.subscriberUrl}`,
|
|
e
|
|
);
|
|
})
|
|
);
|
|
await Promise.all(promises);
|
|
} catch (error) {
|
|
// Silently fail
|
|
log.error("Error in handleBookingRequested", safeStringify(error));
|
|
}
|
|
}
|