feat: Dub App integration (#21321)
Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
35 files changed
+518
-2
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { getAnalyticsService } from "@calcom/app-store/_utils/getAnalytics";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { AnalyticsService, SendEventProps } from "@calcom/types/AnalyticsService";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["AnalyticsManager"] });
|
||||
export default class AnalyticsManager {
|
||||
analyticsService: AnalyticsService | null | undefined = null;
|
||||
credential: CredentialPayload;
|
||||
|
||||
constructor(credential: CredentialPayload) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
private async getAnalyticsService(credential: CredentialPayload) {
|
||||
if (this.analyticsService) return this.analyticsService;
|
||||
const analyticsService = await getAnalyticsService({ credential });
|
||||
this.analyticsService = analyticsService;
|
||||
|
||||
if (!this.analyticsService) {
|
||||
log.error("Analytics service initialization failed");
|
||||
}
|
||||
|
||||
return analyticsService;
|
||||
}
|
||||
|
||||
public async sendEvent(props: SendEventProps) {
|
||||
const analyticsService = await this.getAnalyticsService(this.credential);
|
||||
if (!analyticsService) return;
|
||||
|
||||
return await analyticsService.sendEvent(props);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import tasker from "@calcom/features/tasker";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
|
||||
interface HandleAnalyticsEventsProps {
|
||||
credentials: CredentialForCalendarService[];
|
||||
rawBookingData: Record<string, any>;
|
||||
bookingInfo: {
|
||||
email: string;
|
||||
name: string;
|
||||
eventName: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const handleAnalyticsEvents = async ({
|
||||
credentials,
|
||||
rawBookingData,
|
||||
bookingInfo,
|
||||
}: HandleAnalyticsEventsProps) => {
|
||||
const { dub_id } = await rawBookingData;
|
||||
|
||||
if (!dub_id || typeof dub_id !== "string") return;
|
||||
|
||||
const dubCredential = credentials.find((cred) => cred.appId === "dub");
|
||||
|
||||
if (!dubCredential) return;
|
||||
|
||||
try {
|
||||
await tasker.create("sendAnalyticsEvent", {
|
||||
credentialId: dubCredential.id,
|
||||
info: {
|
||||
id: dub_id,
|
||||
...bookingInfo,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error sending dub lead: ", err);
|
||||
}
|
||||
};
|
||||
@@ -12,6 +12,14 @@ type CredentialCreateInput = {
|
||||
delegationCredentialId?: string | null;
|
||||
};
|
||||
|
||||
type CredentialUpdateInput = {
|
||||
type?: string;
|
||||
key?: any;
|
||||
userId?: number;
|
||||
appId?: string;
|
||||
delegationCredentialId?: string | null;
|
||||
};
|
||||
|
||||
export class CredentialRepository {
|
||||
static async create(data: CredentialCreateInput) {
|
||||
const credential = await prisma.credential.create({ data: { ...data } });
|
||||
@@ -64,6 +72,13 @@ export class CredentialRepository {
|
||||
await prisma.credential.delete({ where: { id } });
|
||||
}
|
||||
|
||||
static async updateCredentialById({ id, data }: { id: number; data: CredentialUpdateInput }) {
|
||||
await prisma.credential.update({
|
||||
where: { id },
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
static async deleteAllByDelegationCredentialId({
|
||||
delegationCredentialId,
|
||||
}: {
|
||||
|
||||
Reference in new issue
Block a user