2023-02-27 20:45:40 +00:00
|
|
|
import type { TFunction } from "next-i18next";
|
2022-12-07 21:47:02 +00:00
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
import type BaseEmail from "@calcom/emails/templates/_base-email";
|
2022-06-10 00:32:34 +00:00
|
|
|
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
2022-03-23 22:00:30 +00:00
|
|
|
|
2022-06-06 17:49:56 +00:00
|
|
|
import AttendeeAwaitingPaymentEmail from "./templates/attendee-awaiting-payment-email";
|
|
|
|
import AttendeeCancelledEmail from "./templates/attendee-cancelled-email";
|
|
|
|
import AttendeeDeclinedEmail from "./templates/attendee-declined-email";
|
|
|
|
import AttendeeLocationChangeEmail from "./templates/attendee-location-change-email";
|
|
|
|
import AttendeeRequestEmail from "./templates/attendee-request-email";
|
|
|
|
import AttendeeRescheduledEmail from "./templates/attendee-rescheduled-email";
|
|
|
|
import AttendeeScheduledEmail from "./templates/attendee-scheduled-email";
|
2022-09-15 01:27:46 +00:00
|
|
|
import AttendeeWasRequestedToRescheduleEmail from "./templates/attendee-was-requested-to-reschedule-email";
|
2022-06-25 05:16:20 +00:00
|
|
|
import BrokenIntegrationEmail from "./templates/broken-integration-email";
|
2022-12-07 21:47:02 +00:00
|
|
|
import DisabledAppEmail from "./templates/disabled-app-email";
|
2023-02-27 20:45:40 +00:00
|
|
|
import type { Feedback } from "./templates/feedback-email";
|
|
|
|
import FeedbackEmail from "./templates/feedback-email";
|
|
|
|
import type { PasswordReset } from "./templates/forgot-password-email";
|
|
|
|
import ForgotPasswordEmail from "./templates/forgot-password-email";
|
2022-06-06 17:49:56 +00:00
|
|
|
import OrganizerCancelledEmail from "./templates/organizer-cancelled-email";
|
|
|
|
import OrganizerLocationChangeEmail from "./templates/organizer-location-change-email";
|
|
|
|
import OrganizerPaymentRefundFailedEmail from "./templates/organizer-payment-refund-failed-email";
|
|
|
|
import OrganizerRequestEmail from "./templates/organizer-request-email";
|
|
|
|
import OrganizerRequestReminderEmail from "./templates/organizer-request-reminder-email";
|
2022-09-15 01:27:46 +00:00
|
|
|
import OrganizerRequestedToRescheduleEmail from "./templates/organizer-requested-to-reschedule-email";
|
2022-06-06 17:49:56 +00:00
|
|
|
import OrganizerRescheduledEmail from "./templates/organizer-rescheduled-email";
|
|
|
|
import OrganizerScheduledEmail from "./templates/organizer-scheduled-email";
|
2023-02-27 20:45:40 +00:00
|
|
|
import type { TeamInvite } from "./templates/team-invite-email";
|
|
|
|
import TeamInviteEmail from "./templates/team-invite-email";
|
|
|
|
|
|
|
|
const sendEmail = (prepare: () => BaseEmail) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const email = prepare();
|
|
|
|
resolve(email.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error(`${prepare.constructor.name}.sendEmail failed`, e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2021-11-26 11:03:43 +00:00
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendScheduledEmails = async (calEvent: CalendarEvent) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent, teamMember })));
|
|
|
|
}
|
|
|
|
}
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2023-02-27 20:45:40 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
|
|
|
return sendEmail(() => new AttendeeScheduledEmail(calEvent, attendee));
|
2021-11-26 11:03:43 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendRescheduledEmails = async (calEvent: CalendarEvent) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2023-02-27 20:45:40 +00:00
|
|
|
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRescheduledEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRescheduledEmail({ calEvent, teamMember })));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-15 01:27:46 +00:00
|
|
|
// @TODO: we should obtain who is rescheduling the event and send them a different email
|
2021-11-26 11:03:43 +00:00
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
return sendEmail(() => new AttendeeRescheduledEmail(calEvent, attendee));
|
2021-11-26 11:03:43 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-07-01 19:19:23 +00:00
|
|
|
export const sendScheduledSeatsEmails = async (
|
|
|
|
calEvent: CalendarEvent,
|
|
|
|
invitee: Person,
|
2022-10-18 19:41:50 +00:00
|
|
|
newSeat: boolean,
|
|
|
|
showAttendees: boolean
|
2022-07-01 19:19:23 +00:00
|
|
|
) => {
|
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent, newSeat })));
|
2022-07-01 19:19:23 +00:00
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
if (calEvent.team) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent, newSeat, teamMember })));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
emailsToSend.push(sendEmail(() => new AttendeeScheduledEmail(calEvent, invitee, showAttendees)));
|
2022-07-01 19:19:23 +00:00
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendOrganizerRequestEmail = async (calEvent: CalendarEvent) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team?.members) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestEmail({ calEvent, teamMember })));
|
2021-11-26 11:03:43 +00:00
|
|
|
}
|
2023-02-27 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendAttendeeRequestEmail = async (calEvent: CalendarEvent, attendee: Person) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
await sendEmail(() => new AttendeeRequestEmail(calEvent, attendee));
|
2022-03-07 18:18:23 +00:00
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendDeclinedEmails = async (calEvent: CalendarEvent) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
return sendEmail(() => new AttendeeDeclinedEmail(calEvent, attendee));
|
2021-11-26 11:03:43 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendCancelledEmails = async (calEvent: CalendarEvent) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerCancelledEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team?.members) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerCancelledEmail({ calEvent, teamMember })));
|
|
|
|
}
|
|
|
|
}
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2023-02-27 20:45:40 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
|
|
|
return sendEmail(() => new AttendeeCancelledEmail(calEvent, attendee));
|
2021-11-26 11:03:43 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendOrganizerRequestReminderEmail = async (calEvent: CalendarEvent) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestReminderEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team?.members) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestReminderEmail({ calEvent, teamMember })));
|
2021-11-26 11:03:43 +00:00
|
|
|
}
|
2023-02-27 20:45:40 +00:00
|
|
|
}
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendAwaitingPaymentEmail = async (calEvent: CalendarEvent) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
return sendEmail(() => new AttendeeAwaitingPaymentEmail(calEvent, attendee));
|
2021-11-26 11:03:43 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendOrganizerPaymentRefundFailedEmail = async (calEvent: CalendarEvent) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team?.members) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent, teamMember })));
|
2021-11-26 11:03:43 +00:00
|
|
|
}
|
2023-02-27 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const sendPasswordResetEmail = async (passwordResetEvent: PasswordReset) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
await sendEmail(() => new ForgotPasswordEmail(passwordResetEvent));
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const sendTeamInviteEmail = async (teamInviteEvent: TeamInvite) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
await sendEmail(() => new TeamInviteEmail(teamInviteEvent));
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
export const sendRequestRescheduleEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
2022-06-10 00:32:34 +00:00
|
|
|
metadata: { rescheduleLink: string }
|
2022-04-14 21:25:24 +00:00
|
|
|
) => {
|
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestedToRescheduleEmail(calEvent, metadata)));
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
emailsToSend.push(sendEmail(() => new AttendeeWasRequestedToRescheduleEmail(calEvent, metadata)));
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
2022-05-24 13:29:39 +00:00
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendLocationChangeEmails = async (calEvent: CalendarEvent) => {
|
2022-05-27 23:27:41 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerLocationChangeEmail({ calEvent })));
|
|
|
|
|
|
|
|
if (calEvent.team?.members) {
|
|
|
|
for (const teamMember of calEvent.team.members) {
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerLocationChangeEmail({ calEvent, teamMember })));
|
|
|
|
}
|
|
|
|
}
|
2022-05-27 23:27:41 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2023-02-27 20:45:40 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
|
|
|
return sendEmail(() => new AttendeeLocationChangeEmail(calEvent, attendee));
|
2022-05-27 23:27:41 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
2022-05-24 13:29:39 +00:00
|
|
|
export const sendFeedbackEmail = async (feedback: Feedback) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
await sendEmail(() => new FeedbackEmail(feedback));
|
2022-05-24 13:29:39 +00:00
|
|
|
};
|
2022-06-25 05:16:20 +00:00
|
|
|
|
|
|
|
export const sendBrokenIntegrationEmail = async (evt: CalendarEvent, type: "video" | "calendar") => {
|
2023-02-27 20:45:40 +00:00
|
|
|
await sendEmail(() => new BrokenIntegrationEmail(evt, type));
|
2022-06-25 05:16:20 +00:00
|
|
|
};
|
2022-12-07 21:47:02 +00:00
|
|
|
|
|
|
|
export const sendDisabledAppEmail = async ({
|
|
|
|
email,
|
|
|
|
appName,
|
|
|
|
appType,
|
|
|
|
t,
|
|
|
|
title = undefined,
|
|
|
|
eventTypeId = undefined,
|
|
|
|
}: {
|
|
|
|
email: string;
|
|
|
|
appName: string;
|
|
|
|
appType: string[];
|
|
|
|
t: TFunction;
|
|
|
|
title?: string;
|
|
|
|
eventTypeId?: number;
|
|
|
|
}) => {
|
2023-02-27 20:45:40 +00:00
|
|
|
await sendEmail(() => new DisabledAppEmail(email, appName, appType, t, title, eventTypeId));
|
2022-12-07 21:47:02 +00:00
|
|
|
};
|