@vapi-ai/web 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/api.ts +755 -0
- package/client.ts +19 -0
- package/dist/api.d.ts +414 -0
- package/dist/api.js +309 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +29 -0
- package/dist/player.d.ts +10 -0
- package/dist/player.js +56 -0
- package/dist/vapi.d.ts +13 -0
- package/dist/vapi.js +82 -0
- package/package.json +38 -0
- package/player.ts +66 -0
- package/tsconfig.json +109 -0
- package/vapi.ts +92 -0
package/api.ts
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/*
|
|
4
|
+
* ---------------------------------------------------------------
|
|
5
|
+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
6
|
+
* ## ##
|
|
7
|
+
* ## AUTHOR: acacode ##
|
|
8
|
+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
9
|
+
* ---------------------------------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface PhoneCallParams {
|
|
13
|
+
callSid?: string;
|
|
14
|
+
customerPhoneNumber: string;
|
|
15
|
+
twilioPhoneNumber: string;
|
|
16
|
+
twilioAccountSid: string;
|
|
17
|
+
twilioAuthToken: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Call {
|
|
21
|
+
type: "inboundPhoneCall" | "outboundPhoneCall" | "webCall";
|
|
22
|
+
id: string;
|
|
23
|
+
orgId: string;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
agentId?: string;
|
|
27
|
+
customerId?: string;
|
|
28
|
+
phoneNumberId?: string;
|
|
29
|
+
startedAt: string;
|
|
30
|
+
endedAt?: string;
|
|
31
|
+
transcript?: string;
|
|
32
|
+
recordingUrl?: string;
|
|
33
|
+
cost?: number;
|
|
34
|
+
summary?: string;
|
|
35
|
+
agentParams?: object;
|
|
36
|
+
callParams?: PhoneCallParams;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface OpenAIFunctionParamaters {
|
|
40
|
+
type: string;
|
|
41
|
+
properties: object;
|
|
42
|
+
required?: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface OpenAIFunction {
|
|
46
|
+
/** This is the the name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. */
|
|
47
|
+
name: string;
|
|
48
|
+
/** This is a description of what the function does, used by the AI to choose when and how to call the function. */
|
|
49
|
+
description?: string;
|
|
50
|
+
/**
|
|
51
|
+
* These are the parameters the functions accepts, described as a JSON Schema object. See the [OpenAI guide](https://platform.openai.com/docs/guides/gpt/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema) for documentation about the format.
|
|
52
|
+
*
|
|
53
|
+
* To describe a function that accepts no parameters, provide the value {"type": "object", "properties": {}}.
|
|
54
|
+
*/
|
|
55
|
+
parameters: OpenAIFunctionParamaters;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface CreateAgentDTO {
|
|
59
|
+
/** This is the OpenAI model that will be used. */
|
|
60
|
+
model?: "gpt-4-32k" | "gpt-4" | "gpt-3.5-turbo-16k" | "gpt-3.5-turbo";
|
|
61
|
+
/**
|
|
62
|
+
* This is the voice that will be used.
|
|
63
|
+
*
|
|
64
|
+
* Pro Voices: steve, joseph, myra, paula, drew, phillip, paul, and mrb.
|
|
65
|
+
*
|
|
66
|
+
* Basic Voices: davis, jenny, aria, steffan, sara, and jason.
|
|
67
|
+
*/
|
|
68
|
+
voice?:
|
|
69
|
+
| "burt"
|
|
70
|
+
| "phillip"
|
|
71
|
+
| "steve"
|
|
72
|
+
| "joseph"
|
|
73
|
+
| "myra"
|
|
74
|
+
| "paula"
|
|
75
|
+
| "ryan"
|
|
76
|
+
| "drew"
|
|
77
|
+
| "paul"
|
|
78
|
+
| "mrb"
|
|
79
|
+
| "matilda"
|
|
80
|
+
| "davis"
|
|
81
|
+
| "jenny"
|
|
82
|
+
| "aria"
|
|
83
|
+
| "steffan"
|
|
84
|
+
| "sara"
|
|
85
|
+
| "jason";
|
|
86
|
+
/** This is the agent’s name, just for your own reference. */
|
|
87
|
+
name?: string;
|
|
88
|
+
/** This is the system prompt, which sets the objective and background before the call. */
|
|
89
|
+
context?: string;
|
|
90
|
+
/** These are the functions that the agent can execute during the call. */
|
|
91
|
+
functions?: OpenAIFunction[];
|
|
92
|
+
/**
|
|
93
|
+
* This is the URL Vapi will send GET / POST requests for retrieving context, function calling, and end-of-call reports. All requests will be sent with customerPhoneNumber, botPhoneNumber, and all the agent parameters.
|
|
94
|
+
*
|
|
95
|
+
* Function Calling POST Request:
|
|
96
|
+
* When the agent wants to call a function, we'll POST your callbackURL with `name` and `arguments`.
|
|
97
|
+
* Respond with a JSON object of the result. For example: `{ result: "Hello world!" }` or `{ result: { temperature: "38 degrees" } }`. If empty, return `{}.
|
|
98
|
+
*
|
|
99
|
+
* End-of-Call Report POST Request:
|
|
100
|
+
* You'll get `transcript`, `recordingUrl` and `summary` of the call.
|
|
101
|
+
*
|
|
102
|
+
* Context Retrieval GET Request:
|
|
103
|
+
* If the agent's context isn't set, it'll ask for context before starting the call. Respond with `{ context: "You are an assistant..." }`
|
|
104
|
+
*/
|
|
105
|
+
callbackUrl?: string;
|
|
106
|
+
/** This is the number the agent will transfer to if it runs into any issues. */
|
|
107
|
+
forwardingPhoneNumber?: string;
|
|
108
|
+
/** Whether the AI should talk first when the call is connected. */
|
|
109
|
+
startTalking?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface CreateOutboundCallDto {
|
|
113
|
+
/** This is the agent that will be used for the call. To create a transient agent, use `agent` instead. */
|
|
114
|
+
agentId?: string;
|
|
115
|
+
/** This is the agent that will be used for the call. To use an existing agent, use `agentId` instead. */
|
|
116
|
+
agent?: CreateAgentDTO;
|
|
117
|
+
/** This is the phone number that will be used for the call. */
|
|
118
|
+
phoneNumberId: string;
|
|
119
|
+
/** This is the number that will be called. */
|
|
120
|
+
customerPhoneNumber: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface CreateWebCallDto {
|
|
124
|
+
/** This is the agent that will be used for the call. To create a transient agent, use `agent` instead. */
|
|
125
|
+
agentId?: string;
|
|
126
|
+
/** This is the agent that will be used for the call. To use an existing agent, use `agentId` instead. */
|
|
127
|
+
agent?: CreateAgentDTO;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface WebCallResponseDto {
|
|
131
|
+
url: string;
|
|
132
|
+
callId: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface Agent {
|
|
136
|
+
/** This is the OpenAI model that will be used. */
|
|
137
|
+
model?: "gpt-4-32k" | "gpt-4" | "gpt-3.5-turbo-16k" | "gpt-3.5-turbo";
|
|
138
|
+
/**
|
|
139
|
+
* This is the voice that will be used.
|
|
140
|
+
*
|
|
141
|
+
* Pro Voices: steve, joseph, myra, paula, drew, phillip, paul, and mrb.
|
|
142
|
+
*
|
|
143
|
+
* Basic Voices: davis, jenny, aria, steffan, sara, and jason.
|
|
144
|
+
*/
|
|
145
|
+
voice?:
|
|
146
|
+
| "burt"
|
|
147
|
+
| "phillip"
|
|
148
|
+
| "steve"
|
|
149
|
+
| "joseph"
|
|
150
|
+
| "myra"
|
|
151
|
+
| "paula"
|
|
152
|
+
| "ryan"
|
|
153
|
+
| "drew"
|
|
154
|
+
| "paul"
|
|
155
|
+
| "mrb"
|
|
156
|
+
| "matilda"
|
|
157
|
+
| "davis"
|
|
158
|
+
| "jenny"
|
|
159
|
+
| "aria"
|
|
160
|
+
| "steffan"
|
|
161
|
+
| "sara"
|
|
162
|
+
| "jason";
|
|
163
|
+
/** Unique identifier for the agent. */
|
|
164
|
+
id: string;
|
|
165
|
+
/** Unique identifier for the organization that this agent belongs to. */
|
|
166
|
+
orgId: string;
|
|
167
|
+
/** ISO 8601 date-time string of when the agent was created. */
|
|
168
|
+
createdAt: string;
|
|
169
|
+
/** ISO 8601 date-time string of when the agent was last updated. */
|
|
170
|
+
updatedAt: string;
|
|
171
|
+
/** This is the agent’s name, just for your own reference. */
|
|
172
|
+
name?: string;
|
|
173
|
+
/** This is the system prompt, which sets the objective and background before the call. */
|
|
174
|
+
context?: string;
|
|
175
|
+
/** These are the functions that the agent can execute during the call. */
|
|
176
|
+
functions?: OpenAIFunction[];
|
|
177
|
+
/**
|
|
178
|
+
* This is the URL Vapi will send GET / POST requests for retrieving context, function calling, and end-of-call reports. All requests will be sent with customerPhoneNumber, botPhoneNumber, and all the agent parameters.
|
|
179
|
+
*
|
|
180
|
+
* Function Calling POST Request:
|
|
181
|
+
* When the agent wants to call a function, we'll POST your callbackURL with `name` and `arguments`.
|
|
182
|
+
* Respond with a JSON object of the result. For example: `{ result: "Hello world!" }` or `{ result: { temperature: "38 degrees" } }`. If empty, return `{}.
|
|
183
|
+
*
|
|
184
|
+
* End-of-Call Report POST Request:
|
|
185
|
+
* You'll get `transcript`, `recordingUrl` and `summary` of the call.
|
|
186
|
+
*
|
|
187
|
+
* Context Retrieval GET Request:
|
|
188
|
+
* If the agent's context isn't set, it'll ask for context before starting the call. Respond with `{ context: "You are an assistant..." }`
|
|
189
|
+
*/
|
|
190
|
+
callbackUrl?: string;
|
|
191
|
+
/** This is the number the agent will transfer to if it runs into any issues. */
|
|
192
|
+
forwardingPhoneNumber?: string;
|
|
193
|
+
/** Whether the AI should talk first when the call is connected. */
|
|
194
|
+
startTalking?: boolean;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface UpdateAgentDTO {
|
|
198
|
+
/** This is the OpenAI model that will be used. */
|
|
199
|
+
model?: "gpt-4-32k" | "gpt-4" | "gpt-3.5-turbo-16k" | "gpt-3.5-turbo";
|
|
200
|
+
/**
|
|
201
|
+
* This is the voice that will be used.
|
|
202
|
+
*
|
|
203
|
+
* Pro Voices: steve, joseph, myra, paula, drew, phillip, paul, and mrb.
|
|
204
|
+
*
|
|
205
|
+
* Basic Voices: davis, jenny, aria, steffan, sara, and jason.
|
|
206
|
+
*/
|
|
207
|
+
voice?:
|
|
208
|
+
| "burt"
|
|
209
|
+
| "phillip"
|
|
210
|
+
| "steve"
|
|
211
|
+
| "joseph"
|
|
212
|
+
| "myra"
|
|
213
|
+
| "paula"
|
|
214
|
+
| "ryan"
|
|
215
|
+
| "drew"
|
|
216
|
+
| "paul"
|
|
217
|
+
| "mrb"
|
|
218
|
+
| "matilda"
|
|
219
|
+
| "davis"
|
|
220
|
+
| "jenny"
|
|
221
|
+
| "aria"
|
|
222
|
+
| "steffan"
|
|
223
|
+
| "sara"
|
|
224
|
+
| "jason";
|
|
225
|
+
/** This is the agent’s name, just for your own reference. */
|
|
226
|
+
name?: string;
|
|
227
|
+
/** This is the system prompt, which sets the objective and background before the call. */
|
|
228
|
+
context?: string;
|
|
229
|
+
/** These are the functions that the agent can execute during the call. */
|
|
230
|
+
functions?: OpenAIFunction[];
|
|
231
|
+
/**
|
|
232
|
+
* This is the URL Vapi will send GET / POST requests for retrieving context, function calling, and end-of-call reports. All requests will be sent with customerPhoneNumber, botPhoneNumber, and all the agent parameters.
|
|
233
|
+
*
|
|
234
|
+
* Function Calling POST Request:
|
|
235
|
+
* When the agent wants to call a function, we'll POST your callbackURL with `name` and `arguments`.
|
|
236
|
+
* Respond with a JSON object of the result. For example: `{ result: "Hello world!" }` or `{ result: { temperature: "38 degrees" } }`. If empty, return `{}.
|
|
237
|
+
*
|
|
238
|
+
* End-of-Call Report POST Request:
|
|
239
|
+
* You'll get `transcript`, `recordingUrl` and `summary` of the call.
|
|
240
|
+
*
|
|
241
|
+
* Context Retrieval GET Request:
|
|
242
|
+
* If the agent's context isn't set, it'll ask for context before starting the call. Respond with `{ context: "You are an assistant..." }`
|
|
243
|
+
*/
|
|
244
|
+
callbackUrl?: string;
|
|
245
|
+
/** This is the number the agent will transfer to if it runs into any issues. */
|
|
246
|
+
forwardingPhoneNumber?: string;
|
|
247
|
+
/** Whether the AI should talk first when the call is connected. */
|
|
248
|
+
startTalking?: boolean;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface BuyPhoneNumberDto {
|
|
252
|
+
/** This is the area code of the phone number to purchase. */
|
|
253
|
+
areaCode: string;
|
|
254
|
+
agentId?: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface PhoneNumber {
|
|
258
|
+
id: string;
|
|
259
|
+
createdAt: string;
|
|
260
|
+
updatedAt: string;
|
|
261
|
+
orgId: string;
|
|
262
|
+
stripeSubscriptionId?: string;
|
|
263
|
+
number: string;
|
|
264
|
+
agentId?: string;
|
|
265
|
+
twilioAccountSid: string;
|
|
266
|
+
twilioAuthToken: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface ImportTwilioPhoneNumberDto {
|
|
270
|
+
/** This is the area code of the phone number to purchase. */
|
|
271
|
+
twilioAccountSid: string;
|
|
272
|
+
twilioAuthToken: string;
|
|
273
|
+
twilioPhoneNumber: string;
|
|
274
|
+
agentId?: string;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface UpdatePhoneNumberDto {
|
|
278
|
+
/** This is the agent that will be used to handle inbound calls to this phone number. */
|
|
279
|
+
agentId?: string;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type QueryParamsType = Record<string | number, any>;
|
|
283
|
+
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
284
|
+
|
|
285
|
+
export interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
286
|
+
/** set parameter to `true` for call `securityWorker` for this request */
|
|
287
|
+
secure?: boolean;
|
|
288
|
+
/** request path */
|
|
289
|
+
path: string;
|
|
290
|
+
/** content type of request body */
|
|
291
|
+
type?: ContentType;
|
|
292
|
+
/** query params */
|
|
293
|
+
query?: QueryParamsType;
|
|
294
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
295
|
+
format?: ResponseFormat;
|
|
296
|
+
/** request body */
|
|
297
|
+
body?: unknown;
|
|
298
|
+
/** base url */
|
|
299
|
+
baseUrl?: string;
|
|
300
|
+
/** request cancellation token */
|
|
301
|
+
cancelToken?: CancelToken;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
305
|
+
|
|
306
|
+
export interface ApiConfig<SecurityDataType = unknown> {
|
|
307
|
+
baseUrl?: string;
|
|
308
|
+
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
|
|
309
|
+
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
|
|
310
|
+
customFetch?: typeof fetch;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
314
|
+
data: D;
|
|
315
|
+
error: E;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
type CancelToken = Symbol | string | number;
|
|
319
|
+
|
|
320
|
+
export enum ContentType {
|
|
321
|
+
Json = "application/json",
|
|
322
|
+
FormData = "multipart/form-data",
|
|
323
|
+
UrlEncoded = "application/x-www-form-urlencoded",
|
|
324
|
+
Text = "text/plain",
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export class HttpClient<SecurityDataType = unknown> {
|
|
328
|
+
public baseUrl: string = "";
|
|
329
|
+
private securityData: SecurityDataType | null = null;
|
|
330
|
+
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
|
|
331
|
+
private abortControllers = new Map<CancelToken, AbortController>();
|
|
332
|
+
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams);
|
|
333
|
+
|
|
334
|
+
private baseApiParams: RequestParams = {
|
|
335
|
+
credentials: "same-origin",
|
|
336
|
+
headers: {},
|
|
337
|
+
redirect: "follow",
|
|
338
|
+
referrerPolicy: "no-referrer",
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
constructor(apiConfig: ApiConfig<SecurityDataType> = {}) {
|
|
342
|
+
Object.assign(this, apiConfig);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
public setSecurityData = (data: SecurityDataType | null) => {
|
|
346
|
+
this.securityData = data;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
protected encodeQueryParam(key: string, value: any) {
|
|
350
|
+
const encodedKey = encodeURIComponent(key);
|
|
351
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
protected addQueryParam(query: QueryParamsType, key: string) {
|
|
355
|
+
return this.encodeQueryParam(key, query[key]);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
protected addArrayQueryParam(query: QueryParamsType, key: string) {
|
|
359
|
+
const value = query[key];
|
|
360
|
+
return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
protected toQueryString(rawQuery?: QueryParamsType): string {
|
|
364
|
+
const query = rawQuery || {};
|
|
365
|
+
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
366
|
+
return keys
|
|
367
|
+
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
|
|
368
|
+
.join("&");
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
protected addQueryParams(rawQuery?: QueryParamsType): string {
|
|
372
|
+
const queryString = this.toQueryString(rawQuery);
|
|
373
|
+
return queryString ? `?${queryString}` : "";
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
private contentFormatters: Record<ContentType, (input: any) => any> = {
|
|
377
|
+
[ContentType.Json]: (input: any) =>
|
|
378
|
+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
|
|
379
|
+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
|
|
380
|
+
[ContentType.FormData]: (input: any) =>
|
|
381
|
+
Object.keys(input || {}).reduce((formData, key) => {
|
|
382
|
+
const property = input[key];
|
|
383
|
+
formData.append(
|
|
384
|
+
key,
|
|
385
|
+
property instanceof Blob
|
|
386
|
+
? property
|
|
387
|
+
: typeof property === "object" && property !== null
|
|
388
|
+
? JSON.stringify(property)
|
|
389
|
+
: `${property}`,
|
|
390
|
+
);
|
|
391
|
+
return formData;
|
|
392
|
+
}, new FormData()),
|
|
393
|
+
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
|
|
397
|
+
return {
|
|
398
|
+
...this.baseApiParams,
|
|
399
|
+
...params1,
|
|
400
|
+
...(params2 || {}),
|
|
401
|
+
headers: {
|
|
402
|
+
...(this.baseApiParams.headers || {}),
|
|
403
|
+
...(params1.headers || {}),
|
|
404
|
+
...((params2 && params2.headers) || {}),
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
protected createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => {
|
|
410
|
+
if (this.abortControllers.has(cancelToken)) {
|
|
411
|
+
const abortController = this.abortControllers.get(cancelToken);
|
|
412
|
+
if (abortController) {
|
|
413
|
+
return abortController.signal;
|
|
414
|
+
}
|
|
415
|
+
return void 0;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const abortController = new AbortController();
|
|
419
|
+
this.abortControllers.set(cancelToken, abortController);
|
|
420
|
+
return abortController.signal;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
public abortRequest = (cancelToken: CancelToken) => {
|
|
424
|
+
const abortController = this.abortControllers.get(cancelToken);
|
|
425
|
+
|
|
426
|
+
if (abortController) {
|
|
427
|
+
abortController.abort();
|
|
428
|
+
this.abortControllers.delete(cancelToken);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
public request = async <T = any, E = any>({
|
|
433
|
+
body,
|
|
434
|
+
secure,
|
|
435
|
+
path,
|
|
436
|
+
type,
|
|
437
|
+
query,
|
|
438
|
+
format,
|
|
439
|
+
baseUrl,
|
|
440
|
+
cancelToken,
|
|
441
|
+
...params
|
|
442
|
+
}: FullRequestParams): Promise<HttpResponse<T, E>> => {
|
|
443
|
+
const secureParams =
|
|
444
|
+
((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
|
|
445
|
+
this.securityWorker &&
|
|
446
|
+
(await this.securityWorker(this.securityData))) ||
|
|
447
|
+
{};
|
|
448
|
+
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
449
|
+
const queryString = query && this.toQueryString(query);
|
|
450
|
+
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
|
|
451
|
+
const responseFormat = format || requestParams.format;
|
|
452
|
+
|
|
453
|
+
return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, {
|
|
454
|
+
...requestParams,
|
|
455
|
+
headers: {
|
|
456
|
+
...(requestParams.headers || {}),
|
|
457
|
+
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
|
|
458
|
+
},
|
|
459
|
+
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
|
|
460
|
+
body: typeof body === "undefined" || body === null ? null : payloadFormatter(body),
|
|
461
|
+
}).then(async (response) => {
|
|
462
|
+
const r = response as HttpResponse<T, E>;
|
|
463
|
+
r.data = null as unknown as T;
|
|
464
|
+
r.error = null as unknown as E;
|
|
465
|
+
|
|
466
|
+
const data = !responseFormat
|
|
467
|
+
? r
|
|
468
|
+
: await response[responseFormat]()
|
|
469
|
+
.then((data) => {
|
|
470
|
+
if (r.ok) {
|
|
471
|
+
r.data = data;
|
|
472
|
+
} else {
|
|
473
|
+
r.error = data;
|
|
474
|
+
}
|
|
475
|
+
return r;
|
|
476
|
+
})
|
|
477
|
+
.catch((e) => {
|
|
478
|
+
r.error = e;
|
|
479
|
+
return r;
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
if (cancelToken) {
|
|
483
|
+
this.abortControllers.delete(cancelToken);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (!response.ok) throw data;
|
|
487
|
+
return data;
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* @title Vapi API
|
|
494
|
+
* @version 1.0
|
|
495
|
+
* @contact
|
|
496
|
+
*
|
|
497
|
+
* API for talking AIs
|
|
498
|
+
*/
|
|
499
|
+
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
500
|
+
call = {
|
|
501
|
+
/**
|
|
502
|
+
* No description
|
|
503
|
+
*
|
|
504
|
+
* @tags Calls
|
|
505
|
+
* @name CallControllerFindAll
|
|
506
|
+
* @summary List Calls
|
|
507
|
+
* @request GET:/call
|
|
508
|
+
*/
|
|
509
|
+
callControllerFindAll: (params: RequestParams = {}) =>
|
|
510
|
+
this.request<Call[], any>({
|
|
511
|
+
path: `/call`,
|
|
512
|
+
method: "GET",
|
|
513
|
+
format: "json",
|
|
514
|
+
...params,
|
|
515
|
+
}),
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* No description
|
|
519
|
+
*
|
|
520
|
+
* @tags Calls
|
|
521
|
+
* @name CallControllerFindOne
|
|
522
|
+
* @summary Get Call
|
|
523
|
+
* @request GET:/call/{id}
|
|
524
|
+
*/
|
|
525
|
+
callControllerFindOne: (id: string, params: RequestParams = {}) =>
|
|
526
|
+
this.request<Call, any>({
|
|
527
|
+
path: `/call/${id}`,
|
|
528
|
+
method: "GET",
|
|
529
|
+
format: "json",
|
|
530
|
+
...params,
|
|
531
|
+
}),
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* No description
|
|
535
|
+
*
|
|
536
|
+
* @tags Calls
|
|
537
|
+
* @name CallControllerCreatePhoneCall
|
|
538
|
+
* @summary Create Phone Call
|
|
539
|
+
* @request POST:/call/phone
|
|
540
|
+
*/
|
|
541
|
+
callControllerCreatePhoneCall: (data: CreateOutboundCallDto, params: RequestParams = {}) =>
|
|
542
|
+
this.request<Call, any>({
|
|
543
|
+
path: `/call/phone`,
|
|
544
|
+
method: "POST",
|
|
545
|
+
body: data,
|
|
546
|
+
type: ContentType.Json,
|
|
547
|
+
format: "json",
|
|
548
|
+
...params,
|
|
549
|
+
}),
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* No description
|
|
553
|
+
*
|
|
554
|
+
* @tags Calls
|
|
555
|
+
* @name CallControllerCreateWebCall
|
|
556
|
+
* @summary Create Web Call
|
|
557
|
+
* @request POST:/call/web
|
|
558
|
+
*/
|
|
559
|
+
callControllerCreateWebCall: (data: CreateWebCallDto, params: RequestParams = {}) =>
|
|
560
|
+
this.request<WebCallResponseDto, any>({
|
|
561
|
+
path: `/call/web`,
|
|
562
|
+
method: "POST",
|
|
563
|
+
body: data,
|
|
564
|
+
type: ContentType.Json,
|
|
565
|
+
format: "json",
|
|
566
|
+
...params,
|
|
567
|
+
}),
|
|
568
|
+
};
|
|
569
|
+
agent = {
|
|
570
|
+
/**
|
|
571
|
+
* No description
|
|
572
|
+
*
|
|
573
|
+
* @tags Agents
|
|
574
|
+
* @name AgentControllerCreate
|
|
575
|
+
* @summary Create Agent
|
|
576
|
+
* @request POST:/agent
|
|
577
|
+
*/
|
|
578
|
+
agentControllerCreate: (data: CreateAgentDTO, params: RequestParams = {}) =>
|
|
579
|
+
this.request<Agent, any>({
|
|
580
|
+
path: `/agent`,
|
|
581
|
+
method: "POST",
|
|
582
|
+
body: data,
|
|
583
|
+
type: ContentType.Json,
|
|
584
|
+
format: "json",
|
|
585
|
+
...params,
|
|
586
|
+
}),
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* No description
|
|
590
|
+
*
|
|
591
|
+
* @tags Agents
|
|
592
|
+
* @name AgentControllerFindAll
|
|
593
|
+
* @summary List Agents
|
|
594
|
+
* @request GET:/agent
|
|
595
|
+
*/
|
|
596
|
+
agentControllerFindAll: (params: RequestParams = {}) =>
|
|
597
|
+
this.request<Agent[], any>({
|
|
598
|
+
path: `/agent`,
|
|
599
|
+
method: "GET",
|
|
600
|
+
format: "json",
|
|
601
|
+
...params,
|
|
602
|
+
}),
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* No description
|
|
606
|
+
*
|
|
607
|
+
* @tags Agents
|
|
608
|
+
* @name AgentControllerFindOne
|
|
609
|
+
* @summary Get Agent
|
|
610
|
+
* @request GET:/agent/{id}
|
|
611
|
+
*/
|
|
612
|
+
agentControllerFindOne: (id: string, params: RequestParams = {}) =>
|
|
613
|
+
this.request<Agent, any>({
|
|
614
|
+
path: `/agent/${id}`,
|
|
615
|
+
method: "GET",
|
|
616
|
+
format: "json",
|
|
617
|
+
...params,
|
|
618
|
+
}),
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* No description
|
|
622
|
+
*
|
|
623
|
+
* @tags Agents
|
|
624
|
+
* @name AgentControllerUpdate
|
|
625
|
+
* @summary Update Agent
|
|
626
|
+
* @request PATCH:/agent/{id}
|
|
627
|
+
*/
|
|
628
|
+
agentControllerUpdate: (id: string, data: UpdateAgentDTO, params: RequestParams = {}) =>
|
|
629
|
+
this.request<Agent, any>({
|
|
630
|
+
path: `/agent/${id}`,
|
|
631
|
+
method: "PATCH",
|
|
632
|
+
body: data,
|
|
633
|
+
type: ContentType.Json,
|
|
634
|
+
format: "json",
|
|
635
|
+
...params,
|
|
636
|
+
}),
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* No description
|
|
640
|
+
*
|
|
641
|
+
* @tags Agents
|
|
642
|
+
* @name AgentControllerRemove
|
|
643
|
+
* @summary Delete Agent
|
|
644
|
+
* @request DELETE:/agent/{id}
|
|
645
|
+
*/
|
|
646
|
+
agentControllerRemove: (id: string, params: RequestParams = {}) =>
|
|
647
|
+
this.request<void, any>({
|
|
648
|
+
path: `/agent/${id}`,
|
|
649
|
+
method: "DELETE",
|
|
650
|
+
...params,
|
|
651
|
+
}),
|
|
652
|
+
};
|
|
653
|
+
phoneNumber = {
|
|
654
|
+
/**
|
|
655
|
+
* No description
|
|
656
|
+
*
|
|
657
|
+
* @tags Phone Numbers
|
|
658
|
+
* @name PhoneNumberControllerBuy
|
|
659
|
+
* @summary Buy Phone Number
|
|
660
|
+
* @request POST:/phone-number/buy
|
|
661
|
+
*/
|
|
662
|
+
phoneNumberControllerBuy: (data: BuyPhoneNumberDto, params: RequestParams = {}) =>
|
|
663
|
+
this.request<PhoneNumber, any>({
|
|
664
|
+
path: `/phone-number/buy`,
|
|
665
|
+
method: "POST",
|
|
666
|
+
body: data,
|
|
667
|
+
type: ContentType.Json,
|
|
668
|
+
format: "json",
|
|
669
|
+
...params,
|
|
670
|
+
}),
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* No description
|
|
674
|
+
*
|
|
675
|
+
* @tags Phone Numbers
|
|
676
|
+
* @name PhoneNumberControllerImport
|
|
677
|
+
* @summary Import Twilio Number
|
|
678
|
+
* @request POST:/phone-number/import
|
|
679
|
+
*/
|
|
680
|
+
phoneNumberControllerImport: (data: ImportTwilioPhoneNumberDto, params: RequestParams = {}) =>
|
|
681
|
+
this.request<PhoneNumber, any>({
|
|
682
|
+
path: `/phone-number/import`,
|
|
683
|
+
method: "POST",
|
|
684
|
+
body: data,
|
|
685
|
+
type: ContentType.Json,
|
|
686
|
+
format: "json",
|
|
687
|
+
...params,
|
|
688
|
+
}),
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* No description
|
|
692
|
+
*
|
|
693
|
+
* @tags Phone Numbers
|
|
694
|
+
* @name PhoneNumberControllerFindAll
|
|
695
|
+
* @summary List Phone Numbers
|
|
696
|
+
* @request GET:/phone-number
|
|
697
|
+
*/
|
|
698
|
+
phoneNumberControllerFindAll: (params: RequestParams = {}) =>
|
|
699
|
+
this.request<PhoneNumber[], any>({
|
|
700
|
+
path: `/phone-number`,
|
|
701
|
+
method: "GET",
|
|
702
|
+
format: "json",
|
|
703
|
+
...params,
|
|
704
|
+
}),
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* No description
|
|
708
|
+
*
|
|
709
|
+
* @tags Phone Numbers
|
|
710
|
+
* @name PhoneNumberControllerFindOne
|
|
711
|
+
* @summary Get Phone Number
|
|
712
|
+
* @request GET:/phone-number/{id}
|
|
713
|
+
*/
|
|
714
|
+
phoneNumberControllerFindOne: (id: string, params: RequestParams = {}) =>
|
|
715
|
+
this.request<PhoneNumber, any>({
|
|
716
|
+
path: `/phone-number/${id}`,
|
|
717
|
+
method: "GET",
|
|
718
|
+
format: "json",
|
|
719
|
+
...params,
|
|
720
|
+
}),
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* No description
|
|
724
|
+
*
|
|
725
|
+
* @tags Phone Numbers
|
|
726
|
+
* @name PhoneNumberControllerUpdate
|
|
727
|
+
* @summary Update Phone Number
|
|
728
|
+
* @request PATCH:/phone-number/{id}
|
|
729
|
+
*/
|
|
730
|
+
phoneNumberControllerUpdate: (id: string, data: UpdatePhoneNumberDto, params: RequestParams = {}) =>
|
|
731
|
+
this.request<PhoneNumber, any>({
|
|
732
|
+
path: `/phone-number/${id}`,
|
|
733
|
+
method: "PATCH",
|
|
734
|
+
body: data,
|
|
735
|
+
type: ContentType.Json,
|
|
736
|
+
format: "json",
|
|
737
|
+
...params,
|
|
738
|
+
}),
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* No description
|
|
742
|
+
*
|
|
743
|
+
* @tags Phone Numbers
|
|
744
|
+
* @name PhoneNumberControllerRemove
|
|
745
|
+
* @summary Delete Phone Number
|
|
746
|
+
* @request DELETE:/phone-number/{id}
|
|
747
|
+
*/
|
|
748
|
+
phoneNumberControllerRemove: (id: string, params: RequestParams = {}) =>
|
|
749
|
+
this.request<void, any>({
|
|
750
|
+
path: `/phone-number/${id}`,
|
|
751
|
+
method: "DELETE",
|
|
752
|
+
...params,
|
|
753
|
+
}),
|
|
754
|
+
};
|
|
755
|
+
}
|