feat: Add consistent iCalUID (#12122)
Co-authored-by: Hariom <[email protected]> Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
33 files changed
+568
-195
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import type { DateArray, ParticipationStatus, ParticipationRole, EventStatus } from "ics";
|
||||
import { createEvent } from "ics";
|
||||
import type { TFunction } from "next-i18next";
|
||||
import { RRule } from "rrule";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getRichDescription } from "@calcom/lib/CalEventParser";
|
||||
import { getWhen } from "@calcom/lib/CalEventParser";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
export enum BookingAction {
|
||||
Create = "create",
|
||||
Cancel = "cancel",
|
||||
Reschedule = "reschedule",
|
||||
RequestReschedule = "request_reschedule",
|
||||
LocationChange = "location_change",
|
||||
}
|
||||
|
||||
const generateIcsString = ({
|
||||
event,
|
||||
title,
|
||||
subtitle,
|
||||
status,
|
||||
role,
|
||||
isRequestReschedule,
|
||||
t,
|
||||
}: {
|
||||
event: CalendarEvent;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
status: EventStatus;
|
||||
role: "attendee" | "organizer";
|
||||
isRequestReschedule?: boolean;
|
||||
t?: TFunction;
|
||||
}) => {
|
||||
// Taking care of recurrence rule
|
||||
let recurrenceRule: string | undefined = undefined;
|
||||
const partstat: ParticipationStatus = "ACCEPTED";
|
||||
const icsRole: ParticipationRole = "REQ-PARTICIPANT";
|
||||
if (event.recurringEvent?.count) {
|
||||
// ics appends "RRULE:" already, so removing it from RRule generated string
|
||||
recurrenceRule = new RRule(event.recurringEvent).toString().replace("RRULE:", "");
|
||||
}
|
||||
|
||||
const getTextBody = (title: string, subtitle: string): string => {
|
||||
let body: string;
|
||||
if (isRequestReschedule && role === "attendee" && t) {
|
||||
body = `
|
||||
${title}
|
||||
${getWhen(event, t)}
|
||||
${subtitle}`;
|
||||
}
|
||||
body = `
|
||||
${title}
|
||||
${subtitle}
|
||||
|
||||
${getRichDescription(event, t)}
|
||||
`.trim();
|
||||
|
||||
return body;
|
||||
};
|
||||
|
||||
const icsEvent = createEvent({
|
||||
uid: event.iCalUID || event.uid!,
|
||||
sequence: event.iCalSequence || 0,
|
||||
start: dayjs(event.startTime)
|
||||
.utc()
|
||||
.toArray()
|
||||
.slice(0, 6)
|
||||
.map((v, i) => (i === 1 ? v + 1 : v)) as DateArray,
|
||||
startInputType: "utc",
|
||||
productId: "calcom/ics",
|
||||
title: event.title,
|
||||
description: getTextBody(title, subtitle),
|
||||
duration: { minutes: dayjs(event.endTime).diff(dayjs(event.startTime), "minute") },
|
||||
organizer: { name: event.organizer.name, email: event.organizer.email },
|
||||
...{ recurrenceRule },
|
||||
attendees: [
|
||||
...event.attendees.map((attendee: Person) => ({
|
||||
name: attendee.name,
|
||||
email: attendee.email,
|
||||
partstat,
|
||||
role: icsRole,
|
||||
rsvp: true,
|
||||
})),
|
||||
...(event.team?.members
|
||||
? event.team?.members.map((member: Person) => ({
|
||||
name: member.name,
|
||||
email: member.email,
|
||||
partstat,
|
||||
role: icsRole,
|
||||
rsvp: true,
|
||||
}))
|
||||
: []),
|
||||
],
|
||||
method: "REQUEST",
|
||||
status,
|
||||
});
|
||||
if (icsEvent.error) {
|
||||
throw icsEvent.error;
|
||||
}
|
||||
return icsEvent.value;
|
||||
};
|
||||
|
||||
export default generateIcsString;
|
||||
@@ -0,0 +1,36 @@
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
|
||||
/**
|
||||
* This function returns the iCalUID if a uid is passed or if it is present in the event that is passed
|
||||
* @param uid - the uid of the event
|
||||
* @param event - an event that already has an iCalUID or one that has a uid
|
||||
* @param defaultToEventUid - if true, will default to the event.uid if present
|
||||
*
|
||||
* @returns the iCalUID whether already present or generated
|
||||
*/
|
||||
const getICalUID = ({
|
||||
uid,
|
||||
event,
|
||||
defaultToEventUid,
|
||||
}: {
|
||||
uid?: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
event?: { iCalUID?: string | null; uid?: string | null; [key: string]: any };
|
||||
defaultToEventUid?: boolean;
|
||||
}) => {
|
||||
if (event?.iCalUID) return event.iCalUID;
|
||||
|
||||
if (defaultToEventUid && event?.uid) return `${event.uid}@${APP_NAME}`;
|
||||
|
||||
if (uid) return `${uid}@${APP_NAME}`;
|
||||
|
||||
const translator = short();
|
||||
|
||||
uid = translator.fromUUID(uuidv5(APP_NAME, uuidv5.URL));
|
||||
return `${uid}@${APP_NAME}`;
|
||||
};
|
||||
|
||||
export default getICalUID;
|
||||
@@ -0,0 +1,137 @@
|
||||
import { describe, expect } from "vitest";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
import { buildCalendarEvent, buildPerson } from "../../../lib/test/builder";
|
||||
import generateIcsString from "../generateIcsString";
|
||||
|
||||
const assertHasIcsString = (icsString: string | undefined) => {
|
||||
if (!icsString) throw new Error("icsString is undefined");
|
||||
|
||||
expect(icsString).toBeDefined();
|
||||
|
||||
return icsString;
|
||||
};
|
||||
|
||||
const testIcsStringContains = ({
|
||||
icsString,
|
||||
event,
|
||||
status,
|
||||
}: {
|
||||
icsString: string;
|
||||
event: CalendarEvent;
|
||||
status: string;
|
||||
}) => {
|
||||
const DTSTART = event.startTime.split(".")[0].replace(/[-:]/g, "");
|
||||
const startTime = dayjs(event.startTime);
|
||||
const endTime = dayjs(event.endTime);
|
||||
const duration = endTime.diff(startTime, "minute");
|
||||
|
||||
expect(icsString).toEqual(expect.stringContaining(`UID:${event.iCalUID}`));
|
||||
// Sometimes the deeply equal stringMatching error appears. Don't want to add flakey tests
|
||||
// expect(icsString).toEqual(expect.stringContaining(`SUMMARY:${event.title}`));
|
||||
expect(icsString).toEqual(expect.stringContaining(`DTSTART:${DTSTART}`));
|
||||
expect(icsString).toEqual(
|
||||
expect.stringContaining(`ORGANIZER;CN=${event.organizer.name}:mailto:${event.organizer.email}`)
|
||||
);
|
||||
expect(icsString).toEqual(expect.stringContaining(`DURATION:PT${duration}M`));
|
||||
expect(icsString).toEqual(expect.stringContaining(`STATUS:${status}`));
|
||||
// Getting an error expected icsString to deeply equal stringMatching
|
||||
// for (const attendee of event.attendees) {
|
||||
// expect(icsString).toEqual(
|
||||
// expect.stringMatching(
|
||||
// `RSVP=TRUE;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=${attendee.name}:mailto:${attendee.email}`
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
};
|
||||
|
||||
describe("generateIcsString", () => {
|
||||
test("when bookingAction is Create", () => {
|
||||
const event = buildCalendarEvent({
|
||||
iCalSequence: 0,
|
||||
attendees: [buildPerson()],
|
||||
});
|
||||
|
||||
const title = "new_event_scheduled_recurring";
|
||||
const subtitle = "emailed_you_and_any_other_attendees";
|
||||
const status = "CONFIRMED";
|
||||
|
||||
const icsString = generateIcsString({
|
||||
event: event,
|
||||
title,
|
||||
subtitle,
|
||||
role: "organizer",
|
||||
status,
|
||||
});
|
||||
|
||||
const assertedIcsString = assertHasIcsString(icsString);
|
||||
|
||||
testIcsStringContains({ icsString: assertedIcsString, event, status });
|
||||
});
|
||||
test("when bookingAction is Cancel", () => {
|
||||
const event = buildCalendarEvent({
|
||||
iCalSequence: 0,
|
||||
attendees: [buildPerson()],
|
||||
});
|
||||
const title = "event_request_cancelled";
|
||||
const subtitle = "emailed_you_and_any_other_attendees";
|
||||
const status = "CANCELLED";
|
||||
|
||||
const icsString = generateIcsString({
|
||||
event: event,
|
||||
title,
|
||||
subtitle,
|
||||
role: "organizer",
|
||||
status,
|
||||
});
|
||||
|
||||
const assertedIcsString = assertHasIcsString(icsString);
|
||||
|
||||
testIcsStringContains({ icsString: assertedIcsString, event, status });
|
||||
});
|
||||
test("when bookingAction is Reschedule", () => {
|
||||
const event = buildCalendarEvent({
|
||||
iCalSequence: 0,
|
||||
attendees: [buildPerson()],
|
||||
});
|
||||
const title = "event_type_has_been_rescheduled";
|
||||
const subtitle = "emailed_you_and_any_other_attendees";
|
||||
const status = "CONFIRMED";
|
||||
|
||||
const icsString = generateIcsString({
|
||||
event: event,
|
||||
title,
|
||||
subtitle,
|
||||
role: "organizer",
|
||||
status,
|
||||
});
|
||||
|
||||
const assertedIcsString = assertHasIcsString(icsString);
|
||||
|
||||
testIcsStringContains({ icsString: assertedIcsString, event, status });
|
||||
});
|
||||
test("when bookingAction is RequestReschedule", () => {
|
||||
const event = buildCalendarEvent({
|
||||
iCalSequence: 0,
|
||||
attendees: [buildPerson()],
|
||||
});
|
||||
const title = "request_reschedule_title_organizer";
|
||||
const subtitle = "request_reschedule_subtitle_organizer";
|
||||
const status = "CANCELLED";
|
||||
|
||||
const icsString = generateIcsString({
|
||||
event: event,
|
||||
title,
|
||||
subtitle,
|
||||
role: "organizer",
|
||||
status,
|
||||
});
|
||||
|
||||
const assertedIcsString = assertHasIcsString(icsString);
|
||||
|
||||
testIcsStringContains({ icsString: assertedIcsString, event, status });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect } from "vitest";
|
||||
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
import { buildCalendarEvent } from "@calcom/lib/test/builder";
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
import getICalUID from "../getICalUID";
|
||||
|
||||
describe("getICalUid", () => {
|
||||
test("returns iCalUID when passing a uid", () => {
|
||||
const iCalUID = getICalUID({ uid: "123" });
|
||||
expect(iCalUID).toEqual(`123@${APP_NAME}`);
|
||||
});
|
||||
test("returns iCalUID when passing an event", () => {
|
||||
const event = buildCalendarEvent({ iCalUID: `123@${APP_NAME}` });
|
||||
const iCalUID = getICalUID({ event });
|
||||
expect(iCalUID).toEqual(`123@${APP_NAME}`);
|
||||
});
|
||||
test("returns new iCalUID when passing in an event with no iCalUID but has an uid", () => {
|
||||
const event = buildCalendarEvent({ iCalUID: "" });
|
||||
const iCalUID = getICalUID({ event, defaultToEventUid: true });
|
||||
expect(iCalUID).toEqual(`${event.uid}@${APP_NAME}`);
|
||||
});
|
||||
test("returns new iCalUID when passing in an event with no iCalUID and uses uid passed", () => {
|
||||
const event = buildCalendarEvent({ iCalUID: "" });
|
||||
const iCalUID = getICalUID({ event, uid: "123" });
|
||||
expect(iCalUID).toEqual(`123@${APP_NAME}`);
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,21 @@
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import AttendeeScheduledEmail from "./attendee-scheduled-email";
|
||||
|
||||
export default class AttendeeCancelledEmail extends AttendeeScheduledEmail {
|
||||
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("event_request_cancelled"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
status: "CANCELLED",
|
||||
role: "attendee",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
to: `${this.attendee.name} <${this.attendee.email}>`,
|
||||
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
|
||||
replyTo: this.calEvent.organizer.email,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import AttendeeScheduledEmail from "./attendee-scheduled-email";
|
||||
|
||||
export default class AttendeeLocationChangeEmail extends AttendeeScheduledEmail {
|
||||
@@ -6,7 +7,14 @@ export default class AttendeeLocationChangeEmail extends AttendeeScheduledEmail
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("event_location_changed"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
role: "attendee",
|
||||
status: "CONFIRMED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
to: `${this.attendee.name} <${this.attendee.email}>`,
|
||||
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import AttendeeScheduledEmail from "./attendee-scheduled-email";
|
||||
|
||||
export default class AttendeeRescheduledEmail extends AttendeeScheduledEmail {
|
||||
@@ -6,7 +7,14 @@ export default class AttendeeRescheduledEmail extends AttendeeScheduledEmail {
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("event_type_has_been_rescheduled"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
role: "attendee",
|
||||
status: "CONFIRMED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
to: `${this.attendee.name} <${this.attendee.email}>`,
|
||||
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import type { DateArray, ParticipationStatus, ParticipationRole } from "ics";
|
||||
import { createEvent } from "ics";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { cloneDeep } from "lodash";
|
||||
import type { TFunction } from "next-i18next";
|
||||
import { RRule } from "rrule";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getRichDescription } from "@calcom/lib/CalEventParser";
|
||||
import { TimeFormat } from "@calcom/lib/timeFormat";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import BaseEmail from "./_base-email";
|
||||
|
||||
export default class AttendeeScheduledEmail extends BaseEmail {
|
||||
@@ -32,65 +29,21 @@ export default class AttendeeScheduledEmail extends BaseEmail {
|
||||
this.t = attendee.language.translate;
|
||||
}
|
||||
|
||||
protected getiCalEventAsString(): string | undefined {
|
||||
// Taking care of recurrence rule
|
||||
let recurrenceRule: string | undefined = undefined;
|
||||
if (this.calEvent.recurringEvent?.count) {
|
||||
// ics appends "RRULE:" already, so removing it from RRule generated string
|
||||
recurrenceRule = new RRule(this.calEvent.recurringEvent).toString().replace("RRULE:", "");
|
||||
}
|
||||
const partstat: ParticipationStatus = "ACCEPTED";
|
||||
const role: ParticipationRole = "REQ-PARTICIPANT";
|
||||
const icsEvent = createEvent({
|
||||
uid: this.calEvent.iCalUID || this.calEvent.uid!,
|
||||
start: dayjs(this.calEvent.startTime)
|
||||
.utc()
|
||||
.toArray()
|
||||
.slice(0, 6)
|
||||
.map((v, i) => (i === 1 ? v + 1 : v)) as DateArray,
|
||||
startInputType: "utc",
|
||||
productId: "calcom/ics",
|
||||
title: this.calEvent.title,
|
||||
description: this.getTextBody(),
|
||||
duration: { minutes: dayjs(this.calEvent.endTime).diff(dayjs(this.calEvent.startTime), "minute") },
|
||||
organizer: { name: this.calEvent.organizer.name, email: this.calEvent.organizer.email },
|
||||
attendees: [
|
||||
...this.calEvent.attendees.map((attendee: Person) => ({
|
||||
name: attendee.name,
|
||||
email: attendee.email,
|
||||
partstat,
|
||||
role,
|
||||
rsvp: true,
|
||||
})),
|
||||
...(this.calEvent.team?.members
|
||||
? this.calEvent.team?.members.map((member: Person) => ({
|
||||
name: member.name,
|
||||
email: member.email,
|
||||
partstat,
|
||||
role,
|
||||
rsvp: true,
|
||||
}))
|
||||
: []),
|
||||
],
|
||||
method: "REQUEST",
|
||||
...{ recurrenceRule },
|
||||
status: "CONFIRMED",
|
||||
});
|
||||
if (icsEvent.error) {
|
||||
throw icsEvent.error;
|
||||
}
|
||||
return icsEvent.value;
|
||||
}
|
||||
|
||||
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
|
||||
const clonedCalEvent = cloneDeep(this.calEvent);
|
||||
|
||||
this.getiCalEventAsString();
|
||||
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.calEvent.recurringEvent?.count
|
||||
? this.t("your_event_has_been_scheduled_recurring")
|
||||
: this.t("your_event_has_been_scheduled"),
|
||||
role: "attendee",
|
||||
subtitle: "emailed_you_and_any_other_attendees",
|
||||
status: "CONFIRMED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
to: `${this.attendee.name} <${this.attendee.email}>`,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { DateArray } from "ics";
|
||||
import { createEvent } from "ics";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getManageLink } from "@calcom/lib/CalEventParser";
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "..";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
|
||||
export default class AttendeeWasRequestedToRescheduleEmail extends OrganizerScheduledEmail {
|
||||
@@ -22,7 +19,16 @@ export default class AttendeeWasRequestedToRescheduleEmail extends OrganizerSche
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("request_reschedule_booking"),
|
||||
subtitle: this.t("request_reschedule_subtitle", {
|
||||
organizer: this.calEvent.organizer.name,
|
||||
}),
|
||||
role: "attendee",
|
||||
status: "CANCELLED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: toAddresses.join(","),
|
||||
@@ -39,35 +45,6 @@ export default class AttendeeWasRequestedToRescheduleEmail extends OrganizerSche
|
||||
};
|
||||
}
|
||||
|
||||
// @OVERRIDE
|
||||
protected getiCalEventAsString(): string | undefined {
|
||||
const icsEvent = createEvent({
|
||||
start: dayjs(this.calEvent.startTime)
|
||||
.utc()
|
||||
.toArray()
|
||||
.slice(0, 6)
|
||||
.map((v, i) => (i === 1 ? v + 1 : v)) as DateArray,
|
||||
startInputType: "utc",
|
||||
productId: "calcom/ics",
|
||||
title: this.t("ics_event_title", {
|
||||
eventType: this.calEvent.type,
|
||||
name: this.calEvent.attendees[0].name,
|
||||
}),
|
||||
description: this.getTextBody(),
|
||||
duration: { minutes: dayjs(this.calEvent.endTime).diff(dayjs(this.calEvent.startTime), "minute") },
|
||||
organizer: { name: this.calEvent.organizer.name, email: this.calEvent.organizer.email },
|
||||
attendees: this.calEvent.attendees.map((attendee: Person) => ({
|
||||
name: attendee.name,
|
||||
email: attendee.email,
|
||||
})),
|
||||
status: "CANCELLED",
|
||||
method: "CANCEL",
|
||||
});
|
||||
if (icsEvent.error) {
|
||||
throw icsEvent.error;
|
||||
}
|
||||
return icsEvent.value;
|
||||
}
|
||||
// @OVERRIDE
|
||||
protected getWhen(): string {
|
||||
return `
|
||||
|
||||
@@ -53,7 +53,7 @@ ${this.t(
|
||||
)}
|
||||
${this.t(subtitle)}
|
||||
${extraInfo}
|
||||
${getRichDescription(this.calEvent)}
|
||||
${getRichDescription(this.calEvent, this.t, true)}
|
||||
${callToAction}
|
||||
`.trim();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
|
||||
export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
|
||||
@@ -8,6 +9,17 @@ export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
|
||||
const toAddresses = [this.teamMember?.email || this.calEvent.organizer.email];
|
||||
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("event_request_cancelled"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
status: "CANCELLED",
|
||||
role: "organizer",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: toAddresses.join(","),
|
||||
subject: `${this.t("event_cancelled_subject", {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
|
||||
export default class OrganizerLocationChangeEmail extends OrganizerScheduledEmail {
|
||||
@@ -10,7 +11,14 @@ export default class OrganizerLocationChangeEmail extends OrganizerScheduledEmai
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("event_location_changed"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
role: "organizer",
|
||||
status: "CONFIRMED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: toAddresses.join(","),
|
||||
|
||||
@@ -7,6 +7,7 @@ import { APP_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "..";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
|
||||
export default class OrganizerRequestedToRescheduleEmail extends OrganizerScheduledEmail {
|
||||
@@ -21,7 +22,18 @@ export default class OrganizerRequestedToRescheduleEmail extends OrganizerSchedu
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("request_reschedule_title_organizer", {
|
||||
attendee: this.calEvent.attendees[0].name,
|
||||
}),
|
||||
subtitle: this.t("request_reschedule_subtitle_organizer", {
|
||||
attendee: this.calEvent.attendees[0].name,
|
||||
}),
|
||||
role: "organizer",
|
||||
status: "CANCELLED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: toAddresses.join(","),
|
||||
@@ -83,13 +95,11 @@ export default class OrganizerRequestedToRescheduleEmail extends OrganizerSchedu
|
||||
}
|
||||
|
||||
// @OVERRIDE
|
||||
protected getTextBody(title = "", subtitle = "", extraInfo = "", callToAction = ""): string {
|
||||
protected getTextBody(title = "", subtitle = ""): string {
|
||||
return `
|
||||
${this.t(title)}
|
||||
${this.t(subtitle)}
|
||||
${extraInfo}
|
||||
${getRichDescription(this.calEvent)}
|
||||
${callToAction}
|
||||
${getRichDescription(this.calEvent, this.t, true)}
|
||||
`.trim();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
|
||||
export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
|
||||
@@ -10,7 +11,14 @@ export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.t("event_type_has_been_rescheduled"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
role: "organizer",
|
||||
status: "CONFIRMED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: toAddresses.join(","),
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import type { DateArray } from "ics";
|
||||
import { createEvent } from "ics";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { cloneDeep } from "lodash";
|
||||
import type { TFunction } from "next-i18next";
|
||||
import { RRule } from "rrule";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getRichDescription } from "@calcom/lib/CalEventParser";
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
import { TimeFormat } from "@calcom/lib/timeFormat";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsString from "../lib/generateIcsString";
|
||||
import BaseEmail from "./_base-email";
|
||||
|
||||
export default class OrganizerScheduledEmail extends BaseEmail {
|
||||
@@ -29,47 +26,6 @@ export default class OrganizerScheduledEmail extends BaseEmail {
|
||||
this.teamMember = input.teamMember;
|
||||
}
|
||||
|
||||
protected getiCalEventAsString(): string | undefined {
|
||||
// Taking care of recurrence rule
|
||||
let recurrenceRule: string | undefined = undefined;
|
||||
if (this.calEvent.recurringEvent?.count) {
|
||||
// ics appends "RRULE:" already, so removing it from RRule generated string
|
||||
recurrenceRule = new RRule(this.calEvent.recurringEvent).toString().replace("RRULE:", "");
|
||||
}
|
||||
const icsEvent = createEvent({
|
||||
uid: this.calEvent.iCalUID || this.calEvent.uid!,
|
||||
start: dayjs(this.calEvent.startTime)
|
||||
.utc()
|
||||
.toArray()
|
||||
.slice(0, 6)
|
||||
.map((v, i) => (i === 1 ? v + 1 : v)) as DateArray,
|
||||
startInputType: "utc",
|
||||
productId: "calcom/ics",
|
||||
title: this.calEvent.title,
|
||||
description: this.getTextBody(),
|
||||
duration: { minutes: dayjs(this.calEvent.endTime).diff(dayjs(this.calEvent.startTime), "minute") },
|
||||
organizer: { name: this.calEvent.organizer.name, email: this.calEvent.organizer.email },
|
||||
...{ recurrenceRule },
|
||||
attendees: [
|
||||
...this.calEvent.attendees.map((attendee: Person) => ({
|
||||
name: attendee.name,
|
||||
email: attendee.email,
|
||||
})),
|
||||
...(this.calEvent.team?.members
|
||||
? this.calEvent.team?.members.map((member: Person) => ({
|
||||
name: member.name,
|
||||
email: member.email,
|
||||
}))
|
||||
: []),
|
||||
],
|
||||
status: "CONFIRMED",
|
||||
});
|
||||
if (icsEvent.error) {
|
||||
throw icsEvent.error;
|
||||
}
|
||||
return icsEvent.value;
|
||||
}
|
||||
|
||||
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
|
||||
const clonedCalEvent = cloneDeep(this.calEvent);
|
||||
const toAddresses = [this.teamMember?.email || this.calEvent.organizer.email];
|
||||
@@ -77,7 +33,16 @@ export default class OrganizerScheduledEmail extends BaseEmail {
|
||||
return {
|
||||
icalEvent: {
|
||||
filename: "event.ics",
|
||||
content: this.getiCalEventAsString(),
|
||||
content: generateIcsString({
|
||||
event: this.calEvent,
|
||||
title: this.calEvent.recurringEvent?.count
|
||||
? this.t("new_event_scheduled_recurring")
|
||||
: this.t("new_event_scheduled"),
|
||||
subtitle: this.t("emailed_you_and_any_other_attendees"),
|
||||
role: "organizer",
|
||||
status: "CONFIRMED",
|
||||
}),
|
||||
method: "REQUEST",
|
||||
},
|
||||
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: toAddresses.join(","),
|
||||
@@ -105,7 +70,7 @@ ${this.t(
|
||||
)}
|
||||
${this.t(subtitle)}
|
||||
${extraInfo}
|
||||
${getRichDescription(this.calEvent)}
|
||||
${getRichDescription(this.calEvent, this.t, true)}
|
||||
${callToAction}
|
||||
`.trim();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user