//native
type Ultravox = {
apiKey: string;
};
/**
* Calls create
*
*/
export async function main(
auth: Ultravox,
priorCallId: string | undefined,
body: {
systemPrompt?: string;
temperature?: number;
model?: string;
voice?: string;
languageHint?: string;
initialMessages?: {
role?:
| "MESSAGE_ROLE_UNSPECIFIED"
| "MESSAGE_ROLE_USER"
| "MESSAGE_ROLE_AGENT"
| "MESSAGE_ROLE_TOOL_CALL"
| "MESSAGE_ROLE_TOOL_RESULT";
text?: string;
invocationId?: string;
toolName?: string;
errorDetails?: string;
medium?:
| "MESSAGE_MEDIUM_UNSPECIFIED"
| "MESSAGE_MEDIUM_VOICE"
| "MESSAGE_MEDIUM_TEXT";
callStageMessageIndex?: number;
callStageId?: string;
}[];
joinTimeout?: string;
maxDuration?: string;
timeExceededMessage?: string;
inactivityMessages?: {
duration?: string;
message?: string;
endBehavior?:
| "END_BEHAVIOR_UNSPECIFIED"
| "END_BEHAVIOR_HANG_UP_SOFT"
| "END_BEHAVIOR_HANG_UP_STRICT";
}[];
selectedTools?: {
toolId?: string;
toolName?: string;
temporaryTool?: {
modelToolName?: string;
description?: string;
dynamicParameters?: {
name?: string;
location?:
| "PARAMETER_LOCATION_UNSPECIFIED"
| "PARAMETER_LOCATION_QUERY"
| "PARAMETER_LOCATION_PATH"
| "PARAMETER_LOCATION_HEADER"
| "PARAMETER_LOCATION_BODY";
schema?: {};
required?: false | true;
}[];
staticParameters?: {
name?: string;
location?:
| "PARAMETER_LOCATION_UNSPECIFIED"
| "PARAMETER_LOCATION_QUERY"
| "PARAMETER_LOCATION_PATH"
| "PARAMETER_LOCATION_HEADER"
| "PARAMETER_LOCATION_BODY";
value?: {};
}[];
automaticParameters?: {
name?: string;
location?:
| "PARAMETER_LOCATION_UNSPECIFIED"
| "PARAMETER_LOCATION_QUERY"
| "PARAMETER_LOCATION_PATH"
| "PARAMETER_LOCATION_HEADER"
| "PARAMETER_LOCATION_BODY";
knownValue?:
| "KNOWN_PARAM_UNSPECIFIED"
| "KNOWN_PARAM_CALL_ID"
| "KNOWN_PARAM_CONVERSATION_HISTORY"
| "KNOWN_PARAM_OUTPUT_SAMPLE_RATE";
}[];
requirements?: {
httpSecurityOptions?: { options?: { requirements?: {} }[] };
requiredParameterOverrides?: string[];
};
timeout?: string;
precomputable?: false | true;
http?: { baseUrlPattern?: string; httpMethod?: string };
client?: {};
};
nameOverride?: string;
authTokens?: {};
parameterOverrides?: {};
}[];
medium?: {
webRtc?: {};
twilio?: {};
serverWebSocket?: {
inputSampleRate?: number;
outputSampleRate?: number;
clientBufferSizeMs?: number;
};
telnyx?: {};
plivo?: {};
};
recordingEnabled?: false | true;
firstSpeaker?:
| "FIRST_SPEAKER_UNSPECIFIED"
| "FIRST_SPEAKER_AGENT"
| "FIRST_SPEAKER_USER";
transcriptOptional?: false | true;
initialOutputMedium?:
| "MESSAGE_MEDIUM_UNSPECIFIED"
| "MESSAGE_MEDIUM_VOICE"
| "MESSAGE_MEDIUM_TEXT";
vadSettings?: {
turnEndpointDelay?: string;
minimumTurnDuration?: string;
minimumInterruptionDuration?: string;
};
firstSpeakerSettings?: {
user?: {};
agent?: { uninterruptible?: false | true; text?: string };
};
},
) {
const url = new URL(`https://api.ultravox.ai/api/calls`);
for (const [k, v] of [["priorCallId", priorCallId]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago