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:
85 files changed
+2078
-274
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class AwaitingPaymentSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("meeting_awaiting_payment")}: ${t("complete_your_booking_subject", {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(attendee.timeZone, attendee.language.locale),
|
||||
})}. \n\n ${t("you_can_view_booking_details_with_this_url", {
|
||||
url: `${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${this.calEvent.uid}?changes=true`,
|
||||
})} `;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class CancelledSeatSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
return `${attendee.language.translate("no_longer_attending", {
|
||||
name: attendee.name,
|
||||
})}. \n\n${attendee.language.translate("event_no_longer_attending_subject", {
|
||||
name: this.calEvent.team?.name || this.calEvent.organizer.name,
|
||||
date: this.getFormattedDate(attendee.timeZone, attendee.language.locale),
|
||||
})} `;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventCancelledSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("hey_there")} ${attendee.name}, ${t("event_request_cancelled")}/n/n ${t(
|
||||
"event_cancelled_subject",
|
||||
{
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(attendee.timeZone, attendee.language.locale),
|
||||
}
|
||||
)}. /n/n ${t("visit_cancelled_booking")} ${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${
|
||||
this.calEvent.uid
|
||||
} `;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventDeclinedSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("hey_there")} ${attendee.name}, ${t("event_request_declined")} ${t("event_declined_subject", {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(attendee.timeZone, attendee.language.locale),
|
||||
})}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventLocationChangedSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("event_location_changed")}. \n\n ${t("you_can_view_booking_details_with_this_url", {
|
||||
url: `${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${this.calEvent.uid}?changes=true`,
|
||||
})}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventRequestSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("booking_submitted", {
|
||||
name: attendee.name,
|
||||
})}. ${t("user_needs_to_confirm_or_reject_booking", {
|
||||
user: this.calEvent.organizer.name,
|
||||
})}\n\n ${t("you_can_view_booking_details_with_this_url", {
|
||||
url: `${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${this.calEvent.uid}`,
|
||||
})}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventRequestToRescheduleSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("request_reschedule_booking")}: ${t("request_reschedule_subtitle", {
|
||||
organizer: this.calEvent.organizer.name,
|
||||
})} \n\n${t("need_to_reschedule_or_cancel")} ${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${
|
||||
this.calEvent.uid
|
||||
}?changes=true`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventSuccessfullyReScheduledSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("hey_there")} ${attendee.name}, ${t("event_type_has_been_rescheduled_on_time_date", {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(attendee.timeZone, attendee.language.locale),
|
||||
})} \n\n ${t("you_can_view_booking_details_with_this_url", {
|
||||
url: `${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${this.calEvent.uid}`,
|
||||
})}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import SMSManager from "../sms-manager";
|
||||
|
||||
export default class EventSuccessfullyScheduledSMS extends SMSManager {
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
super(calEvent);
|
||||
}
|
||||
|
||||
getMessage(attendee: Person) {
|
||||
const t = attendee.language.translate;
|
||||
return `${t("confirming_your_booking_sms", {
|
||||
name: attendee.name,
|
||||
date: this.getFormattedDate(attendee.timeZone, attendee.language.locale),
|
||||
})} \n\n ${t("you_can_view_booking_details_with_this_url", {
|
||||
url: `${this.calEvent.bookerUrl ?? WEBAPP_URL}/booking/${this.calEvent.uid}`,
|
||||
})}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getSenderId } from "@calcom/features/ee/workflows/lib/alphanumericSenderIdSupport";
|
||||
import * as twilio from "@calcom/features/ee/workflows/lib/reminders/providers/twilioProvider";
|
||||
import { checkSMSRateLimit } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { SENDER_ID } from "@calcom/lib/constants";
|
||||
import { TimeFormat } from "@calcom/lib/timeFormat";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
const handleSendingSMS = ({
|
||||
reminderPhone,
|
||||
smsMessage,
|
||||
senderID,
|
||||
teamId,
|
||||
}: {
|
||||
reminderPhone: string;
|
||||
smsMessage: string;
|
||||
senderID: string;
|
||||
teamId: number;
|
||||
}) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const team = await prisma.team.findUnique({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
select: {
|
||||
parent: {
|
||||
select: {
|
||||
isOrganization: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!team?.parent?.isOrganization) return;
|
||||
|
||||
await checkSMSRateLimit({ identifier: `handleSendingSMS:team:${teamId}`, rateLimitingType: "sms" });
|
||||
const sms = twilio.sendSMS(reminderPhone, smsMessage, senderID, teamId);
|
||||
resolve(sms);
|
||||
} catch (e) {
|
||||
reject(console.error(`twilio.sendSMS failed`, e));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default abstract class SMSManager {
|
||||
calEvent: CalendarEvent;
|
||||
isTeamEvent = false;
|
||||
teamId: number | undefined = undefined;
|
||||
|
||||
constructor(calEvent: CalendarEvent) {
|
||||
this.calEvent = calEvent;
|
||||
this.teamId = this.calEvent?.team?.id;
|
||||
this.isTeamEvent = !!this.calEvent?.team?.id;
|
||||
}
|
||||
|
||||
getFormattedTime(
|
||||
timezone: string,
|
||||
locale: string,
|
||||
time: string,
|
||||
format = `dddd, LL | ${TimeFormat.TWELVE_HOUR}`
|
||||
) {
|
||||
return dayjs(time).tz(timezone).locale(locale).format(format);
|
||||
}
|
||||
|
||||
getFormattedDate(timezone: string, locale: string) {
|
||||
return `${this.getFormattedTime(timezone, locale, this.calEvent.startTime)} - ${this.getFormattedTime(
|
||||
timezone,
|
||||
locale,
|
||||
this.calEvent.endTime
|
||||
)} (${timezone})`;
|
||||
}
|
||||
|
||||
abstract getMessage(attendee: Person): string;
|
||||
|
||||
async sendSMSToAttendee(attendee: Person) {
|
||||
const teamId = this.teamId;
|
||||
if (!this.isTeamEvent || !teamId) return;
|
||||
|
||||
const attendeePhoneNumber = attendee.phoneNumber;
|
||||
if (!attendeePhoneNumber) return;
|
||||
|
||||
const smsMessage = this.getMessage(attendee);
|
||||
const senderID = getSenderId(attendeePhoneNumber, SENDER_ID);
|
||||
return handleSendingSMS({ reminderPhone: attendeePhoneNumber, smsMessage, senderID, teamId });
|
||||
}
|
||||
|
||||
async sendSMSToAttendees() {
|
||||
if (!this.isTeamEvent) return;
|
||||
const smsToSend: Promise<unknown>[] = [];
|
||||
|
||||
for (const attendee of this.calEvent.attendees) {
|
||||
smsToSend.push(this.sendSMSToAttendee(attendee));
|
||||
}
|
||||
|
||||
await Promise.all(smsToSend);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user