fix: v2 booking confirmation emails not sent (#17764)
* fix: round robin recurring don't send email if noEmail * fix: noEmail: false for non platform requests * fix: booking e2e tests * refactor: move bookings e2e tests in folder and uniform name * test: emails * test: team emails * reschedule and cancel emails with api key * test: round robin reassign emails * test: confirm and decline emails * test: confirm and decline emails * fix tests * test: recurring booking emails * remove unused imports and spies * fix test * remove log * chore: bump libraries * try to fix ci tests
This commit is contained in:
1 parent
8e7ce1216c
commit
9fa73aca86
34 files changed
+2544
-358
No files matched your search
@@ -24,7 +24,7 @@ export default class AttendeeCancelledEmail extends AttendeeScheduledEmail {
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("AttendeeCancelledEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
|
||||
@@ -20,7 +20,7 @@ export default class AttendeeDeclinedEmail extends AttendeeScheduledEmail {
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("AttendeeDeclinedEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import AttendeeScheduledEmail from "./attendee-scheduled-email";
|
||||
@@ -15,10 +16,7 @@ export default class AttendeeRequestEmail extends AttendeeScheduledEmail {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(),
|
||||
})}`,
|
||||
html: await renderEmail("AttendeeRequestEmail", {
|
||||
calEvent: this.calEvent,
|
||||
attendee: this.attendee,
|
||||
}),
|
||||
html: await this.getHtmlRequestEmail(this.calEvent, this.attendee),
|
||||
text: this.getTextBody(
|
||||
this.calEvent.attendees[0].language.translate("booking_submitted", {
|
||||
name: this.calEvent.attendees[0].name,
|
||||
@@ -29,4 +27,11 @@ export default class AttendeeRequestEmail extends AttendeeScheduledEmail {
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
async getHtmlRequestEmail(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("AttendeeRequestEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
|
||||
import AttendeeScheduledEmail from "./attendee-scheduled-email";
|
||||
@@ -17,11 +19,15 @@ export default class AttendeeRescheduledEmail extends AttendeeScheduledEmail {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(),
|
||||
})}`,
|
||||
html: await renderEmail("AttendeeRescheduledEmail", {
|
||||
calEvent: this.calEvent,
|
||||
attendee: this.attendee,
|
||||
}),
|
||||
html: await this.getHtml(this.calEvent, this.attendee),
|
||||
text: this.getTextBody("event_has_been_rescheduled", "emailed_you_and_any_other_attendees"),
|
||||
};
|
||||
}
|
||||
|
||||
async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("AttendeeRescheduledEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ export default class AttendeeScheduledEmail extends BaseEmail {
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("AttendeeScheduledEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
|
||||
@@ -26,7 +26,7 @@ export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, organizer: Person) {
|
||||
async getHtml(calEvent: CalendarEvent, organizer: Person) {
|
||||
return await renderEmail("OrganizerCancelledEmail", {
|
||||
calEvent,
|
||||
attendee: organizer,
|
||||
|
||||
@@ -27,7 +27,7 @@ export default class OrganizerReassignedEmail extends OrganizerScheduledEmail {
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, attendee: Person, reassigned: Reassigned | undefined) {
|
||||
async getHtml(calEvent: CalendarEvent, attendee: Person, reassigned: Reassigned | undefined) {
|
||||
return await renderEmail("OrganizerReassignedEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { checkIfUserHasFeatureController } from "@calcom/features/flags/operations/check-if-user-has-feature.controller";
|
||||
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
@@ -22,10 +23,7 @@ export default class OrganizerRequestEmail extends OrganizerScheduledEmail {
|
||||
to: toAddresses.join(","),
|
||||
replyTo: [this.calEvent.organizer.email, ...this.calEvent.attendees.map(({ email }) => email)],
|
||||
subject: `${this.t("awaiting_approval")}: ${this.calEvent.title}`,
|
||||
html: await renderEmail(template, {
|
||||
calEvent: this.calEvent,
|
||||
attendee: this.calEvent.organizer,
|
||||
}),
|
||||
html: await this.getHtmlRequestEmail(template, this.calEvent, this.calEvent.organizer),
|
||||
text: this.getTextBody("event_awaiting_approval"),
|
||||
};
|
||||
}
|
||||
@@ -41,4 +39,15 @@ ${process.env.NEXT_PUBLIC_WEBAPP_URL} + ${
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
async getHtmlRequestEmail(
|
||||
template: "OrganizerRequestEmailV2" | "OrganizerRequestEmail",
|
||||
calEvent: CalendarEvent,
|
||||
attendee: Person
|
||||
) {
|
||||
return await renderEmail(template, {
|
||||
calEvent,
|
||||
attendee,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
|
||||
@@ -21,11 +22,15 @@ export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(),
|
||||
})}`,
|
||||
html: await renderEmail("OrganizerRescheduledEmail", {
|
||||
calEvent: { ...this.calEvent, attendeeSeatId: undefined },
|
||||
attendee: this.calEvent.organizer,
|
||||
}),
|
||||
html: await this.getHtml({ ...this.calEvent, attendeeSeatId: undefined }, this.calEvent.organizer),
|
||||
text: this.getTextBody("event_has_been_rescheduled"),
|
||||
};
|
||||
}
|
||||
|
||||
async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("OrganizerRescheduledEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export default class OrganizerScheduledEmail extends BaseEmail {
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(
|
||||
async getHtml(
|
||||
calEvent: CalendarEvent,
|
||||
attendee: Person,
|
||||
teamMember?: Person,
|
||||
|
||||
@@ -67,8 +67,9 @@ export async function handleConfirmation(args: {
|
||||
userId: number | null;
|
||||
};
|
||||
paid?: boolean;
|
||||
emailsEnabled?: boolean;
|
||||
}) {
|
||||
const { user, evt, recurringEventId, prisma, bookingId, booking, paid } = args;
|
||||
const { user, evt, recurringEventId, prisma, bookingId, booking, paid, emailsEnabled = true } = args;
|
||||
const eventType = booking.eventType;
|
||||
const eventTypeMetadata = EventTypeMetaDataSchema.parse(eventType?.metadata || {});
|
||||
const eventManager = new EventManager(user, eventTypeMetadata?.apps);
|
||||
@@ -113,13 +114,15 @@ export async function handleConfirmation(args: {
|
||||
}
|
||||
}
|
||||
|
||||
await sendScheduledEmailsAndSMS(
|
||||
{ ...evt, additionalInformation: metadata },
|
||||
undefined,
|
||||
isHostConfirmationEmailsDisabled,
|
||||
isAttendeeConfirmationEmailDisabled,
|
||||
eventTypeMetadata
|
||||
);
|
||||
if (emailsEnabled) {
|
||||
await sendScheduledEmailsAndSMS(
|
||||
{ ...evt, additionalInformation: metadata },
|
||||
undefined,
|
||||
isHostConfirmationEmailsDisabled,
|
||||
isAttendeeConfirmationEmailDisabled,
|
||||
eventTypeMetadata
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export const handleNewRecurringBooking = async (
|
||||
thirdPartyRecurringEventId,
|
||||
numSlotsToCheckForAvailability,
|
||||
currentRecurringIndex: 0,
|
||||
noEmail: false,
|
||||
noEmail: req.noEmail !== undefined ? req.noEmail : false,
|
||||
};
|
||||
|
||||
const firstBookingResult = await handleNewBooking(recurringEventReq);
|
||||
|
||||
@@ -44,12 +44,14 @@ export const roundRobinManualReassignment = async ({
|
||||
orgId,
|
||||
reassignReason,
|
||||
reassignedById,
|
||||
emailsEnabled = true,
|
||||
}: {
|
||||
bookingId: number;
|
||||
newUserId: number;
|
||||
orgId: number | null;
|
||||
reassignReason?: string;
|
||||
reassignedById: number;
|
||||
emailsEnabled?: boolean;
|
||||
}) => {
|
||||
const roundRobinReassignLogger = logger.getSubLogger({
|
||||
prefix: ["roundRobinManualReassign", `${bookingId}`],
|
||||
@@ -289,24 +291,26 @@ export const roundRobinManualReassignment = async ({
|
||||
const { cancellationReason, ...evtWithoutCancellationReason } = evtWithAdditionalInfo;
|
||||
|
||||
// Send emails
|
||||
await sendRoundRobinScheduledEmailsAndSMS({
|
||||
calEvent: evtWithoutCancellationReason,
|
||||
members: [
|
||||
{
|
||||
...newUser,
|
||||
name: newUser.name || "",
|
||||
username: newUser.username || "",
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(newUser.timeFormat),
|
||||
language: { translate: newUserT, locale: newUser.locale || "en" },
|
||||
if (emailsEnabled) {
|
||||
await sendRoundRobinScheduledEmailsAndSMS({
|
||||
calEvent: evtWithoutCancellationReason,
|
||||
members: [
|
||||
{
|
||||
...newUser,
|
||||
name: newUser.name || "",
|
||||
username: newUser.username || "",
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(newUser.timeFormat),
|
||||
language: { translate: newUserT, locale: newUser.locale || "en" },
|
||||
},
|
||||
],
|
||||
reassigned: {
|
||||
name: newUser.name,
|
||||
email: newUser.email,
|
||||
reason: reassignReason,
|
||||
byUser: originalOrganizer.name || undefined,
|
||||
},
|
||||
],
|
||||
reassigned: {
|
||||
name: newUser.name,
|
||||
email: newUser.email,
|
||||
reason: reassignReason,
|
||||
byUser: originalOrganizer.name || undefined,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Send cancellation email to previous RR host
|
||||
const cancelledEvt = cloneDeep(evtWithAdditionalInfo);
|
||||
@@ -317,7 +321,7 @@ export const roundRobinManualReassignment = async ({
|
||||
language: { translate: originalOrganizerT, locale: originalOrganizer.locale || "en" },
|
||||
};
|
||||
|
||||
if (previousRRHost) {
|
||||
if (previousRRHost && emailsEnabled) {
|
||||
await sendRoundRobinCancelledEmailsAndSMS(
|
||||
cancelledEvt,
|
||||
[
|
||||
|
||||
@@ -37,9 +37,11 @@ import { getTeamMembers } from "./utils/getTeamMembers";
|
||||
export const roundRobinReassignment = async ({
|
||||
bookingId,
|
||||
orgId,
|
||||
emailsEnabled = true,
|
||||
}: {
|
||||
bookingId: number;
|
||||
orgId: number | null;
|
||||
emailsEnabled?: boolean;
|
||||
}) => {
|
||||
const roundRobinReassignLogger = logger.getSubLogger({
|
||||
prefix: ["roundRobinReassign", `${bookingId}`],
|
||||
@@ -321,18 +323,20 @@ export const roundRobinReassignment = async ({
|
||||
const { cancellationReason, ...evtWithoutCancellationReason } = evtWithAdditionalInfo;
|
||||
|
||||
// Send to new RR host
|
||||
await sendRoundRobinScheduledEmailsAndSMS({
|
||||
calEvent: evtWithoutCancellationReason,
|
||||
members: [
|
||||
{
|
||||
...reassignedRRHost,
|
||||
name: reassignedRRHost.name || "",
|
||||
username: reassignedRRHost.username || "",
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(reassignedRRHost.timeFormat),
|
||||
language: { translate: reassignedRRHostT, locale: reassignedRRHost.locale || "en" },
|
||||
},
|
||||
],
|
||||
});
|
||||
if (emailsEnabled) {
|
||||
await sendRoundRobinScheduledEmailsAndSMS({
|
||||
calEvent: evtWithoutCancellationReason,
|
||||
members: [
|
||||
{
|
||||
...reassignedRRHost,
|
||||
name: reassignedRRHost.name || "",
|
||||
username: reassignedRRHost.username || "",
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(reassignedRRHost.timeFormat),
|
||||
language: { translate: reassignedRRHostT, locale: reassignedRRHost.locale || "en" },
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (previousRRHost) {
|
||||
// Send to cancelled RR host
|
||||
@@ -365,20 +369,22 @@ export const roundRobinReassignment = async ({
|
||||
});
|
||||
}
|
||||
|
||||
await sendRoundRobinCancelledEmailsAndSMS(
|
||||
cancelledRRHostEvt,
|
||||
[
|
||||
{
|
||||
...previousRRHost,
|
||||
name: previousRRHost.name || "",
|
||||
username: previousRRHost.username || "",
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(previousRRHost.timeFormat),
|
||||
language: { translate: previousRRHostT, locale: previousRRHost.locale || "en" },
|
||||
},
|
||||
],
|
||||
eventType?.metadata as EventTypeMetadata,
|
||||
{ name: reassignedRRHost.name, email: reassignedRRHost.email }
|
||||
);
|
||||
if (emailsEnabled) {
|
||||
await sendRoundRobinCancelledEmailsAndSMS(
|
||||
cancelledRRHostEvt,
|
||||
[
|
||||
{
|
||||
...previousRRHost,
|
||||
name: previousRRHost.name || "",
|
||||
username: previousRRHost.username || "",
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(previousRRHost.timeFormat),
|
||||
language: { translate: previousRRHostT, locale: previousRRHost.locale || "en" },
|
||||
},
|
||||
],
|
||||
eventType?.metadata as EventTypeMetadata,
|
||||
{ name: reassignedRRHost.name, email: reassignedRRHost.email }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle changing workflows with organizer
|
||||
|
||||
@@ -7,9 +7,13 @@ import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import type { CredentialDataWithTeamName, LocationOption } from "@calcom/app-store/utils";
|
||||
import AttendeeCancelledEmail from "@calcom/emails/templates/attendee-cancelled-email";
|
||||
import AttendeeDeclinedEmail from "@calcom/emails/templates/attendee-declined-email";
|
||||
import AttendeeRequestEmail from "@calcom/emails/templates/attendee-request-email";
|
||||
import AttendeeRescheduledEmail from "@calcom/emails/templates/attendee-rescheduled-email";
|
||||
import AttendeeScheduledEmail from "@calcom/emails/templates/attendee-scheduled-email";
|
||||
import OrganizerCancelledEmail from "@calcom/emails/templates/organizer-cancelled-email";
|
||||
import OrganizerReassignedEmail from "@calcom/emails/templates/organizer-reassigned-email";
|
||||
import OrganizerRequestEmail from "@calcom/emails/templates/organizer-request-email";
|
||||
import OrganizerRescheduledEmail from "@calcom/emails/templates/organizer-rescheduled-email";
|
||||
import OrganizerScheduledEmail from "@calcom/emails/templates/organizer-scheduled-email";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import getBookingInfo from "@calcom/features/bookings/lib/getBookingInfo";
|
||||
@@ -203,3 +207,11 @@ export { AttendeeCancelledEmail };
|
||||
export { OrganizerCancelledEmail };
|
||||
|
||||
export { OrganizerReassignedEmail };
|
||||
|
||||
export { OrganizerRescheduledEmail };
|
||||
|
||||
export { AttendeeRescheduledEmail };
|
||||
|
||||
export { OrganizerRequestEmail };
|
||||
|
||||
export { AttendeeRequestEmail };
|
||||
@@ -281,6 +281,7 @@ export const bookingConfirmPatchBodySchema = z.object({
|
||||
confirmed: z.boolean(),
|
||||
recurringEventId: z.string().optional(),
|
||||
reason: z.string().optional(),
|
||||
emailsEnabled: z.boolean().default(true),
|
||||
});
|
||||
|
||||
// `responses` is merged with it during handleNewBooking call because `responses` schema is dynamic and depends on eventType
|
||||
|
||||
@@ -41,7 +41,7 @@ type ConfirmOptions = {
|
||||
|
||||
export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
const { user } = ctx;
|
||||
const { bookingId, recurringEventId, reason: rejectionReason, confirmed } = input;
|
||||
const { bookingId, recurringEventId, reason: rejectionReason, confirmed, emailsEnabled } = input;
|
||||
|
||||
const tOrganizer = await getTranslation(user.locale ?? "en", "common");
|
||||
|
||||
@@ -269,6 +269,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
prisma,
|
||||
bookingId,
|
||||
booking,
|
||||
emailsEnabled,
|
||||
});
|
||||
} else {
|
||||
evt.rejectionReason = rejectionReason;
|
||||
@@ -368,7 +369,9 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
});
|
||||
}
|
||||
|
||||
await sendDeclinedEmailsAndSMS(evt, booking.eventType?.metadata as EventTypeMetadata);
|
||||
if (emailsEnabled) {
|
||||
await sendDeclinedEmailsAndSMS(evt, booking.eventType?.metadata as EventTypeMetadata);
|
||||
}
|
||||
|
||||
const teamId = await getTeamIdFromEventType({
|
||||
eventType: {
|
||||
|
||||
Reference in new issue
Block a user