import {z} from 'zod' export type IvrMenuSiteInfo = {id?: string | undefined, name?: string | undefined}; export type AudioPromptInfo = {uri?: string | undefined, id?: string | undefined}; export type PromptLanguageInfo = {uri?: string | undefined, id?: string | undefined, name?: string | undefined, localeCode?: string | undefined}; export type IvrMenuPromptInfo = {mode?: ('Audio' | 'TextToSpeech') | undefined, audio?: AudioPromptInfo | undefined, text?: string | undefined, language?: PromptLanguageInfo | undefined}; export type IVRMenuExtensionInfo = {uri?: string | undefined, id?: string | undefined, name?: string | undefined}; export type IVRMenuActionsInfo = {input?: string | undefined, action?: ('Connect' | 'Voicemail' | 'DialByName' | 'Transfer' | 'Repeat' | 'ReturnToRoot' | 'ReturnToPrevious' | 'Disconnect' | 'ReturnToTopLevelMenu' | 'DoNothing' | 'ConnectToOperator') | undefined, extension?: IVRMenuExtensionInfo | undefined, phoneNumber?: string | undefined}; export type IVRMenuInfo = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, extensionNumber?: string | undefined, site?: IvrMenuSiteInfo | undefined, prompt?: IvrMenuPromptInfo | undefined, actions?: Array | undefined}; export type UpdateApiRestapiV10AccountAccountIdIvrMenusIvrMenuIdArgs = {accountId: string, ivrMenuId: string, body: IVRMenuInfo}; export type UpdateApiRestapiV10AccountAccountIdIvrMenusIvrMenuIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const ivrMenuSiteInfo = z.object({id: z.string().optional(), name: z.string().optional()}); export const audioPromptInfo = z.object({uri: z.string().optional(), id: z.string().optional()}); export const promptLanguageInfo = z.object({uri: z.string().optional(), id: z.string().optional(), name: z.string().optional(), localeCode: z.string().optional()}); export const ivrMenuPromptInfo = z.object({mode: z.enum(["Audio", "TextToSpeech"]).optional(), audio: audioPromptInfo.optional(), text: z.string().optional(), language: promptLanguageInfo.optional()}); export const iVRMenuExtensionInfo = z.object({uri: z.string().optional(), id: z.string().optional(), name: z.string().optional()}); export const iVRMenuActionsInfo = z.object({input: z.string().optional(), action: z.enum(["Connect", "Voicemail", "DialByName", "Transfer", "Repeat", "ReturnToRoot", "ReturnToPrevious", "Disconnect", "ReturnToTopLevelMenu", "DoNothing", "ConnectToOperator"]).optional(), extension: iVRMenuExtensionInfo.optional(), phoneNumber: z.string().optional()}); export const iVRMenuInfo = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), extensionNumber: z.string().optional(), site: ivrMenuSiteInfo.optional(), prompt: ivrMenuPromptInfo.optional(), actions: z.array(iVRMenuActionsInfo).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 IVR Menu * * PUT /restapi/v1.0/account/{accountId}/ivr-menus/{ivrMenuId} */ export const updateApiRestapiV10AccountAccountIdIvrMenusIvrMenuId = async (args: UpdateApiRestapiV10AccountAccountIdIvrMenusIvrMenuIdArgs, options?: UpdateApiRestapiV10AccountAccountIdIvrMenusIvrMenuIdOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/v1.0/account/${encodeURIComponent(String(args.accountId))}/ivr-menus/${encodeURIComponent(String(args.ivrMenuId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(iVRMenuInfo, await res.json()) };