共用方式為


適用於 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擷取。
回呼事件 回呼事件是呼叫期間傳回的事件。 它會提供呼叫的資訊和狀態,例如 CallConnectedCallbackUrl 必須在 createCall 期間提供,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");

後續步驟

貢獻

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