import {z} from 'zod' export type EBrainModelType = number; export type EPredefinedCallLabelColors = number; export type CallLabelApi = {id?: (string | null) | undefined, name?: (string | null) | undefined, description?: (string | null) | undefined, color?: EPredefinedCallLabelColors | undefined}; export type ENodeTypeApi = number; export type ETransitionApiResult = number; export type TransitionApi = {name?: (string | null) | undefined, toNodeId?: (string | null) | undefined, apiResult?: (ETransitionApiResult | null) | undefined}; export type APIMethod = number; export type EStateDataType = number; export type APIDataSchemaPropertyApi = {key?: (string | null) | undefined, variableId?: (string | null) | undefined, type?: (EStateDataType | null) | undefined, value?: (string | null) | undefined, required?: boolean | undefined}; export type NodeAPISettingsApi = {name?: (string | null) | undefined, method?: APIMethod | undefined, endpointUrl?: (string | null) | undefined, body?: (Array | null) | undefined, headers?: ({[key: string]: string} | null) | undefined, description?: (string | null) | undefined, outputBody?: (Array | null) | undefined, credentialId?: (string | null) | undefined}; export type NodeSMSTemplateApi = {body?: (string | null) | undefined}; export type EmailProvider = number; export type SmtpSettings = {id?: (string | null) | undefined, provider?: (EmailProvider | null) | undefined, smtpServer?: (string | null) | undefined, port?: (number | null) | undefined, enableSsl?: (boolean | null) | undefined, senderEmail?: (string | null) | undefined, senderPassword?: (string | null) | undefined, displayName?: (string | null) | undefined}; export type NodeEmailTemplateApi = {to?: (Array | null) | undefined, cc?: (Array | null) | undefined, subject?: (string | null) | undefined, body?: (string | null) | undefined, smtpSettings?: (SmtpSettings | null) | undefined}; export type TransferCallSettingsApi = {transferCallPhoneNumber?: (string | null) | undefined, triggerDescription?: (string | null) | undefined, warmTransferMessage?: (string | null) | undefined}; export type NodeApi = {nodeId?: (string | null) | undefined, name?: (string | null) | undefined, nodeType?: ENodeTypeApi | undefined, transitions?: (Array | null) | undefined, script?: (string | null) | undefined, instructions?: (string | null) | undefined, apiSettings?: (NodeAPISettingsApi | null) | undefined, smsSettings?: (NodeSMSTemplateApi | null) | undefined, emailSettings?: (NodeEmailTemplateApi | null) | undefined, transferCallSettings?: (TransferCallSettingsApi | null) | undefined, handOffAction?: (Array | null) | undefined, postCallActions?: (Array | null) | undefined}; export type AgentConfigToAddApi = {name?: (string | null) | undefined, voiceId?: (string | null) | undefined}; export type VocabularyEntry = {word?: (string | null) | undefined, pronunciations?: (Array | null) | undefined}; export type AdvancedVoicePearlApi = {agentPersonality?: (string | null) | undefined, timeZone?: (string | null) | undefined, modelType?: (EBrainModelType | null) | undefined, companyName?: (string | null) | undefined, companyDescription?: (string | null) | undefined, generalInstructions?: (string | null) | undefined, knowledgeBase?: (string | null) | undefined, memory?: (boolean | null) | undefined, successDescription?: (string | null) | undefined, indicatorTags?: (Array | null) | undefined, nodes?: (Array | null) | undefined, agents?: (Array | null) | undefined, speechRecognitionKeywords?: (Array | null) | undefined}; export type EDataSettingsGroup = number; export type OptionChoice = {value?: (string | null) | undefined, code?: (string | null) | undefined}; export type DataSettingsApi = {id?: (string | null) | undefined, name?: (string | null) | undefined, group?: EDataSettingsGroup | undefined, type?: EStateDataType | undefined, isList?: boolean | undefined, description?: (string | null) | undefined, value?: (string | null) | undefined, options?: (Array | null) | undefined}; export type ETranscriptOptions = number; export type InboundVoiceSettingsApi = {totalAgents?: number | undefined, transcriptOptions?: ETranscriptOptions | undefined, callWebhookUrl?: (string | null) | undefined, phoneNumberId?: (string | null) | undefined, recordingOptions?: boolean | undefined, isStopRecordingAfterTransferCall?: (boolean | null) | undefined, waitingSentence?: (string | null) | undefined, isSayQueueDetails?: boolean | undefined}; export type DayOfWeek = number; export type DayWorkingHours = {day?: DayOfWeek | undefined, start?: unknown | undefined, end?: unknown | undefined}; export type ERecordingTrack = number; export type EMinimumRetryIntervalHours = number; export type OutboundVoiceSettingsApi = {totalAgents?: number | undefined, transcriptOptions?: ETranscriptOptions | undefined, budgetTotal?: (number | null) | undefined, timeZone?: (string | null) | undefined, callingHours?: (Array | null) | undefined, callWebhookUrl?: (string | null) | undefined, leadWebhookUrl?: (string | null) | undefined, phoneNumberId?: (string | null) | undefined, recordingTrack?: ERecordingTrack | undefined, isStopRecordingAfterTransferCall?: (boolean | null) | undefined, maximumCallAttempts?: number | undefined, minimumRetryIntervalHours?: EMinimumRetryIntervalHours | undefined, voiceMail?: (string | null) | undefined, bypassIVRInstruction?: (string | null) | undefined, ringDuration?: (number | null) | undefined, callTimeout?: (number | null) | undefined}; export type AddProjectVoiceApiRequest = {name?: (string | null) | undefined, pearl?: (AdvancedVoicePearlApi | null) | undefined, variables?: (Array | null) | undefined, inbound?: (InboundVoiceSettingsApi | null) | undefined, outbound?: (OutboundVoiceSettingsApi | null) | undefined}; export type CreateApiV2PearlVoiceArgs = {body: AddProjectVoiceApiRequest}; export type CreateApiV2PearlVoiceOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2PearlVoiceResponse = z.string(); 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 }; /** * Create Voice Pearl * * POST /v2/Pearl/Voice */ export const createApiV2PearlVoice = async (args: CreateApiV2PearlVoiceArgs, options?: CreateApiV2PearlVoiceOptions) => { const {baseUrl = "https://api.nlpearl.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/Pearl/Voice${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV2PearlVoiceResponse, await res.json()) };