Skip to content

Commit b581882

Browse files
authored
microsoft teams app identifier (Azure#26996)
### 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)
1 parent a74541d commit b581882

File tree

6 files changed

+84
-116
lines changed

6 files changed

+84
-116
lines changed

sdk/communication/communication-common/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release History
22

3+
## 3.0.0 (Unreleased)
4+
5+
### Features Added
6+
7+
- Added support for a new communication identifier `MicrosoftTeamsAppIdentifier`.
8+
- Added a type `MicrosoftTeamsAppKind`.
9+
- Added a method `isMicrosoftTeamsAppIdentifier` to check if the identifier is `MicrosoftTeamsAppIdentifier`.
10+
- Added a field `teamsAppId` to `MicrosoftTeamsAppIdentifier`.
11+
312
## 3.0.0-beta.2 (Unreleased)
413

514
### Features Added

sdk/communication/communication-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/communication-common",
3-
"version": "3.0.0-beta.2",
3+
"version": "3.0.0",
44
"description": "Common package for Azure Communication services.",
55
"sdk-type": "client",
66
"main": "dist/index.js",

sdk/communication/communication-common/review/communication-common.api.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export interface CommunicationGetTokenOptions {
2424
}
2525

2626
// @public
27-
export type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftBotIdentifier | UnknownIdentifier;
27+
export type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftTeamsAppIdentifier | UnknownIdentifier;
2828

2929
// @public
30-
export type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftBotKind | UnknownIdentifierKind;
30+
export type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftTeamsAppKind | UnknownIdentifierKind;
3131

3232
// @public
3333
export interface CommunicationTokenCredential {
@@ -83,7 +83,7 @@ export const isCommunicationUserIdentifier: (identifier: CommunicationIdentifier
8383
export const isKeyCredential: (credential: unknown) => credential is KeyCredential;
8484

8585
// @public
86-
export const isMicrosoftBotIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftBotIdentifier;
86+
export const isMicrosoftTeamsAppIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftTeamsAppIdentifier;
8787

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

9797
// @public
98-
export interface MicrosoftBotIdentifier {
99-
botId: string;
98+
export interface MicrosoftTeamsAppIdentifier {
10099
cloud?: "public" | "dod" | "gcch";
101-
isResourceAccountConfigured?: boolean;
102100
rawId?: string;
101+
teamsAppId: string;
103102
}
104103

105104
// @public
106-
export interface MicrosoftBotKind extends MicrosoftBotIdentifier {
107-
kind: "microsoftBot";
105+
export interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {
106+
kind: "microsoftTeamsApp";
108107
}
109108

110109
// @public
@@ -147,7 +146,7 @@ export type SerializedCommunicationCloudEnvironment = "public" | "dod" | "gcch";
147146
export interface SerializedCommunicationIdentifier {
148147
communicationUser?: SerializedCommunicationUserIdentifier;
149148
kind?: string;
150-
microsoftBot?: SerializedMicrosoftBotIdentifier;
149+
microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;
151150
microsoftTeamsUser?: SerializedMicrosoftTeamsUserIdentifier;
152151
phoneNumber?: SerializedPhoneNumberIdentifier;
153152
rawId?: string;
@@ -159,10 +158,9 @@ export interface SerializedCommunicationUserIdentifier {
159158
}
160159

161160
// @public
162-
export interface SerializedMicrosoftBotIdentifier {
163-
botId: string;
161+
export interface SerializedMicrosoftTeamsAppIdentifier {
164162
cloud?: SerializedCommunicationCloudEnvironment;
165-
isResourceAccountConfigured?: boolean;
163+
teamsAppId: string;
166164
}
167165

168166
// @public

sdk/communication/communication-common/src/identifierModelSerializer.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export interface SerializedCommunicationIdentifier {
3434
*/
3535
microsoftTeamsUser?: SerializedMicrosoftTeamsUserIdentifier;
3636
/**
37-
* The Microsoft bot.
37+
* The Microsoft Teams App.
3838
*/
39-
microsoftBot?: SerializedMicrosoftBotIdentifier;
39+
microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;
4040
}
4141

4242
/**
@@ -82,19 +82,16 @@ export interface SerializedMicrosoftTeamsUserIdentifier {
8282

8383
/**
8484
* @hidden
85-
* A Microsoft bot.
85+
* A Microsoft Teams App.
8686
*/
87-
export interface SerializedMicrosoftBotIdentifier {
87+
export interface SerializedMicrosoftTeamsAppIdentifier {
8888
/**
89-
* Id of the Microsoft bot.
89+
* Id of the Microsoft Teams App.
9090
*/
91-
botId: string;
92-
/**
93-
* True (or missing) if the bot is global and no resource account is configured and false if the bot is tenantized.
94-
*/
95-
isResourceAccountConfigured?: boolean;
91+
teamsAppId: string;
92+
9693
/**
97-
* The cloud that the Microsoft bot belongs to. By default 'public' if missing.
94+
* The cloud that the Microsoft Teams App belongs to. By default 'public' if missing.
9895
*/
9996
cloud?: SerializedCommunicationCloudEnvironment;
10097
}
@@ -129,8 +126,8 @@ const assertMaximumOneNestedModel = (identifier: SerializedCommunicationIdentifi
129126
if (identifier.microsoftTeamsUser !== undefined) {
130127
presentProperties.push("microsoftTeamsUser");
131128
}
132-
if (identifier.microsoftBot !== undefined) {
133-
presentProperties.push("microsoftBot");
129+
if (identifier.microsoftTeamsApp !== undefined) {
130+
presentProperties.push("microsoftTeamsApp");
134131
}
135132
if (identifier.phoneNumber !== undefined) {
136133
presentProperties.push("phoneNumber");
@@ -173,12 +170,11 @@ export const serializeCommunicationIdentifier = (
173170
cloud: identifierKind.cloud ?? "public",
174171
},
175172
};
176-
case "microsoftBot":
173+
case "microsoftTeamsApp":
177174
return {
178175
rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),
179-
microsoftBot: {
180-
botId: identifierKind.botId,
181-
isResourceAccountConfigured: identifierKind.isResourceAccountConfigured ?? true,
176+
microsoftTeamsApp: {
177+
teamsAppId: identifierKind.teamsAppId,
182178
cloud: identifierKind.cloud ?? "public",
183179
},
184180
};
@@ -202,8 +198,8 @@ const getKind = (serializedIdentifier: SerializedCommunicationIdentifier): strin
202198
return "microsoftTeamsUser";
203199
}
204200

205-
if (serializedIdentifier.microsoftBot) {
206-
return "microsoftBot";
201+
if (serializedIdentifier.microsoftTeamsApp) {
202+
return "microsoftTeamsApp";
207203
}
208204

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

222-
const { communicationUser, microsoftTeamsUser, microsoftBot, phoneNumber } = serializedIdentifier;
218+
const { communicationUser, microsoftTeamsUser, microsoftTeamsApp, phoneNumber } =
219+
serializedIdentifier;
223220
const kind = serializedIdentifier.kind ?? getKind(serializedIdentifier);
224221

225222
if (kind === "communicationUser" && communicationUser) {
@@ -244,16 +241,12 @@ export const deserializeCommunicationIdentifier = (
244241
rawId: assertNotNullOrUndefined({ microsoftTeamsUser: serializedIdentifier }, "rawId"),
245242
};
246243
}
247-
if (kind === "microsoftBot" && microsoftBot) {
244+
if (kind === "microsoftTeamsApp" && microsoftTeamsApp) {
248245
return {
249-
kind: "microsoftBot",
250-
botId: assertNotNullOrUndefined({ microsoftBot }, "botId"),
251-
isResourceAccountConfigured: assertNotNullOrUndefined(
252-
{ microsoftBot },
253-
"isResourceAccountConfigured"
254-
),
255-
cloud: assertNotNullOrUndefined({ microsoftBot }, "cloud"),
256-
rawId: assertNotNullOrUndefined({ microsoftBot: serializedIdentifier }, "rawId"),
246+
kind: "microsoftTeamsApp",
247+
teamsAppId: assertNotNullOrUndefined({ microsoftTeamsApp }, "teamsAppId"),
248+
cloud: assertNotNullOrUndefined({ microsoftTeamsApp }, "cloud"),
249+
rawId: assertNotNullOrUndefined({ microsoftTeamsApp: serializedIdentifier }, "rawId"),
257250
};
258251
}
259252
return {

sdk/communication/communication-common/src/identifierModels.ts

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type CommunicationIdentifier =
88
| CommunicationUserIdentifier
99
| PhoneNumberIdentifier
1010
| MicrosoftTeamsUserIdentifier
11-
| MicrosoftBotIdentifier
11+
| MicrosoftTeamsAppIdentifier
1212
| UnknownIdentifier;
1313

1414
/**
@@ -61,26 +61,21 @@ export interface MicrosoftTeamsUserIdentifier {
6161
}
6262

6363
/**
64-
* A Microsoft bot.
64+
* A Microsoft Teams App.
6565
*/
66-
export interface MicrosoftBotIdentifier {
66+
export interface MicrosoftTeamsAppIdentifier {
6767
/**
68-
* Optional raw id of the Microsoft bot.
68+
* Optional raw id of the Microsoft Teams App.
6969
*/
7070
rawId?: string;
7171

7272
/**
73-
* The unique Microsoft app ID for the bot as registered with the Bot Framework.
73+
* The unique Microsoft Teams app ID.
7474
*/
75-
botId: string;
75+
teamsAppId: string;
7676

7777
/**
78-
* True (or missing) if the bot is global and no resource account is configured and false if the bot is tenantized.
79-
*/
80-
isResourceAccountConfigured?: boolean;
81-
82-
/**
83-
* The cloud that the Microsoft bot belongs to. If missing, the cloud is "public".
78+
* The cloud that the Microsoft Temas App belongs to. If missing, the cloud is "public".
8479
*/
8580
cloud?: "public" | "dod" | "gcch";
8681
}
@@ -129,14 +124,14 @@ export const isMicrosoftTeamsUserIdentifier = (
129124
};
130125

131126
/**
132-
* Tests an Identifier to determine whether it implements MicrosoftBotIdentifier.
127+
* Tests an Identifier to determine whether it implements MicrosoftTeamsAppIdentifier.
133128
*
134129
* @param identifier - The assumed available to be tested.
135130
*/
136-
export const isMicrosoftBotIdentifier = (
131+
export const isMicrosoftTeamsAppIdentifier = (
137132
identifier: CommunicationIdentifier
138-
): identifier is MicrosoftBotIdentifier => {
139-
return typeof (identifier as any).botId === "string";
133+
): identifier is MicrosoftTeamsAppIdentifier => {
134+
return typeof (identifier as any).teamsAppId === "string";
140135
};
141136

142137
/**
@@ -157,7 +152,7 @@ export type CommunicationIdentifierKind =
157152
| CommunicationUserKind
158153
| PhoneNumberKind
159154
| MicrosoftTeamsUserKind
160-
| MicrosoftBotKind
155+
| MicrosoftTeamsAppKind
161156
| UnknownIdentifierKind;
162157

163158
/**
@@ -191,13 +186,13 @@ export interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
191186
}
192187

193188
/**
194-
* IdentifierKind for a MicrosoftBotIdentifier.
189+
* IdentifierKind for a MicrosoftTeamsAppIdentifier.
195190
*/
196-
export interface MicrosoftBotKind extends MicrosoftBotIdentifier {
191+
export interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {
197192
/**
198193
* The identifier kind.
199194
*/
200-
kind: "microsoftBot";
195+
kind: "microsoftTeamsApp";
201196
}
202197

203198
/**
@@ -227,8 +222,8 @@ export const getIdentifierKind = (
227222
if (isMicrosoftTeamsUserIdentifier(identifier)) {
228223
return { ...identifier, kind: "microsoftTeamsUser" };
229224
}
230-
if (isMicrosoftBotIdentifier(identifier)) {
231-
return { ...identifier, kind: "microsoftBot" };
225+
if (isMicrosoftTeamsAppIdentifier(identifier)) {
226+
return { ...identifier, kind: "microsoftTeamsApp" };
232227
}
233228
return { ...identifier, kind: "unknown" };
234229
};
@@ -257,25 +252,16 @@ export const getIdentifierRawId = (identifier: CommunicationIdentifier): string
257252
}
258253
return `8:orgid:${microsoftTeamsUserId}`;
259254
}
260-
case "microsoftBot": {
261-
const { botId, rawId, cloud, isResourceAccountConfigured } = identifierKind;
255+
case "microsoftTeamsApp": {
256+
const { teamsAppId, rawId, cloud } = identifierKind;
262257
if (rawId) return rawId;
263-
if (!isResourceAccountConfigured) {
264-
switch (cloud) {
265-
case "dod":
266-
return `28:dod-global:${botId}`;
267-
case "gcch":
268-
return `28:gcch-global:${botId}`;
269-
}
270-
return `28:${botId}`;
271-
}
272258
switch (cloud) {
273259
case "dod":
274-
return `28:dod:${botId}`;
260+
return `28:dod:${teamsAppId}`;
275261
case "gcch":
276-
return `28:gcch:${botId}`;
262+
return `28:gcch:${teamsAppId}`;
277263
}
278-
return `28:orgid:${botId}`;
264+
return `28:orgid:${teamsAppId}`;
279265
}
280266
case "phoneNumber": {
281267
const { phoneNumber, rawId } = identifierKind;
@@ -288,16 +274,14 @@ export const getIdentifierRawId = (identifier: CommunicationIdentifier): string
288274
}
289275
};
290276

291-
const buildMicrosoftBotIdentifier = (
292-
id: string,
293-
cloud: "public" | "dod" | "gcch",
294-
isResourceAccountConfigured: boolean
277+
const buildMicrosoftTeamsAppIdentifier = (
278+
teamsAppId: string,
279+
cloud: "public" | "dod" | "gcch"
295280
): CommunicationIdentifierKind => {
296281
return {
297-
kind: "microsoftBot",
298-
botId: id,
282+
kind: "microsoftTeamsApp",
283+
teamsAppId: teamsAppId,
299284
cloud: cloud,
300-
isResourceAccountConfigured: isResourceAccountConfigured,
301285
};
302286
};
303287

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

327311
const segments = rawId.split(":");
328312
if (segments.length !== 3) {
329-
if (segments.length === 2 && segments[0] === "28") {
330-
return buildMicrosoftBotIdentifier(segments[1], "public", false);
331-
}
332313
return { kind: "unknown", id: rawId };
333314
}
334315

@@ -349,16 +330,12 @@ export const createIdentifierFromRawId = (rawId: string): CommunicationIdentifie
349330
case "8:dod-acs:":
350331
case "8:gcch-acs:":
351332
return { kind: "communicationUser", communicationUserId: rawId };
352-
case "28:gcch-global:":
353-
return buildMicrosoftBotIdentifier(suffix, "gcch", false);
354333
case "28:orgid:":
355-
return buildMicrosoftBotIdentifier(suffix, "public", true);
356-
case "28:dod-global:":
357-
return buildMicrosoftBotIdentifier(suffix, "dod", false);
334+
return buildMicrosoftTeamsAppIdentifier(suffix, "public");
358335
case "28:gcch:":
359-
return buildMicrosoftBotIdentifier(suffix, "gcch", true);
336+
return buildMicrosoftTeamsAppIdentifier(suffix, "gcch");
360337
case "28:dod:":
361-
return buildMicrosoftBotIdentifier(suffix, "dod", true);
338+
return buildMicrosoftTeamsAppIdentifier(suffix, "dod");
362339
}
363340
return { kind: "unknown", id: rawId };
364341
};

0 commit comments

Comments
 (0)