分享方式:


使用通話自動化將 Microsoft Teams 使用者新增至現有通話

在本快速入門中,我們會使用 Azure 通訊服務通話自動化 API 來新增、移除和轉移 Teams 使用者的通話。

必要條件

  • 具有有效訂用帳戶的 Azure 帳戶。
  • 具有系統管理權限的 Microsoft Teams 電話授權和 Teams 租用戶。 若要使用此功能,必須有 Teams 電話授權,在 這裡 深入瞭解 Teams 授權。 Microsoft Teams 使用者也必須 voice 啟用,請參閱 設定您的電話系統。 需要系統管理權限才能授權通訊服務資源來和 Teams 使用者通話,如步驟 1 稍後所述。
  • 透過選取 Azure 入口網站左側功能表中的 [金鑰],找到已部署的通訊服務資源和有效的連接字串。
  • 從通訊服務資源取得 PSTN 電話號碼。 請記下您在本快速入門中使用的電話號碼。
  • Azure 事件方格訂用帳戶,以接收 IncomingCall 事件。
  • 您的操作系統最新的 Azure 通訊服務通話自動化 API 程式庫
  • 實作通話自動化 API 程式庫的 Web 服務,請遵循 本教學課程

步驟 1: Azure 通訊服務資源的授權,以啟用對 Microsoft Teams 使用者的通話

若要透過通話自動化 API 啟用通話,Microsoft Teams 系統管理員全域管理員 必須明確啟用通訊服務資源對其租用戶的存取權,才能允許通話。

Set-CsTeamsAcsFederationConfiguration (MicrosoftTeamsPowerShell) 租用戶層級設定,可啟用/停用其租用戶與特定通訊服務資源之間的同盟。

Set-CsExternalAccessPolicy (SkypeForBusiness) 使用者原則,可讓系統管理員進一步控制組織中的哪些使用者可以參與與通訊服務使用者的同盟通訊。

請注意,Teams 用戶必須有 電話 授權才能使用這項功能。 若要指派授權,請使用 Set-Cs 電話 NumberAssignment Cmdlet,並將 EnterpriseVoiceEnabled 參數設定為 $true。 如需詳細資訊,請參閱在組織中設定Teams電話。

步驟 2: 使用圖形 API 取得 Teams 使用者的 Microsoft Entra 物件識別碼,並選擇性地檢查其是否存在

Teams 使用者的 Microsoft Entra 物件識別碼 (OID) 必須將它們新增至通訊服務通話,或從通訊服務進行轉移。 OID 可以透過 1) Office 入口網站、2) Microsoft Entra 系統管理中心、3) Microsoft Entra 連線;或 4) 圖形 API。 下列範例使用圖形 API。

Microsoft Entra 系統管理員必須先授與同意,才能使用 Graph 來搜尋使用者,請遵循 Microsoft Graph 安全性 API 概觀 文件深入瞭解。 使用清單使用者 API 來擷取 OID,以搜尋使用者。 以下顯示了依顯示名稱搜尋,但也可以搜尋其他屬性:

使用 Microsoft Graph v1.0 列出使用者:

Request:
	https://graph.microsoft.com/v1.0/users?$search="displayName:Art Anderson"
Permissions:
	Application and delegated. Refer to documentation.
Response:
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    "value": [
        {
            "displayName": "Art Anderson",
            "mail": "artanderson@contoso.com",
            "id": "fc4ccb5f-8046-4812-803f-6c344a5d1560"
        }

或者,可以使用取得目前狀態 API 和使用者 ObjectId 來擷取使用者的目前狀態。 深入了解 Microsoft Graph v1.0 文件

Request:
https://graph.microsoft.com/v1.0/users/fc4ccb5f-8046-4812-803f-6c344a5d1560/presence
Permissions:
Delegated only. Application not supported.  Refer to documentation.
Response:
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('fc4ccb5f-8046-4812-803f-6c344a5d1560')/presence/$entity",
    "id": "fc4ccb5f-8046-4812-803f-6c344a5d1560",
    "availability": "Offline",
    "activity": "Offline"

步驟 3: 將 Teams 使用者新增至由通話自動化 API 控制的現有通訊服務通話

您必須完成必要條件步驟,並讓 Web 服務應用程式控制通訊服務通話。 使用 callConnection 物件,將參與者新增至通話。

CallAutomationClient client = new CallAutomationClient('<Connection_String>');
AnswerCallResult answer = await client.AnswerCallAsync(incomingCallContext, new Uri('<Callback_URI>'));
await answer.Value.CallConnection.AddParticipantAsync(
    new CallInvite(new MicrosoftTeamsUserIdentifier('<Teams_User_Guid>'))
    {
        SourceDisplayName = "Jack (Contoso Tech Support)"
    });
CallAutomationClient client = new CallAutomationClientBuilder().connectionString("<resource_connection_string>").buildClient();
AnswerCallResult answer = client.answerCall(incomingCallContext, "<Callback_URI>"));
answer.getCallConnection().addParticipant(
    new CallInvite(new MicrosoftTeamsUserIdentifier("<Teams_User_Guid>"))
        .setSourceDisplayName("Jack (Contoso Tech Support)"));
const client = new CallAutomationClient("<resource_connection_string>");
const answer = await client.answerCall(incomingCallContext, "<Callback_URI>"));
answer.callConnection.addParticipant({
    targetParticipant: { microsoftTeamsUserId: "<Teams_User_Guid>" },
    sourceDisplayName: "Jack (Contoso Tech Support)"
});
call_automation_client = CallAutomationClient.from_connection_string("<resource_connection_string>")
answer = call_automation_client.answer_call(incoming_call_context = incoming_call_context, callback_url = "<Callback_URI>")
call_connection_client = call_automation_client.get_call_connection(answer.call_connection_id)
call_connection_client.add_participant(target_participant = CallInvite(
    target = MicrosoftTeamsUserIdentifier(user_id="<USER_ID>"),
    source_display_name = "Jack (Contoso Tech Support)"))

在 Microsoft Teams 桌面用戶端上,Jack 的通話將會透過來電彈窗通知傳送給 Microsoft Teams 使用者。

Microsoft Teams 桌面用戶端的螢幕快照,Jack 的通話會透過來電快顯通知傳送給 Microsoft Teams 使用者。

在 Microsoft Teams 使用者接受通話之後,Microsoft Teams 使用者的通話體驗將會讓所有參與者顯示在 Microsoft Teams 名冊上。 請注意,使用通話自動化 API 管理話的應用程式將會在通話畫面上對 Teams 使用者保持隱藏,但當您開始與 Teams 使用者的 1:1 通話時除外。
Microsoft Teams 使用者接受通話並輸入 Microsoft Teams 使用者通話體驗的螢幕快照。

步驟 4: 將 Teams 使用者從由通話自動化 API 控制的現有通訊服務通話中移除

await answer.Value.CallConnection.RemoveParticipantAsync(new MicrosoftTeamsUserIdentifier('<Teams_User_Guid>'));
answer.getCallConnection().removeParticipant(new MicrosoftTeamsUserIdentifier("<Teams_User_Guid>"));
answer.callConnection.removeParticipant({ microsoftTeamsUserId: "<Teams_User_Guid>" });
call_connection_client.remove_participant(target_participant = MicrosoftTeamsUserIdentifier(user_id="<USER_ID>"))

選用功能: 從由通話自動化 API 控制的現有通訊服務通話轉移至 Teams 使用者

await answer.Value.CallConnection.TransferCallToParticipantAsync(new MicrosoftTeamsUserIdentifier('<Teams_User_Guid>'));
answer.getCallConnection().transferCallToParticipant(new MicrosoftTeamsUserIdentifier("<Teams_User_Guid>"));
answer.callConnection.transferCallToParticipant({ microsoftTeamsUserId: "<Teams_User_Guid>" });
call_connection_client.transfer_call_to_participant(target_participant = MicrosoftTeamsUserIdentifier(user_id = "<USER_ID>"))

清除資源

如果您想要清除並移除通訊服務訂用帳戶,您可以刪除資源或資源群組。 刪除資源群組也會刪除與其相關聯的任何其他資源。 深入了解如何清除資源

下一步