2021-06-16 21:40:13 +00:00
|
|
|
import {createEvent} from "ics";
|
|
|
|
import dayjs, {Dayjs} from "dayjs";
|
2021-06-16 22:26:51 +00:00
|
|
|
import EventMail from "./EventMail";
|
2021-06-16 21:40:13 +00:00
|
|
|
|
2021-06-18 00:44:41 +00:00
|
|
|
export default class EventOrganizerMail extends EventMail {
|
2021-06-16 21:40:13 +00:00
|
|
|
/**
|
|
|
|
* Returns the instance's event as an iCal event in string representation.
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected getiCalEventAsString(): string {
|
|
|
|
const icsEvent = createEvent({
|
2021-06-20 14:37:51 +00:00
|
|
|
start: dayjs(this.calEvent.startTime).utc().toArray().slice(0, 6).map((v, i) => i === 1 ? v + 1 : v),
|
2021-06-16 21:40:13 +00:00
|
|
|
startInputType: 'utc',
|
|
|
|
productId: 'calendso/ics',
|
|
|
|
title: `${this.calEvent.type} with ${this.calEvent.attendees[0].name}`,
|
2021-06-20 15:04:00 +00:00
|
|
|
description: this.calEvent.description + this.stripHtml(this.getAdditionalBody()) + this.stripHtml(this.getAdditionalFooter()),
|
2021-06-20 14:37:51 +00:00
|
|
|
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: any) => ({ name: attendee.name, email: attendee.email }) ),
|
2021-06-16 21:40:13 +00:00
|
|
|
status: "CONFIRMED",
|
|
|
|
});
|
|
|
|
if (icsEvent.error) {
|
|
|
|
throw icsEvent.error;
|
|
|
|
}
|
|
|
|
return icsEvent.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the email text as HTML representation.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected getHtmlRepresentation(): string {
|
|
|
|
return `
|
|
|
|
<div>
|
|
|
|
Hi ${this.calEvent.organizer.name},<br />
|
|
|
|
<br />
|
|
|
|
A new event has been scheduled.<br />
|
|
|
|
<br />
|
|
|
|
<strong>Event Type:</strong><br />
|
|
|
|
${this.calEvent.type}<br />
|
|
|
|
<br />
|
|
|
|
<strong>Invitee Email:</strong><br />
|
|
|
|
<a href="mailto:${this.calEvent.attendees[0].email}">${this.calEvent.attendees[0].email}</a><br />
|
|
|
|
<br />` + this.getAdditionalBody() +
|
|
|
|
(
|
|
|
|
this.calEvent.location ? `
|
|
|
|
<strong>Location:</strong><br />
|
|
|
|
${this.calEvent.location}<br />
|
|
|
|
<br />
|
|
|
|
` : ''
|
|
|
|
) +
|
|
|
|
`<strong>Invitee Time Zone:</strong><br />
|
|
|
|
${this.calEvent.attendees[0].timeZone}<br />
|
|
|
|
<br />
|
|
|
|
<strong>Additional notes:</strong><br />
|
|
|
|
${this.calEvent.description}
|
2021-06-16 22:26:51 +00:00
|
|
|
` + this.getAdditionalFooter() + `
|
2021-06-16 21:40:13 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-06-16 22:26:51 +00:00
|
|
|
* Returns the payload object for the nodemailer.
|
2021-06-16 21:40:13 +00:00
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*/
|
2021-06-16 22:26:51 +00:00
|
|
|
protected getNodeMailerPayload(): Object {
|
2021-06-16 21:40:13 +00:00
|
|
|
const organizerStart: Dayjs = <Dayjs>dayjs(this.calEvent.startTime).tz(this.calEvent.organizer.timeZone);
|
|
|
|
|
|
|
|
return {
|
2021-06-16 22:26:51 +00:00
|
|
|
icalEvent: {
|
|
|
|
filename: 'event.ics',
|
|
|
|
content: this.getiCalEventAsString(),
|
|
|
|
},
|
|
|
|
from: `Calendso <${this.getMailerOptions().from}>`,
|
|
|
|
to: this.calEvent.organizer.email,
|
|
|
|
subject: `New event: ${this.calEvent.attendees[0].name} - ${organizerStart.format('LT dddd, LL')} - ${this.calEvent.type}`,
|
|
|
|
html: this.getHtmlRepresentation(),
|
|
|
|
text: this.getPlainTextRepresentation(),
|
2021-06-16 21:40:13 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-16 22:26:51 +00:00
|
|
|
protected printNodeMailerError(error: string): void {
|
|
|
|
console.error("SEND_NEW_EVENT_NOTIFICATION_ERROR", this.calEvent.organizer.email, error);
|
2021-06-16 21:40:13 +00:00
|
|
|
}
|
|
|
|
}
|