import dayjs, { Dayjs } from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import timezone from "dayjs/plugin/timezone"; import utc from "dayjs/plugin/utc"; import EventMail from "./EventMail"; dayjs.extend(utc); dayjs.extend(timezone); dayjs.extend(localizedFormat); export default class EventAttendeeMail extends EventMail { /** * Returns the email text as HTML representation. * * @protected */ protected getHtmlRepresentation(): string { return ( `

${this.calEvent.language( "your_meeting_has_been_booked" )}

${this.calEvent.language("emailed_you_and_attendees")}


${this.calEvent.language("what")} ${this.calEvent.type}
${this.calEvent.language("when")} ${this.getInviteeStart().format("dddd, LL")}
${this.getInviteeStart().format("h:mma")} (${ this.calEvent.attendees[0].timeZone })
${this.calEvent.language("who")} ${this.calEvent.team?.name || this.calEvent.organizer.name}
${this.calEvent.organizer.email && !this.calEvent.team ? this.calEvent.organizer.email : ""} ${this.calEvent.team ? this.calEvent.team.members.join(", ") : ""}
${this.calEvent.language("where")} ${this.getLocation()}
${this.calEvent.language("notes")} ${this.calEvent.description}
` + this.getAdditionalBody() + "
" + `
` + this.getAdditionalFooter() + `
Cal.com Logo
` ); } /** * Adds the video call information to the mail body. * * @protected */ protected getLocation(): string { if (this.calEvent.additionInformation?.hangoutLink) { return `${this.calEvent.additionInformation?.hangoutLink}
`; } if ( this.calEvent.additionInformation?.entryPoints && this.calEvent.additionInformation?.entryPoints.length > 0 ) { const locations = this.calEvent.additionInformation?.entryPoints .map((entryPoint) => { return ` ${this.calEvent.language("join_by_entrypoint", { entryPoint: entryPoint.entryPointType })}:
${entryPoint.label}
`; }) .join("
"); return `${locations}`; } return this.calEvent.location ? `${this.calEvent.location}

` : ""; } protected getAdditionalBody(): string { return ``; } protected getAdditionalFooter(): string { return this.parser.getChangeEventFooterHtml(); } /** * Returns the payload object for the nodemailer. * * @protected */ protected getNodeMailerPayload(): Record { return { to: `${this.calEvent.attendees[0].name} <${this.calEvent.attendees[0].email}>`, from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`, replyTo: this.calEvent.organizer.email, subject: this.calEvent.language("confirmed_event_type_subject", { eventType: this.calEvent.type, name: this.calEvent.team?.name || this.calEvent.organizer.name, date: this.getInviteeStart().format("LT dddd, LL"), }), html: this.getHtmlRepresentation(), text: this.getPlainTextRepresentation(), }; } protected printNodeMailerError(error: Error): void { console.error("SEND_BOOKING_CONFIRMATION_ERROR", this.calEvent.attendees[0].email, error); } /** * Returns the inviteeStart value used at multiple points. * * @private */ protected getInviteeStart(): Dayjs { return dayjs(this.calEvent.startTime).tz(this.calEvent.attendees[0].timeZone); } }