2022-12-07 21:47:02 +00:00
|
|
|
import { TFunction } from "next-i18next";
|
|
|
|
|
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";
|
2022-06-06 17:49:56 +00:00
|
|
|
import FeedbackEmail, { Feedback } from "./templates/feedback-email";
|
|
|
|
import ForgotPasswordEmail, { PasswordReset } from "./templates/forgot-password-email";
|
|
|
|
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";
|
|
|
|
import TeamInviteEmail, { TeamInvite } from "./templates/team-invite-email";
|
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
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new AttendeeScheduledEmail(calEvent, attendee);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new OrganizerScheduledEmail(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerScheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
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>[] = [];
|
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) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new AttendeeRescheduledEmail(calEvent, attendee);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new OrganizerRescheduledEmail(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
2022-09-15 01:27:46 +00:00
|
|
|
reject(console.error("OrganizerRescheduledEmail.sendEmail failed", e));
|
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>[] = [];
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-10-18 19:41:50 +00:00
|
|
|
const scheduledEmail = new AttendeeScheduledEmail(calEvent, invitee, showAttendees);
|
2022-07-01 19:19:23 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
2022-10-18 19:41:50 +00:00
|
|
|
reject(console.error("AttendeeScheduledEmail.sendEmail failed", e));
|
2022-07-01 19:19:23 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const scheduledEmail = new OrganizerScheduledEmail(calEvent, newSeat);
|
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerScheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendOrganizerRequestEmail = async (calEvent: CalendarEvent) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const organizerRequestEmail = new OrganizerRequestEmail(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(organizerRequestEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerRequestEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendAttendeeRequestEmail = async (calEvent: CalendarEvent, attendee: Person) => {
|
2022-03-07 18:18:23 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const attendeeRequestEmail = new AttendeeRequestEmail(calEvent, attendee);
|
2022-03-07 18:18:23 +00:00
|
|
|
resolve(attendeeRequestEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendRequestEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const declinedEmail = new AttendeeDeclinedEmail(calEvent, attendee);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(declinedEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new AttendeeCancelledEmail(calEvent, attendee);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeCancelledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new OrganizerCancelledEmail(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerCancelledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendOrganizerRequestReminderEmail = async (calEvent: CalendarEvent) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const organizerRequestReminderEmail = new OrganizerRequestReminderEmail(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(organizerRequestReminderEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerRequestReminderEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const paymentEmail = new AttendeeAwaitingPaymentEmail(calEvent, attendee);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(paymentEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeAwaitingPaymentEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
export const sendOrganizerPaymentRefundFailedEmail = async (calEvent: CalendarEvent) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const paymentRefundFailedEmail = new OrganizerPaymentRefundFailedEmail(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(paymentRefundFailedEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerPaymentRefundFailedEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sendPasswordResetEmail = async (passwordResetEvent: PasswordReset) => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const passwordResetEmail = new ForgotPasswordEmail(passwordResetEvent);
|
|
|
|
resolve(passwordResetEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerPaymentRefundFailedEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sendTeamInviteEmail = async (teamInviteEvent: TeamInvite) => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const teamInviteEmail = new TeamInviteEmail(teamInviteEvent);
|
|
|
|
resolve(teamInviteEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("TeamInviteEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
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>[] = [];
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-09-15 01:27:46 +00:00
|
|
|
const requestRescheduleEmail = new AttendeeWasRequestedToRescheduleEmail(calEvent, metadata);
|
2022-04-14 21:25:24 +00:00
|
|
|
resolve(requestRescheduleEmail.sendEmail());
|
|
|
|
} catch (e) {
|
2022-09-15 01:27:46 +00:00
|
|
|
reject(console.error("AttendeeWasRequestedToRescheduleEmail.sendEmail failed", e));
|
2022-04-14 21:25:24 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-09-15 01:27:46 +00:00
|
|
|
const requestRescheduleEmail = new OrganizerRequestedToRescheduleEmail(calEvent, metadata);
|
2022-04-14 21:25:24 +00:00
|
|
|
resolve(requestRescheduleEmail.sendEmail());
|
|
|
|
} catch (e) {
|
2022-09-15 01:27:46 +00:00
|
|
|
reject(console.error("OrganizerRequestedToRescheduleEmail.sendEmail failed", e));
|
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>[] = [];
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
...calEvent.attendees.map((attendee) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new AttendeeLocationChangeEmail(calEvent, attendee);
|
2022-05-27 23:27:41 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeLocationChangeEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-06-10 00:32:34 +00:00
|
|
|
const scheduledEmail = new OrganizerLocationChangeEmail(calEvent);
|
2022-05-27 23:27:41 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerLocationChangeEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
2022-05-24 13:29:39 +00:00
|
|
|
export const sendFeedbackEmail = async (feedback: Feedback) => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const feedbackEmail = new FeedbackEmail(feedback);
|
|
|
|
resolve(feedbackEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("FeedbackEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2022-06-25 05:16:20 +00:00
|
|
|
|
|
|
|
export const sendBrokenIntegrationEmail = async (evt: CalendarEvent, type: "video" | "calendar") => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const brokenIntegrationEmail = new BrokenIntegrationEmail(evt, type);
|
|
|
|
resolve(brokenIntegrationEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("FeedbackEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
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;
|
|
|
|
}) => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const disabledPaymentEmail = new DisabledAppEmail(email, appName, appType, t, title, eventTypeId);
|
|
|
|
resolve(disabledPaymentEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("DisabledPaymentEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|