import {z} from 'zod' export type GetApiApiPhoneVoiceCallEventsIdArgs = {id: number}; export type GetApiApiPhoneVoiceCallEventsIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const voiceCallEvent = z.object({id: z.number().int().optional(), type: z.enum(["phone-call-answered", "phone-call-ringing", "phone-call-dial-failed", "phone-call-agent-dialed", "incoming-phone-call", "outgoing-phone-call", "completed-phone-call", "call-recording", "missed-phone-call", "declined-phone-call", "call-ending-triggered", "voicemail-recording", "phone-call-conversation-started", "phone-call-forwarded-to-external-number", "phone-call-forwarded-to-gorgias-number", "phone-call-forwarded", "message-played", "outgoing-phone-call-connected", "child-call-not_answered", "phone-call-transfer-initiated", "phone-call-transfer-failed", "phone-call-enqueued", "phone-call-enqueue-skipped", "phone-call-dequeued", "phone-call-wrap-up-started", "phone-call-wrap-up-ended", "ivr-menu-presented", "ivr-option-selected", "phone-call-deflected-to-sms", "customer-field-conditional-evaluated", "monitoring-started", "monitoring-ended", "monitoring-updated"]).optional(), account_id: z.number().int().optional(), call_id: z.number().int().optional(), user_id: z.number().int().optional(), customer_id: z.number().int().optional(), created_datetime: z.string().optional(), meta: z.object({}).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 }; /** * Retrieve a voice call event * * GET /api/phone/voice-call-events/{id} */ export const getApiApiPhoneVoiceCallEventsId = async (args: GetApiApiPhoneVoiceCallEventsIdArgs, options?: GetApiApiPhoneVoiceCallEventsIdOptions) => { const {baseUrl = "https://your-domain.gorgias.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/phone/voice-call-events/${encodeURIComponent(String(args.id))}${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(voiceCallEvent, await res.json()) };