export type CreateApiV20EndpointInjectArgs = {body: {userId: string, text: string, data: Record, URLToken: string, sessionId: string}}; export type CreateApiV20EndpointInjectOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send a Message as a User Input * * POST /v2.0/endpoint/inject * * Also accepts auth: APIKeyQueryParam, CXoneTokenHeader, OAuth2 */ export const createApiV20EndpointInject = async (args: CreateApiV20EndpointInjectArgs, options?: CreateApiV20EndpointInjectOptions) => { 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/inject${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() };