通話間でコンテキスト データを渡す

呼び出し自動化を使用すると、開発者は呼び出しをルーティングするときにカスタム コンテキスト情報を渡すことができます。 開発者は、呼び出し、呼び出し元、またはアプリケーションまたはビジネス ロジックに関連するその他の情報に関するメタデータを渡すことができます。 その後、企業は、コンテキストの損失を心配することなく、ネットワーク間で通話を管理およびルーティングできます。

コンテキストの受け渡しは、カスタム ヘッダーを指定することでサポートされます。 このオプションのキーと値のペアのリストは、 AddParticipant アクションまたは Transfer アクションの一部として含まれます。 コンテキストは、後で IncomingCall イベント ペイロードの一部として取得されます。

カスタム呼び出しコンテキストもセッション開始プロトコル (SIP) に転送されます。これには、フリーフォーム カスタム ヘッダーと標準ユーザー間情報 (UUI) SIP ヘッダーの両方が含まれます。 テレフォニー ネットワークからの着信呼び出しがルーティングされると、カスタム ヘッダーと UUI のセッション ボーダー コントローラー (SBC) からのデータ セットも同様に、 IncomingCall イベント ペイロードに含まれます。

すべてのカスタム コンテキスト データは、コール オートメーションまたは SIP プロトコルに対して不透明であり、その内容は基本的な機能とは無関係です。

次のサンプルは、Call Automation でカスタム コンテキスト ヘッダーを使用して開始する方法を示しています。

Prerequisites

  • アクション イベント プログラミング モデルとイベント コールバックについて説明した Call Automation の 概念に 関する記事を参照してください。
  • この記事で使用する や PhoneNumberIdentifier' などのCommunicationUserIdentifierについて説明します。

すべてのコード サンプルでは、clientは作成できるCallAutomationClient オブジェクトであり、callConnectionは、CallConnectionまたはAnswer応答から取得するCreateCall オブジェクトです。 アプリケーションが受け取るコールバック イベントから取得することもできます。

技術パラメーター

Call Automation では、最大 5 つのカスタム SIP ヘッダーと 1,000 個のカスタム音声オーバー IP (VoIP) ヘッダーがサポートされます。 開発者は、SIP ヘッダー リストの一部として専用のユーザー間ヘッダーを含めることができます。

カスタム SIP ヘッダー キーは、 X-* プレフィックスまたは X-MS-Custom-* プレフィックスで開始できるようになりました。

  • X-* が新しくサポートされました。
  • X-MS-Custom-* は、下位互換性のために引き続きサポートされています。
  • その他の X-MS-* プレフィックスは予約されているため、使用しないでください。

SIP ヘッダー キーの最大長はプレフィックスを含めて 64 文字で、SIP ヘッダー値の最大長は 256 文字です。 キーには、英数字と次の記号を含めることができます。

`.`, `!`, `%`, `*`, `_`, `+`, `~`, and `-`

SIP ヘッダー値は、英数字と、次のようないくつかの選択したシンボルで構成されます。

`=`, `;`, `.`, `!`, `%`, `*`, `_`, `+`, `~`, and `-`.

SBC で SIP ヘッダーを構成する場合も、同じ制限が適用されます。

VoIP ヘッダーの場合、VoIP ヘッダー キーの最大長は 64 文字 で、VoIP ヘッダー値の最大長は 1,024 文字です。 これらのヘッダーは、カスタム プレフィックスなしで送信できます。

参加者を招待するときにカスタム コンテキストを追加する

// Invite an Azure 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");

// The provided key will be automatically prefixed with X-MS-Custom on SIP protocol, such as 'X-MS-Custom-{key}'
addThisPerson.CustomCallingContext.AddSipX("header1", "customSipHeaderValue1");
// The provided key prefix is based on SipHeaderPrefix param: SipHeaderPrefix.X → 'X-{key}', SipHeaderPrefix.XmsCustom → 'X-MS-Custom-{key}'
addThisPerson.CustomCallingContext.AddSipX("header2", "customSipHeaderValue2", SipHeaderPrefix.X);
AddParticipantsResult result = await callConnection.AddParticipantAsync(addThisPerson);

通話転送中にカスタム コンテキストを追加する

//Transfer to an Azure 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");
// The provided key will be automatically prefixed with X-MS-Custom on SIP protocol, such as 'X-MS-Custom-{key}'
transferOption.CustomCallingContext.AddSipX("header1", "headerValue");
// The provided key prefix is based on SipHeaderPrefix param: SipHeaderPrefix.X → 'X-{key}', SipHeaderPrefix.XmsCustom → 'X-MS-Custom-{key}'
transferOption.CustomCallingContext.AddSipX("header2", "headerValue2", SipHeaderPrefix.X);
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