-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Send Attendee No Show Data To Salesforce (#17423)
- Loading branch information
1 parent
ebd5ca6
commit 06f83e6
Showing
8 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/features/noShow/handleSendingAttendeeNoShowDataToApps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { z } from "zod"; | ||
|
||
import type { eventTypeAppCardZod } from "@calcom/app-store/eventTypeAppCardZod"; | ||
import CrmManager from "@calcom/core/crmManager/crmManager"; | ||
import logger from "@calcom/lib/logger"; | ||
import prisma from "@calcom/prisma"; | ||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; | ||
|
||
import type { NoShowAttendees } from "../handleMarkNoShow"; | ||
import { noShowEnabledApps } from "./noShowEnabledApps"; | ||
|
||
const log = logger.getSubLogger({ prefix: ["handleSendingNoShowDataToApps"] }); | ||
|
||
export default async function handleSendingAttendeeNoShowDataToApps( | ||
bookingUid: string, | ||
attendees: NoShowAttendees | ||
) { | ||
// Get event type metadata | ||
const eventTypeQuery = await prisma.booking.findFirst({ | ||
where: { | ||
uid: bookingUid, | ||
}, | ||
select: { | ||
eventType: { | ||
select: { | ||
metadata: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
if (!eventTypeQuery || !eventTypeQuery?.eventType?.metadata) { | ||
log.warn(`For no show, could not find eventType for bookingUid ${bookingUid}`); | ||
return; | ||
} | ||
|
||
const eventTypeMetadataParse = EventTypeMetaDataSchema.safeParse(eventTypeQuery?.eventType?.metadata); | ||
if (!eventTypeMetadataParse.success) { | ||
log.error(`Malformed event type metadata for bookingUid ${bookingUid}`); | ||
return; | ||
} | ||
const eventTypeAppMetadata = eventTypeMetadataParse.data?.apps; | ||
|
||
for (const slug in eventTypeAppMetadata) { | ||
if (noShowEnabledApps.includes(slug)) { | ||
const app = eventTypeAppMetadata[slug as keyof typeof eventTypeAppMetadata]; | ||
|
||
const appCategory = app.appCategories[0]; | ||
|
||
if (appCategory === "crm") { | ||
await handleCRMNoShow(bookingUid, app, attendees); | ||
} | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
async function handleCRMNoShow( | ||
bookingUid: string, | ||
appData: z.infer<typeof eventTypeAppCardZod>, | ||
attendees: NoShowAttendees | ||
) { | ||
// Handle checking if no she in CrmService | ||
|
||
const credential = await prisma.credential.findFirst({ | ||
where: { | ||
id: appData.credentialId, | ||
}, | ||
include: { | ||
user: { | ||
select: { | ||
email: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!credential) { | ||
log.warn(`CRM credential not found for bookingUid ${bookingUid}`); | ||
return; | ||
} | ||
|
||
const crm = new CrmManager(credential, appData); | ||
await crm.handleAttendeeNoShow(bookingUid, attendees); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** Slugs of apps that have the option to send no show data to */ | ||
export const noShowEnabledApps = ["salesforce"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters