Skip to content

Commit

Permalink
Update start to support multiple assistants
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinzhng committed May 24, 2024
1 parent bfb6be4 commit a86c119
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
32 changes: 21 additions & 11 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -2303,20 +2319,14 @@ 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
* @max 3600
* @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.
*
Expand Down
14 changes: 10 additions & 4 deletions vapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -113,20 +112,27 @@ export default class Vapi extends VapiEventEmitter {
}

async start(
assistant: CreateAssistantDTO | string,
assistantOverrides?: OverrideAssistantDTO,
assistant?: CreateAssistantDTO | string,
assistants?: CreateAssistantDTO[],
assistantOverride?: OverrideAssistantDTO,
assistantOverrides?: OverrideAssistantDTO[],
): Promise<Call | null> {
if (!assistant && !assistants) {
throw new Error('Assistant or assistants must be provided.');
}

if (this.started) {
return null;
}

this.started = true;

try {
const webCall = (
await client.call.callControllerCreateWebCall({
assistant: typeof assistant === 'string' ? undefined : assistant,
assistantId: typeof assistant === 'string' ? assistant : undefined,
assistants,
assistantOverride,
assistantOverrides,
})
).data;
Expand Down

0 comments on commit a86c119

Please sign in to comment.