From 5bc0e1265ddb5c3e485234f9f0f90a43f51407a1 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:35:56 +0530 Subject: [PATCH] fix: use meeting id to get transcripts (#16320) * fix: use meeting id to get transcripts * chore --------- Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> --- apps/web/pages/api/recorded-daily-video.ts | 10 ++++---- .../dailyvideo/lib/VideoApiAdapter.ts | 18 ++++++++++++++ packages/core/videoClient.ts | 24 +++++++++++++++++++ packages/types/VideoApiAdapter.d.ts | 2 ++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/apps/web/pages/api/recorded-daily-video.ts b/apps/web/pages/api/recorded-daily-video.ts index ceab1c5ffc..54e8d5adf6 100644 --- a/apps/web/pages/api/recorded-daily-video.ts +++ b/apps/web/pages/api/recorded-daily-video.ts @@ -6,7 +6,7 @@ import { getDownloadLinkOfCalVideoByRecordingId, submitBatchProcessorTranscriptionJob, } from "@calcom/core/videoClient"; -import { getAllTranscriptsAccessLinkFromRoomName } from "@calcom/core/videoClient"; +import { getAllTranscriptsAccessLinkFromMeetingId } from "@calcom/core/videoClient"; import { sendDailyVideoRecordingEmails } from "@calcom/emails"; import { sendDailyVideoTranscriptEmails } from "@calcom/emails"; import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType"; @@ -153,15 +153,17 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { }); } - const { room } = meetingEndedResponse.data.payload; + const { room, meeting_id } = meetingEndedResponse.data.payload; const bookingReference = await getBookingReference(room); const booking = await getBooking(bookingReference.bookingId as number); - const transcripts = await getAllTranscriptsAccessLinkFromRoomName(room); + const transcripts = await getAllTranscriptsAccessLinkFromMeetingId(meeting_id); if (!transcripts || !transcripts.length) - return res.status(200).json({ message: `No Transcripts found for room name ${room}` }); + return res + .status(200) + .json({ message: `No Transcripts found for room name ${room} and meeting id ${meeting_id}` }); const evt = await getCalendarEvent(booking); await sendDailyVideoTranscriptEmails(evt, transcripts); diff --git a/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts b/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts index f9b3cef1df..05ea642247 100644 --- a/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts +++ b/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts @@ -314,6 +314,24 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => { throw new Error("Something went wrong! Unable to get transcription access link"); } }, + getAllTranscriptsAccessLinkFromMeetingId: async (meetingId: string): Promise> => { + try { + const allTranscripts = await fetcher(`/transcript?mtgSessionId=${meetingId}`).then( + getTranscripts.parse + ); + + if (!allTranscripts.data.length) return []; + + 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"); + } + }, submitBatchProcessorJob: async (body: batchProcessorBody): Promise => { try { const batchProcessorJob = await postToDailyAPI("/batch-processor", body).then( diff --git a/packages/core/videoClient.ts b/packages/core/videoClient.ts index 8cfba66aee..acb7aeecfc 100644 --- a/packages/core/videoClient.ts +++ b/packages/core/videoClient.ts @@ -301,6 +301,29 @@ const getAllTranscriptsAccessLinkFromRoomName = async (roomName: string) => { return videoAdapter?.getAllTranscriptsAccessLinkFromRoomName?.(roomName); }; +const getAllTranscriptsAccessLinkFromMeetingId = async (meetingId: string) => { + let dailyAppKeys: Awaited>; + 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?.getAllTranscriptsAccessLinkFromMeetingId?.(meetingId); +}; + const submitBatchProcessorTranscriptionJob = async (recordingId: string) => { let dailyAppKeys: Awaited>; try { @@ -392,6 +415,7 @@ export { getRecordingsOfCalVideoByRoomName, getDownloadLinkOfCalVideoByRecordingId, getAllTranscriptsAccessLinkFromRoomName, + getAllTranscriptsAccessLinkFromMeetingId, submitBatchProcessorTranscriptionJob, getTranscriptsAccessLinkFromRecordingId, checkIfRoomNameMatchesInRecording, diff --git a/packages/types/VideoApiAdapter.d.ts b/packages/types/VideoApiAdapter.d.ts index 136a4fdf9d..96331d2ccf 100644 --- a/packages/types/VideoApiAdapter.d.ts +++ b/packages/types/VideoApiAdapter.d.ts @@ -34,6 +34,8 @@ export type VideoApiAdapter = getAllTranscriptsAccessLinkFromRoomName?(roomName: string): Promise>; + getAllTranscriptsAccessLinkFromMeetingId?(meetingId: string): Promise>; + submitBatchProcessorJob?(body: batchProcessorBody): Promise; getTranscriptsAccessLinkFromRecordingId?(