phonic
Version:
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FPhonic-Co%2Fphonic-node) [ • 44.6 kB
JavaScript
// This file was auto-generated by Fern from our API Definition.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs";
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
import * as core from "../../../../core/index.mjs";
import * as environments from "../../../../environments.mjs";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
import * as errors from "../../../../errors/index.mjs";
import * as Phonic from "../../../index.mjs";
export class AgentsClient {
constructor(options = {}) {
this._options = normalizeClientOptionsWithAuth(options);
}
/**
* Returns all agents in a project.
*
* @param {Phonic.AgentsListRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.agents.list()
*/
list(request = {}, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__list(request, requestOptions));
}
__list() {
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request;
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, "agents"),
method: "GET",
headers: _headers,
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
case 500:
throw new Phonic.InternalServerError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/agents");
});
}
/**
* Creates a new agent in a project.
*
* @param {Phonic.AgentsCreateRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.agents.create({
* project: "main",
* name: "support-agent",
* phone_number: "assign-automatically",
* timezone: "America/Los_Angeles",
* voice_id: "sabrina",
* audio_speed: 1,
* background_noise_level: 0,
* generate_welcome_message: false,
* is_welcome_message_interruptible: true,
* welcome_message: "Hi {{customer_name}}. How can I help you today?",
* system_prompt: "You are an expert in {{subject}}. Be friendly, helpful and concise.",
* template_variables: {
* "customer_name": {
* default_value: "David"
* },
* "subject": {
* default_value: "Chess"
* }
* },
* tools: ["keypad_input"],
* generate_no_input_poke_text: false,
* no_input_poke_sec: 30,
* no_input_poke_text: "Are you still there?",
* default_language: "en",
* additional_languages: ["es"],
* multilingual_mode: "request",
* push_to_talk: false,
* boosted_keywords: ["Load ID", "dispatch"],
* pronunciation_dictionary: [{
* word: "Phuket",
* pronunciation: "Poo-ket"
* }],
* min_words_to_interrupt: 1,
* configuration_endpoint: {
* url: "https://api.example.com/config",
* headers: {
* "Authorization": "Bearer token123"
* },
* timeout_ms: 7000
* }
* })
*/
create(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions));
}
__create(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request, _body = __rest(request, ["project"]);
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, "agents"),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Phonic.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Phonic.UnauthorizedError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
case 500:
throw new Phonic.InternalServerError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/agents");
});
}
/**
* Upserts an agent by name. If an agent with the same name already exists, it will be updated. Otherwise, it will be created.
*
* @param {Phonic.UpsertAgentRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.NotFoundError}
*
* @example
* await client.agents.upsert({
* project: "main",
* name: "support-agent",
* phone_number: "assign-automatically",
* timezone: "America/Los_Angeles",
* voice_id: "sabrina",
* audio_speed: 1,
* background_noise_level: 0,
* generate_welcome_message: false,
* is_welcome_message_interruptible: true,
* welcome_message: "Hi {{customer_name}}. How can I help you today?",
* system_prompt: "You are an expert in {{subject}}. Be friendly, helpful and concise.",
* template_variables: {
* "customer_name": {
* default_value: "David"
* },
* "subject": {
* default_value: "Chess"
* }
* },
* tools: ["keypad_input"],
* generate_no_input_poke_text: false,
* no_input_poke_sec: 30,
* no_input_poke_text: "Are you still there?",
* default_language: "en",
* additional_languages: ["es"],
* multilingual_mode: "request",
* push_to_talk: false,
* boosted_keywords: ["Load ID", "dispatch"],
* pronunciation_dictionary: [{
* word: "Phuket",
* pronunciation: "Poo-ket"
* }],
* min_words_to_interrupt: 1,
* configuration_endpoint: {
* url: "https://api.example.com/config",
* headers: {
* "Authorization": "Bearer token123"
* },
* timeout_ms: 7000
* }
* })
*/
upsert(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__upsert(request, requestOptions));
}
__upsert(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request, _body = __rest(request, ["project"]);
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, "agents/upsert"),
method: "PUT",
headers: _headers,
contentType: "application/json",
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Phonic.BadRequestError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "PUT", "/agents/upsert");
});
}
/**
* Returns an agent by name or ID.
*
* @param {string} nameOrId - The name or the ID of the agent to get.
* @param {Phonic.AgentsGetRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
*
* @example
* await client.agents.get("nameOrId", {
* project: "main"
* })
*/
get(nameOrId, request = {}, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__get(nameOrId, request, requestOptions));
}
__get(nameOrId_1) {
return __awaiter(this, arguments, void 0, function* (nameOrId, request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request;
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, `agents/${core.url.encodePathParam(nameOrId)}`),
method: "GET",
headers: _headers,
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 403:
throw new Phonic.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/agents/{nameOrId}");
});
}
/**
* Deletes an agent by name or ID.
*
* @param {string} nameOrId - The name or the ID of the agent to delete.
* @param {Phonic.AgentsDeleteRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
*
* @example
* await client.agents.delete("nameOrId", {
* project: "main"
* })
*/
delete(nameOrId, request = {}, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__delete(nameOrId, request, requestOptions));
}
__delete(nameOrId_1) {
return __awaiter(this, arguments, void 0, function* (nameOrId, request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request;
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, `agents/${core.url.encodePathParam(nameOrId)}`),
method: "DELETE",
headers: _headers,
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 403:
throw new Phonic.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "DELETE", "/agents/{nameOrId}");
});
}
/**
* Updates an agent by name or ID.
*
* @param {string} nameOrId - The name or the ID of the agent to update.
* @param {Phonic.UpdateAgentRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
*
* @example
* await client.agents.update("nameOrId", {
* project: "main",
* name: "updated-support-agent",
* phone_number: "assign-automatically",
* timezone: "America/Los_Angeles",
* voice_id: "sabrina",
* audio_speed: 1,
* background_noise_level: 0,
* generate_welcome_message: false,
* is_welcome_message_interruptible: true,
* welcome_message: "Hi {{customer_name}}. How can I help you today?",
* system_prompt: "You are an expert in {{subject}}. Be friendly, helpful and concise.",
* template_variables: {
* "customer_name": {
* default_value: "David"
* },
* "subject": {
* default_value: "Chess"
* }
* },
* tools: ["keypad_input"],
* generate_no_input_poke_text: false,
* no_input_poke_sec: 30,
* no_input_poke_text: "Are you still there?",
* default_language: "en",
* additional_languages: ["es"],
* multilingual_mode: "request",
* push_to_talk: false,
* boosted_keywords: ["Load ID", "dispatch"],
* pronunciation_dictionary: [{
* word: "Phuket",
* pronunciation: "Poo-ket"
* }],
* min_words_to_interrupt: 1,
* configuration_endpoint: {
* url: "https://api.example.com/config",
* headers: {
* "Authorization": "Bearer token123"
* },
* timeout_ms: 7000
* }
* })
*/
update(nameOrId, request = {}, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__update(nameOrId, request, requestOptions));
}
__update(nameOrId_1) {
return __awaiter(this, arguments, void 0, function* (nameOrId, request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request, _body = __rest(request, ["project"]);
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, `agents/${core.url.encodePathParam(nameOrId)}`),
method: "PATCH",
headers: _headers,
contentType: "application/json",
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Phonic.BadRequestError(_response.error.body, _response.rawResponse);
case 403:
throw new Phonic.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "PATCH", "/agents/{nameOrId}");
});
}
/**
* Adds a custom phone number to an agent. The user must configure their SIP trunk to point to Phonic's SIP server.
*
* @param {string} nameOrId - The name or the ID of the agent.
* @param {Phonic.AgentsAddCustomPhoneNumberRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.ConflictError}
*
* @example
* await client.agents.addCustomPhoneNumber("nameOrId", {
* project: "main",
* phone_number: "+15551234567",
* configuration_endpoint: {
* url: "https://api.example.com/config",
* headers: {
* "Authorization": "Bearer token123"
* },
* timeout_ms: 7000
* }
* })
*/
addCustomPhoneNumber(nameOrId, request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__addCustomPhoneNumber(nameOrId, request, requestOptions));
}
__addCustomPhoneNumber(nameOrId, request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project, "X-Sip-Address": sipAddress, "X-Sip-Auth-Username": sipAuthUsername, "X-Sip-Auth-Password": sipAuthPassword } = request, _body = __rest(request, ["project", "X-Sip-Address", "X-Sip-Auth-Username", "X-Sip-Auth-Password"]);
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({
"X-Sip-Address": sipAddress,
"X-Sip-Auth-Username": sipAuthUsername,
"X-Sip-Auth-Password": sipAuthPassword,
}), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, `agents/${core.url.encodePathParam(nameOrId)}/custom-phone-numbers`),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Phonic.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Phonic.UnauthorizedError(_response.error.body, _response.rawResponse);
case 403:
throw new Phonic.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
case 409:
throw new Phonic.ConflictError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/agents/{nameOrId}/custom-phone-numbers");
});
}
/**
* Deletes a custom phone number from an agent.
*
* @param {string} nameOrId - The name or the ID of the agent.
* @param {Phonic.AgentsDeleteCustomPhoneNumberRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.ConflictError}
*
* @example
* await client.agents.deleteCustomPhoneNumber("nameOrId", {
* project: "main",
* phone_number: "+15551234567"
* })
*/
deleteCustomPhoneNumber(nameOrId, request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__deleteCustomPhoneNumber(nameOrId, request, requestOptions));
}
__deleteCustomPhoneNumber(nameOrId, request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request, _body = __rest(request, ["project"]);
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, `agents/${core.url.encodePathParam(nameOrId)}/custom-phone-numbers`),
method: "DELETE",
headers: _headers,
contentType: "application/json",
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Phonic.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Phonic.UnauthorizedError(_response.error.body, _response.rawResponse);
case 403:
throw new Phonic.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
case 409:
throw new Phonic.ConflictError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "DELETE", "/agents/{nameOrId}/custom-phone-numbers");
});
}
/**
* Updates a phone number on an agent.
*
* @param {string} nameOrId - The name or the ID of the agent.
* @param {Phonic.AgentsUpdatePhoneNumberRequest} request
* @param {AgentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.ConflictError}
*
* @example
* await client.agents.updatePhoneNumber("nameOrId", {
* project: "main",
* phone_number: "+15551234567",
* configuration_endpoint: {
* url: "https://api.example.com/config",
* headers: {
* "Authorization": "Bearer token123"
* },
* timeout_ms: 7000
* }
* })
*/
updatePhoneNumber(nameOrId, request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__updatePhoneNumber(nameOrId, request, requestOptions));
}
__updatePhoneNumber(nameOrId, request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { project } = request, _body = __rest(request, ["project"]);
const _queryParams = {
project,
};
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.PhonicEnvironment.Default)
.base, `agents/${core.url.encodePathParam(nameOrId)}/phone-numbers`),
method: "PATCH",
headers: _headers,
contentType: "application/json",
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Phonic.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Phonic.UnauthorizedError(_response.error.body, _response.rawResponse);
case 403:
throw new Phonic.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Phonic.NotFoundError(_response.error.body, _response.rawResponse);
case 409:
throw new Phonic.ConflictError(_response.error.body, _response.rawResponse);
default:
throw new errors.PhonicError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "PATCH", "/agents/{nameOrId}/phone-numbers");
});
}
}