@@ -3,17 +3,23 @@ import short from "short-uuid";
33import { v5 as uuidv5 } from "uuid" ;
44
55import dayjs from "@calcom/dayjs" ;
6+ import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource" ;
67import type {
78 CreateInstantBookingData ,
89 InstantBookingCreateResult ,
910} from "@calcom/features/bookings/lib/dto/types" ;
1011import getBookingDataSchema from "@calcom/features/bookings/lib/getBookingDataSchema" ;
1112import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields" ;
1213import { getBookingData } from "@calcom/features/bookings/lib/handleNewBooking/getBookingData" ;
14+ import { buildBookingCreatedAuditData } from "@calcom/features/bookings/lib/handleNewBooking/buildBookingEventAuditData" ;
15+ import { getAuditActionSource } from "@calcom/features/bookings/lib/handleNewBooking/getAuditActionSource" ;
16+ import { getBookingAuditActorForNewBooking } from "@calcom/features/bookings/lib/handleNewBooking/getBookingAuditActorForNewBooking" ;
1317import { getCustomInputsResponses } from "@calcom/features/bookings/lib/handleNewBooking/getCustomInputsResponses" ;
1418import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB" ;
1519import type { IBookingCreateService } from "@calcom/features/bookings/lib/interfaces/IBookingCreateService" ;
20+ import type { BookingEventHandlerService } from "@calcom/features/bookings/lib/onBookingEvents/BookingEventHandlerService" ;
1621import { createInstantMeetingWithCalVideo } from "@calcom/features/conferencing/lib/videoClient" ;
22+ import type { FeaturesRepository } from "@calcom/features/flags/features.repository" ;
1723import { getFullName } from "@calcom/features/form-builder/utils" ;
1824import { sendNotification } from "@calcom/features/notifications/sendNotification" ;
1925import { sendGenericWebhookPayload } from "@calcom/features/webhooks/lib/sendPayload" ;
@@ -31,6 +37,8 @@ import { WebhookVersion } from "../../../webhooks/lib/interface/IWebhookReposito
3137
3238interface IInstantBookingCreateServiceDependencies {
3339 prismaClient : PrismaClient ;
40+ bookingEventHandler : BookingEventHandlerService ;
41+ featuresRepository : FeaturesRepository ;
3442}
3543
3644const handleInstantMeetingWebhookTrigger = async ( args : {
@@ -343,6 +351,60 @@ export async function handler(
343351 prismaClient : prisma ,
344352 } ) ;
345353
354+ // Fire booking audit event
355+ try {
356+ const orgId = eventType . team ?. parentId ?? null ;
357+ const isBookingAuditEnabled = orgId
358+ ? await deps . featuresRepository . checkIfTeamHasFeature ( orgId , "booking-audit" )
359+ : false ;
360+
361+ const actionSource : ActionSource = getAuditActionSource ( {
362+ creationSource : bookingData . creationSource ?? null ,
363+ eventTypeId : eventType . id ,
364+ rescheduleUid : null ,
365+ } ) ;
366+
367+ const bookerAttendeeId = newBooking . attendees ?. find ( ( a ) => a . email === bookerEmail ) ?. id ?? null ;
368+ const auditActor = getBookingAuditActorForNewBooking ( {
369+ bookerAttendeeId,
370+ actorUserUuid : null ,
371+ bookerEmail,
372+ bookerName : fullName ,
373+ rescheduledBy : null ,
374+ logger,
375+ } ) ;
376+
377+ await deps . bookingEventHandler . onBookingCreated ( {
378+ payload : {
379+ config : { isDryRun : false } ,
380+ bookingFormData : { hashedLink : null } ,
381+ booking : {
382+ uid : newBooking . uid ,
383+ startTime : newBooking . startTime ,
384+ endTime : newBooking . endTime ,
385+ status : newBooking . status ,
386+ userId : newBooking . userId ,
387+ } ,
388+ organizationId : orgId ,
389+ } ,
390+ actor : auditActor ,
391+ auditData : buildBookingCreatedAuditData ( {
392+ booking : {
393+ startTime : newBooking . startTime ,
394+ endTime : newBooking . endTime ,
395+ status : newBooking . status ,
396+ userUuid : null ,
397+ } ,
398+ attendeeSeatId : null ,
399+ } ) ,
400+ source : actionSource ,
401+ operationId : null ,
402+ isBookingAuditEnabled,
403+ } ) ;
404+ } catch ( error ) {
405+ logger . error ( "Error firing booking audit event for instant booking" , error ) ;
406+ }
407+
346408 return {
347409 message : "Success" ,
348410 meetingTokenId : instantMeetingToken . id ,
0 commit comments