feat: AI Transcribe (#14140)

* chore: transcribe

* chore: provider

* chore: use daily provider

* chore: rebase

* chore: remove types file

* chore: remove recoil

* chore: progress

* chore: add recoil

* chore: save progress

* chore: save progress

* fix: type err

* fix: err

* fix: save progress

* feat: finish emails

* chore: add new env variable

* chore: fix type err

* chore: turbo

* chore: improvements

---------

Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-04-17 11:09:11 -04:00
1 parent ebca5c6409
commit b9ac22d4ed
20 files changed
+859 -55

No files matched your search

@@ -30,9 +30,30 @@ const dailyReturnTypeSchema = z.object({
enable_chat: z.boolean(),
enable_knocking: z.boolean(),
enable_prejoin_ui: z.boolean(),
enable_transcription_storage: z.boolean(),
}),
});
const getTranscripts = z.object({
total_count: z.number(),
data: z.array(
z.object({
transcriptId: z.string(),
domainId: z.string(),
roomId: z.string(),
mtgSessionId: z.string(),
duration: z.number(),
status: z.string(),
})
),
});
const getRooms = z
.object({
id: z.string(),
})
.passthrough();
export interface DailyEventResult {
id: string;
name: string;
@@ -86,6 +107,33 @@ function postToDailyAPI(endpoint: string, body: Record<string, unknown>) {
});
}
async function processTranscriptsInBatches(transcriptIds: Array<string>) {
const batchSize = 5; // Batch size
const batches = []; // Array to hold batches of transcript IDs
// Split transcript IDs into batches
for (let i = 0; i < transcriptIds.length; i += batchSize) {
batches.push(transcriptIds.slice(i, i + batchSize));
}
const allTranscriptsAccessLinks = []; // Array to hold all access links
// Process each batch sequentially
for (const batch of batches) {
const batchPromises = batch.map((id) =>
fetcher(`/transcript/${id}/access-link`)
.then(z.object({ link: z.string() }).parse)
.then((res) => res.link)
);
const accessLinks = await Promise.all(batchPromises);
allTranscriptsAccessLinks.push(...accessLinks);
}
return allTranscriptsAccessLinks;
}
const DailyVideoApiAdapter = (): VideoApiAdapter => {
async function createOrUpdateMeeting(endpoint: string, event: CalendarEvent): Promise<VideoCallData> {
if (!event.uid) {
@@ -120,19 +168,18 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {
},
},
});
if (scalePlan === "true" && !!hasTeamPlan === true) {
return {
privacy: "public",
properties: {
enable_prejoin_ui: true,
enable_knocking: true,
enable_screenshare: true,
enable_chat: true,
exp: exp,
enable_recording: "cloud",
},
};
}
// Check if organizer has subscribed to Cal.ai
const isCalAiSubscribed = await prisma.credential.findMany({
where: {
userId: event.organizer.id,
type: "cal-ai_automation",
invalid: false,
paymentStatus: "active",
},
});
return {
privacy: "public",
properties: {
@@ -141,6 +188,11 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {
enable_screenshare: true,
enable_chat: true,
exp: exp,
enable_recording: scalePlan === "true" && !!hasTeamPlan === true ? "cloud" : undefined,
enable_transcription_storage: !!isCalAiSubscribed,
permissions: {
canAdmin: ["transcription"],
},
},
};
};
@@ -159,6 +211,7 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {
exp: exp,
enable_recording: "cloud",
start_video_off: true,
enable_transcription_storage: true,
},
};
@@ -210,6 +263,24 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {
throw new Error("Something went wrong! Unable to get recording access link");
}
},
getAllTranscriptsAccessLinkFromRoomName: async (roomName: string): Promise<Array<string>> => {
try {
const res = await fetcher(`/rooms/${roomName}`).then(getRooms.parse);
const roomId = res.id;
const allTranscripts = await fetcher(`/transcript?roomId=${roomId}`).then(getTranscripts.parse);
const allTranscriptsIds = allTranscripts.data.map((transcript) => transcript.transcriptId);
const allTranscriptsAccessLink = await processTranscriptsInBatches(allTranscriptsIds);
const accessLinks = await Promise.all(allTranscriptsAccessLink);
return Promise.resolve(accessLinks);
} catch (err) {
console.log("err", err);
throw new Error("Something went wrong! Unable to get transcription access link");
}
},
};
};
+24
View File
@@ -274,6 +274,29 @@ const getDownloadLinkOfCalVideoByRecordingId = async (recordingId: string) => {
return videoAdapter?.getRecordingDownloadLink?.(recordingId);
};
const getAllTranscriptsAccessLinkFromRoomName = async (roomName: string) => {
let dailyAppKeys: Awaited<ReturnType<typeof getDailyAppKeys>>;
try {
dailyAppKeys = await getDailyAppKeys();
} catch (e) {
console.error("Error: Cal video provider is not installed.");
return;
}
const [videoAdapter] = await getVideoAdapters([
{
id: 0,
appId: "daily-video",
type: "daily_video",
userId: null,
user: { email: "" },
teamId: null,
key: dailyAppKeys,
invalid: false,
},
]);
return videoAdapter?.getAllTranscriptsAccessLinkFromRoomName?.(roomName);
};
export {
getBusyVideoTimes,
createMeeting,
@@ -281,4 +304,5 @@ export {
deleteMeeting,
getRecordingsOfCalVideoByRoomName,
getDownloadLinkOfCalVideoByRecordingId,
getAllTranscriptsAccessLinkFromRoomName,
};
+15
View File
@@ -17,6 +17,7 @@ import AttendeeAwaitingPaymentEmail from "./templates/attendee-awaiting-payment-
import AttendeeCancelledEmail from "./templates/attendee-cancelled-email";
import AttendeeCancelledSeatEmail from "./templates/attendee-cancelled-seat-email";
import AttendeeDailyVideoDownloadRecordingEmail from "./templates/attendee-daily-video-download-recording-email";
import AttendeeDailyVideoDownloadTranscriptEmail from "./templates/attendee-daily-video-download-transcript-email";
import AttendeeDeclinedEmail from "./templates/attendee-declined-email";
import AttendeeLocationChangeEmail from "./templates/attendee-location-change-email";
import AttendeeRequestEmail from "./templates/attendee-request-email";
@@ -46,6 +47,7 @@ import OrganizationEmailVerification from "./templates/organization-email-verifi
import OrganizerAttendeeCancelledSeatEmail from "./templates/organizer-attendee-cancelled-seat-email";
import OrganizerCancelledEmail from "./templates/organizer-cancelled-email";
import OrganizerDailyVideoDownloadRecordingEmail from "./templates/organizer-daily-video-download-recording-email";
import OrganizerDailyVideoDownloadTranscriptEmail from "./templates/organizer-daily-video-download-transcript-email";
import OrganizerLocationChangeEmail from "./templates/organizer-location-change-email";
import OrganizerPaymentRefundFailedEmail from "./templates/organizer-payment-refund-failed-email";
import OrganizerRequestEmail from "./templates/organizer-request-email";
@@ -481,6 +483,19 @@ export const sendDailyVideoRecordingEmails = async (calEvent: CalendarEvent, dow
await Promise.all(emailsToSend);
};
export const sendDailyVideoTranscriptEmails = async (calEvent: CalendarEvent, transcripts: string[]) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(sendEmail(() => new OrganizerDailyVideoDownloadTranscriptEmail(calEvent, transcripts)));
for (const attendee of calEvent.attendees) {
emailsToSend.push(
sendEmail(() => new AttendeeDailyVideoDownloadTranscriptEmail(calEvent, attendee, transcripts))
);
}
await Promise.all(emailsToSend);
};
export const sendOrganizationEmailVerification = async (sendOrgInput: OrganizationEmailVerify) => {
await sendEmail(() => new OrganizationEmailVerification(sendOrgInput));
};
@@ -0,0 +1,103 @@
import type { TFunction } from "next-i18next";
import { WEBAPP_URL, APP_NAME, COMPANY_NAME } from "@calcom/lib/constants";
import { V2BaseEmailHtml, CallToAction } from "../components";
interface DailyVideoDownloadTranscriptEmailProps {
language: TFunction;
transcriptDownloadLinks: Array<string>;
title: string;
date: string;
name: string;
}
export const DailyVideoDownloadTranscriptEmail = (
props: DailyVideoDownloadTranscriptEmailProps & Partial<React.ComponentProps<typeof V2BaseEmailHtml>>
) => {
const image = `${WEBAPP_URL}/emails/logo.png`;
return (
<V2BaseEmailHtml
subject={props.language("download_transcript_email_subject", {
title: props.title,
date: props.date,
})}>
<div style={{ width: "89px", marginBottom: "35px" }}>
<a href={WEBAPP_URL} target="_blank" rel="noreferrer">
<img
height="19"
src={image}
style={{
border: "0",
display: "block",
outline: "none",
textDecoration: "none",
height: "19px",
width: "100%",
fontSize: "13px",
}}
width="89"
alt=""
/>
</a>
</div>
<p
style={{
fontSize: "32px",
fontWeight: "600",
lineHeight: "38.5px",
marginBottom: "40px",
color: "black",
}}>
<>{props.language("download_your_transcripts")}</>
</p>
<p style={{ fontWeight: 400, lineHeight: "24px" }}>
<>{props.language("hi_user_name", { name: props.name })},</>
</p>
<p style={{ fontWeight: 400, lineHeight: "24px", marginBottom: "40px" }}>
<>{props.language("transcript_from_previous_call", { appName: APP_NAME })}</>
</p>
{props.transcriptDownloadLinks.map((downloadLink, index) => {
return (
<div
key={downloadLink}
style={{
backgroundColor: "#F3F4F6",
padding: "32px",
marginBottom: "40px",
}}>
<p
style={{
fontSize: "18px",
lineHeight: "20px",
fontWeight: 600,
marginBottom: "8px",
color: "black",
}}>
<>{props.title}</>
</p>
<p
style={{
fontWeight: 400,
lineHeight: "24px",
marginBottom: "24px",
marginTop: "0px",
color: "black",
}}>
{props.date} Transcript {index + 1}
</p>
<CallToAction label={props.language("download_transcript")} href={downloadLink} />
</div>
);
})}
<p style={{ fontWeight: 400, lineHeight: "24px", marginTop: "32px", marginBottom: "8px" }}>
<>{props.language("happy_scheduling")},</>
</p>
<p style={{ fontWeight: 400, lineHeight: "24px", marginTop: "0px" }}>
<>{props.language("the_calcom_team", { companyName: COMPANY_NAME })}</>
</p>
</V2BaseEmailHtml>
);
};
+1
View File
@@ -27,6 +27,7 @@ export { VerifyAccountEmail } from "./VerifyAccountEmail";
export { VerifyEmailByCode } from "./VerifyEmailByCode";
export * from "@calcom/app-store/routing-forms/emails/components";
export { DailyVideoDownloadRecordingEmail } from "./DailyVideoDownloadRecordingEmail";
export { DailyVideoDownloadTranscriptEmail } from "./DailyVideoDownloadTranscriptEmail";
export { OrganisationAccountVerifyEmail } from "./OrganizationAccountVerifyEmail";
export { OrgAutoInviteEmail } from "./OrgAutoInviteEmail";
export { MonthlyDigestEmail } from "./MonthlyDigestEmail";
@@ -0,0 +1,71 @@
import type { TFunction } from "next-i18next";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
import BaseEmail from "./_base-email";
export default class AttendeeDailyVideoDownloadTranscriptEmail extends BaseEmail {
calEvent: CalendarEvent;
attendee: Person;
transcriptDownloadLinks: Array<string>;
t: TFunction;
constructor(calEvent: CalendarEvent, attendee: Person, transcriptDownloadLinks: string[]) {
super();
this.name = "SEND_TRANSCRIPT_DOWNLOAD_LINK";
this.calEvent = calEvent;
this.attendee = attendee;
this.transcriptDownloadLinks = transcriptDownloadLinks;
this.t = attendee.language.translate;
}
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: [...this.calEvent.attendees.map(({ email }) => email), this.calEvent.organizer.email],
subject: `${this.t("download_transcript_email_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
})}`,
html: await renderEmail("DailyVideoDownloadTranscriptEmail", {
title: this.calEvent.title,
date: this.getFormattedDate(),
transcriptDownloadLinks: this.transcriptDownloadLinks,
language: this.t,
name: this.attendee.name,
}),
};
}
protected getTimezone(): string {
return this.attendee.timeZone;
}
protected getLocale(): string {
return this.attendee.language.locale;
}
protected getInviteeStart(format: string) {
return this.getFormattedRecipientTime({
time: this.calEvent.startTime,
format,
});
}
protected getInviteeEnd(format: string) {
return this.getFormattedRecipientTime({
time: this.calEvent.endTime,
format,
});
}
protected getFormattedDate() {
const inviteeTimeFormat = this.attendee.timeFormat || TimeFormat.TWELVE_HOUR;
return `${this.getInviteeStart(inviteeTimeFormat)} - ${this.getInviteeEnd(inviteeTimeFormat)}, ${this.t(
this.getInviteeStart("dddd").toLowerCase()
)}, ${this.t(this.getInviteeStart("MMMM").toLowerCase())} ${this.getInviteeStart("D, YYYY")}`;
}
}
@@ -0,0 +1,66 @@
import type { TFunction } from "next-i18next";
import { APP_NAME } from "@calcom/lib/constants";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { renderEmail } from "..";
import BaseEmail from "./_base-email";
export default class OrganizerDailyVideoDownloadTranscriptEmail extends BaseEmail {
calEvent: CalendarEvent;
transcriptDownloadLinks: Array<string>;
t: TFunction;
constructor(calEvent: CalendarEvent, transcriptDownloadLinks: string[]) {
super();
this.name = "SEND_TRANSCRIPT_DOWNLOAD_LINK";
this.calEvent = calEvent;
this.transcriptDownloadLinks = transcriptDownloadLinks;
this.t = this.calEvent.organizer.language.translate;
}
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
return {
to: `${this.calEvent.organizer.email}>`,
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
replyTo: [...this.calEvent.attendees.map(({ email }) => email), this.calEvent.organizer.email],
subject: `${this.t("download_transcript_email_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
})}`,
html: await renderEmail("DailyVideoDownloadTranscriptEmail", {
title: this.calEvent.title,
date: this.getFormattedDate(),
transcriptDownloadLinks: this.transcriptDownloadLinks,
language: this.t,
name: this.calEvent.organizer.name,
}),
};
}
protected getTimezone(): string {
return this.calEvent.organizer.timeZone;
}
protected getOrganizerStart(format: string) {
return this.getFormattedRecipientTime({ time: this.calEvent.startTime, format });
}
protected getOrganizerEnd(format: string) {
return this.getFormattedRecipientTime({ time: this.calEvent.endTime, format });
}
protected getLocale(): string {
return this.calEvent.organizer.language.locale;
}
protected getFormattedDate() {
const organizerTimeFormat = this.calEvent.organizer.timeFormat || TimeFormat.TWELVE_HOUR;
return `${this.getOrganizerStart(organizerTimeFormat)} - ${this.getOrganizerEnd(
organizerTimeFormat
)}, ${this.t(this.getOrganizerStart("dddd").toLowerCase())}, ${this.t(
this.getOrganizerStart("MMMM").toLowerCase()
)} ${this.getOrganizerStart("D, YYYY")}`;
}
}
+2
View File
@@ -26,6 +26,8 @@ export type VideoApiAdapter =
getRecordingDownloadLink?(recordingId: string): Promise<GetAccessLinkResponseSchema>;
createInstantCalVideoRoom?(endTime: string): Promise<VideoCallData>;
getAllTranscriptsAccessLinkFromRoomName?(roomName: string): Promise<Array<string>>;
}
| undefined;