次の方法で共有


識別子について

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 を参照してください。 または、ユーザーがサインインしてトークンを取得した後、oidまたは Microsoft Entra アクセス トークン要求として ID を見つけることができます。

基本的な使用方法

// 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

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

// 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();

// Get the tenantId from Graph API
const org = await graphClient.api("/organization").get();
const tenantId = org.value[0].id;

//Communication Services Resource ID
const resourceId = "<resource-id-guid>";

// create an identifier
const teamsExtensionUser = { userId: user.id, tenantId: tenantId, resourceId: resourceId };

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

API リファレンス

TeamsExtensionUserIdentifier

未知

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 "microsoftTeamsApp":
        // narrowed to MicrosoftTeamsAppIdentifier
        console.log(`Teams app: ${communicationIdentifier.teamsAppId}`);
        break;
    case "phoneNumber":
         // narrowed to PhoneNumberKind
        console.log(`Phone number: ${communicationIdentifier.phoneNumber}`);
        break;
    case "unknown":
         // narrowed to UnknownIdentifierKind
        console.log(`Unknown: ${communicationIdentifier.id}`);
        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);

無効な生 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 を参照してください。 または、サインインしてトークンを取得した後、oidまたは Microsoft Entra アクセス トークンで、id を要求として見つけることができます。

基本的な使用方法

// 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

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

// 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();

// Get the tenantId from Graph API
var organization = await graphClient.Organization
    .Request()
    .GetAsync();

string tenantId = organization.CurrentPage.FirstOrDefault()?.Id;

//Communication Services Resource ID
var resourceId = "<resource-id-guid>";

// create an identifier
var teamsExtensionUser = new TeamsExtensionUserIdentifier(user.Id, tenantId, resourceId);

// if you're not operating in the public cloud, you must also pass the right Cloud type.
var gcchTeamsExtensionUser = new TeamsExtensionUserIdentifier(userId: user.Id, tenantId: tenantId, resourceId: resourceId, cloud: CommunicationCloudEnvironment.Gcch);

API リファレンス

TeamsExtensionUserIdentifier

未知

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 MicrosoftTeamsAppIdentifier teamsApp:
        Console.WriteLine($"Teams app: {teamsApp.AppId}");
        break;
    case PhoneNumberIdentifier phoneNumber:
        Console.WriteLine($"Phone number: {phoneNumber.PhoneNumber}");
        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);

無効な生 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 を参照してください。 または、サインインしてトークンを取得した後、oidまたは Microsoft Entra アクセス トークンで、id を要求として見つけることができます。

基本的な使用方法

# 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

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

# 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");

# get the tenantId from Graph API
tenant_id = graph_client.get("/organization").json()["value"][0]["id"]

# Communication Services Resource ID
resourceId = "<resource-id-guid>"

# create an identifier
teams_user = TeamsExtensionUserIdentifier(user_id, tenant_id, resource_id)

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

API リファレンス

TeamsExtensionUserIdentifier

未知

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.MICROSOFT_TEAMS_APP:
        print(f"Teams app: {communication_identifier.properties['app_id']}")
    case CommunicationIdentifierKind.PHONE_NUMBER:
        print(f"Phone number: {communication_identifier.properties['value']}")
    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)

無効な生 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 を参照してください。 または、ユーザーがサインインしてトークンを取得した後、oidまたは Microsoft Entra アクセス トークン要求として ID を見つけることができます。

基本的な使用方法

// 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

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

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

// get the tenantId from Graph API
OrganizationCollectionPage organizations = graphClient.organization()
    .buildRequest()
    .get();
String tenantId = organizations.getCurrentPage().get(0).id;

// Communication Services Resource ID
var resourceId = "<resource-id-guid>";

// create an identifier
var teamsExtensionUser = new TeamsExtensionUserIdentifier(user.id, tenantId, resourceId);

// if you're not operating in the public cloud, you must also set the right Cloud type.
var gcchTeamsExtensionUser = new TeamsExtensionUserIdentifier(user.id, tenantId, resourceId).setCloudEnvironment(CommunicationCloudEnvironment.GCCH);

API リファレンス

TeamsExtensionUserIdentifier

未知

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  MicrosoftTeamsAppIdentifier) {
    Log.i(tag, "Teams app: " + (( MicrosoftTeamsAppIdentifier)communicationIdentifier).getAppId());
}
else if (communicationIdentifier instanceof PhoneNumberIdentifier) {
    System.out.println("Phone number: " + ((PhoneNumberIdentifier)communicationIdentifier).getPhoneNumber());
}
else if (communicationIdentifier instanceof UnknownIdentifier) {
    System.out.println("Unknown 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);

無効な生 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 トークンoidMicrosoft Entra アクセス トークンにおける ID クレームとして見つけることができます。

基本的な使用方法

// 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

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

// 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")

// get the tenantId from Graph API
let tenantId = await getTenantIdFromGraph()

// Communication Services Resource ID
let resourceId = "<resource-id-guid>"

// create an identifier
let teamsExtensionUser = TeamsExtensionUserIdentifier(userId: userId, tenantId: tenantId, resourceId: resourceId)

// if you're not operating in the public cloud, you must also pass the right Cloud type.
let gcchTeamsExtensionUser = TeamsExtensionUserIdentifier(userId: userId, tenantId: tenantId, resourceId: resourceId, cloudEnvironment: CommunicationCloudEnvironment.Gcch)

API リファレンス

TeamsExtensionUserIdentifier

未知

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 teamsApp as MicrosoftTeamsAppIdentifier:
        print(#"Teams app: \(teamsApp.appId)"#)
    case let phoneNumber as PhoneNumberIdentifier:
        print(#"Phone number: \(phoneNumber.PhoneNumber)"#)
    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 で行うことができます。

速い

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

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

無効な生 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 トークンoidMicrosoft Entra アクセス トークンにおける ID クレームとして見つけることができます。

基本的な使用方法

// 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

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

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

// get the tenantId from Graph API
OrganizationCollectionPage organizations = graphClient.organization()
    .buildRequest()
    .get();
String tenantId = organizations.getCurrentPage().get(0).id;

// Communication Services Resource ID
var resourceId = "<resource-id-guid>";

// create an identifier
var teamsExtensionUser = new TeamsExtensionUserIdentifier(user.id, tenantId, resourceId);

// if you're not operating in the public cloud, you must also set the right Cloud type.
var gcchTeamsExtensionUser = new TeamsExtensionUserIdentifier(user.id, tenantId, resourceId).setCloudEnvironment(CommunicationCloudEnvironment.GCCH);

API リファレンス

TeamsExtensionUserIdentifier

未知

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  MicrosoftTeamsAppIdentifier) {
    Log.i(tag, "Teams app: " + (( MicrosoftTeamsAppIdentifier)communicationIdentifier).getAppId());
}
else if (communicationIdentifier instanceof PhoneNumberIdentifier) {
    Log.i(tag, "Phone number: " + ((PhoneNumberIdentifier)communicationIdentifier).getPhoneNumber());
}
else if (communicationIdentifier instanceof UnknownIdentifier) {
    Log.i(tag, "Unknown 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);

無効な生 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 を参照してください。 または、ユーザーがサインインしてトークンを取得した後、oidまたは Microsoft Entra アクセス トークン要求として ID を見つけることができます。

基本的な使用方法

// request
{
    "microsoftTeamsUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee"
    }
}

// response
{
    "kind": "microsoftTeamsUser",
    "rawId": "8:orgid:00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
    "microsoftTeamsUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee"
    }
}


// if you're not operating in the public cloud, you must also pass the right Cloud type in a request
{
    "microsoftTeamsUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
        "cloud": "gcch"
    }
}

// response
{
    "kind": "microsoftTeamsUser",
    "rawId": "8:gcch:00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
    "microsoftTeamsUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
        "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": "00001111-aaaa-2222-bbbb-3333cccc4444"
    }
}

// response
{
    "kind": "microsoftTeamsApp",
    "rawId": "28:orgid:00001111-aaaa-2222-bbbb-3333cccc4444",
    "microsoftTeamsApp": {
        "appId": "00001111-aaaa-2222-bbbb-3333cccc4444"
    }
}


// if you're not operating in the public cloud, you must also pass the right Cloud type in a request
{
    "microsoftTeamsApp": {
        "appId": "00001111-aaaa-2222-bbbb-3333cccc4444",
        "cloud": "gcch"
    }
}

// response
{
    "kind": "microsoftTeamsApp",
    "rawId": "28:gcch:00001111-aaaa-2222-bbbb-3333cccc4444",
    "microsoftTeamsApp": {
        "appId": "00001111-aaaa-2222-bbbb-3333cccc4444",
        "cloud": "gcch"
    }
}

API リファレンス

MicrosoftTeamsAppIdentifierModel

Teams 拡張機能ユーザー

TeamsExtensionUserIdentifier インターフェイスは、Teams Phone Extensibility で有効になっている Teams ユーザーを表します。 TeamsExtensionUserIdentifierには、Teams ユーザーの Microsoft Entra ユーザー オブジェクト ID、ユーザーが存在する Microsoft Entra テナント ID、および Azure Communication Services リソース ID が必要です。 応答の プロパティから id エンドポイントを使用して Microsoft Entra ユーザー オブジェクト ID を取得し、応答の プロパティから id エンドポイントを介して Microsoft Entra テナント ID を取得できます。 Microsoft Graph の操作の詳細については、「 Graph エクスプローラー 」を参照し、 Graph SDK を参照してください。 または、ユーザーがサインインしてトークンを取得した後で、オブジェクト ID をoid要求として、テナント ID を tidまたは Microsoft Entra アクセス トークン要求として見つけることができます。

基本的な使用方法

// request
{
    "teamsExtensionUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
        "tenantId": "d4f5a8c3-2c49-4b9e-a5c6-3c85e80a7f4d",
        "resourceId": "f7e1e3c6-3a1d-4415-8b7d-9e1d4bda2d45"
    }
}

// response
{
    "kind": "teamsExtensionUser",
    "rawId": "8:acs:f7e1e3c6-3a1d-4415-8b7d-9e1d4bda2d45_d4f5a8c3-2c49-4b9e-a5c6-3c85e80a7f4d_00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
    "teamsExtensionUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
        "tenantId": "d4f5a8c3-2c49-4b9e-a5c6-3c85e80a7f4d",
        "resourceId": "f7e1e3c6-3a1d-4415-8b7d-9e1d4bda2d45"
    }
}


// if you're not operating in the public cloud, you must also pass the right Cloud type in a request
{
    "microsoftTeamsUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
        "tenantId": "d4f5a8c3-2c49-4b9e-a5c6-3c85e80a7f4d",
        "resourceId": "f7e1e3c6-3a1d-4415-8b7d-9e1d4bda2d45",
        "cloud": "gcch"
    }
}

// response
{
    "kind": "teamsExtensionUser",
    "rawId": "8:gcch-acs:f7e1e3c6-3a1d-4415-8b7d-9e1d4bda2d45_d4f5a8c3-2c49-4b9e-a5c6-3c85e80a7f4d_00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
    "teamsExtensionUser": {
        "userId": "00aa00aa-bb11-cc22-dd33-44ee44ee44ee",
        "tenantId": "d4f5a8c3-2c49-4b9e-a5c6-3c85e80a7f4d",
        "resourceId": "f7e1e3c6-3a1d-4415-8b7d-9e1d4bda2d45",
        "cloud": "gcch"
    }
}

API リファレンス

TeamsExtensionUserIdentifierModel

未知

サービスで新しい識別子が導入された場合、古い 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 "microsoftTeamsApp":
        console.log(`Teams user: ${communicationIdentifier.microsoftTeamsApp.appId}`);
        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.microsoftTeamsApp) {
    console.log(`Teams app: ${communicationIdentifier.microsoftTeamsApp.appId}`);
} 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 を直接使用する場合は、次のように生 ID を手動で作成する必要があります。

Communication ユーザー

識別子:

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

未加工 ID:

[communicationUserId]

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

Microsoft Teams ユーザー

識別子:

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

未加工 ID:

8:orgid:[entraUserId]

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

識別子:

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

未加工 ID:

8:gcch:[entraUserId]

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

識別子:

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

未加工 ID:

8:teamsvisitor:[visitorUserId]

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

電話番号

識別子:

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

未加工 ID:

4:+1123455567

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

Microsoft Teams アプリ

識別子:

{
    "microsoftTeamsApp": {
        "appId": "[entraUserId]"
    }
}

未加工 ID:

28:orgid:[entraUserId]

生のIDは、28:orgid:で始まるアプリケーションのMicrosoft EntraユーザーオブジェクトIDです。

識別子:

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

未加工 ID:

28:gcch:[entraUserId]

アプリケーションの Microsoft Entra ユーザー オブジェクト ID の生の識別子は、クラウド環境に応じて 28:gcch: または 28:dod: がプレフィックスとして追加されます。

未知

識別子:

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

未加工 ID:

[unknown identifier id]

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

次のステップ