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:
22 files changed
+845
-408
No files matched your search
@@ -27,6 +27,7 @@ import {
|
||||
} from "../lib/reminders/providers/sendgridProvider";
|
||||
import type { VariablesType } from "../lib/reminders/templates/customTemplate";
|
||||
import customTemplate from "../lib/reminders/templates/customTemplate";
|
||||
import emailRatingTemplate from "../lib/reminders/templates/emailRatingTemplate";
|
||||
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -188,6 +189,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
meetingUrl: bookingMetadataSchema.parse(reminder.booking.metadata || {})?.videoCallUrl,
|
||||
cancelLink: `${bookerUrl}/booking/${reminder.booking.uid}?cancel=true`,
|
||||
rescheduleLink: `${bookerUrl}/reschedule/${reminder.booking.uid}`,
|
||||
ratingUrl: `${bookerUrl}/booking/${reminder.booking.uid}?rating`,
|
||||
noShowUrl: `${bookerUrl}/booking/${reminder.booking.uid}?noShow=true`,
|
||||
};
|
||||
const emailLocale = locale || "en";
|
||||
const emailSubject = customTemplate(
|
||||
@@ -226,6 +229,30 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
name || "",
|
||||
!!reminder.booking.user?.hideBranding
|
||||
);
|
||||
} else if (reminder.workflowStep.template === WorkflowTemplates.RATING) {
|
||||
const organizerOrganizationProfile = await prisma.profile.findFirst({
|
||||
where: {
|
||||
userId: reminder.booking.user?.id,
|
||||
},
|
||||
});
|
||||
|
||||
const organizerOrganizationId = organizerOrganizationProfile?.organizationId;
|
||||
const bookerUrl = await getBookerBaseUrl(
|
||||
reminder.booking.eventType?.team?.parentId ?? organizerOrganizationId ?? null
|
||||
);
|
||||
emailContent = emailRatingTemplate({
|
||||
isEditingMode: true,
|
||||
action: reminder.workflowStep.action || WorkflowActions.EMAIL_ADDRESS,
|
||||
timeFormat: getTimeFormatStringFromUserTimeFormat(reminder.booking.user?.timeFormat),
|
||||
startTime: reminder.booking.startTime.toISOString() || "",
|
||||
endTime: reminder.booking.endTime.toISOString() || "",
|
||||
eventName: reminder.booking.eventType?.title || "",
|
||||
timeZone: timeZone || "",
|
||||
organizer: reminder.booking.user?.name || "",
|
||||
name: name || "",
|
||||
ratingUrl: `${bookerUrl}/booking/${reminder.booking.uid}?rating` || "",
|
||||
noShowUrl: `${bookerUrl}/booking/${reminder.booking.uid}?noShow=true` || "",
|
||||
});
|
||||
}
|
||||
|
||||
if (emailContent.emailSubject.length > 0 && !emailBodyEmpty && sendTo) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
} from "../lib/actionHelperFunctions";
|
||||
import { DYNAMIC_TEXT_VARIABLES } from "../lib/constants";
|
||||
import { getWorkflowTemplateOptions, getWorkflowTriggerOptions } from "../lib/getOptions";
|
||||
import emailRatingTemplate from "../lib/reminders/templates/emailRatingTemplate";
|
||||
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
|
||||
import smsReminderTemplate from "../lib/reminders/templates/smsReminderTemplate";
|
||||
import { whatsappReminderTemplate } from "../lib/reminders/templates/whatsapp";
|
||||
@@ -739,6 +740,15 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
emailReminderTemplate(true, action, timeFormat).emailSubject
|
||||
);
|
||||
}
|
||||
} else if (val.value === WorkflowTemplates.RATING) {
|
||||
form.setValue(
|
||||
`steps.${step.stepNumber - 1}.reminderBody`,
|
||||
emailRatingTemplate({ isEditingMode: true, action, timeFormat }).emailBody
|
||||
);
|
||||
form.setValue(
|
||||
`steps.${step.stepNumber - 1}.emailSubject`,
|
||||
emailRatingTemplate({ isEditingMode: true, action, timeFormat }).emailSubject
|
||||
);
|
||||
} else {
|
||||
if (isWhatsappAction(action)) {
|
||||
form.setValue(
|
||||
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user