Re-implemented event confirmation mails object based
This commit is contained in:
1 parent
04e0b55b51
commit
f56ced0ff1
7 files changed
+231
-304
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import {VideoCallData} from "./confirm-booked";
|
||||
import {CalendarEvent} from "../calendarClient";
|
||||
import EventAttendeeMail from "./EventAttendeeMail";
|
||||
import {getFormattedMeetingId, getIntegrationName} from "./helpers";
|
||||
import {VideoCallData} from "../videoClient";
|
||||
|
||||
export default class VideoEventAttendeeMail extends EventAttendeeMail {
|
||||
videoCallData: VideoCallData;
|
||||
@@ -10,25 +11,6 @@ export default class VideoEventAttendeeMail extends EventAttendeeMail {
|
||||
this.videoCallData = videoCallData;
|
||||
}
|
||||
|
||||
private getIntegrationName(): string {
|
||||
//TODO: When there are more complex integration type strings, we should consider using an extra field in the DB for that.
|
||||
const nameProto = this.videoCallData.type.split("_")[0];
|
||||
return nameProto.charAt(0).toUpperCase() + nameProto.slice(1);
|
||||
}
|
||||
|
||||
private getFormattedMeetingId(): string {
|
||||
switch(this.videoCallData.type) {
|
||||
case 'zoom_video':
|
||||
const strId = this.videoCallData.id.toString();
|
||||
const part1 = strId.slice(0, 3);
|
||||
const part2 = strId.slice(3, 7);
|
||||
const part3 = strId.slice(7, 11);
|
||||
return part1 + " " + part2 + " " + part3;
|
||||
default:
|
||||
return this.videoCallData.id.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the video call information to the mail body.
|
||||
*
|
||||
@@ -36,8 +18,8 @@ export default class VideoEventAttendeeMail extends EventAttendeeMail {
|
||||
*/
|
||||
protected getAdditionalBody(): string {
|
||||
return `
|
||||
<strong>Video call provider:</strong> ${this.getIntegrationName()}<br />
|
||||
<strong>Meeting ID:</strong> ${this.getFormattedMeetingId()}<br />
|
||||
<strong>Video call provider:</strong> ${getIntegrationName(this.videoCallData)}<br />
|
||||
<strong>Meeting ID:</strong> ${getFormattedMeetingId(this.videoCallData)}<br />
|
||||
<strong>Meeting Password:</strong> ${this.videoCallData.password}<br />
|
||||
<strong>Meeting URL:</strong> <a href="${this.videoCallData.url}">${this.videoCallData.url}</a><br />
|
||||
`;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {CalendarEvent} from "../calendarClient";
|
||||
import EventOwnerMail from "./EventOwnerMail";
|
||||
import {formattedId, integrationTypeToName, VideoCallData} from "./confirm-booked";
|
||||
import {VideoCallData} from "../videoClient";
|
||||
import {getFormattedMeetingId, getIntegrationName} from "./helpers";
|
||||
|
||||
export default class VideoEventOwnerMail extends EventOwnerMail {
|
||||
videoCallData: VideoCallData;
|
||||
@@ -18,8 +19,8 @@ export default class VideoEventOwnerMail extends EventOwnerMail {
|
||||
*/
|
||||
protected getAdditionalBody(): string {
|
||||
return `
|
||||
<strong>Video call provider:</strong> ${integrationTypeToName(this.videoCallData.type)}<br />
|
||||
<strong>Meeting ID:</strong> ${formattedId(this.videoCallData)}<br />
|
||||
<strong>Video call provider:</strong> ${getIntegrationName(this.videoCallData)}<br />
|
||||
<strong>Meeting ID:</strong> ${getFormattedMeetingId(this.videoCallData)}<br />
|
||||
<strong>Meeting Password:</strong> ${this.videoCallData.password}<br />
|
||||
<strong>Meeting URL:</strong> <a href="${this.videoCallData.url}">${this.videoCallData.url}</a><br />
|
||||
`;
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import {serverConfig} from "../serverConfig";
|
||||
import {CalendarEvent} from "../calendarClient";
|
||||
import dayjs, {Dayjs} from "dayjs";
|
||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
|
||||
dayjs.extend(localizedFormat);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export interface VideoCallData {
|
||||
type: string;
|
||||
id: string;
|
||||
password: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export function integrationTypeToName(type: string): string {
|
||||
//TODO: When there are more complex integration type strings, we should consider using an extra field in the DB for that.
|
||||
const nameProto = type.split("_")[0];
|
||||
return nameProto.charAt(0).toUpperCase() + nameProto.slice(1);
|
||||
}
|
||||
|
||||
export function formattedId(videoCallData: VideoCallData): string {
|
||||
switch(videoCallData.type) {
|
||||
case 'zoom_video':
|
||||
const strId = videoCallData.id.toString();
|
||||
const part1 = strId.slice(0, 3);
|
||||
const part2 = strId.slice(3, 7);
|
||||
const part3 = strId.slice(7, 11);
|
||||
return part1 + " " + part2 + " " + part3;
|
||||
default:
|
||||
return videoCallData.id.toString();
|
||||
}
|
||||
}
|
||||
|
||||
export default function createConfirmBookedEmail(calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, options: any = {}, videoCallData?: VideoCallData) {
|
||||
return sendEmail(calEvent, cancelLink, rescheduleLink, {
|
||||
provider: {
|
||||
transport: serverConfig.transport,
|
||||
from: serverConfig.from,
|
||||
},
|
||||
...options
|
||||
}, videoCallData);
|
||||
}
|
||||
|
||||
const sendEmail = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, {
|
||||
provider,
|
||||
}, videoCallData?: VideoCallData) => new Promise((resolve, reject) => {
|
||||
|
||||
const {from, transport} = provider;
|
||||
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
|
||||
|
||||
nodemailer.createTransport(transport).sendMail(
|
||||
{
|
||||
to: `${calEvent.attendees[0].name} <${calEvent.attendees[0].email}>`,
|
||||
from: `${calEvent.organizer.name} <${from}>`,
|
||||
replyTo: calEvent.organizer.email,
|
||||
subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`,
|
||||
html: html(calEvent, cancelLink, rescheduleLink, videoCallData),
|
||||
text: text(calEvent, cancelLink, rescheduleLink, videoCallData),
|
||||
},
|
||||
(error, info) => {
|
||||
if (error) {
|
||||
console.error("SEND_BOOKING_CONFIRMATION_ERROR", calEvent.attendees[0].email, error);
|
||||
return reject(new Error(error));
|
||||
}
|
||||
return resolve();
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
const html = (calEvent: CalendarEvent, cancelLink, rescheduleLink: string, videoCallData?: VideoCallData) => {
|
||||
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
|
||||
return `
|
||||
<div>
|
||||
Hi ${calEvent.attendees[0].name},<br />
|
||||
<br />
|
||||
Your ${calEvent.type} with ${calEvent.organizer.name} at ${inviteeStart.format('h:mma')}
|
||||
(${calEvent.attendees[0].timeZone}) on ${inviteeStart.format('dddd, LL')} is scheduled.<br />
|
||||
<br />` + (
|
||||
videoCallData ? `<strong>Video call provider:</strong> ${integrationTypeToName(videoCallData.type)}<br />
|
||||
<strong>Meeting ID:</strong> ${formattedId(videoCallData)}<br />
|
||||
<strong>Meeting Password:</strong> ${videoCallData.password}<br />
|
||||
<strong>Meeting URL:</strong> <a href="${videoCallData.url}">${videoCallData.url}</a><br /><br />` : ''
|
||||
) + (
|
||||
calEvent.location ? `<strong>Location:</strong> ${calEvent.location}<br /><br />` : ''
|
||||
) +
|
||||
`<strong>Additional notes:</strong><br />
|
||||
${calEvent.description}<br />
|
||||
<br />
|
||||
Need to change this event?<br />
|
||||
Cancel: <a href="${cancelLink}">${cancelLink}</a><br />
|
||||
Reschedule: <a href="${rescheduleLink}">${rescheduleLink}</a>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const text = (evt: CalendarEvent, cancelLink: string, rescheduleLink: string, videoCallData?: VideoCallData) => html(evt, cancelLink, rescheduleLink, videoCallData).replace('<br />', "\n").replace(/<[^>]+>/g, '');
|
||||
@@ -0,0 +1,20 @@
|
||||
import {VideoCallData} from "../videoClient";
|
||||
|
||||
export function getIntegrationName(videoCallData: VideoCallData): string {
|
||||
//TODO: When there are more complex integration type strings, we should consider using an extra field in the DB for that.
|
||||
const nameProto = videoCallData.type.split("_")[0];
|
||||
return nameProto.charAt(0).toUpperCase() + nameProto.slice(1);
|
||||
}
|
||||
|
||||
export function getFormattedMeetingId(videoCallData: VideoCallData): string {
|
||||
switch(videoCallData.type) {
|
||||
case 'zoom_video':
|
||||
const strId = videoCallData.id.toString();
|
||||
const part1 = strId.slice(0, 3);
|
||||
const part2 = strId.slice(3, 7);
|
||||
const part3 = strId.slice(7, 11);
|
||||
return part1 + " " + part2 + " " + part3;
|
||||
default:
|
||||
return videoCallData.id.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user