2022-01-06 17:28:31 +00:00
|
|
|
import { Person } from "ics";
|
2021-06-29 21:43:18 +00:00
|
|
|
import short from "short-uuid";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { v5 as uuidv5 } from "uuid";
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
import { getIntegrationName } from "@lib/integrations";
|
|
|
|
|
2021-11-26 11:03:43 +00:00
|
|
|
import { BASE_URL } from "./config/constants";
|
2022-01-06 17:28:31 +00:00
|
|
|
import { CalendarEvent } from "./integrations/calendar/interfaces/Calendar";
|
2021-06-29 21:43:18 +00:00
|
|
|
|
|
|
|
const translator = short();
|
|
|
|
|
2021-12-07 15:32:07 +00:00
|
|
|
// The odd indentation in this file is necessary because otherwise the leading tabs will be applied into the event description.
|
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
export const getWhat = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
2021-12-07 15:32:07 +00:00
|
|
|
${calEvent.language("what")}:
|
2021-12-06 19:34:31 +00:00
|
|
|
${calEvent.type}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getWhen = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
2021-12-07 15:32:07 +00:00
|
|
|
${calEvent.language("invitee_timezone")}:
|
|
|
|
${calEvent.attendees[0].timeZone}
|
2021-12-06 19:34:31 +00:00
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getWho = (calEvent: CalendarEvent) => {
|
|
|
|
const attendees = calEvent.attendees
|
|
|
|
.map((attendee) => {
|
|
|
|
return `
|
|
|
|
${attendee?.name || calEvent.language("guest")}
|
|
|
|
${attendee.email}
|
|
|
|
`;
|
|
|
|
})
|
|
|
|
.join("");
|
|
|
|
|
|
|
|
const organizer = `
|
|
|
|
${calEvent.organizer.name} - ${calEvent.language("organizer")}
|
|
|
|
${calEvent.organizer.email}
|
|
|
|
`;
|
|
|
|
|
|
|
|
return `
|
2021-12-07 15:32:07 +00:00
|
|
|
${calEvent.language("who")}:
|
2021-12-06 19:34:31 +00:00
|
|
|
${organizer + attendees}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAdditionalNotes = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
2021-12-07 15:32:07 +00:00
|
|
|
${calEvent.language("additional_notes")}:
|
2021-12-06 19:34:31 +00:00
|
|
|
${calEvent.description}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getLocation = (calEvent: CalendarEvent) => {
|
|
|
|
let providerName = calEvent.location ? getIntegrationName(calEvent.location) : "";
|
|
|
|
|
|
|
|
if (calEvent.location && calEvent.location.includes("integrations:")) {
|
|
|
|
const location = calEvent.location.split(":")[1];
|
|
|
|
providerName = location[0].toUpperCase() + location.slice(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calEvent.videoCallData) {
|
|
|
|
return calEvent.videoCallData.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calEvent.additionInformation?.hangoutLink) {
|
|
|
|
return calEvent.additionInformation.hangoutLink;
|
|
|
|
}
|
|
|
|
|
2021-12-09 15:51:37 +00:00
|
|
|
return providerName || calEvent.location || "";
|
2021-12-06 19:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getManageLink = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
|
|
|
${calEvent.language("need_to_reschedule_or_cancel")}
|
|
|
|
${getCancelLink(calEvent)}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUid = (calEvent: CalendarEvent): string => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return calEvent.uid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
|
|
|
};
|
2021-07-21 12:01:48 +00:00
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
export const getCancelLink = (calEvent: CalendarEvent): string => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return BASE_URL + "/cancel/" + getUid(calEvent);
|
|
|
|
};
|
2021-12-06 19:34:31 +00:00
|
|
|
|
2021-12-07 15:32:07 +00:00
|
|
|
export const getRichDescription = (calEvent: CalendarEvent, attendee?: Person) => {
|
|
|
|
// Only the original attendee can make changes to the event
|
|
|
|
// Guests cannot
|
|
|
|
|
|
|
|
if (attendee && attendee === calEvent.attendees[0]) {
|
|
|
|
return `
|
|
|
|
${getWhat(calEvent)}
|
|
|
|
${getWhen(calEvent)}
|
|
|
|
${getWho(calEvent)}
|
|
|
|
${calEvent.language("where")}:
|
|
|
|
${getLocation(calEvent)}
|
|
|
|
${getAdditionalNotes(calEvent)}
|
|
|
|
`.trim();
|
|
|
|
}
|
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
return `
|
2021-12-07 15:32:07 +00:00
|
|
|
${getWhat(calEvent)}
|
|
|
|
${getWhen(calEvent)}
|
|
|
|
${getWho(calEvent)}
|
|
|
|
${calEvent.language("where")}:
|
|
|
|
${getLocation(calEvent)}
|
|
|
|
${getAdditionalNotes(calEvent)}
|
|
|
|
${getManageLink(calEvent)}
|
|
|
|
`.trim();
|
2021-12-06 19:34:31 +00:00
|
|
|
};
|