fix: meeting url variable in workflow notifitcations (#12308)
Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
1 parent
621f7639ff
commit
f29328e6a2
4 files changed
+52
-7
No files matched your search
@@ -12,9 +12,14 @@ import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
|||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import type { PrismaClient } from "@calcom/prisma";
|
import type { PrismaClient } from "@calcom/prisma";
|
||||||
import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||||
import { bookingMetadataSchema } from "@calcom/prisma/zod-utils";
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
|
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
|
||||||
|
|
||||||
|
import {
|
||||||
|
allowDisablingAttendeeConfirmationEmails,
|
||||||
|
allowDisablingHostConfirmationEmails,
|
||||||
|
} from "../../ee/workflows/lib/allowDisablingStandardEmails";
|
||||||
|
|
||||||
const log = logger.getSubLogger({ prefix: ["[handleConfirmation] book:user"] });
|
const log = logger.getSubLogger({ prefix: ["[handleConfirmation] book:user"] });
|
||||||
|
|
||||||
export async function handleConfirmation(args: {
|
export async function handleConfirmation(args: {
|
||||||
@@ -31,10 +36,17 @@ export async function handleConfirmation(args: {
|
|||||||
length: number;
|
length: number;
|
||||||
price: number;
|
price: number;
|
||||||
requiresConfirmation: boolean;
|
requiresConfirmation: boolean;
|
||||||
|
metadata?: Prisma.JsonValue;
|
||||||
title: string;
|
title: string;
|
||||||
teamId?: number | null;
|
teamId?: number | null;
|
||||||
parentId?: number | null;
|
parentId?: number | null;
|
||||||
|
workflows?: {
|
||||||
|
workflow: Workflow & {
|
||||||
|
steps: WorkflowStep[];
|
||||||
|
};
|
||||||
|
}[];
|
||||||
} | null;
|
} | null;
|
||||||
|
metadata?: Prisma.JsonValue;
|
||||||
eventTypeId: number | null;
|
eventTypeId: number | null;
|
||||||
smsReminderNumber: string | null;
|
smsReminderNumber: string | null;
|
||||||
userId: number | null;
|
userId: number | null;
|
||||||
@@ -45,6 +57,7 @@ export async function handleConfirmation(args: {
|
|||||||
const eventManager = new EventManager(user);
|
const eventManager = new EventManager(user);
|
||||||
const scheduleResult = await eventManager.create(evt);
|
const scheduleResult = await eventManager.create(evt);
|
||||||
const results = scheduleResult.results;
|
const results = scheduleResult.results;
|
||||||
|
const metadata: AdditionalInformation = {};
|
||||||
|
|
||||||
if (results.length > 0 && results.every((res) => !res.success)) {
|
if (results.length > 0 && results.every((res) => !res.success)) {
|
||||||
const error = {
|
const error = {
|
||||||
@@ -54,8 +67,6 @@ export async function handleConfirmation(args: {
|
|||||||
|
|
||||||
log.error(`Booking ${user.username} failed`, JSON.stringify({ error, results }));
|
log.error(`Booking ${user.username} failed`, JSON.stringify({ error, results }));
|
||||||
} else {
|
} else {
|
||||||
const metadata: AdditionalInformation = {};
|
|
||||||
|
|
||||||
if (results.length) {
|
if (results.length) {
|
||||||
// TODO: Handle created event metadata more elegantly
|
// TODO: Handle created event metadata more elegantly
|
||||||
metadata.hangoutLink = results[0].createdEvent?.hangoutLink;
|
metadata.hangoutLink = results[0].createdEvent?.hangoutLink;
|
||||||
@@ -63,7 +74,34 @@ export async function handleConfirmation(args: {
|
|||||||
metadata.entryPoints = results[0].createdEvent?.entryPoints;
|
metadata.entryPoints = results[0].createdEvent?.entryPoints;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await sendScheduledEmails({ ...evt, additionalInformation: metadata });
|
const eventType = booking.eventType;
|
||||||
|
const eventTypeMetadata = EventTypeMetaDataSchema.parse(eventType?.metadata || {});
|
||||||
|
let isHostConfirmationEmailsDisabled = false;
|
||||||
|
let isAttendeeConfirmationEmailDisabled = false;
|
||||||
|
|
||||||
|
const workflows = eventType?.workflows?.map((workflow) => workflow.workflow);
|
||||||
|
|
||||||
|
if (workflows) {
|
||||||
|
isHostConfirmationEmailsDisabled =
|
||||||
|
eventTypeMetadata?.disableStandardEmails?.confirmation?.host || false;
|
||||||
|
isAttendeeConfirmationEmailDisabled =
|
||||||
|
eventTypeMetadata?.disableStandardEmails?.confirmation?.attendee || false;
|
||||||
|
|
||||||
|
if (isHostConfirmationEmailsDisabled) {
|
||||||
|
isHostConfirmationEmailsDisabled = allowDisablingHostConfirmationEmails(workflows);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAttendeeConfirmationEmailDisabled) {
|
||||||
|
isAttendeeConfirmationEmailDisabled = allowDisablingAttendeeConfirmationEmails(workflows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await sendScheduledEmails(
|
||||||
|
{ ...evt, additionalInformation: metadata },
|
||||||
|
undefined,
|
||||||
|
isHostConfirmationEmailsDisabled,
|
||||||
|
isAttendeeConfirmationEmailDisabled
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(error);
|
log.error(error);
|
||||||
}
|
}
|
||||||
@@ -97,6 +135,8 @@ export async function handleConfirmation(args: {
|
|||||||
} | null;
|
} | null;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
|
const videoCallUrl = metadata.hangoutLink ? metadata.hangoutLink : evt.videoCallData?.url || "";
|
||||||
|
|
||||||
if (recurringEventId) {
|
if (recurringEventId) {
|
||||||
// The booking to confirm is a recurring event and comes from /booking/recurring, proceeding to mark all related
|
// The booking to confirm is a recurring event and comes from /booking/recurring, proceeding to mark all related
|
||||||
// bookings as confirmed. Prisma updateMany does not support relations, so doing this in two steps for now.
|
// bookings as confirmed. Prisma updateMany does not support relations, so doing this in two steps for now.
|
||||||
@@ -118,6 +158,10 @@ export async function handleConfirmation(args: {
|
|||||||
create: scheduleResult.referencesToCreate,
|
create: scheduleResult.referencesToCreate,
|
||||||
},
|
},
|
||||||
paid,
|
paid,
|
||||||
|
metadata: {
|
||||||
|
...(typeof recurringBooking.metadata === "object" ? recurringBooking.metadata : {}),
|
||||||
|
videoCallUrl,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
eventType: {
|
eventType: {
|
||||||
@@ -169,6 +213,7 @@ export async function handleConfirmation(args: {
|
|||||||
references: {
|
references: {
|
||||||
create: scheduleResult.referencesToCreate,
|
create: scheduleResult.referencesToCreate,
|
||||||
},
|
},
|
||||||
|
metadata: { ...(typeof booking.metadata === "object" ? booking.metadata : {}), videoCallUrl },
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
eventType: {
|
eventType: {
|
||||||
@@ -218,8 +263,6 @@ export async function handleConfirmation(args: {
|
|||||||
const eventTypeSlug = updatedBookings[index].eventType?.slug || "";
|
const eventTypeSlug = updatedBookings[index].eventType?.slug || "";
|
||||||
|
|
||||||
const isFirstBooking = index === 0;
|
const isFirstBooking = index === 0;
|
||||||
const videoCallUrl =
|
|
||||||
bookingMetadataSchema.parse(updatedBookings[index].metadata || {})?.videoCallUrl || "";
|
|
||||||
|
|
||||||
await scheduleWorkflowReminders({
|
await scheduleWorkflowReminders({
|
||||||
workflows: updatedBookings[index]?.eventType?.workflows || [],
|
workflows: updatedBookings[index]?.eventType?.workflows || [],
|
||||||
|
|||||||
@@ -2516,7 +2516,7 @@ async function handler(
|
|||||||
...evt,
|
...evt,
|
||||||
...{ metadata: metadataFromEvent, eventType: { slug: eventType.slug } },
|
...{ metadata: metadataFromEvent, eventType: { slug: eventType.slug } },
|
||||||
},
|
},
|
||||||
isNotConfirmed: evt.requiresConfirmation || false,
|
isNotConfirmed: !isConfirmedByDefault,
|
||||||
isRescheduleEvent: !!rescheduleUid,
|
isRescheduleEvent: !!rescheduleUid,
|
||||||
isFirstRecurringEvent: true,
|
isFirstRecurringEvent: true,
|
||||||
hideBranding: !!eventType.owner?.hideBranding,
|
hideBranding: !!eventType.owner?.hideBranding,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export async function getBooking(bookingId: number) {
|
|||||||
...bookingMinimalSelect,
|
...bookingMinimalSelect,
|
||||||
responses: true,
|
responses: true,
|
||||||
eventType: true,
|
eventType: true,
|
||||||
|
metadata: true,
|
||||||
smsReminderNumber: true,
|
smsReminderNumber: true,
|
||||||
location: true,
|
location: true,
|
||||||
eventTypeId: true,
|
eventTypeId: true,
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
|||||||
attendees: true,
|
attendees: true,
|
||||||
eventTypeId: true,
|
eventTypeId: true,
|
||||||
responses: true,
|
responses: true,
|
||||||
|
metadata: true,
|
||||||
eventType: {
|
eventType: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
Reference in new issue
Block a user