import {z} from 'zod' export type CalendarBotStatusChange = {status?: ('READY' | 'JOINING_CALL' | 'IN_WAITING_ROOM' | 'IN_CALL_NOT_RECORDING' | 'RECORDING_PERMISSION_ALLOWED' | 'RECORDING_PERMISSION_DENIED' | 'IN_CALL_RECORDING' | 'CALL_ENDED' | 'DONE' | 'FATAL') | undefined, changed_at?: string | undefined, sub_code?: string | undefined, message?: string | undefined}; export type PropertyCalendarBotStatusChanges = Array; export type PropertyCalendarBotRecordingConfigTranscription = {provider?: ('MEETING_CAPTIONS' | 'AWS_TRANSCRIBE' | 'GOOGLE_SPEECH' | 'ASSEMBLYAI' | 'DEEPGRAM' | 'CUSTOM') | undefined, mode?: ('PRIORITIZE_ACCURACY' | 'PRIORITIZE_LOW_LATENCY') | undefined, language?: string | undefined, enable_speaker_labels?: boolean | undefined, enable_word_timestamps?: boolean | undefined}; export type PropertyCalendarBotRecordingConfig = {record_video?: boolean | undefined, record_audio?: boolean | undefined, record_transcript?: boolean | undefined, record_chat?: boolean | undefined, record_screenshare?: boolean | undefined, transcription?: PropertyCalendarBotRecordingConfigTranscription | undefined}; export type PropertyCalendarBotAutomaticLeave = {waiting_room_timeout?: number | undefined, no_participants_timeout?: number | undefined, detect_bots?: boolean | undefined}; export type PropertyCalendarBotMeetingMetadata = {title?: string | undefined, platform?: string | undefined, host_name?: string | undefined, host_email?: string | undefined, meeting_identifier?: string | undefined, started_at?: string | undefined, ended_at?: string | undefined, participant_count?: number | undefined}; export type CalendarBotParticipant = {id?: string | undefined, name?: string | undefined, email?: string | undefined, is_host?: boolean | undefined, is_cohost?: boolean | undefined, joined_at?: string | undefined, left_at?: string | undefined, platform?: string | undefined, is_bot?: boolean | undefined, is_self?: boolean | undefined, speaking?: boolean | undefined, webcam_on?: boolean | undefined, screenshare_on?: boolean | undefined, platform_metadata?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined}; export type PropertyCalendarBotParticipants = Array; export type CalendarBot = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, name?: string | undefined, meeting_url?: string | undefined, event_id?: string | undefined, status?: ('READY' | 'JOINING_CALL' | 'IN_WAITING_ROOM' | 'IN_CALL_NOT_RECORDING' | 'RECORDING_PERMISSION_ALLOWED' | 'RECORDING_PERMISSION_DENIED' | 'IN_CALL_RECORDING' | 'CALL_ENDED' | 'DONE' | 'FATAL') | undefined, status_changes?: PropertyCalendarBotStatusChanges | undefined, join_at?: string | undefined, started_at?: string | undefined, ended_at?: string | undefined, recording_config?: PropertyCalendarBotRecordingConfig | undefined, automatic_leave?: PropertyCalendarBotAutomaticLeave | undefined, meeting_metadata?: PropertyCalendarBotMeetingMetadata | undefined, participants?: PropertyCalendarBotParticipants | undefined, recording_id?: string | undefined, raw?: {[key: string]: unknown} | undefined}; export type PatchApiCalendarConnectionIdBotIdArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'name' | 'meeting_url' | 'event_id' | 'status' | 'status_changes' | 'join_at' | 'started_at' | 'ended_at' | 'recording_config' | 'automatic_leave' | 'meeting_metadata' | 'participants' | 'recording_id' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, id: string, body: CalendarBot}; export type PatchApiCalendarConnectionIdBotIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const calendarBotStatusChange = z.object({status: z.enum(["READY", "JOINING_CALL", "IN_WAITING_ROOM", "IN_CALL_NOT_RECORDING", "RECORDING_PERMISSION_ALLOWED", "RECORDING_PERMISSION_DENIED", "IN_CALL_RECORDING", "CALL_ENDED", "DONE", "FATAL"]).optional(), changed_at: z.string().optional(), sub_code: z.string().optional(), message: z.string().optional()}); export const propertyCalendarBotStatusChanges = z.array(calendarBotStatusChange); export const propertyCalendarBotRecordingConfigTranscription = z.object({provider: z.enum(["MEETING_CAPTIONS", "AWS_TRANSCRIBE", "GOOGLE_SPEECH", "ASSEMBLYAI", "DEEPGRAM", "CUSTOM"]).optional(), mode: z.enum(["PRIORITIZE_ACCURACY", "PRIORITIZE_LOW_LATENCY"]).optional(), language: z.string().optional(), enable_speaker_labels: z.boolean().optional(), enable_word_timestamps: z.boolean().optional()}); export const propertyCalendarBotRecordingConfig = z.object({record_video: z.boolean().optional(), record_audio: z.boolean().optional(), record_transcript: z.boolean().optional(), record_chat: z.boolean().optional(), record_screenshare: z.boolean().optional(), transcription: propertyCalendarBotRecordingConfigTranscription.optional()}); export const propertyCalendarBotAutomaticLeave = z.object({waiting_room_timeout: z.number().optional(), no_participants_timeout: z.number().optional(), detect_bots: z.boolean().optional()}); export const propertyCalendarBotMeetingMetadata = z.object({title: z.string().optional(), platform: z.string().optional(), host_name: z.string().optional(), host_email: z.string().optional(), meeting_identifier: z.string().optional(), started_at: z.string().optional(), ended_at: z.string().optional(), participant_count: z.number().optional()}); export const calendarBotParticipant = z.object({id: z.string().optional(), name: z.string().optional(), email: z.string().optional(), is_host: z.boolean().optional(), is_cohost: z.boolean().optional(), joined_at: z.string().optional(), left_at: z.string().optional(), platform: z.string().optional(), is_bot: z.boolean().optional(), is_self: z.boolean().optional(), speaking: z.boolean().optional(), webcam_on: z.boolean().optional(), screenshare_on: z.boolean().optional(), platform_metadata: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional()}); export const propertyCalendarBotParticipants = z.array(calendarBotParticipant); export const calendarBot = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), meeting_url: z.string().optional(), event_id: z.string().optional(), status: z.enum(["READY", "JOINING_CALL", "IN_WAITING_ROOM", "IN_CALL_NOT_RECORDING", "RECORDING_PERMISSION_ALLOWED", "RECORDING_PERMISSION_DENIED", "IN_CALL_RECORDING", "CALL_ENDED", "DONE", "FATAL"]).optional(), status_changes: propertyCalendarBotStatusChanges.optional(), join_at: z.string().optional(), started_at: z.string().optional(), ended_at: z.string().optional(), recording_config: propertyCalendarBotRecordingConfig.optional(), automatic_leave: propertyCalendarBotAutomaticLeave.optional(), meeting_metadata: propertyCalendarBotMeetingMetadata.optional(), participants: propertyCalendarBotParticipants.optional(), recording_id: z.string().optional(), raw: z.record(z.string(), z.unknown()).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update a bot * * PATCH /calendar/{connection_id}/bot/{id} */ export const patchApiCalendarConnectionIdBotId = async (args: PatchApiCalendarConnectionIdBotIdArgs, options?: PatchApiCalendarConnectionIdBotIdOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/calendar/${encodeURIComponent(String(args.connection_id))}/bot/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(calendarBot, await res.json()) };