Azure Communication Call Automation client library for JavaScript - version 1.6.0

此套件包含適用於 Azure 通訊通話自動化的 JavaScript SDK。 通話自動化可讓開發人員建置伺服器型、智慧型手機工作流程,以及語音和 PSTN 通道的通話錄製。

呼叫自動化概觀 | 產品檔

開始

先決條件

安裝

npm install @azure/communication-call-automation

瀏覽器支援

JavaScript 套件組合

若要在瀏覽器中使用此用戶端連結庫,您必須先使用配套程式。 如需如何執行這項操作的詳細資訊,請參閱我們的 組合檔。

重要概念

名字 描述
呼叫自動化用戶端 CallAutomationClient 是使用此用戶端連結庫的開發人員的主要介面。 它可用來透過 createCall 或 answerCall來起始呼叫。
呼叫連接 CallConnection 代表進行中的呼叫。 一旦使用 createCall 或 answerCall建立呼叫之後,就可以針對呼叫執行進一步的動作,例如 transfer 或 addParticipant。
呼叫媒體 CallMedia 可用來執行媒體相關動作,例如 play,以播放媒體檔案。 這可以從已建立的 CallConnection擷取。
通話錄音 CallRecording 可用來執行錄製相關動作,例如 startRecording。 這可以從 CallAutomationClient擷取。
回呼事件 回呼事件是在通話期間傳回的事件。 它提供呼叫的資訊和狀態,例如 CallConnected。 CallbackUrl必須在 和 createCall期間answerCall提供,回呼事件將傳送至此 URL。 您可以使用來 callAutomationEventParser 剖解析這些事件到達時。
來電事件 當發生來電時 (可以接 answerCall聽 ),將會傳送來電事件格事件。 這與上述回呼事件不同,應該在 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");

後續步驟

貢獻

如果您想要參與此連結庫,請閱讀 參與指南,以深入瞭解如何建置和測試程序代碼。