import {z} from 'zod' export type GetApiV1ConferencesConferenceSidParticipantsArgs = {ConferenceSid: string, ParticipantSid?: string | undefined, Label?: string | undefined, Events?: string | undefined, PageSize?: number | undefined, Page?: number | undefined, PageToken?: string | undefined}; export type GetApiV1ConferencesConferenceSidParticipantsOptions = {baseUrl?: string | undefined, accountSidAuthToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const conferenceParticipantEnumCallDirection = z.enum(["inbound", "outbound"]); export const conferenceParticipantEnumCallStatus = z.enum(["answered", "completed", "busy", "fail", "noanswer", "ringing", "canceled"]); export const conferenceParticipantEnumJitterBufferSize = z.enum(["large", "small", "medium", "off"]); export const conferenceParticipantEnumRegion = z.enum(["us1", "us2", "au1", "br1", "ie1", "jp1", "sg1", "de1", "in1"]); export const conferenceParticipantEnumCallType = z.enum(["carrier", "client", "sip"]); export const conferenceParticipantEnumProcessingState = z.enum(["complete", "in_progress", "timeout"]); export const insightsV1ConferenceConferenceParticipant = z.object({participant_sid: z.string().min(34).max(34).nullable().optional(), label: z.string().nullable().optional(), conference_sid: z.string().min(34).max(34).nullable().optional(), call_sid: z.string().min(34).max(34).nullable().optional(), account_sid: z.string().min(34).max(34).nullable().optional(), call_direction: conferenceParticipantEnumCallDirection.optional(), from: z.string().nullable().optional(), to: z.string().nullable().optional(), call_status: conferenceParticipantEnumCallStatus.optional(), country_code: z.string().nullable().optional(), is_moderator: z.boolean().nullable().optional(), join_time: z.string().nullable().optional(), leave_time: z.string().nullable().optional(), duration_seconds: z.number().int().nullable().optional(), outbound_queue_length: z.number().int().nullable().optional(), outbound_time_in_queue: z.number().int().nullable().optional(), jitter_buffer_size: conferenceParticipantEnumJitterBufferSize.optional(), is_coach: z.boolean().nullable().optional(), coached_participants: z.array(z.string()).nullable().optional(), participant_region: conferenceParticipantEnumRegion.optional(), conference_region: conferenceParticipantEnumRegion.optional(), call_type: conferenceParticipantEnumCallType.optional(), processing_state: conferenceParticipantEnumProcessingState.optional(), properties: z.unknown(), events: z.unknown(), metrics: z.unknown(), url: z.string().nullable().optional()}); export const getApiV1ConferencesConferenceSidParticipantsResponse = z.object({participants: z.array(insightsV1ConferenceConferenceParticipant).optional(), meta: z.object({first_page_url: z.string().optional(), key: z.string().optional(), next_page_url: z.string().nullable().optional(), page: z.number().int().optional(), page_size: z.number().int().optional(), previous_page_url: z.string().nullable().optional(), url: z.string().optional()}).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 }; /** * Get a list of Conference Participants Summaries for a Conference. * * GET /v1/Conferences/{ConferenceSid}/Participants */ export const getApiV1ConferencesConferenceSidParticipants = async (args: GetApiV1ConferencesConferenceSidParticipantsArgs, options?: GetApiV1ConferencesConferenceSidParticipantsOptions) => { const {baseUrl = "https://insights.twilio.com", fetch: fetchFn = fetch, accountSidAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ParticipantSid != null) query.append("ParticipantSid", String(args.ParticipantSid)) if (args.Label != null) query.append("Label", String(args.Label)) if (args.Events != null) query.append("Events", String(args.Events)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageToken != null) query.append("PageToken", String(args.PageToken)) if (accountSidAuthToken !== undefined) headers.set('authorization', `Basic ${btoa(`${accountSidAuthToken.username}:${accountSidAuthToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Conferences/${encodeURIComponent(String(args.ConferenceSid))}/Participants${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1ConferencesConferenceSidParticipantsResponse, await res.json()) };