export type CreateApiV20EndpointNotifyArgs = {body: {userId: string, text: string, data: Record, attachments?: (Array<{name: string, caption?: string | undefined, url: string, type: 'file' | 'document', mimeType?: string | undefined} | {name: string, caption?: string | undefined, url: string, type: 'image', mimeType?: string | undefined} | {name: string, caption?: string | undefined, url: string, type: 'video', mimeType?: string | undefined} | {name: string, caption?: string | undefined, url: string, type: 'audio', mimeType?: string | undefined} | {name: string, caption?: string | undefined, url: string, type: 'sticker', mimeType?: string | undefined} | {type: 'contact', addresses?: (Array<{city?: string | undefined, country?: string | undefined, countryCode?: string | undefined, state?: string | undefined, street?: string | undefined, type?: ('HOME' | 'WORK') | undefined, zip?: string | undefined, postOfficeBox?: string | undefined, extendedAddress?: string | undefined, latitude?: number | undefined, longitude?: number | undefined}>) | undefined, birthday?: string | undefined, emails?: (Array<{email?: string | undefined, type?: ('HOME' | 'WORK') | undefined}>) | undefined, urls?: (Array<{url?: string | undefined, type?: ('HOME' | 'WORK') | undefined}>) | undefined, photos?: Array | undefined, gender?: string | undefined, languages?: Array | undefined, timeZone?: string | undefined, notes?: Array | undefined} | {type: 'location', latitude: number, longitude: number, name?: string | undefined, title?: string | undefined, address?: string | undefined}>) | undefined, URLToken: string, sessionId?: string | undefined}}; export type CreateApiV20EndpointNotifyOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send a Message as an AI Agent Output * * POST /v2.0/endpoint/notify * * Also accepts auth: APIKeyQueryParam, CXoneTokenHeader, OAuth2 */ export const createApiV20EndpointNotify = async (args: CreateApiV20EndpointNotifyArgs, options?: CreateApiV20EndpointNotifyOptions) => { const {baseUrl = "https://api-trial.cognigy.ai/testing", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/html") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v2.0/endpoint/notify${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 res.text() };