Skip to content

Commit 27e7739

Browse files
committed
feat: add sms and email notifications
1 parent 5e5a91c commit 27e7739

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

apps/api/v2/src/ee/bookings/2024-08-13/services/booking-location.service.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
BookingReferenceRepository,
44
buildCalEventFromBooking,
55
CredentialRepository,
6+
sendLocationChangeEmailsAndSMS,
67
updateEvent,
78
} from "@calcom/platform-libraries";
89
import { makeUserActor } from "@calcom/platform-libraries/bookings";
@@ -171,14 +172,40 @@ export class BookingLocationService_2024_08_13 {
171172
});
172173
}
173174

175+
/**
176+
* sends location change email and SMS notifications.
177+
* fetches eventType metadata from the booking for email settings.
178+
*/
179+
private async sendLocationChangeNotifications(
180+
evt: CalendarEvent,
181+
bookingId: number,
182+
bookingUid: string,
183+
newLocation: string
184+
): Promise<void> {
185+
const bookingWithEventType =
186+
await this.bookingsRepository.getBookingByIdWithUserAndEventDetails(bookingId);
187+
try {
188+
await sendLocationChangeEmailsAndSMS(
189+
{ ...evt, location: newLocation },
190+
bookingWithEventType?.eventType?.metadata as Record<string, unknown> | undefined
191+
);
192+
} catch (error) {
193+
this.logger.error(
194+
`Failed to send location change emails for booking uid=${bookingUid}`,
195+
error instanceof Error ? error.message : String(error)
196+
);
197+
}
198+
}
199+
174200
/**
175201
* updates booking with video location data and emits location changed event.
176202
* returns the updated booking response.
177203
*/
178204
private async updateBookingWithVideoLocation(
179205
ctx: IntegrationHandlerContext,
180206
videoCallUrl: string | undefined,
181-
bookingLocation: string
207+
bookingLocation: string,
208+
evt: CalendarEvent
182209
): Promise<BookingLocationResponse> {
183210
const existingMetadata = (ctx.existingBooking.metadata || {}) as Record<string, unknown>;
184211
const updatedMetadata = {
@@ -217,6 +244,13 @@ export class BookingLocationService_2024_08_13 {
217244
},
218245
});
219246

247+
await this.sendLocationChangeNotifications(
248+
evt,
249+
ctx.existingBooking.id,
250+
ctx.existingBooking.uid,
251+
bookingLocation
252+
);
253+
220254
return this.bookingsService.getBooking(updatedBooking.uid, ctx.user);
221255
}
222256

@@ -340,6 +374,25 @@ export class BookingLocationService_2024_08_13 {
340374
},
341375
});
342376

377+
if (bookingLocation) {
378+
const bookingWithDetails = await this.bookingsRepository.getBookingByIdWithUserAndEventDetails(
379+
existingBooking.id
380+
);
381+
if (bookingWithDetails?.user) {
382+
const evt = await this.buildCalEventForIntegration(
383+
bookingWithDetails as BookingWithDetails,
384+
bookingLocation,
385+
null
386+
);
387+
await this.sendLocationChangeNotifications(
388+
evt,
389+
existingBooking.id,
390+
existingBooking.uid,
391+
bookingLocation
392+
);
393+
}
394+
}
395+
343396
return this.bookingsService.getBooking(updatedBooking.uid, user);
344397
}
345398

@@ -471,7 +524,7 @@ export class BookingLocationService_2024_08_13 {
471524
await this.syncCalendarEvent(ctx.existingBooking.id, bookingLocation);
472525
}
473526

474-
return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation);
527+
return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation, evt);
475528
}
476529

477530
/**
@@ -529,7 +582,7 @@ export class BookingLocationService_2024_08_13 {
529582
await this.syncCalendarEvent(ctx.existingBooking.id, bookingLocation);
530583
}
531584

532-
return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation);
585+
return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation, evt);
533586
}
534587

535588
/**
@@ -622,6 +675,13 @@ export class BookingLocationService_2024_08_13 {
622675
},
623676
});
624677

678+
await this.sendLocationChangeNotifications(
679+
evt,
680+
ctx.existingBooking.id,
681+
ctx.existingBooking.uid,
682+
bookingLocation
683+
);
684+
625685
return this.bookingsService.getBooking(updatedBooking.uid, ctx.user);
626686
}
627687

0 commit comments

Comments
 (0)