import {z} from 'zod' export type GetApiMessagingProfilesProfileIdAutorespConfigsArgs = {profile_id: string, country_code?: string | undefined, created_at?: ({gte?: string | undefined, lte?: string | undefined}) | undefined, updated_at?: ({gte?: string | undefined, lte?: string | undefined}) | undefined}; export type GetApiMessagingProfilesProfileIdAutorespConfigsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const autorespConfigSchema = z.object({op: z.enum(["start", "stop", "info"]), keywords: z.array(z.string()), resp_text: z.string().optional(), country_code: z.string(), id: z.string(), created_at: z.string(), updated_at: z.string()}); export const messagingPaginationMeta0b38e7044b = z.object({total_pages: z.number().int(), total_results: z.number().int(), page_number: z.number().int(), page_size: z.number().int()}); export const messagingAutorespConfigsResponseSchema = z.object({data: z.array(autorespConfigSchema), meta: messagingPaginationMeta0b38e7044b}); 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 }; /** * List Auto-Response Settings * * GET /messaging_profiles/{profile_id}/autoresp_configs */ export const getApiMessagingProfilesProfileIdAutorespConfigs = async (args: GetApiMessagingProfilesProfileIdAutorespConfigsArgs, options?: GetApiMessagingProfilesProfileIdAutorespConfigsOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.country_code != null) query.append("country_code", String(args.country_code)) if (args.created_at != null) query.append("created_at", JSON.stringify(args.created_at)) if (args.updated_at != null) query.append("updated_at", JSON.stringify(args.updated_at)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/messaging_profiles/${encodeURIComponent(String(args.profile_id))}/autoresp_configs${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(messagingAutorespConfigsResponseSchema, await res.json()) };