feat: added Rating Template to Workflows (#14215)

Co-authored-by: alishaz-polymath <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-04-04 09:58:52 -07:00
1 parent 844076badb
commit 9bd3a362a2
22 files changed
+845 -408

No files matched your search

@@ -38,6 +38,10 @@ export function isAttendeeAction(action: WorkflowActions) {
);
}
export function isEmailToAttendeeAction(action: WorkflowActions) {
return action === WorkflowActions.EMAIL_ATTENDEE;
}
export function isTextMessageToAttendeeAction(action?: WorkflowActions) {
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.WHATSAPP_ATTENDEE;
}
@@ -23,6 +23,7 @@ export const TIME_UNIT = [TimeUnit.DAY, TimeUnit.HOUR, TimeUnit.MINUTE] as const
export const WORKFLOW_TEMPLATES = [
WorkflowTemplates.CUSTOM,
WorkflowTemplates.REMINDER,
WorkflowTemplates.RATING,
WorkflowTemplates.CANCELLED,
WorkflowTemplates.COMPLETED,
WorkflowTemplates.RESCHEDULED,
@@ -30,6 +31,12 @@ export const WORKFLOW_TEMPLATES = [
export const BASIC_WORKFLOW_TEMPLATES = [WorkflowTemplates.CUSTOM, WorkflowTemplates.REMINDER] as const;
export const ATTENDEE_WORKFLOW_TEMPLATES = [
WorkflowTemplates.CUSTOM,
WorkflowTemplates.REMINDER,
WorkflowTemplates.RATING,
] as const;
export const WHATSAPP_WORKFLOW_TEMPLATES = [
WorkflowTemplates.REMINDER,
WorkflowTemplates.COMPLETED,
@@ -53,6 +60,8 @@ export const DYNAMIC_TEXT_VARIABLES = [
"meeting_url",
"cancel_url",
"reschedule_url",
"rating_url",
"no_show_url",
];
export const FORMATTED_DYNAMIC_TEXT_VARIABLES = ["event_date_", "event_time_", "event_end_time_"];
@@ -6,6 +6,7 @@ import {
isTextMessageToAttendeeAction,
isSMSOrWhatsappAction,
isWhatsappAction,
isEmailToAttendeeAction,
} from "./actionHelperFunctions";
import {
TIME_UNIT,
@@ -13,6 +14,7 @@ import {
WORKFLOW_ACTIONS,
BASIC_WORKFLOW_TEMPLATES,
WORKFLOW_TRIGGER_EVENTS,
ATTENDEE_WORKFLOW_TEMPLATES,
} from "./constants";
export function getWorkflowActionOptions(t: TFunction, isTeamsPlan?: boolean, isOrgsPlan?: boolean) {
@@ -46,7 +48,11 @@ export function getWorkflowTimeUnitOptions(t: TFunction) {
export function getWorkflowTemplateOptions(t: TFunction, action: WorkflowActions | undefined) {
const TEMPLATES =
action && isWhatsappAction(action) ? WHATSAPP_WORKFLOW_TEMPLATES : BASIC_WORKFLOW_TEMPLATES;
action && isWhatsappAction(action)
? WHATSAPP_WORKFLOW_TEMPLATES
: action && isEmailToAttendeeAction(action)
? ATTENDEE_WORKFLOW_TEMPLATES
: BASIC_WORKFLOW_TEMPLATES;
return TEMPLATES.map((template) => {
return { label: t(`${template.toLowerCase()}`), value: template };
}) as { label: string; value: any }[];
@@ -23,6 +23,7 @@ import { getBatchId, sendSendgridMail } from "./providers/sendgridProvider";
import type { AttendeeInBookingInfo, BookingInfo, timeUnitLowerCase } from "./smsReminderManager";
import type { VariablesType } from "./templates/customTemplate";
import customTemplate from "./templates/customTemplate";
import emailRatingTemplate from "./templates/emailRatingTemplate";
import emailReminderTemplate from "./templates/emailReminderTemplate";
const log = logger.getSubLogger({ prefix: ["[emailReminderManager]"] });
@@ -200,6 +201,8 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
meetingUrl: bookingMetadataSchema.parse(evt.metadata || {})?.videoCallUrl,
cancelLink: `${evt.bookerUrl}/booking/${evt.uid}?cancel=true`,
rescheduleLink: `${evt.bookerUrl}/reschedule/${evt.uid}`,
ratingUrl: `${evt.bookerUrl}/booking/${evt.uid}?rating`,
noShowUrl: `${evt.bookerUrl}/booking/${evt.uid}?noShow=true`,
};
const locale =
@@ -228,6 +231,20 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
attendeeName,
name
);
} else if (template === WorkflowTemplates.RATING) {
emailContent = emailRatingTemplate({
isEditingMode: true,
action,
timeFormat: evt.organizer.timeFormat,
startTime,
endTime,
eventName: evt.title,
timeZone,
organizer: evt.organizer.name,
name,
ratingUrl: `${evt.bookerUrl}/booking/${evt.uid}?rating`,
noShowUrl: `${evt.bookerUrl}/booking/${evt.uid}?noShow=true`,
});
}
// Allows debugging generated email content without waiting for sendgrid to send emails
@@ -21,6 +21,8 @@ export type VariablesType = {
meetingUrl?: string;
cancelLink?: string;
rescheduleLink?: string;
ratingUrl?: string;
noShowUrl?: string;
};
const customTemplate = (
@@ -79,7 +81,9 @@ const customTemplate = (
.replaceAll("{TIMEZONE}", variables.timeZone || "")
.replaceAll("{CANCEL_URL}", cancelLink)
.replaceAll("{RESCHEDULE_URL}", rescheduleLink)
.replaceAll("{MEETING_URL}", variables.meetingUrl || "");
.replaceAll("{MEETING_URL}", variables.meetingUrl || "")
.replaceAll("{RATING_URL}", variables.ratingUrl || "")
.replaceAll("{NO_SHOW_URL}", variables.noShowUrl || "");
const customInputvariables = dynamicText.match(/\{(.+?)}/g)?.map((variable) => {
return variable.replace("{", "").replace("}", "");
@@ -0,0 +1,79 @@
import dayjs from "@calcom/dayjs";
import { APP_NAME } from "@calcom/lib/constants";
import { TimeFormat } from "@calcom/lib/timeFormat";
import { WorkflowActions } from "@calcom/prisma/enums";
const emailRatingTemplate = ({
isEditingMode,
action,
timeFormat,
startTime,
endTime,
eventName,
timeZone,
organizer,
name,
isBrandingDisabled,
ratingUrl,
noShowUrl,
}: {
isEditingMode: boolean;
action: WorkflowActions;
timeFormat?: TimeFormat;
startTime?: string;
endTime?: string;
eventName?: string;
timeZone?: string;
organizer?: string;
name?: string;
isBrandingDisabled?: boolean;
ratingUrl?: string;
noShowUrl?: string;
}) => {
const currentTimeFormat = timeFormat || TimeFormat.TWELVE_HOUR;
const dateTimeFormat = `ddd, MMM D, YYYY ${currentTimeFormat}`;
let eventDate = "";
if (isEditingMode) {
endTime = "{EVENT_END_TIME}";
eventName = "{EVENT_NAME}";
timeZone = "{TIMEZONE}";
organizer = "{ORGANIZER}";
name = action === WorkflowActions.EMAIL_ATTENDEE ? "{ATTENDEE}" : "{ORGANIZER}";
eventDate = `{EVENT_DATE_${dateTimeFormat}}`;
ratingUrl = "{RATING_URL}";
noShowUrl = "{NO_SHOW_URL}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format(dateTimeFormat);
endTime = dayjs(endTime).tz(timeZone).format(currentTimeFormat);
}
const emailSubject = `How was your recent experience?: ${eventName}`;
const introHtml = `<body>Hi${
name ? ` ${name}` : ""
},<br><br>We're always looking to improve our customer's experience. How satisfied were you with your recent meeting?<br><br>`;
const ratingHtml = `<a href="${ratingUrl}=1">😠</a> <a href="${ratingUrl}=2">🙁</a> <a href="${ratingUrl}=3">😐</a> <a href="${ratingUrl}=4">😄</a> <a href="${ratingUrl}=5">😍</a><br><br>`;
const noShowHtml = `<div><a href="${noShowUrl}">${organizer} didn't join the meeting</a></div><br><br>`;
const eventHtml = `<div><strong class="editor-text-bold">Event: </strong></div>${eventName}<br><br>`;
const dateTimeHtml = `<div><strong class="editor-text-bold">Date & Time: </strong></div>${eventDate} - ${endTime} (${timeZone})<br><br>`;
const attendeeHtml = `<div><strong class="editor-text-bold">Attendees: </strong></div>You & ${organizer}<br><br>`;
const branding = !isBrandingDisabled && !isEditingMode ? `<br><br>_<br><br>Scheduling by ${APP_NAME}` : "";
const endingHtml = `This survey was triggered by a Workflow in Cal.${branding}</body>`;
const emailBody =
introHtml + ratingHtml + noShowHtml + eventHtml + dateTimeHtml + attendeeHtml + endingHtml;
return { emailSubject, emailBody };
};
export default emailRatingTemplate;