如何在呼叫之間傳遞關係型數據

呼叫自動化可讓開發人員在路由呼叫時傳遞自定義內容資訊。 開發人員可以傳遞有關呼叫、被呼叫者或任何其他與其應用程式或商業規則相關信息的元數據。 這可讓企業跨網路管理和路由呼叫,而不必擔心遺失內容。

指定自定義標頭支援傳遞內容。 這些是可包含在 或 Transfer 動作中的AddParticipant索引鍵/值組選擇性清單。 稍後可以擷取內容作為事件承載的 IncomingCall 一部分。

自定義呼叫內容也會轉送至 SIP 通訊協定,這包括手繪多邊形自定義標頭,以及標準使用者對使用者資訊 (UUI) SIP 標頭。 從您的電話語音網路路由輸入呼叫時,自定義標頭中的 SBC 數據集和 UUI 同樣包含在事件承載中 IncomingCall

所有自定義內容數據都與呼叫自動化或 SIP 通訊協定不透明,而且其內容與任何基本函式無關。

以下是如何在通話自動化中使用自定義內容標頭的範例。

作為必要條件,建議您閱讀這些文章,以充分利用本指南:

針對所有程式代碼範例,是 CallAutomationClient 物件,client可以如所示建立,而且callConnection是從 Answer 或 CreateCall 回應取得的 Call 連線 ion 物件。 您也可以從應用程式收到的回呼事件取得它。

技術參數

通話自動化最多可支援 5 個自定義 SIP 標頭和 1000 個自定義 VOIP 標頭。 此外,開發人員可以包含專用的使用者對用戶標頭,作為 SIP 標頭清單的一部分。

自定義 SIP 標頭金鑰必須以必要的 'X-MS-Custom-' 前置詞開頭。 SIP 標頭金鑰的最大長度為 64 個字元,包括 X-MS-Custom 前置詞。 SIP 標頭索引鍵可能包含英數位元和一些選取的符號,其中包括 .!_%~*+、 。 - SIP 標頭值的最大長度是 256 個字元。 在 SBC 上設定 SIP 標頭時,會套用相同的限制。 SIP 標頭值可能包含英數位元和一些選取的符號,其中包括 =、、、、 %._!~*+-;

VOIP 標頭金鑰的最大長度為 64 個字元。 這些標頭可以在沒有 'x-MS-Custom' 前置詞的情況下傳送。 VOIP 標頭值的最大長度是 1024 個字元。

邀請參與者時新增自定義內容

// Invite a communication services user and include one VOIP header
var addThisPerson = new CallInvite(new CommunicationUserIdentifier("<user_id>"));
addThisPerson.CustomCallingContext.AddVoip("myHeader", "myValue");
AddParticipantsResult result = await callConnection.AddParticipantAsync(addThisPerson);
// Invite a PSTN user and set UUI and custom SIP headers
var callerIdNumber = new PhoneNumberIdentifier("+16044561234"); 
var addThisPerson = new CallInvite(new PhoneNumberIdentifier("+16041234567"), callerIdNumber);

// Set custom UUI header. This key is sent on SIP protocol as User-to-User
addThisPerson.CustomCallingContext.AddSipUui("value");

// This provided key will be automatically prefixed with X-MS-Custom on SIP protocol, such as 'X-MS-Custom-{key}'
addThisPerson.CustomCallingContext.AddSipX("header1", "customSipHeaderValue1");
AddParticipantsResult result = await callConnection.AddParticipantAsync(addThisPerson);

在通話轉移期間新增自定義內容

//Transfer to communication services user and include one VOIP header
var transferDestination = new CommunicationUserIdentifier("<user_id>"); 
var transferOption = new TransferToParticipantOptions(transferDestination);   
var transferOption = new TransferToParticipantOptions(transferDestination) {
    OperationContext = "<Your_context>",
    OperationCallbackUri = new Uri("<uri_endpoint>") // Sending event to a non-default endpoint.
};
transferOption.CustomCallingContext.AddVoip("customVoipHeader1", "customVoipHeaderValue1");
TransferCallToParticipantResult result = await callConnection.TransferCallToParticipantAsync(transferOption);

//Transfer a PSTN call to phone number and set UUI and custom SIP headers
var transferDestination = new PhoneNumberIdentifier("<target_phoneNumber>");
var transferOption = new TransferToParticipantOptions(transferDestination);
transferOption.CustomCallingContext.AddSipUui("uuivalue");
transferOption.CustomCallingContext.AddSipX("header1", "headerValue");
TransferCallToParticipantResult result = await callConnection.TransferCallToParticipantAsync(transferOption)

從傳入呼叫事件讀取自定義內容

AcsIncomingCallEventData incomingEvent = <incoming call event from Event Grid>;
// Retrieve incoming call custom context
AcsIncomingCallCustomContext callCustomContext = incomingEvent.CustomContext;

// Inspect dictionary with key/value pairs
var voipHeaders = callCustomContext.VoipHeaders;
var sipHeaders = callCustomContext.SipHeaders;

// Get SIP UUI header value
var userToUser = sipHeaders["user-To-User"]

// Proceed to answer or reject call as usual

其他資源