import dayjs, { Dayjs } from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import timezone from "dayjs/plugin/timezone"; import toArray from "dayjs/plugin/toArray"; import utc from "dayjs/plugin/utc"; import { createEvent, DateArray } from "ics"; import { Person } from "@lib/calendarClient"; import EventMail from "./EventMail"; import { stripHtml } from "./helpers"; dayjs.extend(utc); dayjs.extend(timezone); dayjs.extend(toArray); dayjs.extend(localizedFormat); export default class EventOrganizerMail extends EventMail { /** * Returns the instance's event as an iCal event in string representation. * @protected */ 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: "calendso/ics", title: this.calEvent.language("organizer_ics_event_title", { eventType: this.calEvent.type, attendeeName: this.calEvent.attendees[0].name, }), description: this.calEvent.description + stripHtml(this.getAdditionalBody()) + stripHtml(this.getAdditionalFooter()), 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: "CONFIRMED", }); if (icsEvent.error) { throw icsEvent.error; } return icsEvent.value; } protected getBodyHeader(): string { return this.calEvent.language("new_event_scheduled"); } protected getAdditionalFooter(): string { return `
${this.calEvent.language( "need_to_make_a_change" )} ${this.calEvent.language( "manage_my_bookings" )}
`; } protected getImage(): string { return ``; } /** * Returns the email text as HTML representation. * * @protected */ protected getHtmlRepresentation(): string { return ( `${this.calEvent.language("what")} | ${this.calEvent.type} |
${this.calEvent.language("when")} | ${this.getOrganizerStart().format("dddd, LL")} ${this.getOrganizerStart().format("h:mma")} (${ this.calEvent.organizer.timeZone }) |
${this.calEvent.language("who")} | ${this.calEvent.attendees[0].name} ${this.calEvent.attendees[0].email} |
${this.calEvent.language("notes")} | ${this.calEvent.description} |