@azure/communication-call-automation
Version:
Azure client library for Azure Communication Call Automation services
277 lines (276 loc) • 8.7 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var callAutomationApiClient_exports = {};
__export(callAutomationApiClient_exports, {
CallAutomationApiClient: () => CallAutomationApiClient
});
module.exports = __toCommonJS(callAutomationApiClient_exports);
var coreClient = __toESM(require("@azure/core-client"));
var import_operations = require("./operations/index.js");
var Parameters = __toESM(require("./models/parameters.js"));
var Mappers = __toESM(require("./models/mappers.js"));
class CallAutomationApiClient extends coreClient.ServiceClient {
endpoint;
apiVersion;
/**
* Initializes a new instance of the CallAutomationApiClient class.
* @param endpoint The endpoint of the Azure Communication Service resource.
* @param options The parameter options
*/
constructor(endpoint, options) {
if (endpoint === void 0) {
throw new Error("'endpoint' cannot be null");
}
if (!options) {
options = {};
}
const defaults = {
requestContentType: "application/json; charset=utf-8"
};
const packageDetails = `azsdk-js-communication-call-automation/1.6.0`;
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` : `${packageDetails}`;
const optionsWithDefaults = {
...defaults,
...options,
userAgentOptions: {
userAgentPrefix
},
endpoint: options.endpoint ?? options.baseUri ?? "{endpoint}"
};
super(optionsWithDefaults);
this.endpoint = endpoint;
this.apiVersion = options.apiVersion || "2026-03-12";
this.callConnection = new import_operations.CallConnectionImpl(this);
this.callMedia = new import_operations.CallMediaImpl(this);
this.callRecording = new import_operations.CallRecordingImpl(this);
this.addCustomApiVersionPolicy(options.apiVersion);
}
/** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
addCustomApiVersionPolicy(apiVersion) {
if (!apiVersion) {
return;
}
const apiVersionPolicy = {
name: "CustomApiVersionPolicy",
async sendRequest(request, next) {
const param = request.url.split("?");
if (param.length > 1) {
const newParams = param[1].split("&").map((item) => {
if (item.indexOf("api-version") > -1) {
return "api-version=" + apiVersion;
} else {
return item;
}
});
request.url = param[0] + "?" + newParams.join("&");
}
return next(request);
}
};
this.pipeline.addPolicy(apiVersionPolicy);
}
/**
* Create an outbound call.
* @param createCallRequest The create call request.
* @param options The options parameters.
*/
createCall(createCallRequest, options) {
return this.sendOperationRequest(
{ createCallRequest, options },
createCallOperationSpec
);
}
/**
* Answer a call using the IncomingCallContext from Event Grid.
* @param answerCallRequest The answer call request.
* @param options The options parameters.
*/
answerCall(answerCallRequest, options) {
return this.sendOperationRequest(
{ answerCallRequest, options },
answerCallOperationSpec
);
}
/**
* Redirect a call.
* @param redirectCallRequest The redirect call request.
* @param options The options parameters.
*/
redirectCall(redirectCallRequest, options) {
return this.sendOperationRequest(
{ redirectCallRequest, options },
redirectCallOperationSpec
);
}
/**
* Reject the call.
* @param rejectCallRequest The reject call request.
* @param options The options parameters.
*/
rejectCall(rejectCallRequest, options) {
return this.sendOperationRequest(
{ rejectCallRequest, options },
rejectCallOperationSpec
);
}
/**
* Create a connection to a CallLocator.
* @param connectRequest The create connection request.
* @param options The options parameters.
*/
connect(connectRequest, options) {
return this.sendOperationRequest(
{ connectRequest, options },
connectOperationSpec
);
}
callConnection;
callMedia;
callRecording;
}
const serializer = coreClient.createSerializer(
Mappers,
/* isXml */
false
);
const createCallOperationSpec = {
path: "/calling/callConnections",
httpMethod: "POST",
responses: {
201: {
bodyMapper: Mappers.CallConnectionPropertiesInternal
},
default: {
bodyMapper: Mappers.CommunicationErrorResponse
}
},
requestBody: Parameters.createCallRequest,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.endpoint],
headerParameters: [
Parameters.contentType,
Parameters.accept,
Parameters.repeatabilityRequestID,
Parameters.repeatabilityFirstSent
],
mediaType: "json",
serializer
};
const answerCallOperationSpec = {
path: "/calling/callConnections:answer",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.CallConnectionPropertiesInternal
},
default: {
bodyMapper: Mappers.CommunicationErrorResponse
}
},
requestBody: Parameters.answerCallRequest,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.endpoint],
headerParameters: [
Parameters.contentType,
Parameters.accept,
Parameters.repeatabilityRequestID,
Parameters.repeatabilityFirstSent
],
mediaType: "json",
serializer
};
const redirectCallOperationSpec = {
path: "/calling/callConnections:redirect",
httpMethod: "POST",
responses: {
204: {},
default: {
bodyMapper: Mappers.CommunicationErrorResponse
}
},
requestBody: Parameters.redirectCallRequest,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.endpoint],
headerParameters: [
Parameters.contentType,
Parameters.accept,
Parameters.repeatabilityRequestID,
Parameters.repeatabilityFirstSent
],
mediaType: "json",
serializer
};
const rejectCallOperationSpec = {
path: "/calling/callConnections:reject",
httpMethod: "POST",
responses: {
204: {},
default: {
bodyMapper: Mappers.CommunicationErrorResponse
}
},
requestBody: Parameters.rejectCallRequest,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.endpoint],
headerParameters: [
Parameters.contentType,
Parameters.accept,
Parameters.repeatabilityRequestID,
Parameters.repeatabilityFirstSent
],
mediaType: "json",
serializer
};
const connectOperationSpec = {
path: "/calling/callConnections:connect",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.CallConnectionPropertiesInternal
},
default: {
bodyMapper: Mappers.CommunicationErrorResponse
}
},
requestBody: Parameters.connectRequest,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.endpoint],
headerParameters: [
Parameters.contentType,
Parameters.accept,
Parameters.repeatabilityRequestID,
Parameters.repeatabilityFirstSent
],
mediaType: "json",
serializer
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CallAutomationApiClient
});
//# sourceMappingURL=callAutomationApiClient.js.map