@azure/communication-call-automation

中文文档
1.6.0发布于 2026/06/18MITTypeScriptESM + CJS近 30 天下载 19.6万

Azure client library for Azure Communication Call Automation services

原始使用文档
文档目录13 节
  1. Getting started
  2. Prerequisites
  3. Installing
  4. Browser support
  5. Key concepts
  6. Examples
  7. Initialize CallAutomationClient
  8. Create Call
  9. Play Media
  10. Troubleshooting
  11. Logging
  12. Next steps
  13. Contributing

Azure Communication Call Automation client library for JavaScript

This package contains a JavaScript SDK for Azure Communication Call Automation. Call Automation provides developers the ability to build server-based, intelligent call workflows, and call recording for voice and PSTN channels.

Overview of Call Automation | Product documentation

Getting started

Prerequisites

Installing

npm install @azure/communication-call-automation

Browser support

JavaScript Bundle

To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our bundling documentation.

Key concepts

NameDescription
CallAutomationClientCallAutomationClient is the primary interface for developers using this client library. It can be used to initiate calls by createCall or answerCall.
CallConnectionCallConnection represents a ongoing call. Once the call is established with createCall or answerCall, further actions can be performed for the call, such as transfer or addParticipant.
CallMediaCallMedia can be used to do media related actions, such as play, to play media file. This can be retrieved from established CallConnection.
CallRecordingCallRecording can be used to do recording related actions, such as startRecording. This can be retrieved from CallAutomationClient.
Callback EventsCallback events are events sent back during duration of the call. It gives information and state of the call, such as CallConnected. CallbackUrl must be provided during createCall and answerCall, and callback events will be sent to this url. You can use callAutomationEventParser to parse these events when it arrives.
Incoming Call EventWhen incoming call happens (that can be answered with answerCall), incoming call eventgrid event will be sent. This is different from Callback events above, and should be setup on Azure portal. See Incoming Call for detail.

Examples

Initialize 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);

Create Call

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

Play Media

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]);

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

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

setLogLevel("info");

Next steps

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

版本与发布记录

@azure/communication-call-automation 共发布 373 个版本,首次发布于 2023/03/16;过去 12 个月发布了 55 个版本。

版本发布日期距今
1.6.0latest2026/06/184 个月前
1.5.0-alpha.20260211.1dev2026/02/118 个月前
1.5.0-alpha.20260210.12026/02/108 个月前
1.5.0-alpha.20260209.12026/02/098 个月前
1.5.0-alpha.20260206.12026/02/069 个月前
1.5.0-alpha.20260205.12026/02/059 个月前

其他发布通道:next → 1.5.0-beta.2,beta → 1.6.0-beta.2,dev → 1.5.0-alpha.20260211.1。

关于 @azure/communication-call-automation 的常见问题

@azure/communication-call-automation 是什么?

Azure client library for Azure Communication Call Automation services

如何安装 @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 和提交记录判断。