你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 JavaScript 的 Azure 通信呼叫自动化客户端库 - 版本 1.3.1

此包包含用于 Azure 通信呼叫自动化的 JavaScript SDK。 呼叫自动化使开发人员能够生成基于服务器的智能呼叫工作流,以及语音和 PSTN 通道的呼叫录制。

呼叫自动化产品文档 概述

开始

先决条件

安装

npm install @azure/communication-call-automation

浏览器支持

JavaScript 捆绑包

若要在浏览器中使用此客户端库,首先需要使用捆绑程序。 有关如何执行此操作的详细信息,请参阅我们的 捆绑文档

关键概念

名字 描述
CallAutomationClient CallAutomationClient 是使用此客户端库的开发人员的主要接口。 它可用于通过 createCallanswerCall发起调用。
CallConnection CallConnection 表示正在进行的调用。 使用 createCallanswerCall建立呼叫后,可以针对呼叫执行进一步操作,例如 transferaddParticipant
CallMedia CallMedia 可用于执行媒体相关操作,例如 play,以播放媒体文件。 可以从已建立的 CallConnection中检索此数据。
CallRecording CallRecording 可用于执行记录相关操作,例如 startRecording。 可以从 CallAutomationClient中检索此数据。
回调事件 回调事件是在调用期间发送回的事件。 它提供调用的信息和状态,例如 CallConnected。 必须在 CallbackUrlcreateCall期间提供 answerCall,并将回调事件发送到此 URL。 可以使用 callAutomationEventParser 在到达时分析这些事件。
传入呼叫事件 当传入呼叫发生时(可以使用 answerCall应答),将发送传入呼叫 eventgrid 事件。 这与上述回调事件不同,应在 Azure 门户中进行设置。 有关详细信息,请参阅 来电

例子

初始化 CallAutomationClient

import { DefaultAzureCredential } from "@azure/identity";
import { CallAutomationClient } from "@azure/communication-call-automation";

// Your unique Azure Communication service endpoint
const credential = new DefaultAzureCredential();
const endpointUrl = "<ENDPOINT>";
const callAutomationClient = new CallAutomationClient(endpointUrl, credential);

创建呼叫

import { DefaultAzureCredential } from "@azure/identity";
import { CallAutomationClient } from "@azure/communication-call-automation";

// Your unique Azure Communication service endpoint
const credential = new DefaultAzureCredential();
const endpointUrl = "<ENDPOINT>";
const callAutomationClient = new CallAutomationClient(endpointUrl, credential);

// target endpoint for ACS User
const target = {
  communicationUserId: "8:acs:...",
};

// make invitation
const callInvite = {
  targetParticipant: target,
};

// callback url to receive callback events
const callbackUrl = "https://<MY-EVENT-HANDLER-URL>/events";

// send out the invitation, creating call
const response = await callAutomationClient.createCall(callInvite, callbackUrl);

播放媒体

import { DefaultAzureCredential } from "@azure/identity";
import { CallAutomationClient, FileSource } from "@azure/communication-call-automation";

// Your unique Azure Communication service endpoint
const credential = new DefaultAzureCredential();
const endpointUrl = "<ENDPOINT>";
const callAutomationClient = new CallAutomationClient(endpointUrl, credential);

const target = { communicationUserId: "8:acs:..." };
const callInvite = { targetParticipant: target };
const callbackUrl = "https://<MY-EVENT-HANDLER-URL>/events";

const createCallResult = await callAutomationClient.createCall(callInvite, callbackUrl);
const callConnection = createCallResult.callConnection;
// from callconnection of response above, play media of media file
const myFile: FileSource = { url: "https://<FILE-SOURCE>/<SOME-FILE>.wav", kind: "fileSource" };
const response = await callConnection.getCallMedia().playToAll([myFile]);

故障 排除

伐木业

启用日志记录可能有助于发现有关故障的有用信息。 若要查看 HTTP 请求和响应的日志,请将 AZURE_LOG_LEVEL 环境变量设置为 info。 或者,可以在运行时通过调用 setLogLevel 中的 @azure/logger 来启用日志记录:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

后续步骤

贡献

若要参与此库,请阅读 贡献指南 了解有关如何生成和测试代码的详细信息。