cal.pub0.org/lib/CalEventParser.ts

152 lines
4.6 KiB
TypeScript
Raw Normal View History

import short from "short-uuid";
import { v5 as uuidv5 } from "uuid";
import { getIntegrationName } from "@lib/integrations";
import { CalendarEvent } from "./calendarClient";
import { stripHtml } from "./emails/helpers";
const translator = short();
export default class CalEventParser {
2021-07-25 17:15:31 +00:00
protected calEvent: CalendarEvent;
constructor(calEvent: CalendarEvent) {
this.calEvent = calEvent;
}
/**
* Returns a link to reschedule the given booking.
*/
public getRescheduleLink(): string {
return process.env.BASE_URL + "/reschedule/" + this.getUid();
}
/**
* Returns a link to cancel the given booking.
*/
public getCancelLink(): string {
return process.env.BASE_URL + "/cancel/" + this.getUid();
}
/**
* Returns a unique identifier for the given calendar event.
*/
public getUid(): string {
return this.calEvent.uid ?? translator.fromUUID(uuidv5(JSON.stringify(this.calEvent), uuidv5.URL));
}
/**
* Returns a footer section with links to change the event (as HTML).
*/
public getChangeEventFooterHtml(): string {
return `<p style="color: #4b5563; margin-top: 20px;">${this.calEvent.language(
"need_to_make_a_change"
)} <a href="${this.getCancelLink()}" style="color: #161e2e;">${this.calEvent.language(
"cancel"
)}</a> ${this.calEvent
.language("or")
.toLowerCase()} <a href="${this.getRescheduleLink()}" style="color: #161e2e;">${this.calEvent.language(
"reschedule"
)}</a></p>`;
}
/**
* Returns a footer section with links to change the event (as plain text).
*/
public getChangeEventFooter(): string {
return stripHtml(this.getChangeEventFooterHtml());
}
/**
* Returns an extended description with all important information (as HTML).
*
* @protected
*/
public getRichDescriptionHtml(): string {
2021-06-29 22:31:30 +00:00
// This odd indentation is necessary because otherwise the leading tabs will be applied into the event description.
return (
`
<strong>${this.calEvent.language("event_type")}:</strong><br />${this.calEvent.type}<br />
<strong>${this.calEvent.language("invitee_email")}:</strong><br /><a href="mailto:${
this.calEvent.attendees[0].email
}">${this.calEvent.attendees[0].email}</a><br />
2021-06-29 22:31:30 +00:00
` +
(this.getLocation()
? `<strong>${this.calEvent.language("location")}:</strong><br />${this.getLocation()}<br />
2021-06-29 22:31:30 +00:00
`
: "") +
`<strong>${this.calEvent.language("invitee_timezone")}:</strong><br />${
this.calEvent.attendees[0].timeZone
}<br />
<strong>${this.calEvent.language("additional_notes")}:</strong><br />${this.getDescriptionText()}<br />` +
2021-06-29 22:11:16 +00:00
this.getChangeEventFooterHtml()
);
}
/**
* Conditionally returns the event's location. When VideoCallData is set,
* it returns the meeting url. Otherwise, the regular location is returned.
Daily video calls (#542) * :arrow_up: Bump tailwindcss from 2.2.14 to 2.2.15 Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 2.2.14 to 2.2.15. - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v2.2.14...v2.2.15) --- updated-dependencies: - dependency-name: tailwindcss dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * updating cal will provide a zoom meeting url * updating cal will provide a zoom meeting url * modifying how daily emails send * modifying how daily emails send * daily table * migration updates * daily table * rebasing updates * updating Daily references to a new table * updating internal notes * merge updates, adding Daily references to book/events.ts * updated video email templates to remove Daily specific references * updating the events.ts and refactoring in the event manager * removing the package-lock * changing calendso video powered by Daily.co to cal video powered by Daily.co * updating some of the internal Daily notes * added a modal for when the call/ link is invalid * removing handle errors raw from the Daily video client * prettier formatting fixes * Added the Daily location to calendar events and updated Cal video references to Daily.co video * updating references to create in event manager to check for Daily video * fixing spacing on the cancel booking modal and adding Daily references in the event manager * formatting fixes * updating the readme file * adding a daily interface in the event manager * adding daily to the location labels * added a note to cal event parser * resolving yarn merge conflicts * updating dailyReturn to DailyReturnType * removing prettier auto and refactoring integrations: daily in the event manager * removing changes to estlintrc.json * updating read me formatting * indent space for Daily ReadMe section * resolving the merge conflicts in the yarn file Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lola-Ojabowale <lola.ojabowale@gmail.com>
2021-10-07 16:12:39 +00:00
* For Daily video calls returns the direct link
* @protected
*/
protected getLocation(): string | null | undefined {
Daily video calls (#542) * :arrow_up: Bump tailwindcss from 2.2.14 to 2.2.15 Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 2.2.14 to 2.2.15. - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v2.2.14...v2.2.15) --- updated-dependencies: - dependency-name: tailwindcss dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * updating cal will provide a zoom meeting url * updating cal will provide a zoom meeting url * modifying how daily emails send * modifying how daily emails send * daily table * migration updates * daily table * rebasing updates * updating Daily references to a new table * updating internal notes * merge updates, adding Daily references to book/events.ts * updated video email templates to remove Daily specific references * updating the events.ts and refactoring in the event manager * removing the package-lock * changing calendso video powered by Daily.co to cal video powered by Daily.co * updating some of the internal Daily notes * added a modal for when the call/ link is invalid * removing handle errors raw from the Daily video client * prettier formatting fixes * Added the Daily location to calendar events and updated Cal video references to Daily.co video * updating references to create in event manager to check for Daily video * fixing spacing on the cancel booking modal and adding Daily references in the event manager * formatting fixes * updating the readme file * adding a daily interface in the event manager * adding daily to the location labels * added a note to cal event parser * resolving yarn merge conflicts * updating dailyReturn to DailyReturnType * removing prettier auto and refactoring integrations: daily in the event manager * removing changes to estlintrc.json * updating read me formatting * indent space for Daily ReadMe section * resolving the merge conflicts in the yarn file Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lola-Ojabowale <lola.ojabowale@gmail.com>
2021-10-07 16:12:39 +00:00
const isDaily = this.calEvent.location === "integrations:daily";
if (this.calEvent.videoCallData) {
return this.calEvent.videoCallData.url;
}
Daily video calls (#542) * :arrow_up: Bump tailwindcss from 2.2.14 to 2.2.15 Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 2.2.14 to 2.2.15. - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v2.2.14...v2.2.15) --- updated-dependencies: - dependency-name: tailwindcss dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * updating cal will provide a zoom meeting url * updating cal will provide a zoom meeting url * modifying how daily emails send * modifying how daily emails send * daily table * migration updates * daily table * rebasing updates * updating Daily references to a new table * updating internal notes * merge updates, adding Daily references to book/events.ts * updated video email templates to remove Daily specific references * updating the events.ts and refactoring in the event manager * removing the package-lock * changing calendso video powered by Daily.co to cal video powered by Daily.co * updating some of the internal Daily notes * added a modal for when the call/ link is invalid * removing handle errors raw from the Daily video client * prettier formatting fixes * Added the Daily location to calendar events and updated Cal video references to Daily.co video * updating references to create in event manager to check for Daily video * fixing spacing on the cancel booking modal and adding Daily references in the event manager * formatting fixes * updating the readme file * adding a daily interface in the event manager * adding daily to the location labels * added a note to cal event parser * resolving yarn merge conflicts * updating dailyReturn to DailyReturnType * removing prettier auto and refactoring integrations: daily in the event manager * removing changes to estlintrc.json * updating read me formatting * indent space for Daily ReadMe section * resolving the merge conflicts in the yarn file Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lola-Ojabowale <lola.ojabowale@gmail.com>
2021-10-07 16:12:39 +00:00
if (isDaily) {
return process.env.BASE_URL + "/call/" + this.getUid();
}
return this.calEvent.location;
}
/**
* Returns the event's description text. If VideoCallData is set, it prepends
* some video call information before the text as well.
*
* @protected
*/
protected getDescriptionText(): string | null | undefined {
if (this.calEvent.videoCallData) {
return `
${this.calEvent.language("integration_meeting_id", {
integrationName: getIntegrationName(this.calEvent.videoCallData.type),
meetingId: this.calEvent.videoCallData.id,
})}
${this.calEvent.language("password")}: ${this.calEvent.videoCallData.password}
${this.calEvent.description}`;
}
return this.calEvent.description;
}
/**
* Returns an extended description with all important information (as plain text).
*
* @protected
*/
public getRichDescription(): string {
return stripHtml(this.getRichDescriptionHtml());
}
/**
* Returns a calendar event with rich description.
*/
public asRichEvent(): CalendarEvent {
const eventCopy: CalendarEvent = { ...this.calEvent };
eventCopy.description = this.getRichDescriptionHtml();
eventCopy.location = this.getLocation();
return eventCopy;
}
2021-07-21 12:01:48 +00:00
/**
* Returns a calendar event with rich description as plain text.
*/
public asRichEventPlain(): CalendarEvent {
const eventCopy: CalendarEvent = { ...this.calEvent };
eventCopy.description = this.getRichDescription();
eventCopy.location = this.getLocation();
2021-07-21 12:01:48 +00:00
return eventCopy;
}
}