# @azure/communication-call-automation 中文文档

规范地址：https://npmcn.com/package/%40azure/communication-call-automation/

版本：1\.6\.0
npm 元数据更新时间：2026-06-18T00:20:41.749Z
中文译文更新时间：2026-11-07T12:52:26.462Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40azure/communication-call-automation
原文对照：https://npmcn.com/package/%40azure/communication-call-automation/?lang=original
项目主页：https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-call-automation/README.md
源码仓库：https://github.com/Azure/azure-sdk-for-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：2.5 MB，254 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.0\.0
- 运行依赖：11 个
- 首次发布：2023-03-15T21:09:04.274Z
- 最新版本发布：2026-06-18T00:20:41.564Z
- 近 30 天下载量：195744（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：373（近 12 个月 55 个）

## 中文简介

Azure 通信呼叫自动化服务的 Azure 客户端库

## 安装

```sh
npm install @azure/communication-call-automation
```

也可以使用：`pnpm add @azure/communication-call-automation`、`yarn add @azure/communication-call-automation`、`bun add @azure/communication-call-automation`

## README

# Azure 通信呼叫 JavaScript 自动化客户端库

这个包包含一个用于Azure Conference Call Automation的JavaScript SDK. Call Automation为开发者提供了构建基于服务器,智能调用工作流程的能力,并为语音和PSTN频道提供调用录音.

[呼叫自动化概览](https://learn.microsoft.com/azure/communication-services/concepts/voice-video-calling/call-automation) | [产品文档](https://learn.microsoft.com/azure/communication-services/overview)

## 开始

### 先决条件

-   一个 [Azure 订阅](https://azure.microsoft.com/free/)。 。 。 .
-   现有通信服务资源。 如果您需要创建资源, 您可以使用 [Azure 门户](https://portal.azure.com/),则 [Azure 动力壳](https://learn.microsoft.com/powershell/module/az.communication/new-azcommunicationservice),或 [阿苏尔CLI](https://learn.microsoft.com/cli/azure)。 。 。 .

### 安装

```bash
npm install @azure/communication-call-automation
```

### 浏览器支持

#### Java 脚本套装

要在浏览器中使用此客户端库,首先需要使用捆绑器. 关于如何做到这一点的详情,请参见我们 [捆绑文件](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/Bundling.md)。 。 。 .

## 关键概念

| 名称 | 说明 |
| --- | --- |
| 调用自动连接 | `CallAutomationClient` 是开发者使用此客户端库的主要界面。 它可以用来启动呼叫 由 `createCall` 或者说 `answerCall`。 。 。 . |
| 调用连接 | `CallConnection` 代表着不断发出的呼吁。 电话一旦确定 `createCall` 或者说 `answerCall`,可以对该呼吁采取进一步行动,例如: `transfer` 或者说 `addParticipant`。 。 。 . |
| 调用媒体 | `CallMedia` 可用于开展媒体相关行动,例如 `play`,用于播放媒体文件。 可从已建立 `CallConnection`。 。 。 . |
| 调用记录 | `CallRecording` 可用于记录相关的动作,例如 `startRecording`。可从 `CallAutomationClient`。 。 。 . |
| 回调事件 | 召回事件(英語:Callback events)是指在召回期间发回的事件. 它提供了信息和通话状态,例如: `CallConnected`。 。 。 . `CallbackUrl` 必须在 `createCall` 财务报告和审定财务报表 `answerCall`,然后将召回事件发送给此 URL。 你用得着 `callAutomationEventParser` 来分析这些事情. |
| 来电事件 | 当来电发生时( 可用 `answerCall`,将发送来电事件网。 这与上面的Callback事件不同,应该设置在Azure门户网站上. 见 [来电](https://learn.microsoft.com/azure/communication-services/concepts/voice-video-calling/incoming-call-notification) 细节. |

## 实例

### 初始化调用自动连接

```ts
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);
```

### 创建调用

```ts
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);
```

### 播放媒体

```ts
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`数字 :

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

setLogLevel("info");
```

## 今后的步骤

-   [调用自动化概览](https://learn.microsoft.com/azure/communication-services/concepts/voice-video-calling/call-automation)
-   [即将到来的呼叫概念](https://learn.microsoft.com/azure/communication-services/concepts/voice-video-calling/incoming-call-notification)
-   [使用调用自动化构建客户交互工作流程](https://learn.microsoft.com/azure/communication-services/quickstarts/voice-video-calling/callflows-for-customer-interactions?pivots=programming-language-csha)
-   [以呼叫自动化方式重新定向入境电话](https://learn.microsoft.com/azure/communication-services/how-tos/call-automation-sdk/redirect-inbound-telephony-calls?pivots=programming-language-csharp)
-   [快速启动: 播放动作](https://learn.microsoft.com/azure/communication-services/quickstarts/voice-video-calling/play-action?pivots=programming-language-csharp)
-   [快速启动: 确认动作](https://learn.microsoft.com/azure/communication-services/quickstarts/voice-video-calling/recognize-action?pivots=programming-language-csharp)
-   [更多信息,请访问 Azure 通信服务中的呼叫录音](https://learn.microsoft.com/azure/communication-services/concepts/voice-video-calling/call-recording)
-   [用事件网格记录和下载通话](https://learn.microsoft.com/azure/communication-services/quickstarts/voice-video-calling/get-started-call-recording?pivots=programming-language-csharp)

## 捐款

如果您想为图书馆捐钱 请读一下 [贡献指南](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) 学习如何构建和测试密码.

## 常见问题

### @azure/communication-call-automation 是什么？

Azure 通信呼叫自动化服务的 Azure 客户端库

### 如何安装 @azure/communication-call-automation？

在项目目录运行 npm install @azure/communication-call-automation，或使用 pnpm add / yarn add / bun add。

### @azure/communication-call-automation 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @azure/communication-call-automation 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @azure/communication-call-automation 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @azure/communication-call-automation 可以商用吗？

@azure/communication-call-automation 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @azure/communication-call-automation 的下载量有多少？

根据 npm 官方下载统计，@azure/communication-call-automation 在 2026/10/08 – 2026/11/06 这 30 天内被下载 195,744 次，日均约 6,525 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @azure/communication-call-automation 还在维护吗？

最新版本 1\.6\.0 发布于 2026/06/18（4 个月前）；至今共发布 373 个版本，其中过去 12 个月发布了 55 个；首次发布于 2023/03/16。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

