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) [ || 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";
import { ReconnectableConversationsSocket } from "../../../../custom/ReconnectableConversationsSocket.mjs";
import { ConversationsSocket } from "./Socket.mjs";
export class ConversationsClient {
constructor(options = {}) {
this._options = normalizeClientOptionsWithAuth(options);
}
/**
* Returns conversations with optional filtering.
*
* @param {Phonic.ConversationsListRequest} request
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.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, external_id: externalId, duration_min: durationMin, duration_max: durationMax, started_at_min: startedAtMin, started_at_max: startedAtMax, before, after, limit, audio_container: audioContainer, } = request;
const _queryParams = {
project,
external_id: externalId,
duration_min: durationMin,
duration_max: durationMax,
started_at_min: startedAtMin,
started_at_max: startedAtMax,
before,
after,
limit,
audio_container: audioContainer != null ? audioContainer : undefined,
};
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, "conversations"),
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 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 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", "/conversations");
});
}
/**
* Returns a conversation by ID.
*
* @param {string} id - The ID of the conversation to get.
* @param {Phonic.ConversationsGetRequest} request
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.get("id")
*/
get(id, request = {}, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__get(id, request, requestOptions));
}
__get(id_1) {
return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { audio_container: audioContainer } = request;
const _queryParams = {
audio_container: audioContainer != null ? audioContainer : undefined,
};
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, `conversations/${core.url.encodePathParam(id)}`),
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 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 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", "/conversations/{id}");
});
}
/**
* Cancels an active conversation.
*
* @param {string} id - The ID of the conversation to cancel.
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.ConflictError}
* @throws {@link Phonic.InternalServerError}
* @throws {@link Phonic.GatewayTimeoutError}
*
* @example
* await client.conversations.cancel("id")
*/
cancel(id, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__cancel(id, requestOptions));
}
__cancel(id, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/cancel`),
method: "POST",
headers: _headers,
queryParameters: 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 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);
case 500:
throw new Phonic.InternalServerError(_response.error.body, _response.rawResponse);
case 504:
throw new Phonic.GatewayTimeoutError(_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", "/conversations/{id}/cancel");
});
}
/**
* Deletes a conversation, scheduling its transcripts and audio recordings for deletion. The conversation must have ended.
*
* @param {string} id - The ID of the conversation to delete.
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.ConflictError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.delete("id")
*/
delete(id, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__delete(id, requestOptions));
}
__delete(id, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}`),
method: "DELETE",
headers: _headers,
queryParameters: 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 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);
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, "DELETE", "/conversations/{id}");
});
}
/**
* Returns an analysis of the specified conversation.
*
* @param {string} id - The ID of the conversation to analyze.
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.getAnalysis("id")
*/
getAnalysis(id, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__getAnalysis(id, requestOptions));
}
__getAnalysis(id, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/analysis`),
method: "GET",
headers: _headers,
queryParameters: 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 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 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", "/conversations/{id}/analysis");
});
}
/**
* Returns all extractions for a conversation.
*
* @param {string} id - The ID of the conversation to get extractions for.
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.listExtractions("id")
*/
listExtractions(id, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__listExtractions(id, requestOptions));
}
__listExtractions(id, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/extractions`),
method: "GET",
headers: _headers,
queryParameters: 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 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 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", "/conversations/{id}/extractions");
});
}
/**
* Extracts data from a conversation using a schema.
*
* @param {string} id - The ID of the conversation to extract data from.
* @param {Phonic.ExtractDataRequest} request
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.extractData("id", {
* schema_id: "conv_extract_schema_6458e4ac-533c-4bdf-8e6d-c2f06f87fd5c"
* })
*/
extractData(id, request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__extractData(id, request, requestOptions));
}
__extractData(id, request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/extractions`),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
requestType: "json",
body: request,
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 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", "/conversations/{id}/extractions");
});
}
/**
* Returns all evaluations for a conversation.
*
* @param {string} id - The ID of the conversation to get evaluations for.
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.listEvaluations("id")
*/
listEvaluations(id, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__listEvaluations(id, requestOptions));
}
__listEvaluations(id, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/evals`),
method: "GET",
headers: _headers,
queryParameters: 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 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 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", "/conversations/{id}/evals");
});
}
/**
* Evaluates a conversation using an evaluation prompt.
*
* @param {string} id - The ID of the conversation to evaluate.
* @param {Phonic.EvaluateConversationRequest} request
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ForbiddenError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.evaluate("id", {
* prompt_id: "conv_eval_prompt_d7cfe45d-35db-4ef6-a254-81ab1da76ce0"
* })
*/
evaluate(id, request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__evaluate(id, request, requestOptions));
}
__evaluate(id, request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/evals`),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
requestType: "json",
body: request,
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 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", "/conversations/{id}/evals");
});
}
/**
* Replays an ended conversation by re-running its recorded audio through an agent. Requires API key or access
* token authentication. The conversation must have audio recordings available and an associated agent (or one
* specified in the request body).
*
* @param {string} id - The ID of the conversation to replay.
* @param {Phonic.ReplayConversationRequest} request
* @param {ConversationsClient.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}
* @throws {@link Phonic.UnprocessableEntityError}
* @throws {@link Phonic.TooManyRequestsError}
* @throws {@link Phonic.InternalServerError}
* @throws {@link Phonic.ServiceUnavailableError}
*
* @example
* await client.conversations.replay("id", {
* agent: "support-agent"
* })
*/
replay(id, request = {}, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__replay(id, request, requestOptions));
}
__replay(id_1) {
return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, `conversations/${core.url.encodePathParam(id)}/replay`),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
requestType: "json",
body: request,
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);
case 422:
throw new Phonic.UnprocessableEntityError(_response.error.body, _response.rawResponse);
case 429:
throw new Phonic.TooManyRequestsError(_response.error.body, _response.rawResponse);
case 500:
throw new Phonic.InternalServerError(_response.error.body, _response.rawResponse);
case 503:
throw new Phonic.ServiceUnavailableError(_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", "/conversations/{id}/replay");
});
}
/**
* Initiates a call to a given phone number using Phonic's Twilio account.
*
* @param {Phonic.OutboundCallRequest} request
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.NotFoundError}
* @throws {@link Phonic.InternalServerError}
*
* @example
* await client.conversations.outboundCall({
* to_phone_number: "+19189397081",
* config: {
* agent: "support-agent",
* 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": "David",
* "subject": "Chess"
* },
* voice_id: "sabrina",
* generate_no_input_poke_text: false,
* no_input_poke_sec: 30,
* no_input_poke_text: "Are you still there?",
* no_input_end_conversation_sec: 180,
* default_language: "en",
* additional_languages: ["es"],
* multilingual_mode: "request",
* boosted_keywords: ["Load ID", "dispatch"],
* tools: ["keypad_input"]
* }
* })
*/
outboundCall(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__outboundCall(request, requestOptions));
}
__outboundCall(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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, "conversations/outbound_call"),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
requestType: "json",
body: request,
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", "/conversations/outbound_call");
});
}
/**
* Initiates a SIP outbound call using user-supplied SIP credentials in headers.
*
* @param {Phonic.ConversationsSipOutboundCallRequest} request
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Phonic.BadRequestError}
* @throws {@link Phonic.UnauthorizedError}
* @throws {@link Phonic.ConflictError}
* @throws {@link