feat: booking with phone number (#14461)

Co-authored-by: Omar López <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-09-11 17:56:04 -07:00
1 parent 74a9f3c19e
commit 4a59841b02
85 files changed
+2078 -274

No files matched your search

+5 -2
View File
@@ -6,6 +6,7 @@ import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { WEBAPP_URL } from "./constants";
import getLabelValueMapFromResponses from "./getLabelValueMapFromResponses";
import isSmsCalEmail from "./isSmsCalEmail";
const translator = short();
@@ -39,9 +40,11 @@ export const getWho = (calEvent: CalendarEvent, t: TFunction) => {
.map((attendee) => {
return `
${attendee?.name || t("guest")}
${attendee.email}
`;
${!isSmsCalEmail(attendee.email) ? `${attendee.email}\n` : `${attendee.phoneNumber}\n`}
`;
})
.join("");
const organizer = `
+4 -2
View File
@@ -2,7 +2,7 @@
/// <reference path="../types/ical.d.ts"/>
import type { Prisma } from "@prisma/client";
import ICAL from "ical.js";
import type { Attendee, DateArray, DurationObject, Person } from "ics";
import type { Attendee, DateArray, DurationObject } from "ics";
import { createEvent } from "ics";
import type { DAVAccount, DAVCalendar, DAVObject } from "tsdav";
import {
@@ -18,6 +18,7 @@ import { v4 as uuidv4 } from "uuid";
import dayjs from "@calcom/dayjs";
import sanitizeCalendarObject from "@calcom/lib/sanitizeCalendarObject";
import type { Person as AttendeeInCalendarEvent } from "@calcom/types/Calendar";
import type {
Calendar,
CalendarEvent,
@@ -25,6 +26,7 @@ import type {
EventBusyDate,
IntegrationCalendar,
NewCalendarEventType,
TeamMember,
} from "@calcom/types/Calendar";
import type { CredentialPayload } from "@calcom/types/Credential";
@@ -95,7 +97,7 @@ const getDuration = (start: string, end: string): DurationObject => ({
minutes: dayjs(end).diff(dayjs(start), "minute"),
});
const mapAttendees = (attendees: Person[]): Attendee[] =>
const mapAttendees = (attendees: AttendeeInCalendarEvent[] | TeamMember[]): Attendee[] =>
attendees.map(({ email, name }) => ({ name, email, partstat: "NEEDS-ACTION" }));
export default abstract class BaseCalendarService implements Calendar {
@@ -0,0 +1,4 @@
export const contructEmailFromPhoneNumber = (phoneNumber: string) => {
const cleanedPhoneNumber = phoneNumber.replace(/\+/g, "");
return `${cleanedPhoneNumber}@sms.cal.com`;
};
+2 -1
View File
@@ -194,11 +194,12 @@ export const getEventTypeById = async ({
});
}
const isOrgTeamEvent = !!eventType?.teamId && !!eventType.team?.parentId;
const eventTypeObject = Object.assign({}, eventType, {
users: eventTypeUsers,
periodStartDate: eventType.periodStartDate?.toString() ?? null,
periodEndDate: eventType.periodEndDate?.toString() ?? null,
bookingFields: getBookingFieldsWithSystemFields(eventType),
bookingFields: getBookingFieldsWithSystemFields({ ...eventType, isOrgTeamEvent }),
});
const isOrgEventType = !!eventTypeObject.team?.parentId;
+3
View File
@@ -0,0 +1,3 @@
export default function isSmsCalEmail(email: string) {
return email.endsWith("@sms.cal.com");
}
+9
View File
@@ -60,6 +60,8 @@ export async function getBooking(bookingId: number) {
bookingFields: true,
team: {
select: {
id: true,
name: true,
parentId: true,
},
},
@@ -152,6 +154,13 @@ export async function getBooking(bookingId: number) {
language: { translate: t, locale: user.locale ?? "en" },
id: user.id,
},
team: !!booking.eventType?.team
? {
name: booking.eventType.team.name,
id: booking.eventType.team.id,
members: [],
}
: undefined,
attendees: attendeesList,
location: booking.location,
uid: booking.uid,
+6 -3
View File
@@ -25,7 +25,8 @@ const handlePayment = async (
uid: string;
},
bookerName: string,
bookerEmail: string
bookerEmail: string,
bookerPhoneNumber?: string | null
) => {
const paymentApp = (await appStore[
paymentAppCredentials?.app?.dirName as keyof typeof appStore
@@ -50,8 +51,9 @@ const handlePayment = async (
currency: selectedEventType?.metadata?.apps?.[paymentAppCredentials.appId].currency,
},
booking.id,
paymentOption,
bookerEmail,
paymentOption
bookerPhoneNumber
);
} else {
paymentData = await paymentInstance.create(
@@ -63,8 +65,9 @@ const handlePayment = async (
booking.userId,
booking.user?.username ?? null,
bookerName,
bookerEmail,
paymentOption,
bookerEmail,
bookerPhoneNumber,
selectedEventType.title,
evt.title
);
+2 -2
View File
@@ -1,7 +1,7 @@
import type { Prisma } from "@prisma/client";
import EventManager from "@calcom/core/EventManager";
import { sendScheduledEmails } from "@calcom/emails";
import { sendScheduledEmailsAndSMS } from "@calcom/emails";
import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/doesBookingRequireConfirmation";
import { handleBookingRequested } from "@calcom/features/bookings/lib/handleBookingRequested";
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
@@ -76,7 +76,7 @@ export async function handlePaymentSuccess(paymentId: number, bookingId: number)
log.debug(`handling booking request for eventId ${eventType.id}`);
}
} else {
await sendScheduledEmails({ ...evt }, undefined, undefined, undefined, eventType.metadata);
await sendScheduledEmailsAndSMS({ ...evt }, undefined, undefined, undefined, eventType.metadata);
}
throw new HttpCode({