Skip to content

Commit

Permalink
microsoft teams app identifier (Azure#26996)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
@azure/communication-common

### Issues associated with this PR


### Describe the problem that is addressed by this PR
Change MicrosoftBotIdentifier to MicrosoftTeamsAppIdentifier for 3.0.0
GA

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_
No need to add more UTs, current UTs are ok. I've modified UTs in this
PR

### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [X] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [x] Added a changelog (if necessary)
  • Loading branch information
chriswhilar authored Sep 14, 2023
1 parent a74541d commit b581882
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 116 deletions.
9 changes: 9 additions & 0 deletions sdk/communication/communication-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Release History

## 3.0.0 (Unreleased)

### Features Added

- Added support for a new communication identifier `MicrosoftTeamsAppIdentifier`.
- Added a type `MicrosoftTeamsAppKind`.
- Added a method `isMicrosoftTeamsAppIdentifier` to check if the identifier is `MicrosoftTeamsAppIdentifier`.
- Added a field `teamsAppId` to `MicrosoftTeamsAppIdentifier`.

## 3.0.0-beta.2 (Unreleased)

### Features Added
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/communication-common",
"version": "3.0.0-beta.2",
"version": "3.0.0",
"description": "Common package for Azure Communication services.",
"sdk-type": "client",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export interface CommunicationGetTokenOptions {
}

// @public
export type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftBotIdentifier | UnknownIdentifier;
export type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftTeamsAppIdentifier | UnknownIdentifier;

// @public
export type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftBotKind | UnknownIdentifierKind;
export type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftTeamsAppKind | UnknownIdentifierKind;

// @public
export interface CommunicationTokenCredential {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const isCommunicationUserIdentifier: (identifier: CommunicationIdentifier
export const isKeyCredential: (credential: unknown) => credential is KeyCredential;

// @public
export const isMicrosoftBotIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftBotIdentifier;
export const isMicrosoftTeamsAppIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftTeamsAppIdentifier;

// @public
export const isMicrosoftTeamsUserIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftTeamsUserIdentifier;
Expand All @@ -95,16 +95,15 @@ export const isPhoneNumberIdentifier: (identifier: CommunicationIdentifier) => i
export const isUnknownIdentifier: (identifier: CommunicationIdentifier) => identifier is UnknownIdentifier;

// @public
export interface MicrosoftBotIdentifier {
botId: string;
export interface MicrosoftTeamsAppIdentifier {
cloud?: "public" | "dod" | "gcch";
isResourceAccountConfigured?: boolean;
rawId?: string;
teamsAppId: string;
}

// @public
export interface MicrosoftBotKind extends MicrosoftBotIdentifier {
kind: "microsoftBot";
export interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {
kind: "microsoftTeamsApp";
}

// @public
Expand Down Expand Up @@ -147,7 +146,7 @@ export type SerializedCommunicationCloudEnvironment = "public" | "dod" | "gcch";
export interface SerializedCommunicationIdentifier {
communicationUser?: SerializedCommunicationUserIdentifier;
kind?: string;
microsoftBot?: SerializedMicrosoftBotIdentifier;
microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;
microsoftTeamsUser?: SerializedMicrosoftTeamsUserIdentifier;
phoneNumber?: SerializedPhoneNumberIdentifier;
rawId?: string;
Expand All @@ -159,10 +158,9 @@ export interface SerializedCommunicationUserIdentifier {
}

// @public
export interface SerializedMicrosoftBotIdentifier {
botId: string;
export interface SerializedMicrosoftTeamsAppIdentifier {
cloud?: SerializedCommunicationCloudEnvironment;
isResourceAccountConfigured?: boolean;
teamsAppId: string;
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export interface SerializedCommunicationIdentifier {
*/
microsoftTeamsUser?: SerializedMicrosoftTeamsUserIdentifier;
/**
* The Microsoft bot.
* The Microsoft Teams App.
*/
microsoftBot?: SerializedMicrosoftBotIdentifier;
microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;
}

/**
Expand Down Expand Up @@ -82,19 +82,16 @@ export interface SerializedMicrosoftTeamsUserIdentifier {

/**
* @hidden
* A Microsoft bot.
* A Microsoft Teams App.
*/
export interface SerializedMicrosoftBotIdentifier {
export interface SerializedMicrosoftTeamsAppIdentifier {
/**
* Id of the Microsoft bot.
* Id of the Microsoft Teams App.
*/
botId: string;
/**
* True (or missing) if the bot is global and no resource account is configured and false if the bot is tenantized.
*/
isResourceAccountConfigured?: boolean;
teamsAppId: string;

/**
* The cloud that the Microsoft bot belongs to. By default 'public' if missing.
* The cloud that the Microsoft Teams App belongs to. By default 'public' if missing.
*/
cloud?: SerializedCommunicationCloudEnvironment;
}
Expand Down Expand Up @@ -129,8 +126,8 @@ const assertMaximumOneNestedModel = (identifier: SerializedCommunicationIdentifi
if (identifier.microsoftTeamsUser !== undefined) {
presentProperties.push("microsoftTeamsUser");
}
if (identifier.microsoftBot !== undefined) {
presentProperties.push("microsoftBot");
if (identifier.microsoftTeamsApp !== undefined) {
presentProperties.push("microsoftTeamsApp");
}
if (identifier.phoneNumber !== undefined) {
presentProperties.push("phoneNumber");
Expand Down Expand Up @@ -173,12 +170,11 @@ export const serializeCommunicationIdentifier = (
cloud: identifierKind.cloud ?? "public",
},
};
case "microsoftBot":
case "microsoftTeamsApp":
return {
rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),
microsoftBot: {
botId: identifierKind.botId,
isResourceAccountConfigured: identifierKind.isResourceAccountConfigured ?? true,
microsoftTeamsApp: {
teamsAppId: identifierKind.teamsAppId,
cloud: identifierKind.cloud ?? "public",
},
};
Expand All @@ -202,8 +198,8 @@ const getKind = (serializedIdentifier: SerializedCommunicationIdentifier): strin
return "microsoftTeamsUser";
}

if (serializedIdentifier.microsoftBot) {
return "microsoftBot";
if (serializedIdentifier.microsoftTeamsApp) {
return "microsoftTeamsApp";
}

return "unknown";
Expand All @@ -219,7 +215,8 @@ export const deserializeCommunicationIdentifier = (
): CommunicationIdentifierKind => {
assertMaximumOneNestedModel(serializedIdentifier);

const { communicationUser, microsoftTeamsUser, microsoftBot, phoneNumber } = serializedIdentifier;
const { communicationUser, microsoftTeamsUser, microsoftTeamsApp, phoneNumber } =
serializedIdentifier;
const kind = serializedIdentifier.kind ?? getKind(serializedIdentifier);

if (kind === "communicationUser" && communicationUser) {
Expand All @@ -244,16 +241,12 @@ export const deserializeCommunicationIdentifier = (
rawId: assertNotNullOrUndefined({ microsoftTeamsUser: serializedIdentifier }, "rawId"),
};
}
if (kind === "microsoftBot" && microsoftBot) {
if (kind === "microsoftTeamsApp" && microsoftTeamsApp) {
return {
kind: "microsoftBot",
botId: assertNotNullOrUndefined({ microsoftBot }, "botId"),
isResourceAccountConfigured: assertNotNullOrUndefined(
{ microsoftBot },
"isResourceAccountConfigured"
),
cloud: assertNotNullOrUndefined({ microsoftBot }, "cloud"),
rawId: assertNotNullOrUndefined({ microsoftBot: serializedIdentifier }, "rawId"),
kind: "microsoftTeamsApp",
teamsAppId: assertNotNullOrUndefined({ microsoftTeamsApp }, "teamsAppId"),
cloud: assertNotNullOrUndefined({ microsoftTeamsApp }, "cloud"),
rawId: assertNotNullOrUndefined({ microsoftTeamsApp: serializedIdentifier }, "rawId"),
};
}
return {
Expand Down
83 changes: 30 additions & 53 deletions sdk/communication/communication-common/src/identifierModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type CommunicationIdentifier =
| CommunicationUserIdentifier
| PhoneNumberIdentifier
| MicrosoftTeamsUserIdentifier
| MicrosoftBotIdentifier
| MicrosoftTeamsAppIdentifier
| UnknownIdentifier;

/**
Expand Down Expand Up @@ -61,26 +61,21 @@ export interface MicrosoftTeamsUserIdentifier {
}

/**
* A Microsoft bot.
* A Microsoft Teams App.
*/
export interface MicrosoftBotIdentifier {
export interface MicrosoftTeamsAppIdentifier {
/**
* Optional raw id of the Microsoft bot.
* Optional raw id of the Microsoft Teams App.
*/
rawId?: string;

/**
* The unique Microsoft app ID for the bot as registered with the Bot Framework.
* The unique Microsoft Teams app ID.
*/
botId: string;
teamsAppId: string;

/**
* True (or missing) if the bot is global and no resource account is configured and false if the bot is tenantized.
*/
isResourceAccountConfigured?: boolean;

/**
* The cloud that the Microsoft bot belongs to. If missing, the cloud is "public".
* The cloud that the Microsoft Temas App belongs to. If missing, the cloud is "public".
*/
cloud?: "public" | "dod" | "gcch";
}
Expand Down Expand Up @@ -129,14 +124,14 @@ export const isMicrosoftTeamsUserIdentifier = (
};

/**
* Tests an Identifier to determine whether it implements MicrosoftBotIdentifier.
* Tests an Identifier to determine whether it implements MicrosoftTeamsAppIdentifier.
*
* @param identifier - The assumed available to be tested.
*/
export const isMicrosoftBotIdentifier = (
export const isMicrosoftTeamsAppIdentifier = (
identifier: CommunicationIdentifier
): identifier is MicrosoftBotIdentifier => {
return typeof (identifier as any).botId === "string";
): identifier is MicrosoftTeamsAppIdentifier => {
return typeof (identifier as any).teamsAppId === "string";
};

/**
Expand All @@ -157,7 +152,7 @@ export type CommunicationIdentifierKind =
| CommunicationUserKind
| PhoneNumberKind
| MicrosoftTeamsUserKind
| MicrosoftBotKind
| MicrosoftTeamsAppKind
| UnknownIdentifierKind;

/**
Expand Down Expand Up @@ -191,13 +186,13 @@ export interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
}

/**
* IdentifierKind for a MicrosoftBotIdentifier.
* IdentifierKind for a MicrosoftTeamsAppIdentifier.
*/
export interface MicrosoftBotKind extends MicrosoftBotIdentifier {
export interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {
/**
* The identifier kind.
*/
kind: "microsoftBot";
kind: "microsoftTeamsApp";
}

/**
Expand Down Expand Up @@ -227,8 +222,8 @@ export const getIdentifierKind = (
if (isMicrosoftTeamsUserIdentifier(identifier)) {
return { ...identifier, kind: "microsoftTeamsUser" };
}
if (isMicrosoftBotIdentifier(identifier)) {
return { ...identifier, kind: "microsoftBot" };
if (isMicrosoftTeamsAppIdentifier(identifier)) {
return { ...identifier, kind: "microsoftTeamsApp" };
}
return { ...identifier, kind: "unknown" };
};
Expand Down Expand Up @@ -257,25 +252,16 @@ export const getIdentifierRawId = (identifier: CommunicationIdentifier): string
}
return `8:orgid:${microsoftTeamsUserId}`;
}
case "microsoftBot": {
const { botId, rawId, cloud, isResourceAccountConfigured } = identifierKind;
case "microsoftTeamsApp": {
const { teamsAppId, rawId, cloud } = identifierKind;
if (rawId) return rawId;
if (!isResourceAccountConfigured) {
switch (cloud) {
case "dod":
return `28:dod-global:${botId}`;
case "gcch":
return `28:gcch-global:${botId}`;
}
return `28:${botId}`;
}
switch (cloud) {
case "dod":
return `28:dod:${botId}`;
return `28:dod:${teamsAppId}`;
case "gcch":
return `28:gcch:${botId}`;
return `28:gcch:${teamsAppId}`;
}
return `28:orgid:${botId}`;
return `28:orgid:${teamsAppId}`;
}
case "phoneNumber": {
const { phoneNumber, rawId } = identifierKind;
Expand All @@ -288,16 +274,14 @@ export const getIdentifierRawId = (identifier: CommunicationIdentifier): string
}
};

const buildMicrosoftBotIdentifier = (
id: string,
cloud: "public" | "dod" | "gcch",
isResourceAccountConfigured: boolean
const buildMicrosoftTeamsAppIdentifier = (
teamsAppId: string,
cloud: "public" | "dod" | "gcch"
): CommunicationIdentifierKind => {
return {
kind: "microsoftBot",
botId: id,
kind: "microsoftTeamsApp",
teamsAppId: teamsAppId,
cloud: cloud,
isResourceAccountConfigured: isResourceAccountConfigured,
};
};

Expand Down Expand Up @@ -326,9 +310,6 @@ export const createIdentifierFromRawId = (rawId: string): CommunicationIdentifie

const segments = rawId.split(":");
if (segments.length !== 3) {
if (segments.length === 2 && segments[0] === "28") {
return buildMicrosoftBotIdentifier(segments[1], "public", false);
}
return { kind: "unknown", id: rawId };
}

Expand All @@ -349,16 +330,12 @@ export const createIdentifierFromRawId = (rawId: string): CommunicationIdentifie
case "8:dod-acs:":
case "8:gcch-acs:":
return { kind: "communicationUser", communicationUserId: rawId };
case "28:gcch-global:":
return buildMicrosoftBotIdentifier(suffix, "gcch", false);
case "28:orgid:":
return buildMicrosoftBotIdentifier(suffix, "public", true);
case "28:dod-global:":
return buildMicrosoftBotIdentifier(suffix, "dod", false);
return buildMicrosoftTeamsAppIdentifier(suffix, "public");
case "28:gcch:":
return buildMicrosoftBotIdentifier(suffix, "gcch", true);
return buildMicrosoftTeamsAppIdentifier(suffix, "gcch");
case "28:dod:":
return buildMicrosoftBotIdentifier(suffix, "dod", true);
return buildMicrosoftTeamsAppIdentifier(suffix, "dod");
}
return { kind: "unknown", id: rawId };
};
Loading

0 comments on commit b581882

Please sign in to comment.