import {z} from 'zod' export type CreateApiV1DialerCampaignArgs = {Authorization: string, body: {name: string, description?: string | undefined, dial_method: string, auto_dial_duration?: string | undefined, outbound_caller_id: Array, agent_wise_caller_id?: number | undefined, lead_list_map?: Array<{list_id: string, list_status: string}> | undefined, agent_wise_lead_list?: number | undefined, list_traversal_order?: string | undefined, agent_script?: string | undefined, disposition_list: string, number_of_retry: string, retry_after_minutes: string, auto_disposition_cancel_duration: string, dial_status: Array, time_group?: string | undefined, time_group_recording?: string | undefined, ring_timeout: string, quick_transfer_list?: string | undefined, account_dnd_list?: string | undefined, hide_lead_details: number, update_lead_details: number, automatic_schedule_call_enabled?: number | undefined, enable_hangup?: string | undefined, enable_external_transfer?: number | undefined, after_call_work_duration?: string | undefined, enable_web_form: number, webform_url?: string | undefined, music_on_hold?: string | undefined, ring_strategy?: string | undefined, dial_ratio?: string | undefined, enable_transfer?: number | undefined, manual_lead_list?: Array | undefined, break_list?: string | undefined, map_agent_caller_id?: string | undefined, map_agent_lead_list?: string | undefined, connect_agent_through: string, dial_in_type: string, agent_only_callback: number, agent_dial_in_number?: string | undefined, agent: Array, enforce_agent_pause_code?: number | undefined, manual_dial_enabled?: number | undefined, enable_inbound?: number | undefined, inbound_queue?: string | undefined, enable_agent_opt_out?: number | undefined, inbound_lead_list?: string | undefined, enable_auto_answer?: number | undefined, call_qualification_duration?: string | undefined, announcement_recording?: string | undefined, queue_timeout?: string | undefined}}; export type CreateApiV1DialerCampaignOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1DialerCampaignResponse = z.object({}); 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 }; /** * Add a dialer campaign * * POST /v1/dialer/campaign */ export const createApiV1DialerCampaign = async (args: CreateApiV1DialerCampaignArgs, options?: CreateApiV1DialerCampaignOptions) => { const {baseUrl = "https://api-smartflo.tatateleservices.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dialer/campaign${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(createApiV1DialerCampaignResponse, await res.json()) };