feat: generate transcription from recording and API endpoint (#15358)
* feat: generate transcription from recording * fix: api * chore: undo * tests: add unit tests * chore: refactor move zod type * fix: add more security check * chore: update test * chore: type err * chore: test * chore: fix tyoe * fix: build err * chore: add try .. catch * chore: update desc --------- Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
1 parent
68ce9524eb
commit
b66d36a98e
9 files changed
+451
-2
No files matched your search
@@ -3,12 +3,18 @@ import { z } from "zod";
|
||||
import { handleErrorsJson } from "@calcom/lib/errors";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { GetRecordingsResponseSchema, GetAccessLinkResponseSchema } from "@calcom/prisma/zod-utils";
|
||||
import { getRecordingsResponseSchema, getAccessLinkResponseSchema } from "@calcom/prisma/zod-utils";
|
||||
import {
|
||||
getRecordingsResponseSchema,
|
||||
getAccessLinkResponseSchema,
|
||||
recordingItemSchema,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
import type { PartialReference } from "@calcom/types/EventManager";
|
||||
import type { VideoApiAdapter, VideoCallData } from "@calcom/types/VideoApiAdapter";
|
||||
|
||||
import { ZSubmitBatchProcessorJobRes, ZGetTranscriptAccessLink } from "../zod";
|
||||
import type { TSubmitBatchProcessorJobRes, TGetTranscriptAccessLink, batchProcessorBody } from "../zod";
|
||||
import { getDailyAppKeys } from "./getDailyAppKeys";
|
||||
|
||||
/** @link https://docs.daily.co/reference/rest-api/rooms/create-room */
|
||||
@@ -48,6 +54,17 @@ const getTranscripts = z.object({
|
||||
),
|
||||
});
|
||||
|
||||
const getBatchProcessJobs = z.object({
|
||||
total_count: z.number(),
|
||||
data: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
preset: z.string(),
|
||||
status: z.string(),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
const getRooms = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
@@ -272,6 +289,53 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {
|
||||
throw new Error("Something went wrong! Unable to get transcription access link");
|
||||
}
|
||||
},
|
||||
submitBatchProcessorJob: async (body: batchProcessorBody): Promise<TSubmitBatchProcessorJobRes> => {
|
||||
try {
|
||||
const batchProcessorJob = await postToDailyAPI("/batch-processor", body).then(
|
||||
ZSubmitBatchProcessorJobRes.parse
|
||||
);
|
||||
return batchProcessorJob;
|
||||
} catch (err) {
|
||||
console.log("err", err);
|
||||
throw new Error("Something went wrong! Unable to submit batch processor job");
|
||||
}
|
||||
},
|
||||
getTranscriptsAccessLinkFromRecordingId: async (
|
||||
recordingId: string
|
||||
): Promise<TGetTranscriptAccessLink["transcription"] | { message: string }> => {
|
||||
try {
|
||||
const batchProcessorJobs = await fetcher(`/batch-processor?recordingId=${recordingId}`).then(
|
||||
getBatchProcessJobs.parse
|
||||
);
|
||||
if (!batchProcessorJobs.data.length) {
|
||||
return { message: `No Batch processor jobs found for recording id ${recordingId}` };
|
||||
}
|
||||
|
||||
const transcriptJobId = batchProcessorJobs.data.filter(
|
||||
(job) => job.preset === "transcript" && job.status === "finished"
|
||||
)?.[0]?.id;
|
||||
|
||||
if (!transcriptJobId) return [];
|
||||
|
||||
const accessLinkRes = await fetcher(`/batch-processor/${transcriptJobId}/access-link`).then(
|
||||
ZGetTranscriptAccessLink.parse
|
||||
);
|
||||
|
||||
return accessLinkRes.transcription;
|
||||
} catch (err) {
|
||||
console.log("err", err);
|
||||
throw new Error("Something went wrong! can't get transcripts");
|
||||
}
|
||||
},
|
||||
checkIfRoomNameMatchesInRecording: async (roomName: string, recordingId: string): Promise<boolean> => {
|
||||
try {
|
||||
const recording = await fetcher(`/recordings/${recordingId}`).then(recordingItemSchema.parse);
|
||||
return recording.room_name === roomName;
|
||||
} catch (err) {
|
||||
console.error("err", err);
|
||||
throw new Error(`Something went wrong! Unable to checkIfRoomNameMatchesInRecording. ${err}`);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -6,3 +6,36 @@ export const appKeysSchema = z.object({
|
||||
});
|
||||
|
||||
export const appDataSchema = z.object({});
|
||||
|
||||
export const ZSubmitBatchProcessorJobRes = z.object({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export type TSubmitBatchProcessorJobRes = z.infer<typeof ZSubmitBatchProcessorJobRes>;
|
||||
|
||||
export type batchProcessorBody = {
|
||||
preset: "transcript";
|
||||
inParams: {
|
||||
sourceType: "recordingId";
|
||||
recordingId: string;
|
||||
};
|
||||
outParams: {
|
||||
s3Config: {
|
||||
s3KeyTemplate: "transcript";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export const ZGetTranscriptAccessLink = z.object({
|
||||
id: z.string(),
|
||||
preset: z.string(),
|
||||
status: z.string(),
|
||||
transcription: z.array(
|
||||
z.object({
|
||||
format: z.string(),
|
||||
link: z.string().url(),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
export type TGetTranscriptAccessLink = z.infer<typeof ZGetTranscriptAccessLink>;
|
||||
@@ -301,6 +301,89 @@ const getAllTranscriptsAccessLinkFromRoomName = async (roomName: string) => {
|
||||
return videoAdapter?.getAllTranscriptsAccessLinkFromRoomName?.(roomName);
|
||||
};
|
||||
|
||||
const submitBatchProcessorTranscriptionJob = async (recordingId: 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?.submitBatchProcessorJob?.({
|
||||
preset: "transcript",
|
||||
inParams: {
|
||||
sourceType: "recordingId",
|
||||
recordingId: recordingId,
|
||||
},
|
||||
outParams: {
|
||||
s3Config: {
|
||||
s3KeyTemplate: "transcript",
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const getTranscriptsAccessLinkFromRecordingId = async (recordingId: 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?.getTranscriptsAccessLinkFromRecordingId?.(recordingId);
|
||||
};
|
||||
|
||||
const checkIfRoomNameMatchesInRecording = async (roomName: string, recordingId: 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?.checkIfRoomNameMatchesInRecording?.(roomName, recordingId);
|
||||
};
|
||||
|
||||
export {
|
||||
getBusyVideoTimes,
|
||||
createMeeting,
|
||||
@@ -309,4 +392,7 @@ export {
|
||||
getRecordingsOfCalVideoByRoomName,
|
||||
getDownloadLinkOfCalVideoByRecordingId,
|
||||
getAllTranscriptsAccessLinkFromRoomName,
|
||||
submitBatchProcessorTranscriptionJob,
|
||||
getTranscriptsAccessLinkFromRecordingId,
|
||||
checkIfRoomNameMatchesInRecording,
|
||||
};
|
||||
Vendored
+13
@@ -1,3 +1,8 @@
|
||||
import type {
|
||||
TSubmitBatchProcessorJobRes,
|
||||
batchProcessorBody,
|
||||
TGetTranscriptAccessLink,
|
||||
} from "@calcom/app-store/dailyvideo/zod";
|
||||
import type { GetRecordingsResponseSchema, GetAccessLinkResponseSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import type { EventBusyDate } from "./Calendar";
|
||||
@@ -28,6 +33,14 @@ export type VideoApiAdapter =
|
||||
createInstantCalVideoRoom?(endTime: string): Promise<VideoCallData>;
|
||||
|
||||
getAllTranscriptsAccessLinkFromRoomName?(roomName: string): Promise<Array<string>>;
|
||||
|
||||
submitBatchProcessorJob?(body: batchProcessorBody): Promise<TSubmitBatchProcessorJobRes>;
|
||||
|
||||
getTranscriptsAccessLinkFromRecordingId?(
|
||||
recordingId: string
|
||||
): Promise<TGetTranscriptAccessLink["transcription"] | { message: string }>;
|
||||
|
||||
checkIfRoomNameMatchesInRecording?(roomName: string, recordingId: string): Promise<boolean>;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
|
||||
Reference in new issue
Block a user