Skip to content

Commit 38627fc

Browse files
authored
port: [#4274] Add settings.selectedChannel to TeamsChannelData and Type to ChannelInfo and TeamDetails (#6360) (#4295)
* Add teamsGetSelectedChannelId function * Add unit tests for teamsGetSelectedChannelId function * Update botframework-schema compat * Update botbuilder compat * Fix TeamsChannelData doc and reorder imports
1 parent 2bb7475 commit 38627fc

File tree

7 files changed

+120
-6
lines changed

7 files changed

+120
-6
lines changed

libraries/botbuilder/etc/botbuilder.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ export class TeamsActivityHandler extends ActivityHandler {
412412
// @public
413413
export function teamsGetChannelId(activity: Activity): string | null;
414414

415+
// @public
416+
export function teamsGetSelectedChannelId(activity: Activity): string;
417+
415418
// @public
416419
export function teamsGetTeamId(activity: Activity): string | null;
417420

libraries/botbuilder/src/teamsActivityHelpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ function validateActivity(activity: Partial<Activity>): void {
1818
}
1919
}
2020

21+
/**
22+
* Gets the Team's selected channel id from the current activity.
23+
*
24+
* @param activity The current [Activity](xref:botframework-schema.Activity).
25+
* @returns The current activity's team's selected channel, or empty string.
26+
*/
27+
export function teamsGetSelectedChannelId(activity: Activity): string {
28+
validateActivity(activity);
29+
30+
return activity.channelData?.settings?.selectedChannel?.id ?? '';
31+
}
32+
2133
/**
2234
* Gets the TeamsMeetingInfo object from the current [Activity](xref:botframework-schema.Activity).
2335
*

libraries/botbuilder/tests/teamsHelpers.test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
*/
55

66
const assert = require('assert');
7-
const { teamsGetChannelId, teamsGetTeamId, teamsNotifyUser, teamsGetTeamInfo } = require('../');
7+
const {
8+
teamsGetChannelId,
9+
teamsGetSelectedChannelId,
10+
teamsGetTeamId,
11+
teamsGetTeamInfo,
12+
teamsNotifyUser,
13+
} = require('../');
814

915
function createActivityTeamId() {
1016
return {
@@ -175,4 +181,18 @@ describe('TeamsActivityHelpers method', function () {
175181
assert.throws(() => teamsGetTeamInfo(undefined), Error('Missing activity parameter'));
176182
});
177183
});
184+
185+
describe('teamsGetSelectedChannelId()', function () {
186+
it('should return channel id', async function () {
187+
const activity = { channelData: { settings: { selectedChannel: { id: 'channel123' } } } };
188+
const channelId = teamsGetSelectedChannelId(activity);
189+
assert.strictEqual(channelId, 'channel123');
190+
});
191+
192+
it('should return channel id with null settings', async function () {
193+
const activity = { channelData: { settings: null } };
194+
const channelId = teamsGetSelectedChannelId(activity);
195+
assert.strictEqual(channelId, '');
196+
});
197+
});
178198
});

libraries/botbuilder/tests/teamsInfo.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ describe('TeamsInfo', function () {
427427
428428
name: 'TeamName',
429429
aadGroupId: 'Team-aadGroupId',
430+
type: 'standard',
430431
};
431432

432433
const { expectedAuthHeader, expectation: fetchOauthToken } = nockOauth();
@@ -447,6 +448,7 @@ describe('TeamsInfo', function () {
447448
assert(fetchedTeamDetails.id === '19:[email protected]');
448449
assert(fetchedTeamDetails.name === 'TeamName');
449450
assert(fetchedTeamDetails.aadGroupId === 'Team-aadGroupId');
451+
assert(fetchedTeamDetails.type === 'standard');
450452
});
451453

452454
it('should work with a teamId passed in', async function () {

libraries/botframework-connector/src/teams/models/mappers.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export const ChannelInfo: msRest.CompositeMapper = {
2323
name: 'String',
2424
},
2525
},
26+
type: {
27+
serializedName: 'type',
28+
type: {
29+
name: 'String',
30+
},
31+
},
2632
},
2733
},
2834
};
@@ -73,6 +79,12 @@ export const TeamDetails: msRest.CompositeMapper = {
7379
name: 'String',
7480
},
7581
},
82+
type: {
83+
serializedName: 'type',
84+
type: {
85+
name: 'String',
86+
},
87+
},
7688
},
7789
},
7890
};
@@ -189,6 +201,30 @@ export const TeamsChannelData: msRest.CompositeMapper = {
189201
className: 'TenantInfo',
190202
},
191203
},
204+
settings: {
205+
serializedName: 'settings',
206+
type: {
207+
name: 'Composite',
208+
className: 'TeamsChannelDataSettings',
209+
},
210+
},
211+
},
212+
},
213+
};
214+
215+
export const TeamsChannelDataSettings: msRest.CompositeMapper = {
216+
serializedName: 'TeamsChannelDataSettings',
217+
type: {
218+
name: 'Composite',
219+
className: 'TeamsChannelDataSettings',
220+
modelProperties: {
221+
selectedChannel: {
222+
serializedName: 'selectedChannel',
223+
type: {
224+
name: 'Composite',
225+
className: 'ChannelInfo',
226+
},
227+
},
192228
},
193229
},
194230
};

libraries/botframework-schema/etc/botframework-schema.api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ export interface ChannelAccount {
417417
export interface ChannelInfo {
418418
id?: string;
419419
name?: string;
420+
type?: string;
420421
}
421422

422423
// @public
@@ -1667,6 +1668,7 @@ export interface TeamDetails {
16671668
id?: string;
16681669
memberCount?: number;
16691670
name?: string;
1671+
type?: string;
16701672
}
16711673

16721674
// @public
@@ -1698,10 +1700,17 @@ export interface TeamsChannelData {
16981700
eventType?: string;
16991701
meeting?: TeamsMeetingInfo;
17001702
notification?: NotificationInfo;
1703+
settings?: TeamsChannelDataSettings;
17011704
team?: TeamInfo;
17021705
tenant?: TenantInfo;
17031706
}
17041707

1708+
// @public
1709+
export interface TeamsChannelDataSettings {
1710+
[properties: string]: unknown;
1711+
selectedChannel?: ChannelInfo;
1712+
}
1713+
17051714
// @public
17061715
export interface TeamsMeetingInfo {
17071716
id?: string;

libraries/botframework-schema/src/teams/index.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export interface ChannelInfo {
2424
* @member {string} [name] Name of the channel
2525
*/
2626
name?: string;
27+
/**
28+
* @member {string} [type] The type of the channel. Valid values are standard, shared and private.
29+
*/
30+
type?: string;
2731
}
2832

2933
/**
@@ -68,6 +72,10 @@ export interface TeamDetails {
6872
* the team.
6973
*/
7074
memberCount?: number;
75+
/**
76+
* @member {string} [type] The type of the team. Valid values are standard, sharedChannel and privateChannel.
77+
*/
78+
type?: string;
7179
}
7280

7381
/**
@@ -149,7 +157,7 @@ export interface TeamsMeetingInfo {
149157
export interface TeamsChannelData {
150158
/**
151159
* @member {ChannelInfo} [channel] Information about the channel in which the
152-
* message was sent
160+
* message was sent.
153161
*/
154162
channel?: ChannelInfo;
155163
/**
@@ -158,24 +166,29 @@ export interface TeamsChannelData {
158166
eventType?: string;
159167
/**
160168
* @member {TeamInfo} [team] Information about the team in which the message
161-
* was sent
169+
* was sent.
162170
*/
163171
team?: TeamInfo;
164172
/**
165173
* @member {NotificationInfo} [notification] Notification settings for the
166-
* message
174+
* message.
167175
*/
168176
notification?: NotificationInfo;
169177
/**
170178
* @member {TenantInfo} [tenant] Information about the tenant in which the
171-
* message was sent
179+
* message was sent.
172180
*/
173181
tenant?: TenantInfo;
174182
/**
175183
* @member {TeamsMeetingInfo} [meeting] Information about the tenant in which the
176-
* message was sent
184+
* message was sent.
177185
*/
178186
meeting?: TeamsMeetingInfo;
187+
/**
188+
* @member {TeamsChannelDataSettings} [settings] Information about the settings in which the
189+
* message was sent.
190+
*/
191+
settings?: TeamsChannelDataSettings;
179192
}
180193

181194
/**
@@ -212,6 +225,25 @@ export interface TeamsChannelAccount extends ChannelAccount {
212225
userRole?: string;
213226
}
214227

228+
/**
229+
* @interface
230+
* Settings within teams channel data specific to messages received in Microsoft Teams.
231+
*/
232+
export interface TeamsChannelDataSettings {
233+
/**
234+
* @member {ChannelInfo} [selectedChannel] Information about the selected Teams channel.
235+
*/
236+
selectedChannel?: ChannelInfo;
237+
/**
238+
* @member {any} [any] Additional properties that are not otherwise defined by the TeamsChannelDataSettings
239+
* type but that might appear in the REST JSON object.
240+
* @remarks With this, properties not represented in the defined type are not dropped when
241+
* the JSON object is deserialized, but are instead stored in this property. Such properties
242+
* will be written to a JSON object when the instance is serialized.
243+
*/
244+
[properties: string]: unknown;
245+
}
246+
215247
/**
216248
* @interface
217249
* An interface representing a Meeting.

0 commit comments

Comments
 (0)