diff --git a/api.ts b/api.ts index 3822305..cedb527 100644 --- a/api.ts +++ b/api.ts @@ -9,22 +9,38 @@ * --------------------------------------------------------------- */ -export class CreateWebCallDTO { +export class CreateCallAssistantDTO { /** * This is the assistant that will be used for the call. To use a transient assistant, use `assistant` instead. */ - assistantId?: string; + assistantId?: string | null; /** - * Overrides for the assistant's settings and template variables. + * Overrides for a single assistant's settings and template variables. */ - assistantOverrides?: OverrideAssistantDTO; + assistantOverride?: OverrideAssistantDTO; + + /** + * Individual overrides for multiple assistant settings and template variables. + * If only one override is provided and multiple assistants are used, it will apply to all assistants. + * Otherwise, the number of overrides must match the number of assistants. + */ + assistantOverrides?: OverrideAssistantDTO[]; /** * This is the assistant that will be used for the call. To use an existing assistant, use `assistantId` instead. */ assistant?: CreateAssistantDTO; + /** + * This is the set of all assistants that can be used for the call. + * The call can be transferred between these assistants. + * The first assistant in the array will be the primary assistant that starts the call. + */ + assistants?: CreateAssistantDTO[]; +} + +export class CreateWebCallDTO extends CreateCallAssistantDTO { /** * This will expose SIP URI you can use to connect to the call. Disabled by default. */ @@ -2303,7 +2319,7 @@ export interface Call { metadata?: object; } -export interface CreateOutboundCallDTO { +export interface CreateOutboundCallDTO extends CreateCallAssistantDTO { /** * This is the maximum number of seconds that the call will last. When the call reaches this duration, it will be ended. * @min 10 @@ -2311,12 +2327,6 @@ export interface CreateOutboundCallDTO { * @example 1800 */ maxDurationSeconds?: number; - /** This is the assistant that will be used for the call. To use a transient assistant, use `assistant` instead. */ - assistantId?: string | null; - /** Overrides for the assistant's settings and template variables. */ - assistantOverrides?: OverrideAssistantDTO; - /** This is the assistant that will be used for the call. To use an existing assistant, use `assistantId` instead. */ - assistant?: CreateAssistantDTO; /** * This is the customer that will be called. To call a transient customer , use `customer` instead. * diff --git a/vapi.ts b/vapi.ts index bef031f..3c841f0 100644 --- a/vapi.ts +++ b/vapi.ts @@ -97,7 +97,6 @@ export default class Vapi extends VapiEventEmitter { private started: boolean = false; private call: DailyCall | null = null; private speakingTimeout: NodeJS.Timeout | null = null; - private averageSpeechLevel: number = 0; constructor(apiToken: string, apiBaseUrl?: string) { super(); @@ -113,13 +112,18 @@ export default class Vapi extends VapiEventEmitter { } async start( - assistant: CreateAssistantDTO | string, - assistantOverrides?: OverrideAssistantDTO, + assistant?: CreateAssistantDTO | string, + assistants?: CreateAssistantDTO[], + assistantOverride?: OverrideAssistantDTO, + assistantOverrides?: OverrideAssistantDTO[], ): Promise { + if (!assistant && !assistants) { + throw new Error('Assistant or assistants must be provided.'); + } + if (this.started) { return null; } - this.started = true; try { @@ -127,6 +131,8 @@ export default class Vapi extends VapiEventEmitter { await client.call.callControllerCreateWebCall({ assistant: typeof assistant === 'string' ? undefined : assistant, assistantId: typeof assistant === 'string' ? assistant : undefined, + assistants, + assistantOverride, assistantOverrides, }) ).data;