識別子の型について

Communication Services SDK と REST API は、"識別子" 型を使用して、だれがだれと通信しているかを識別します。 たとえば、だれに電話をかけ、だれがチャット メッセージを送信したかは、識別子によって特定されます。

識別子は、コンテキストに応じて ChatParticipant 内 (Chat SDK) や RemoteParticipant 内 (Calling SDK) など、特別なプロパティでラップされます。

この記事では、さまざまな種類の識別子と各プログラミング言語におけるその体裁について説明します。 また、その使い方についてのヒントも紹介します。

CommunicationIdentifier 型

自分自身で作成するユーザー ID と外部 ID があります。 Microsoft Teams のユーザーと電話番号は、相互運用のシナリオに関係する外部 ID です。 こうした ID 型には、それを表す対応する識別子が存在します。 識別子は、タイプ セーフな構造化された型であり、エディターのコード補完と適切に連携します。

Communication ユーザー

CommunicationUserIdentifier インターフェイスは、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用

// at some point you will have created a new user identity in your trusted service
const newUser = await identityClient.createUser();

// and then send newUser.communicationUserId down to your client application
// where you can again create an identifier for the user
const sameUser = { communicationUserId: newUserId };

API リファレンス

CommunicationUserIdentifier

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifier インターフェイスは、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に Microsoft Entra トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

// get the Teams user's ID from Graph APIs if only the email is known
const user = await graphClient.api("/users/bob@contoso.com").get();

// create an identifier
const teamsUser = { microsoftTeamsUserId: user.id };

// if you're not operating in the public cloud, you must also pass the right Cloud type.
const gcchTeamsUser = { microsoftTeamsUserId: userId, cloud: "gcch" };

API リファレンス

MicrosoftTeamsUserIdentifier

電話番号

PhoneNumberIdentifier インターフェイスは電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

// create an identifier
const phoneNumber = { phoneNumber: "+112345556789" };

API リファレンス

PhoneNumberIdentifier

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifier インターフェイスには、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

// Get the Microsoft Teams App's ID from Graph APIs
const users = await graphClient.api("/users")
                    .filter(filterConditions)
                    .select('displayName,id')
                    .get();
//Here we assume that you have a function getBotFromUsers that gets the bot from the returned response
const bot = getBotFromUsers(users);
// Create an identifier
const teamsAppIdentifier = { teamsAppId: bot.id };

// If you're not operating in the public cloud, you must also pass the right Cloud type.
const gcchTeamsAppIdentifier = { teamsAppId: id, cloud: "gcch" };

API リファレンス

MicrosoftTeamsAppIdentifier

Unknown

UnknownIdentifier インターフェイスは将来性を目的に存在するもので、古いバージョンの SDK を使用しているとき最近になって新しい識別子型が導入されたような場合に遭遇します。 このサービスからの不明な識別子はすべて、SDK の UnknownIdentifier に逆シリアル化されます。

基本的な使用

// create an identifier
const unknownId = { id: "a raw id that originated in the service" };

API リファレンス

UnknownIdentifier

CommunicationIdentifier 基底インターフェイスを処理する方法

SDK "に" 渡す識別子として構築するのは具象型ですが、SDK から返されるのは、判別共用体である CommunicationIdentifierKind です。 具象型にナローイング変換するのは簡単です。パターン マッチングを使用した switch-case ステートメントをお勧めします。

switch (communicationIdentifier.kind)
{
    case "communicationUser":
        // TypeScript has narrowed communicationIdentifier to be a CommunicationUserKind
        console.log(`Communication user: ${communicationIdentifier.communicationUserId}`);
        break;
    case "microsoftTeamsUser":
        // narrowed to MicrosoftTeamsUserKind
        console.log(`Teams user: ${communicationIdentifier.microsoftTeamsUserId}`);
        break;
    case "phoneNumber":
         // narrowed to PhoneNumberKind
        console.log(`Phone number: ${communicationIdentifier.phoneNumber}`);
        break;
    case "unknown":
         // narrowed to UnknownIdentifierKind
        console.log(`Unknown: ${communicationIdentifier.id}`);
        break;
    case "microsoftBot":
        // narrowed to MicrosoftBotIdentifier
        console.log(`Microsoft bot: ${communicationIdentifier.botId}`);
        break;
    default:
        // be careful here whether you want to throw because a new SDK version
        // can introduce new identifier types
        break;
}

識別子のインターフェイスは、詳細度を減らすための kind を指定する必要がないように設計されており、kind プロパティを持つ判別共用体が使用されるのは、SDK から返されるときだけです。 ただし、識別子を対応する判別共用体型に変換する必要がある場合は、このヘルパーを使用できます。

const identifierKind = getIdentifierKind(identifier); // now you can switch-case on the kind

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

azure-communication-common@2.1.0 以降では、その変換を SDK で行うことができます。

// get an identifier's raw Id
const rawId = getIdentifierRawId(communicationIdentifier);

// create an identifier from a given raw Id
const identifier = createIdentifierFromRawId(rawId);

無効な Raw ID は SDK 内で UnknownIdentifier に変換されるだけで、検証はサービス側でのみ行われます。

Communication ユーザー

CommunicationUserIdentifier は、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用

// at some point you will have created a new user identity in your trusted service
CommunicationUserIdentifier newUser = await identityClient.CreateUser();

// and then send newUser.Id down to your client application
// where you can again create an identifier for the user
var sameUser = new CommunicationUserIdentifier(newUserId);

API リファレンス

CommunicationUserIdentifier

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifier は、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に Microsoft Entra トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

// get the Teams user's ID from Graph APIs if only the email is known
var user = await graphClient.Users["bob@contoso.com"]
    .Request()
    .GetAsync();

// create an identifier
var teamsUser = new MicrosoftTeamsUserIdentifier(user.Id);

// if you're not operating in the public cloud, you must also pass the right Cloud type.
var gcchTeamsUser = new MicrosoftTeamsUserIdentifier(userId: userId, cloud: CommunicationCloudEnvironment.Gcch);

API リファレンス

MicrosoftTeamsUserIdentifier

電話番号

PhoneNumberIdentifier は電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

// create an identifier
var phoneNumber = new PhoneNumberIdentifier("+112345556789");

API リファレンス

PhoneNumberIdentifier

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifier インターフェイスには、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

// Get the Microsoft Teams App's ID from Graph APIs
var users = await graphClient.Users.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Select = new string []{ "displayName","id" };
	requestConfiguration.QueryParameters.Filter = filterConditions;
});

// Here we assume that you have a function GetBotFromUsers that gets the bot from the returned response
var bot = GetBotFromUsers(users);

// Create an identifier
var teamsAppIdentifier = new MicrosoftTeamsAppIdentifier(bot.Id);

// If you're not operating in the public cloud, you must also pass the right Cloud type.
var gcchTeamsAppIdentifier = new MicrosoftTeamsAppIdentifier(bot.Id, CommunicationCloudEnvironment.Gcch);

API リファレンス

MicrosoftTeamsAppIdentifier

Unknown

UnknownIdentifier は将来性を目的に存在するもので、古いバージョンの SDK を使用しているとき最近になって新しい識別子型が導入されたような場合に遭遇します。 このサービスからの不明な識別子はすべて、SDK の UnknownIdentifier に逆シリアル化されます。

基本的な使用

// create an identifier
var unknown = new UnknownIdentifier("a raw id that originated in the service");

API リファレンス

UnknownIdentifier

CommunicationIdentifier 基底クラスを処理する方法

SDK "に" 渡す識別子として構築するのは具象型ですが、SDK から返されるのは CommunicationIdentifier プロトコルです。 具象型にダウンキャストするのは簡単です。パターン マッチングを使用した switch-case ステートメントをお勧めします。

switch (communicationIdentifier)
{
    case CommunicationUserIdentifier communicationUser:
        Console.WriteLine($"Communication user: {communicationUser.Id}");
        break;
    case MicrosoftTeamsUserIdentifier teamsUser:
        Console.WriteLine($"Teams user: {teamsUser.UserId}");
        break;
    case PhoneNumberIdentifier phoneNumber:
        Console.WriteLine($"Phone number: {phoneNumber.PhoneNumber}");
        break;
    case MicrosoftBotIdentifier bot:
        Console.WriteLine($"Microsoft bot: {bot.BotId}");
        break;
    case UnknownIdentifier unknown:
        Console.WriteLine($"Unknown: {unknown.Id}");
        break;
    default:
        // be careful here whether you want to throw because a new SDK version
        // can introduce new identifier types
        break;
}

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

Azure.Communication.Common 1.2.0 以降では、その変換を SDK で行うことができます。

// get an identifier's raw Id
string rawId = communicationIdentifier.RawId;

// create an identifier from a given raw Id
CommunicationIdentifier identifier = CommunicationIdentifier.FromRawId(rawId);

無効な Raw ID は SDK 内で UnknownIdentifier に変換されるだけで、検証はサービス側でのみ行われます。

Communication ユーザー

CommunicationUserIdentifier は、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用

# at some point you will have created a new user identity in your trusted service
new_user = identity_client.create_user()

# and then send new_user.properties['id'] down to your client application
# where you can again create an identifier for the user
same_user = CommunicationUserIdentifier(new_user_id)

API リファレンス

CommunicationUserIdentifier

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifier は、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に Microsoft Entra トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

# get the Teams user's ID from Graph APIs if only the email is known
user_id = graph_client.get("/users/bob@contoso.com").json().get("id");

# create an identifier
teams_user = MicrosoftTeamsUserIdentifier(user_id)

# if you're not operating in the public cloud, you must also pass the right Cloud type.
gcch_teams_user = MicrosoftTeamsUserIdentifier(user_id, cloud=CommunicationCloudEnvironment.GCCH)

API リファレンス

MicrosoftTeamsUserIdentifier

電話番号

PhoneNumberIdentifier は電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

# create an identifier
phone_number = PhoneNumberIdentifier("+112345556789")

API リファレンス

PhoneNumberIdentifier

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifier インターフェイスには、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

# Get the Microsoft Teams App's ID from Graph APIs
users = graph_client.get("/users").json()

# Here we assume that you have a function get_bot_from_users that gets the bot from the returned response
bot = get_bot_from_users(users);

# Create an identifier
teams_app_identifier = MicrosoftTeamsAppIdentifier(app_id=bot.get("id"))

# If you're not operating in the public cloud, you must also pass the right Cloud type.
gcch_teams_app_identifier = MicrosoftTeamsAppIdentifier(
            app_id=bot.get("id"),
            cloud=CommunicationCloudEnvironment.GCCH
        )

API リファレンス

MicrosoftTeamsAppIdentifier

Unknown

UnknownIdentifier は将来性を目的に存在するもので、古いバージョンの SDK を使用しているとき最近になって新しい識別子型が導入されたような場合に遭遇します。 このサービスからの不明な識別子はすべて、SDK の UnknownIdentifier に逆シリアル化されます。

基本的な使用

# create an identifier
unknown = UnknownIdentifier("a raw id that originated in the service")

API リファレンス

UnknownIdentifier

CommunicationIdentifier 基底クラスを処理する方法

SDK "に" 渡す識別子として構築するのは具象型ですが、SDK から返されるのは CommunicationIdentifier プロトコルです。 具象識別子クラスは CommunicationIdentifier プロトコルに、properties と呼ばれる型指定されたディクショナリを組み合わせたものにすぎません。 そのため、プロトコルの kind インスタンス変数でパターン マッチングを使用して、具象型に変換することができます。

match communication_identifier.kind:
    case CommunicationIdentifierKind.COMMUNICATION_USER:
        print(f"Communication user: {communication_identifier.properties['id']}")
    case CommunicationIdentifierKind.MICROSOFT_TEAMS_USER:
        print(f"Teams user: {communication_identifier.properties['user_id']}")
    case CommunicationIdentifierKind.PHONE_NUMBER:
        print(f"Phone number: {communication_identifier.properties['value']}")
    case CommunicationIdentifierKind.MICROSOFT_BOT:
        print(f"Microsoft bot: {communication_identifier.properties['bot_id']}")
    case CommunicationIdentifierKind.UNKNOWN:
        print(f"Unknown: {communication_identifier.raw_id}")
    case _:
        # be careful here whether you want to throw because a new SDK version
        # can introduce new identifier types

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

その変換は SDK で行うことができます。

# get an identifier's raw Id
raw_id = communication_identifier.raw_id

# create an identifier from a given raw Id
identifier = identifier_from_raw_id(raw_id)

無効な Raw ID は SDK 内で UnknownIdentifier に変換されるだけで、検証はサービス側でのみ行われます。

Communication ユーザー

CommunicationUserIdentifier は、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用

// at some point you will have created a new user identity in your trusted service
CommunicationUserIdentifier newUser = identityClient.CreateUser();

// and then send newUser.getId() down to your client application
// where you can again create an identifier for the user
var sameUser = new CommunicationUserIdentifier(newUserId);

API リファレンス

CommunicationUserIdentifier

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifier は、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に Microsoft Entra トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

// get the Teams user's ID from Graph APIs if only the email is known
var user = graphClient.users("bob@contoso.com")
    .buildRequest()
    .get();

// create an identifier
var teamsUser = new MicrosoftTeamsUserIdentifier(user.id);

// if you're not operating in the public cloud, you must also set the right Cloud type.
var gcchTeamsUser = new MicrosoftTeamsUserIdentifier(userId).setCloudEnvironment(CommunicationCloudEnvironment.GCCH);

API リファレンス

MicrosoftTeamsUserIdentifier

電話番号

PhoneNumberIdentifier は電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

// create an identifier
var phoneNumber = new PhoneNumberIdentifier("+112345556789");

API リファレンス

PhoneNumberIdentifier

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifier インターフェイスには、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

// Get the Microsoft Teams App's ID from Graph APIs
var user = graphClient.users()
	.buildRequest()
	.filter(filterConditions)
	.select("displayName,id")
	.get();

//Here we assume that you have a function getBotFromUsers that gets the bot from the returned response
var bot = getBotFromUsers(users);

// Create an identifier
var teamsAppIdentifier = new MicrosoftTeamsAppIdentifier(bot.id);

// If you're not operating in the public cloud, you must also pass the right Cloud type.
var gcchTeamsAppIdentifier = new MicrosoftTeamsAppIdentifier(bot.id, CommunicationCloudEnvironment.GCCH);

API リファレンス

MicrosoftTeamsAppIdentifier

Unknown

UnknownIdentifier は将来性を目的に存在するもので、古いバージョンの SDK を使用しているとき最近になって新しい識別子型が導入されたような場合に遭遇します。 このサービスからの不明な識別子はすべて、SDK の UnknownIdentifier に逆シリアル化されます。

基本的な使用

// create an identifier
var unknown = new UnknownIdentifier("a raw id that originated in the service");

API リファレンス

UnknownIdentifier

CommunicationIdentifier 基底クラスを処理する方法

SDK "に" 渡す識別子として構築するのは具象型ですが、SDK から返されるのは抽象型の CommunicationIdentifier です。 具象型にダウンキャストすることができます。

if (communicationIdentifier instanceof CommunicationUserIdentifier) {
    System.out.println("Communication user: " + ((CommunicationUserIdentifier)communicationIdentifier).getId());
}
else if (communicationIdentifier instanceof MicrosoftTeamsUserIdentifier) {
    System.out.println("Teams user: " + ((MicrosoftTeamsUserIdentifier)communicationIdentifier).getUserId());
}
else if (communicationIdentifier instanceof PhoneNumberIdentifier) {
    System.out.println("Phone number: " + ((PhoneNumberIdentifier)communicationIdentifier).getPhoneNumber());
}
else if (communicationIdentifier instanceof MicrosoftBotIdentifier) {
    Log.i(tag, "Microsoft bot: " + ((MicrosoftBotIdentifier)communicationIdentifier).getBotId());
}
else if (communicationIdentifier instanceof UnknownIdentifier) {
    System.out.println("Unkown user: " + ((UnknownIdentifier)communicationIdentifier).getId());
}
else {
    // be careful here whether you want to throw because a new SDK version
        // can introduce new identifier types
}

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

azure-communication-common 1.2.0 以降では、その変換を SDK で行うことができます。

// get an identifier's raw Id
String rawId = communicationIdentifier.getRawId();

// create an identifier from a given raw Id
CommunicationIdentifier identifier = CommunicationIdentifier.fromRawId(rawId);

無効な Raw ID は SDK 内で UnknownIdentifier に変換されるだけで、検証はサービス側でのみ行われます。

Communication ユーザー

CommunicationUserIdentifier は、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用

// at some point you will have created a new user identity in your trusted service
// and send the new user id down to your client application
// where you can create an identifier for the user
let user = CommunicationUserIdentifier(newUserId)

API リファレンス

CommunicationUserIdentifier

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifier は、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に ID トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

// get the Teams user's ID if only the email is known, assuming a helper method for the Graph API
let userId = await getUserIdFromGraph("bob@contoso.com")

// create an identifier
let teamsUser = MicrosoftTeamsUserIdentifier(userId: userId)

// if you're not operating in the public cloud, you must also pass the right Cloud type.
let gcchTeamsUser = MicrosoftTeamsUserIdentifier(userId: userId, cloud: CommunicationCloudEnvironment.Gcch)

API リファレンス

MicrosoftTeamsUserIdentifier

電話番号

PhoneNumberIdentifier は電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

// create an identifier
let phoneNumber = PhoneNumberIdentifier(phoneNumber: "+112345556789")

API リファレンス

PhoneNumberIdentifier

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifier インターフェイスには、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

// Get the Microsoft Teams App's ID from Graph APIs, assuming a helper method for the Graph API
let botId = await getBotIdFromGraph()

// Create an identifier
let teamsAppIdentifier = MicrosoftTeamsAppIdentifier(appId: botId)

// If you're not operating in the public cloud, you must also pass the right Cloud type.
let gcchTeamsAppIdentifier = MicrosoftTeamsAppIdentifier(appId: botId, cloudEnvironment: CommunicationCloudEnvironment.Gcch)

API リファレンス

MicrosoftTeamsAppIdentifier

Unknown

UnknownIdentifier は将来性を目的に存在するもので、古いバージョンの SDK を使用しているとき最近になって新しい識別子型が導入されたような場合に遭遇します。 このサービスからの不明な識別子はすべて、SDK の UnknownIdentifier に逆シリアル化されます。

基本的な使用

// create an identifier
let unknown = UnknownIdentifier("a raw id that originated in the service")

API リファレンス

UnknownIdentifier

CommunicationIdentifier 基底プロトコルを処理する方法

SDK "に" 渡す識別子として構築するのは具象型ですが、SDK から返されるのは CommunicationIdentifier プロトコルです。 再び具象型にダウンキャストするのは簡単です。パターン マッチングを使用した switch-case ステートメントをお勧めします。

switch (communicationIdentifier)
{
    case let communicationUser as CommunicationUserIdentifier:
        print(#"Communication user: \(communicationUser.id)"#)
    case let teamsUser as MicrosoftTeamsUserIdentifier:
        print(#"Teams user: \(teamsUser.UserId)"#)
    case let phoneNumber as PhoneNumberIdentifier:
        print(#"Phone number: \(phoneNumber.PhoneNumber)"#)
    case let bot as MicrosoftBotIdentifier:
        print(#"Microsoft bot: \(bot.botId)"#)
    case let unknown as UnknownIdentifier:
        print(#"Unknown: \(unknown.Id)"#)
    @unknown default:
        // be careful here whether you want to throw because a new SDK version
        // can introduce new identifier types
        break;
}

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

Azure.Communication.Common 1.1.0 以降では、その変換を SDK で行うことができます。

Swift

// get an identifier's raw Id
let rawId = communicationIdentifier.rawId;

// create an identifier from a given raw Id
let identifier = createCommunicationIdentifier(fromRawId: rawId);

無効な Raw ID は SDK 内で UnknownIdentifier に変換されるだけで、検証はサービス側でのみ行われます。

Communication ユーザー

CommunicationUserIdentifier は、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用

// at some point you will have created a new user identity in your trusted service
CommunicationUserIdentifier newUser = identityClient.CreateUser();

// and then send newUser.getId() down to your client application
// where you can again create an identifier for the user
CommunicationUserIdentifier sameUser = new CommunicationUserIdentifier(newUserId);

API リファレンス

CommunicationUserIdentifier

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifier は、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に ID トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

// get the Teams user's ID from Graph APIs if only the email is known
User user = graphClient.users("bob@contoso.com")
    .buildRequest()
    .get();

// create an identifier
MicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier(user.id);

// if you're not operating in the public cloud, you must also set the right Cloud type.
MicrosoftTeamsUserIdentifier gcchTeamsUser = new MicrosoftTeamsUserIdentifier(userId).setCloudEnvironment(CommunicationCloudEnvironment.GCCH);

API リファレンス

MicrosoftTeamsUserIdentifier

電話番号

PhoneNumberIdentifier は電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

// create an identifier
PhoneNumberIdentifier phoneNumber = new PhoneNumberIdentifier("+112345556789");

API リファレンス

PhoneNumberIdentifier

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifier インターフェイスには、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

// Get the Microsoft Teams App's ID from Graph APIs
UserCollectionPage users = graphClient.users()
	.buildRequest()
	.filter(filterConditions)
	.select("displayName,id")
	.get();

//Here we assume that you have a function getBotFromUsers that gets the bot from the returned response
User bot = getBotFromUsers(users);

// Create an identifier
MicrosoftTeamsAppIdentifier teamsAppIdentifier = new MicrosoftTeamsAppIdentifier(bot.id);

// If you're not operating in the public cloud, you must also pass the right Cloud type.
MicrosoftTeamsAppIdentifier gcchTeamsAppIdentifier = new MicrosoftTeamsAppIdentifier(bot.id, CommunicationCloudEnvironment.GCCH);

API リファレンス

MicrosoftTeamsAppIdentifier

Unknown

UnknownIdentifier は将来性を目的に存在するもので、古いバージョンの SDK を使用しているとき最近になって新しい識別子型が導入されたような場合に遭遇します。 このサービスからの不明な識別子はすべて、SDK の UnknownIdentifier に逆シリアル化されます。

基本的な使用

// create an identifier
UnknownIdentifier unknown = new UnknownIdentifier("a raw id that originated in the service");

API リファレンス

UnknownIdentifier

CommunicationIdentifier 基底クラスを処理する方法

SDK "に" 渡す識別子として構築するのは具象型ですが、SDK から返されるのは抽象型の CommunicationIdentifier です。 具象型にダウンキャストすることができます。

if (communicationIdentifier instanceof CommunicationUserIdentifier) {
    Log.i(tag, "Communication user: " + ((CommunicationUserIdentifier)communicationIdentifier).getId());
}
else if (communicationIdentifier instanceof MicrosoftTeamsUserIdentifier) {
    Log.i(tag, "Teams user: " + ((MicrosoftTeamsUserIdentifier)communicationIdentifier).getUserId());
}
else if (communicationIdentifier instanceof PhoneNumberIdentifier) {
    Log.i(tag, "Phone number: " + ((PhoneNumberIdentifier)communicationIdentifier).getPhoneNumber());
}
else if (communicationIdentifier instanceof MicrosoftBotIdentifier) {
    Log.i(tag, "Microsoft bot: " + ((MicrosoftBotIdentifier)communicationIdentifier).getBotId());
}
else if (communicationIdentifier instanceof UnknownIdentifier) {
    Log.i(tag, "Unkown user: " + ((UnknownIdentifier)communicationIdentifier).getId());
}
else {
    // be careful here whether you want to throw because a new SDK version
    // can introduce new identifier types
}

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

azure-communication-common 1.1.0 以降では、その変換を SDK で行うことができます。

// get an identifier's raw Id
String rawId = communicationIdentifier.getRawId();

// create an identifier from a given raw Id
CommunicationIdentifier identifier = CommunicationIdentifier.fromRawId(rawId);

無効な Raw ID は SDK 内で UnknownIdentifier に変換されるだけで、検証はサービス側でのみ行われます。

REST API では、識別子はポリモーフィックな型です。つまり開発者は JSON オブジェクト、そして具象識別子のサブタイプにマップするプロパティを構築することになります。 利便性と下位互換性上の理由から、要求では kind プロパティと rawId プロパティは省略可能ですが、サービスの応答で値が設定されます。

Communication ユーザー

CommunicationUserIdentifierModel は、Identity SDK または REST API を使用して作成されたユーザー ID を表します。 Microsoft Teams の相互運用性やテレフォニー機能が使われていないアプリケーションで使用される唯一の識別子になります。

基本的な使用


// at some point you will have created a new user identity in your trusted service
// you can specify an identifier with the id of the new user in a request
{
    "communicationUser": {
        "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_c94ff260-162d-46d6-94fd-e79f4d213715"
    }
}

// the corresponding serialization in a response
{
    "kind": "communicationUser",
    "rawId": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_c94ff260-162d-46d6-94fd-e79f4d213715",
    "communicationUser": {
        "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_c94ff260-162d-46d6-94fd-e79f4d213715"
    }
}

識別子を含む要求の例は、チャットの参加者を追加する REST API に関するページでご覧いただけます。また、識別子を含む応答の例は、チャット メッセージの取得に関する記事でご覧いただけます。

API リファレンス

CommunicationUserIdentifierModel

Microsoft Teams ユーザー

MicrosoftTeamsUserIdentifierModel は、Microsoft Entra ユーザー オブジェクト ID を持つ Teams ユーザーを表します。 Microsoft Entra ユーザー オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。 またこの ID は、ユーザーがサインインしてトークンを取得した後に Microsoft Entra トークンまたは Microsoft Entra アクセス トークン内の oid クレームとして入手することもできます。

基本的な使用

// request
{
    "microsoftTeamsUser": {
        "userId": "daba101a-91c5-44c9-bb9b-e2a9a790571a"
    }
}

// response
{
    "kind": "microsoftTeamsUser",
    "rawId": "8:orgid:daba101a-91c5-44c9-bb9b-e2a9a790571a",
    "microsoftTeamsUser": {
        "userId": "daba101a-91c5-44c9-bb9b-e2a9a790571a"
    }
}


// if you're not operating in the public cloud, you must also pass the right Cloud type in a request
{
    "microsoftTeamsUser": {
        "userId": "daba101a-91c5-44c9-bb9b-e2a9a790571a",
        "cloud": "gcch"
    }
}

// response
{
    "kind": "microsoftTeamsUser",
    "rawId": "8:gcch:daba101a-91c5-44c9-bb9b-e2a9a790571a",
    "microsoftTeamsUser": {
        "userId": "daba101a-91c5-44c9-bb9b-e2a9a790571a",
        "isAnonymous": false,
        "cloud": "gcch"
    }
}

API リファレンス

MicrosoftTeamsUserIdentifierModel

電話番号

PhoneNumberIdentifierModel は電話番号を表します。 このサービスは、電話番号が E.164 形式であることを前提としています。

基本的な使用

// request
{
    "phoneNumber": {
        "value": "+112345556789"
    }
}

// response
{
    "kind": "phoneNumber",
    "rawId": "4:+112345556789",
    "phoneNumber": {
        "value": "+112345556789"
    }
}

API リファレンス

PhoneNumberIdentifierModel

Microsoft Teams アプリケーション

MicrosoftTeamsAppIdentifierModel には、通話キューや自動応答などの Teams Voice アプリケーションのボットと、その Microsoft Entra ボット オブジェクト ID が提示されます。 Teams アプリケーションは、リソース アカウントで構成する必要があります。 Microsoft Entra ボット オブジェクト ID は、Microsoft Graph REST API /users エンドポイントを介して応答の id プロパティから取得できます。 Microsoft Graph の使用方法について詳しくは、Graph エクスプローラーを試すと共に Graph SDK を参照してください。

基本的な使用

// request
{
    "microsoftTeamsApp": {
        "appId": "45ab2481-1c1c-4005-be24-0ffb879b1130"
    }
}

// response
{
    "kind": "microsoftTeamsApp",
    "rawId": "28:orgid:45ab2481-1c1c-4005-be24-0ffb879b1130",
    "microsoftTeamsApp": {
        "appId": "45ab2481-1c1c-4005-be24-0ffb879b1130"
    }
}


// if you're not operating in the public cloud, you must also pass the right Cloud type in a request
{
    "microsoftTeamsApp": {
        "appId": "45ab2481-1c1c-4005-be24-0ffb879b1130",
        "cloud": "gcch"
    }
}

// response
{
    "kind": "microsoftTeamsApp",
    "rawId": "28:gcch:45ab2481-1c1c-4005-be24-0ffb879b1130",
    "microsoftTeamsApp": {
        "appId": "45ab2481-1c1c-4005-be24-0ffb879b1130",
        "cloud": "gcch"
    }
}

API リファレンス

MicrosoftTeamsAppIdentifierModel

Unknown

サービスに新しい識別子が導入されると、古い API バージョンを使用している場合、CommunicationIdentifierModel にダウングレードされます。

基本的な使用

// request
{
    "rawId": "a raw id that originated in the service"
}

// response
{
    "kind": "unknown",
    "rawId": "a raw id that originated in the service"
}

API リファレンス

CommunicationIdentifierModel

応答の CommunicationIdentifierModel を処理する方法

最近の API バージョンでは、判別に使用できる kind プロパティの値が設定されます。

switch (communicationIdentifier.kind)
{
    case "communicationUser":
        console.log(`Communication user: ${communicationIdentifier.communicationUser.id}`);
        break;
    case "microsoftTeamsUser":
        console.log(`Teams user: ${communicationIdentifier.microsoftTeamsUser.userId}`);
        break;
    case "phoneNumber":
        console.log(`Phone number: ${communicationIdentifier.phoneNumber.value}`);
        break;
    case "unknown":
        console.log(`Unknown: ${communicationIdentifier.rawId}`);
        break;
    default:
        // this case should not be hit because adding a new identifier type requires a new API version
        // if it does get hit, please file an issue on https://github.com/Azure/azure-rest-api-specs/issues 
        break;
}

以前の API バージョンには kind プロパティがないため、適切なサブプロパティの存在を自分で確認する必要があります。

if (communicationIdentifier.communicationUser) {
    console.log(`Communication user: ${communicationIdentifier.communicationUser.id}`);
} else if (communicationIdentifier.microsoftTeamsUser) {
    console.log(`Teams user: ${communicationIdentifier.microsoftTeamsUser.userId}`);
} else if (communicationIdentifier.phoneNumber) {
    console.log(`Phone number: ${communicationIdentifier.phoneNumber.value}`);
} else {
    console.log(`Unknown: ${communicationIdentifier.rawId}`);
}

Raw ID 表現

識別子をフラットな文字列にシリアル化しなければならない場合もあります。 たとえば、識別子をデータベース テーブルに格納したい場合や、URL パラメーターとして使用したい場合などです。

その目的のために、識別子には別途、RawId と呼ばれる表現が用意されています。 識別子は常に対応する Raw ID に変換でき、有効な Raw ID は常に識別子に変換できます。

Azure SDK を使用している場合は、それを変換に利用できます。 REST API を直接使用する場合は、以下の説明に従って Raw ID を手動で構築する必要があります。

Communication ユーザー

識別子:

{
    "communicationUser": {
        "id": "[communicationUserId]"
    }
}

Raw ID:

[communicationUserId]

Raw ID は communicationUser.id と同じです。

Microsoft Teams ユーザー

識別子:

{
    "microsoftTeamsUser": {
        "userId": "[aadUserId]"
    }
}

Raw ID:

8:orgid:[aadUserId]

Raw ID は、Microsoft Entra ユーザー オブジェクト ID にプレフィックスとして 8:orgid: が付いたものです。

識別子:

{
    "microsoftTeamsUser": {
        "userId": "[aadUserId]",
        "cloud": "gcch"
    }
}

Raw ID:

8:gcch:[aadUserId]

Raw ID は、クラウド環境に応じて、Microsoft Entra ユーザー オブジェクト ID にプレフィックスとして 8:gcch: または 8:dod: が付いたものです。

識別子:

{
    "microsoftTeamsUser": {
        "userId": "[visitorUserId]",
        "isAnonymous": true
    }
}

Raw ID:

8:teamsvisitor:[visitorUserId]

Raw ID は、Teams ビジター ID にプレフィックスとして 8:teamsvisitor: が付いたものです。 Teams ビジター ID は一時的な ID です。ミーティング アクセスを有効にするために Teams によって生成されます。

電話番号

識別子:

{
    "phoneNumber": {
        "value": "+1123455567"
    }
}

Raw ID:

4:+1123455567

Raw ID は E.164 形式の電話番号で、プレフィックスとして 4: が付いたものです。

Unknown

識別子:

{
    "rawId": "[unknown identifier id]"
}

Raw ID:

[unknown identifier id]

Raw ID が無効な場合、サービスに対する要求は失敗します。

次のステップ