Fixes timezone in reminder templates (workflows) (#3376)
* fix time zone in reminder template * fix timezone in email subject * add missing timezone * fix date in sms reminder template * use organizer time zone if message send to host * fix build error Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Omar López <zomars@me.com>pull/3368/head^2
parent
9162d90504
commit
75b817531e
|
@ -55,16 +55,11 @@ export const scheduleEmailReminder = async (
|
|||
|
||||
const name = action === WorkflowActions.EMAIL_HOST ? evt.organizer.name : evt.attendees[0].name;
|
||||
const attendeeName = action === WorkflowActions.EMAIL_HOST ? evt.attendees[0].name : evt.organizer.name;
|
||||
const timeZone = action === WorkflowActions.EMAIL_HOST ? evt.organizer.timeZone : evt.attendees[0].timeZone;
|
||||
|
||||
switch (template) {
|
||||
case WorkflowTemplates.REMINDER:
|
||||
const emailTemplate = emailReminderTemplate(
|
||||
startTime,
|
||||
evt.title,
|
||||
evt.attendees[0].timeZone,
|
||||
attendeeName,
|
||||
name
|
||||
);
|
||||
const emailTemplate = emailReminderTemplate(startTime, evt.title, timeZone, attendeeName, name);
|
||||
emailSubject = emailTemplate.subject;
|
||||
emailBody = emailTemplate.body;
|
||||
break;
|
||||
|
|
|
@ -20,7 +20,7 @@ export enum timeUnitLowerCase {
|
|||
export type BookingInfo = {
|
||||
uid?: string | null;
|
||||
attendees: { name: string; email: string; timeZone: string }[];
|
||||
organizer: { name: string; email: string };
|
||||
organizer: { name: string; email: string; timeZone: string };
|
||||
startTime: string;
|
||||
title: string;
|
||||
};
|
||||
|
@ -48,12 +48,12 @@ export const scheduleSMSReminder = async (
|
|||
|
||||
const name = action === WorkflowActions.SMS_ATTENDEE ? evt.attendees[0].name : "";
|
||||
const attendeeName = action === WorkflowActions.SMS_ATTENDEE ? evt.organizer.name : evt.attendees[0].name;
|
||||
const timeZone =
|
||||
action === WorkflowActions.SMS_ATTENDEE ? evt.attendees[0].timeZone : evt.organizer.timeZone;
|
||||
|
||||
switch (template) {
|
||||
case WorkflowTemplates.REMINDER:
|
||||
message =
|
||||
smsReminderTemplate(evt.startTime, evt.title, evt.attendees[0].timeZone, attendeeName, name) ||
|
||||
message;
|
||||
message = smsReminderTemplate(evt.startTime, evt.title, timeZone, attendeeName, name) || message;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,19 @@ import dayjs from "@calcom/dayjs";
|
|||
const emailReminderTemplate = (
|
||||
startTime: string,
|
||||
eventName: string,
|
||||
attendeeTimeZone: string,
|
||||
timeZone: string,
|
||||
attendee: string,
|
||||
name: string
|
||||
) => {
|
||||
const templateSubject = `Reminder: ${eventName} at ${dayjs(startTime).format("YYYY MMM D h:mmA")}`;
|
||||
const templateSubject = `Reminder: ${eventName} at ${dayjs(startTime)
|
||||
.tz(timeZone)
|
||||
.format("YYYY MMM D h:mmA")}`;
|
||||
|
||||
const templateBody = `Hi ${name},\n\n this is a reminder that your meeting (${eventName}) with ${attendee} is on ${dayjs(
|
||||
const templateBody = `Hi ${name},\n\nThis is a reminder that your meeting (${eventName}) with ${attendee} is on ${dayjs(
|
||||
startTime
|
||||
).format("YYYY MMM D")} at ${dayjs(startTime).format("h:mmA")} ${attendeeTimeZone}.`;
|
||||
)
|
||||
.tz(timeZone)
|
||||
.format("YYYY MMM D")} at ${dayjs(startTime).tz(timeZone).format("h:mmA")} ${timeZone}.`;
|
||||
|
||||
const emailContent = { subject: templateSubject, body: templateBody };
|
||||
|
||||
|
|
|
@ -3,21 +3,21 @@ import dayjs from "@calcom/dayjs";
|
|||
const smsReminderTemplate = (
|
||||
startTime: string,
|
||||
eventName: string,
|
||||
attendeeTimeZone: string,
|
||||
timeZone: string,
|
||||
attendee: string,
|
||||
name?: string
|
||||
) => {
|
||||
const templateOne = `Hi${name ? ` ${name}` : ``}, this is a reminder that your meeting (${eventName}) with
|
||||
${attendee} is on ${dayjs(startTime).format("MMM D")} at ${dayjs(startTime).format(
|
||||
"h:mmA"
|
||||
)} ${attendeeTimeZone}`;
|
||||
${attendee} is on ${dayjs(startTime).tz(timeZone).format("MMM D")} at ${dayjs(startTime)
|
||||
.tz(timeZone)
|
||||
.format("h:mmA")} ${timeZone}`;
|
||||
|
||||
//Twilio recomments message to be no longer than 320 characters
|
||||
if (templateOne.length <= 320) return templateOne;
|
||||
|
||||
const templateTwo = `Hi, this is a reminder that your meeting with ${attendee} is on ${dayjs(
|
||||
startTime
|
||||
).format("MMM D")} at ${dayjs(startTime).format("h:mmA")}`;
|
||||
const templateTwo = `Hi, this is a reminder that your meeting with ${attendee} is on ${dayjs(startTime)
|
||||
.tz(timeZone)
|
||||
.format("MMM D")} at ${dayjs(startTime).tz(timeZone).format("h:mmA")} ${timeZone}`;
|
||||
|
||||
//Twilio supports up to 1600 characters
|
||||
if (templateTwo.length <= 1600) return templateTwo;
|
||||
|
|
|
@ -87,12 +87,17 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||
? reminder.booking?.user?.name
|
||||
: reminder.booking?.attendees[0].name;
|
||||
|
||||
const timeZone =
|
||||
reminder.workflowStep.action === WorkflowActions.EMAIL_ATTENDEE
|
||||
? reminder.booking?.attendees[0].timeZone
|
||||
: reminder.booking?.user?.timeZone;
|
||||
|
||||
switch (reminder.workflowStep.template) {
|
||||
case WorkflowTemplates.REMINDER:
|
||||
emailTemplate = emailReminderTemplate(
|
||||
reminder.booking?.startTime.toISOString() || "",
|
||||
reminder.booking?.eventType?.title || "",
|
||||
reminder.booking?.attendees[0].timeZone || "",
|
||||
timeZone || "",
|
||||
attendeeName || "",
|
||||
name || ""
|
||||
);
|
||||
|
|
|
@ -66,13 +66,18 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||
? reminder.booking?.user?.name
|
||||
: reminder.booking?.attendees[0].name;
|
||||
|
||||
const timeZone =
|
||||
reminder.workflowStep.action === WorkflowActions.SMS_ATTENDEE
|
||||
? reminder.booking?.attendees[0].timeZone
|
||||
: reminder.booking?.user?.timeZone;
|
||||
|
||||
let message: string | null = reminder.workflowStep.reminderBody;
|
||||
switch (reminder.workflowStep.template) {
|
||||
case WorkflowTemplates.REMINDER:
|
||||
message = smsReminderTemplate(
|
||||
reminder.booking?.startTime.toISOString() || "",
|
||||
reminder.booking?.eventType?.title || "",
|
||||
reminder.booking?.attendees[0].timeZone || "",
|
||||
timeZone || "",
|
||||
attendeeName || "",
|
||||
userName
|
||||
);
|
||||
|
|
|
@ -334,8 +334,12 @@ export const workflowsRouter = createProtectedRouter()
|
|||
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
||||
}),
|
||||
organizer: booking.user
|
||||
? { name: booking.user.name || "", email: booking.user.email }
|
||||
: { name: "", email: "" },
|
||||
? {
|
||||
name: booking.user.name || "",
|
||||
email: booking.user.email,
|
||||
timeZone: booking.user.timeZone,
|
||||
}
|
||||
: { name: "", email: "", timeZone: "" },
|
||||
startTime: booking.startTime.toISOString(),
|
||||
title: booking.title,
|
||||
};
|
||||
|
@ -485,8 +489,12 @@ export const workflowsRouter = createProtectedRouter()
|
|||
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
||||
}),
|
||||
organizer: booking.user
|
||||
? { name: booking.user.name || "", email: booking.user.email }
|
||||
: { name: "", email: "" },
|
||||
? {
|
||||
name: booking.user.name || "",
|
||||
email: booking.user.email,
|
||||
timeZone: booking.user.timeZone,
|
||||
}
|
||||
: { name: "", email: "", timeZone: "" },
|
||||
startTime: booking.startTime.toISOString(),
|
||||
title: booking.title,
|
||||
};
|
||||
|
@ -578,8 +586,12 @@ export const workflowsRouter = createProtectedRouter()
|
|||
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
||||
}),
|
||||
organizer: booking.user
|
||||
? { name: booking.user.name || "", email: booking.user.email }
|
||||
: { name: "", email: "" },
|
||||
? {
|
||||
name: booking.user.name || "",
|
||||
email: booking.user.email,
|
||||
timeZone: booking.user.timeZone,
|
||||
}
|
||||
: { name: "", email: "", timeZone: "" },
|
||||
startTime: booking.startTime.toISOString(),
|
||||
title: booking.title,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue