Skip to content

Commit

Permalink
feat(api): update via SDK Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Mar 25, 2024
1 parent 078bacb commit 28aa126
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 185 deletions.
14 changes: 6 additions & 8 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@

Types:

- <code><a href="./src/resources/call.ts">CallDetail</a></code>
- <code><a href="./src/resources/call.ts">CallCreateResponse</a></code>
- <code><a href="./src/resources/call.ts">CallRetrieveResponse</a></code>
- <code><a href="./src/resources/call.ts">CallListResponse</a></code>
- <code><a href="./src/resources/call.ts">CallRegisterResponse</a></code>

Methods:

- <code title="post /create-phone-call">client.call.<a href="./src/resources/call.ts">create</a>({ ...params }) -> CallCreateResponse</code>
- <code title="get /get-call/{call_id}">client.call.<a href="./src/resources/call.ts">retrieve</a>(callId) -> CallRetrieveResponse</code>
- <code title="get /get-call/{call_id}">client.call.<a href="./src/resources/call.ts">retrieve</a>(callId) -> CallDetail</code>
- <code title="get /list-calls">client.call.<a href="./src/resources/call.ts">list</a>({ ...params }) -> CallListResponse</code>
- <code title="post /register-call">client.call.<a href="./src/resources/call.ts">register</a>({ ...params }) -> CallRegisterResponse</code>

# PhoneNumber

Types:

- <code><a href="./src/resources/phone-number.ts">PhoneNumberCreateResponse</a></code>
- <code><a href="./src/resources/phone-number.ts">PhoneNumberRetrieveResponse</a></code>
- <code><a href="./src/resources/phone-number.ts">PhoneNumberUpdateResponse</a></code>
- <code><a href="./src/resources/phone-number.ts">PhoneNumber</a></code>
- <code><a href="./src/resources/phone-number.ts">PhoneNumberListResponse</a></code>

Methods:

- <code title="post /create-phone-number">client.phoneNumber.<a href="./src/resources/phone-number.ts">create</a>({ ...params }) -> PhoneNumberCreateResponse</code>
- <code title="get /get-phone-number/{phone_number}">client.phoneNumber.<a href="./src/resources/phone-number.ts">retrieve</a>(phoneNumber) -> PhoneNumberRetrieveResponse</code>
- <code title="patch /update-phone-number/{phone_number}">client.phoneNumber.<a href="./src/resources/phone-number.ts">update</a>(phoneNumber, { ...params }) -> PhoneNumberUpdateResponse</code>
- <code title="post /create-phone-number">client.phoneNumber.<a href="./src/resources/phone-number.ts">create</a>({ ...params }) -> PhoneNumber</code>
- <code title="get /get-phone-number/{phone_number}">client.phoneNumber.<a href="./src/resources/phone-number.ts">retrieve</a>(phoneNumber) -> PhoneNumber</code>
- <code title="patch /update-phone-number/{phone_number}">client.phoneNumber.<a href="./src/resources/phone-number.ts">update</a>(phoneNumber, { ...params }) -> PhoneNumber</code>
- <code title="get /list-phone-number">client.phoneNumber.<a href="./src/resources/phone-number.ts">list</a>() -> PhoneNumberListResponse</code>
- <code title="delete /delete-phone-number/{phone_number}">client.phoneNumber.<a href="./src/resources/phone-number.ts">delete</a>(phoneNumber) -> void</code>

Expand Down
16 changes: 7 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as API from 'retell-sdk/resources/index';

export interface ClientOptions {
/**
* Defaults to process.env['TODDLZT_API_KEY'].
* Defaults to process.env['RETELL_API_KEY'].
*/
apiKey?: string | undefined;

Expand Down Expand Up @@ -79,7 +79,7 @@ export class RetellSdk extends Core.APIClient {
/**
* API Client for interfacing with the Retell Sdk API.
*
* @param {string | undefined} [opts.apiKey=process.env['TODDLZT_API_KEY'] ?? undefined]
* @param {string | undefined} [opts.apiKey=process.env['RETELL_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['RETELL_SDK_BASE_URL'] ?? https://api.retellai.com] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
Expand All @@ -90,12 +90,12 @@ export class RetellSdk extends Core.APIClient {
*/
constructor({
baseURL = Core.readEnv('RETELL_SDK_BASE_URL'),
apiKey = Core.readEnv('TODDLZT_API_KEY'),
apiKey = Core.readEnv('RETELL_API_KEY'),
...opts
}: ClientOptions = {}) {
if (apiKey === undefined) {
throw new Errors.RetellSdkError(
"The TODDLZT_API_KEY environment variable is missing or empty; either provide it, or instantiate the RetellSdk client with an apiKey option, like new RetellSdk({ apiKey: 'My API Key' }).",
"The RETELL_API_KEY environment variable is missing or empty; either provide it, or instantiate the RetellSdk client with an apiKey option, like new RetellSdk({ apiKey: 'My API Key' }).",
);
}

Expand All @@ -118,7 +118,7 @@ export class RetellSdk extends Core.APIClient {
}

call: API.Call = new API.Call(this);
phoneNumber: API.PhoneNumber = new API.PhoneNumber(this);
phoneNumber: API.PhoneNumberResource = new API.PhoneNumberResource(this);
agent: API.Agent = new API.Agent(this);
llm: API.Llm = new API.Llm(this);

Expand Down Expand Up @@ -185,18 +185,16 @@ export namespace RetellSdk {
export import RequestOptions = Core.RequestOptions;

export import Call = API.Call;
export import CallDetail = API.CallDetail;
export import CallCreateResponse = API.CallCreateResponse;
export import CallRetrieveResponse = API.CallRetrieveResponse;
export import CallListResponse = API.CallListResponse;
export import CallRegisterResponse = API.CallRegisterResponse;
export import CallCreateParams = API.CallCreateParams;
export import CallListParams = API.CallListParams;
export import CallRegisterParams = API.CallRegisterParams;

export import PhoneNumberResource = API.PhoneNumberResource;
export import PhoneNumber = API.PhoneNumber;
export import PhoneNumberCreateResponse = API.PhoneNumberCreateResponse;
export import PhoneNumberRetrieveResponse = API.PhoneNumberRetrieveResponse;
export import PhoneNumberUpdateResponse = API.PhoneNumberUpdateResponse;
export import PhoneNumberListResponse = API.PhoneNumberListResponse;
export import PhoneNumberCreateParams = API.PhoneNumberCreateParams;
export import PhoneNumberUpdateParams = API.PhoneNumberUpdateParams;
Expand Down
115 changes: 5 additions & 110 deletions src/resources/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Call extends APIResource {
/**
* Retrieve details of a specific call
*/
retrieve(callId: string, options?: Core.RequestOptions): Core.APIPromise<CallRetrieveResponse> {
retrieve(callId: string, options?: Core.RequestOptions): Core.APIPromise<CallDetail> {
return this._client.get(`/get-call/${callId}`, options);
}

Expand All @@ -43,7 +43,7 @@ export class Call extends APIResource {
}
}

export interface CallCreateResponse {
export interface CallDetail {
/**
* Corresponding agent id of this call.
*/
Expand Down Expand Up @@ -146,7 +146,7 @@ export interface CallCreateResponse {
to_number?: string;
}

export interface CallRetrieveResponse {
export interface CallCreateResponse {
/**
* Corresponding agent id of this call.
*/
Expand Down Expand Up @@ -249,112 +249,7 @@ export interface CallRetrieveResponse {
to_number?: string;
}

export type CallListResponse = Array<CallListResponse.CallListResponseItem>;

export namespace CallListResponse {
export interface CallListResponseItem {
/**
* Corresponding agent id of this call.
*/
agent_id: string;

/**
* The audio encoding of the call. The following formats are supported:
*
* - `s16le` 16 bit linear PCM audio, the native format for web audio capture and
* playback.
*
* - `mulaw` non-linear audio encoding technique used in telephony. Commonly used
* by Twilio.
*/
audio_encoding: 's16le' | 'mulaw';

/**
* Where the audio websocket would connect from would determine the format /
* protocol of websocket messages, and would determine how our server read audio
* bytes and send audio bytes.:
*
* - `web`: The protocol defined by Retell, commonly used for connecting from web
* frontend. Also useful for those who want to manipulate audio bytes directly.
*
* - `twilio`: The
* [websocket protocol](https://www.twilio.com/docs/voice/twiml/stream#message-media)
* defined by Twilio, used when your system uses Twilio, and supplies Retell
* audio websocket url to Twilio.
*/
audio_websocket_protocol: 'web' | 'twilio';

/**
* Unique id of the call. Used to identify in LLM websocket and used to
* authenticate in audio websocket.
*/
call_id: string;

/**
* Status of call.
*
* - `registered`: Call id issued, ready to make a call using this id.
*
* - `ongoing`: Call connected and ongoing.
*
* - `ended`: The underlying websocket has ended for the call. Either user or agent
* hanged up, or call transferred.
*
* - `error`: Call encountered error.
*/
call_status: 'registered' | 'ongoing' | 'ended' | 'error';

/**
* Sample rate of the conversation, the input and output audio bytes will all
* conform to this rate. Check the audio source, audio format, and voice used for
* the agent to select one that works. supports value ranging from [8000, 48000].
* Note for Twilio `mulaw` encoding, the sample rate has to be 8000.
*
* - `s16le` sample rate recommendation (natively supported, lowest latency):
*
* - elevenlabs voices: 16000, 22050, 24000, 44100.
* - openai voices: 24000.
*
* - deepgram voices: 8000, 16000, 24000, 32000, 48000.
*/
sample_rate: number;

/**
* Begin timestamp (milliseconds since epoch) of the call.
*/
start_timestamp: number;

/**
* If users stay silent for a period, end the call. By default, it is set to
* 600,000 ms (10 min). The minimum value allowed is 10,000 ms (10 s).
*/
end_call_after_silence_ms?: number;

/**
* The caller number. This field is storage purpose only, set this if you want the
* call object to contain it so that it's easier to reference it. Not used for
* processing, when we connect to your LLM websocket server, you can then get it
* from the call object.
*/
from_number?: string;

/**
* An abtriary object for storage purpose only. You can put anything here like your
* own id for the call, twilio SID, internal customer id. Not used for processing,
* when we connect to your LLM websocket server, you can then get it from the call
* object.
*/
metadata?: unknown;

/**
* The callee number. This field is storage purpose only, set this if you want the
* call object to contain it so that it's easier to reference it. Not used for
* processing, when we connect to your LLM websocket server, you can then get it
* from the call object.
*/
to_number?: string;
}
}
export type CallListResponse = Array<CallDetail>;

export interface CallRegisterResponse {
/**
Expand Down Expand Up @@ -617,8 +512,8 @@ export interface CallRegisterParams {
}

export namespace Call {
export import CallDetail = CallAPI.CallDetail;
export import CallCreateResponse = CallAPI.CallCreateResponse;
export import CallRetrieveResponse = CallAPI.CallRetrieveResponse;
export import CallListResponse = CallAPI.CallListResponse;
export import CallRegisterResponse = CallAPI.CallRegisterResponse;
export import CallCreateParams = CallAPI.CallCreateParams;
Expand Down
8 changes: 3 additions & 5 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export {
Agent,
} from './agent';
export {
CallDetail,
CallCreateResponse,
CallRetrieveResponse,
CallListResponse,
CallRegisterResponse,
CallCreateParams,
Expand All @@ -29,11 +29,9 @@ export {
Llm,
} from './llm';
export {
PhoneNumberCreateResponse,
PhoneNumberRetrieveResponse,
PhoneNumberUpdateResponse,
PhoneNumber,
PhoneNumberListResponse,
PhoneNumberCreateParams,
PhoneNumberUpdateParams,
PhoneNumber,
PhoneNumberResource,
} from './phone-number';
59 changes: 8 additions & 51 deletions src/resources/phone-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ import * as Core from 'retell-sdk/core';
import { APIResource } from 'retell-sdk/resource';
import * as PhoneNumberAPI from 'retell-sdk/resources/phone-number';

export class PhoneNumber extends APIResource {
export class PhoneNumberResource extends APIResource {
/**
* Buy a new phone number
*/
create(
body: PhoneNumberCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<PhoneNumberCreateResponse> {
create(body: PhoneNumberCreateParams, options?: Core.RequestOptions): Core.APIPromise<PhoneNumber> {
return this._client.post('/create-phone-number', { body, ...options });
}

/**
* Retrieve details of a specific phone number
*/
retrieve(phoneNumber: string, options?: Core.RequestOptions): Core.APIPromise<PhoneNumberRetrieveResponse> {
retrieve(phoneNumber: string, options?: Core.RequestOptions): Core.APIPromise<PhoneNumber> {
return this._client.get(`/get-phone-number/${phoneNumber}`, options);
}

Expand All @@ -29,7 +26,7 @@ export class PhoneNumber extends APIResource {
phoneNumber: string,
body: PhoneNumberUpdateParams,
options?: Core.RequestOptions,
): Core.APIPromise<PhoneNumberUpdateResponse> {
): Core.APIPromise<PhoneNumber> {
return this._client.patch(`/update-phone-number/${phoneNumber}`, { body, ...options });
}

Expand All @@ -51,31 +48,7 @@ export class PhoneNumber extends APIResource {
}
}

export interface PhoneNumberCreateResponse {
agent_id: string;

area_code: number;

last_modification_timestamp: number;

phone_number: string;

phone_number_pretty: string;
}

export interface PhoneNumberRetrieveResponse {
agent_id: string;

area_code: number;

last_modification_timestamp: number;

phone_number: string;

phone_number_pretty: string;
}

export interface PhoneNumberUpdateResponse {
export interface PhoneNumber {
agent_id: string;

area_code: number;
Expand All @@ -87,21 +60,7 @@ export interface PhoneNumberUpdateResponse {
phone_number_pretty: string;
}

export type PhoneNumberListResponse = Array<PhoneNumberListResponse.PhoneNumberListResponseItem>;

export namespace PhoneNumberListResponse {
export interface PhoneNumberListResponseItem {
agent_id: string;

area_code: number;

last_modification_timestamp: number;

phone_number: string;

phone_number_pretty: string;
}
}
export type PhoneNumberListResponse = Array<PhoneNumber>;

export interface PhoneNumberCreateParams {
/**
Expand All @@ -123,10 +82,8 @@ export interface PhoneNumberUpdateParams {
agent_id: string;
}

export namespace PhoneNumber {
export import PhoneNumberCreateResponse = PhoneNumberAPI.PhoneNumberCreateResponse;
export import PhoneNumberRetrieveResponse = PhoneNumberAPI.PhoneNumberRetrieveResponse;
export import PhoneNumberUpdateResponse = PhoneNumberAPI.PhoneNumberUpdateResponse;
export namespace PhoneNumberResource {
export import PhoneNumber = PhoneNumberAPI.PhoneNumber;
export import PhoneNumberListResponse = PhoneNumberAPI.PhoneNumberListResponse;
export import PhoneNumberCreateParams = PhoneNumberAPI.PhoneNumberCreateParams;
export import PhoneNumberUpdateParams = PhoneNumberAPI.PhoneNumberUpdateParams;
Expand Down
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ describe('instantiate client', () => {

test('with environment variable arguments', () => {
// set options via env var
process.env['TODDLZT_API_KEY'] = 'My API Key';
process.env['RETELL_API_KEY'] = 'My API Key';
const client = new RetellSdk();
expect(client.apiKey).toBe('My API Key');
});

test('with overriden environment variable arguments', () => {
// set options via env var
process.env['TODDLZT_API_KEY'] = 'another My API Key';
process.env['RETELL_API_KEY'] = 'another My API Key';
const client = new RetellSdk({ apiKey: 'My API Key' });
expect(client.apiKey).toBe('My API Key');
});
Expand Down

0 comments on commit 28aa126

Please sign in to comment.