Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: undefined in meeting url workflow variable #16771

Merged
merged 14 commits into from
Sep 30, 2024
12 changes: 12 additions & 0 deletions packages/features/bookings/lib/handleCancelBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { deleteWebhookScheduledTriggers } from "@calcom/features/webhooks/lib/sc
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
import type { EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
import { HttpError } from "@calcom/lib/http-error";
Expand Down Expand Up @@ -275,7 +276,18 @@ async function handler(req: CustomRequest) {
const teamMembers = await Promise.all(teamMembersPromises);
const tOrganizer = await getTranslation(organizer.locale ?? "en", "common");

const ownerProfile = await prisma.profile.findFirst({
where: {
userId: bookingToDelete.userId,
},
});

const bookerUrl = await getBookerBaseUrl(
bookingToDelete.eventType?.team?.parentId ?? ownerProfile?.organizationId ?? null
);

const evt: CalendarEvent = {
bookerUrl,
title: bookingToDelete?.title,
length: bookingToDelete?.eventType?.length,
type: bookingToDelete?.eventType?.slug as string,
Expand Down
18 changes: 16 additions & 2 deletions packages/features/ee/round-robin/roundRobinReassignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
import { isPrismaObjOrUndefined } from "@calcom/lib";
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import logger from "@calcom/lib/logger";
import { getLuckyUser } from "@calcom/lib/server";
import { getTranslation } from "@calcom/lib/server/i18n";
Expand Down Expand Up @@ -50,7 +51,13 @@ const bookingSelect = {
references: true,
};

export const roundRobinReassignment = async ({ bookingId }: { bookingId: number }) => {
export const roundRobinReassignment = async ({
bookingId,
orgId,
}: {
bookingId: number;
orgId: number | null;
}) => {
const roundRobinReassignLogger = logger.getSubLogger({
prefix: ["roundRobinReassign", `${bookingId}`],
});
Expand Down Expand Up @@ -308,6 +315,8 @@ export const roundRobinReassignment = async ({ bookingId }: { bookingId: number
})
: null;

const bookerUrl = await getBookerBaseUrl(orgId);

const evt: CalendarEvent = {
organizer: {
name: organizer.name || "",
Expand All @@ -319,6 +328,7 @@ export const roundRobinReassignment = async ({ bookingId }: { bookingId: number
timeZone: organizer.timeZone,
timeFormat: getTimeFormatStringFromUserTimeFormat(organizer.timeFormat),
},
bookerUrl,
startTime: dayjs(booking.startTime).utc().format(),
endTime: dayjs(booking.endTime).utc().format(),
type: eventType.slug,
Expand Down Expand Up @@ -538,7 +548,11 @@ export const roundRobinReassignment = async ({ bookingId }: { bookingId: number
await scheduleWorkflowReminders({
workflows: newEventWorkflows,
smsReminderNumber: null,
calendarEvent: { ...evt, metadata: workflowEventMetadata, eventType: { slug: eventType.slug } },
calendarEvent: {
...evt,
metadata: workflowEventMetadata,
eventType: { slug: eventType.slug },
},
hideBranding: !!eventType?.owner?.hideBranding,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { v4 as uuidv4 } from "uuid";
import { guessEventLocationType } from "@calcom/app-store/locations";
import dayjs from "@calcom/dayjs";
import { preprocessNameFieldDataWithVariant } from "@calcom/features/form-builder/utils";
import { WEBSITE_URL } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import prisma from "@calcom/prisma";
import type { TimeUnit } from "@calcom/prisma/enums";
Expand Down Expand Up @@ -189,6 +190,8 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
emailSubject,
emailBody: `<body style="white-space: pre-wrap;">${emailBody}</body>`,
};
const bookerUrl = evt.bookerUrl ?? WEBSITE_URL;

if (emailBody) {
const variables: VariablesType = {
eventName: evt.title || "",
Expand All @@ -204,10 +207,10 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
additionalNotes: evt.additionalNotes,
responses: evt.responses,
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`,
cancelLink: `${bookerUrl}/booking/${evt.uid}?cancel=true`,
rescheduleLink: `${bookerUrl}/reschedule/${evt.uid}`,
ratingUrl: `${bookerUrl}/booking/${evt.uid}?rating`,
noShowUrl: `${bookerUrl}/booking/${evt.uid}?noShow=true`,
};

const locale =
Expand Down Expand Up @@ -247,8 +250,8 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
timeZone,
organizer: evt.organizer.name,
name,
ratingUrl: `${evt.bookerUrl}/booking/${evt.uid}?rating`,
noShowUrl: `${evt.bookerUrl}/booking/${evt.uid}?noShow=true`,
ratingUrl: `${bookerUrl}/booking/${evt.uid}?rating`,
noShowUrl: `${bookerUrl}/booking/${evt.uid}?noShow=true`,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dayjs from "@calcom/dayjs";
import { SENDER_ID } from "@calcom/lib/constants";
import { SENDER_ID, WEBSITE_URL } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import type { TimeFormat } from "@calcom/lib/timeFormat";
import type { PrismaClient } from "@calcom/prisma";
Expand Down Expand Up @@ -158,8 +158,8 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => {
additionalNotes: evt.additionalNotes,
responses: evt.responses,
meetingUrl: bookingMetadataSchema.parse(evt.metadata || {})?.videoCallUrl,
cancelLink: `${evt.bookerUrl}/booking/${evt.uid}?cancel=true`,
rescheduleLink: `${evt.bookerUrl}/reschedule/${evt.uid}`,
cancelLink: `${evt.bookerUrl ?? WEBSITE_URL}/booking/${evt.uid}?cancel=true`,
rescheduleLink: `${evt.bookerUrl ?? WEBSITE_URL}/reschedule/${evt.uid}`,
};
const customMessage = customTemplate(smsMessage, variables, locale, evt.organizer.timeFormat);
smsMessage = customMessage.text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const roundRobinReassignHandler = async ({ ctx, input }: RoundRobinReassi
throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permission" });
}

await roundRobinReassignment({ bookingId });
await roundRobinReassignment({ bookingId, orgId: ctx.user.organizationId });
};

export default roundRobinReassignHandler;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { scheduleEmailReminder } from "@calcom/features/ee/workflows/lib/reminders/emailReminderManager";
import { scheduleSMSReminder } from "@calcom/features/ee/workflows/lib/reminders/smsReminderManager";
import { scheduleWhatsappReminder } from "@calcom/features/ee/workflows/lib/reminders/whatsappReminderManager";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
import { prisma } from "@calcom/prisma";
import { BookingStatus } from "@calcom/prisma/client";
Expand Down Expand Up @@ -224,10 +225,13 @@ export const activateEventTypeHandler = async ({ ctx, input }: ActivateEventType
},
});

const bookerUrl = await getBookerBaseUrl(ctx.user.organizationId ?? null);

for (const booking of bookingsForReminders) {
const defaultLocale = "en";
const bookingInfo = {
uid: booking.uid,
bookerUrl,
attendees: booking.attendees.map((attendee) => {
return {
name: attendee.name,
Expand Down
11 changes: 9 additions & 2 deletions packages/trpc/server/routers/viewer/workflows/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "@calcom/features/bookings/lib/getBookingFields";
import { removeBookingField, upsertBookingField } from "@calcom/features/eventtypes/lib/bookingFieldsManager";
import { SENDER_ID, SENDER_NAME } from "@calcom/lib/constants";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
import logger from "@calcom/lib/logger";
Expand Down Expand Up @@ -606,7 +607,8 @@ export async function scheduleWorkflowNotifications(
timeUnit,
trigger,
userId,
teamId
teamId,
isOrg
);
}

Expand Down Expand Up @@ -712,10 +714,14 @@ export async function scheduleBookingReminders(
timeUnit: TimeUnit | null,
trigger: WorkflowTriggerEvents,
userId: number,
teamId: number | null
teamId: number | null,
isOrg: boolean
) {
if (!bookings.length) return;
if (trigger !== WorkflowTriggerEvents.BEFORE_EVENT && trigger !== WorkflowTriggerEvents.AFTER_EVENT) return;

const bookerUrl = await getBookerBaseUrl(isOrg ? teamId : null);

//create reminders for all bookings for each workflow step
const promiseSteps = workflowSteps.map(async (step) => {
// we do not have attendees phone number (user is notified about that when setting this action)
Expand All @@ -726,6 +732,7 @@ export async function scheduleBookingReminders(
const defaultLocale = "en";
const bookingInfo = {
uid: booking.uid,
bookerUrl,
attendees: booking.attendees.map((attendee) => {
return {
name: attendee.name,
Expand Down
Loading