Full zoom integration (except availability check)
This commit is contained in:
parent
9ff8e9bd00
commit
51a8bafaa7
4 changed files with 56 additions and 18 deletions
|
@ -10,21 +10,47 @@ dayjs.extend(localizedFormat);
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
|
|
||||||
export default function createConfirmBookedEmail(calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, options: any = {}) {
|
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, {
|
return sendEmail(calEvent, cancelLink, rescheduleLink, {
|
||||||
provider: {
|
provider: {
|
||||||
transport: serverConfig.transport,
|
transport: serverConfig.transport,
|
||||||
from: serverConfig.from,
|
from: serverConfig.from,
|
||||||
},
|
},
|
||||||
...options
|
...options
|
||||||
});
|
}, videoCallData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendEmail = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, {
|
const sendEmail = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, {
|
||||||
provider,
|
provider,
|
||||||
}) => new Promise( (resolve, reject) => {
|
}, videoCallData?: VideoCallData) => new Promise((resolve, reject) => {
|
||||||
|
|
||||||
const { from, transport } = provider;
|
const {from, transport} = provider;
|
||||||
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
|
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
|
||||||
|
|
||||||
nodemailer.createTransport(transport).sendMail(
|
nodemailer.createTransport(transport).sendMail(
|
||||||
|
@ -33,8 +59,8 @@ const sendEmail = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink:
|
||||||
from: `${calEvent.organizer.name} <${from}>`,
|
from: `${calEvent.organizer.name} <${from}>`,
|
||||||
replyTo: calEvent.organizer.email,
|
replyTo: calEvent.organizer.email,
|
||||||
subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`,
|
subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`,
|
||||||
html: html(calEvent, cancelLink, rescheduleLink),
|
html: html(calEvent, cancelLink, rescheduleLink, videoCallData),
|
||||||
text: text(calEvent, cancelLink, rescheduleLink),
|
text: text(calEvent, cancelLink, rescheduleLink, videoCallData),
|
||||||
},
|
},
|
||||||
(error, info) => {
|
(error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -46,7 +72,7 @@ const sendEmail = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink:
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
const html = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string) => {
|
const html = (calEvent: CalendarEvent, cancelLink, rescheduleLink: string, videoCallData?: VideoCallData) => {
|
||||||
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
|
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
|
||||||
return `
|
return `
|
||||||
<div>
|
<div>
|
||||||
|
@ -55,9 +81,14 @@ const html = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: strin
|
||||||
Your ${calEvent.type} with ${calEvent.organizer.name} at ${inviteeStart.format('h:mma')}
|
Your ${calEvent.type} with ${calEvent.organizer.name} at ${inviteeStart.format('h:mma')}
|
||||||
(${calEvent.attendees[0].timeZone}) on ${inviteeStart.format('dddd, LL')} is scheduled.<br />
|
(${calEvent.attendees[0].timeZone}) on ${inviteeStart.format('dddd, LL')} is scheduled.<br />
|
||||||
<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 />` : ''
|
calEvent.location ? `<strong>Location:</strong> ${calEvent.location}<br /><br />` : ''
|
||||||
) +
|
) +
|
||||||
`Additional notes:<br />
|
`<strong>Additional notes:</strong><br />
|
||||||
${calEvent.description}<br />
|
${calEvent.description}<br />
|
||||||
<br />
|
<br />
|
||||||
Need to change this event?<br />
|
Need to change this event?<br />
|
||||||
|
@ -67,4 +98,4 @@ const html = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: strin
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const text = (evt: CalendarEvent, cancelLink: string, rescheduleLink: string) => html(evt, cancelLink, rescheduleLink).replace('<br />', "\n").replace(/<[^>]+>/g, '');
|
const text = (evt: CalendarEvent, cancelLink: string, rescheduleLink: string, videoCallData?: VideoCallData) => html(evt, cancelLink, rescheduleLink, videoCallData).replace('<br />', "\n").replace(/<[^>]+>/g, '');
|
|
@ -97,8 +97,8 @@ const ZoomVideo = (credential): VideoApiAdapter => {
|
||||||
settings: {
|
settings: {
|
||||||
host_video: true,
|
host_video: true,
|
||||||
participant_video: true,
|
participant_video: true,
|
||||||
cn_meeting: false, // TODO: true if host meeting in china
|
cn_meeting: false, // TODO: true if host meeting in China
|
||||||
in_meeting: false, // TODO: true if host meeting in india
|
in_meeting: false, // TODO: true if host meeting in India
|
||||||
join_before_host: true,
|
join_before_host: true,
|
||||||
mute_upon_entry: false,
|
mute_upon_entry: false,
|
||||||
watermark: false,
|
watermark: false,
|
||||||
|
@ -149,7 +149,6 @@ const ZoomVideo = (credential): VideoApiAdapter => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});*/
|
});*/
|
||||||
},
|
},
|
||||||
//TODO Also add the client user to the meeting after creation
|
|
||||||
createMeeting: (meeting: VideoMeeting) => auth.getToken().then(accessToken => fetch('https://api.zoom.us/v2/users/me/meetings', {
|
createMeeting: (meeting: VideoMeeting) => auth.getToken().then(accessToken => fetch('https://api.zoom.us/v2/users/me/meetings', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -194,7 +193,7 @@ const getBusyTimes = (withCredentials, dateFrom, dateTo) => Promise.all(
|
||||||
|
|
||||||
const createMeeting = (credential, meeting: VideoMeeting): Promise<any> => {
|
const createMeeting = (credential, meeting: VideoMeeting): Promise<any> => {
|
||||||
|
|
||||||
//TODO Implement email template
|
//TODO Send email to event host
|
||||||
/*createNewMeetingEmail(
|
/*createNewMeetingEmail(
|
||||||
meeting,
|
meeting,
|
||||||
);*/
|
);*/
|
||||||
|
|
|
@ -76,7 +76,7 @@ export default function Book(props) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let successUrl = `/success?date=${date}&type=${props.eventType.id}&user=${props.user.username}&reschedule=1`;
|
let successUrl = `/success?date=${date}&type=${props.eventType.id}&user=${props.user.username}&reschedule=${!!rescheduleUid}`;
|
||||||
if (payload['location']) {
|
if (payload['location']) {
|
||||||
successUrl += "&location=" + encodeURIComponent(payload['location']);
|
successUrl += "&location=" + encodeURIComponent(payload['location']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
import type {NextApiRequest, NextApiResponse} from 'next';
|
||||||
import prisma from '../../../lib/prisma';
|
import prisma from '../../../lib/prisma';
|
||||||
import {CalendarEvent, createEvent, updateEvent} from '../../../lib/calendarClient';
|
import {CalendarEvent, createEvent, updateEvent} from '../../../lib/calendarClient';
|
||||||
import createConfirmBookedEmail from "../../../lib/emails/confirm-booked";
|
import createConfirmBookedEmail, {VideoCallData} from "../../../lib/emails/confirm-booked";
|
||||||
import async from 'async';
|
import async from 'async';
|
||||||
import {v5 as uuidv5} from 'uuid';
|
import {v5 as uuidv5} from 'uuid';
|
||||||
import short from 'short-uuid';
|
import short from 'short-uuid';
|
||||||
|
@ -182,10 +182,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const videoResults = results.filter((res) => res.type.endsWith('_video'));
|
||||||
|
const videoCallData: VideoCallData = videoResults.length === 0 ? undefined : {
|
||||||
|
type: videoResults[0].type,
|
||||||
|
id: videoResults[0].response.id,
|
||||||
|
password: videoResults[0].response.password,
|
||||||
|
url: videoResults[0].response.join_url,
|
||||||
|
};
|
||||||
|
|
||||||
// If one of the integrations allows email confirmations or no integrations are added, send it.
|
// If one of the integrations allows email confirmations or no integrations are added, send it.
|
||||||
if (currentUser.credentials.length === 0 || !results.every((result) => result.disableConfirmationEmail)) {
|
if (currentUser.credentials.length === 0 || !results.every((result) => result.disableConfirmationEmail)) {
|
||||||
await createConfirmBookedEmail(
|
await createConfirmBookedEmail(
|
||||||
evt, cancelLink, rescheduleLink
|
evt, cancelLink, rescheduleLink, {}, videoCallData
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue