Azure 通信呼叫 JavaScript 自动化客户端库
这个包包含一个用于Azure Conference Call Automation的JavaScript SDK. Call Automation为开发者提供了构建基于服务器,智能调用工作流程的能力,并为语音和PSTN频道提供调用录音.
开始
先决条件
安装
npm install @azure/communication-call-automation
浏览器支持
Java 脚本套装
要在浏览器中使用此客户端库,首先需要使用捆绑器. 关于如何做到这一点的详情,请参见我们 捆绑文件。 。 。 .
关键概念
| 名称 | 说明 |
|---|---|
| 调用自动连接 | 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门户网站上. 见 来电 细节. |
实例
初始化调用自动连接
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");
今后的步骤
- 调用自动化概览
- 即将到来的呼叫概念
- 使用调用自动化构建客户交互工作流程
- 以呼叫自动化方式重新定向入境电话
- 快速启动: 播放动作
- 快速启动: 确认动作
- 更多信息,请访问 Azure 通信服务中的呼叫录音
- 用事件网格记录和下载通话
捐款
如果您想为图书馆捐钱 请读一下 贡献指南 学习如何构建和测试密码.