diff --git a/libraries/botbuilder/src/teamsActivityHelpers.ts b/libraries/botbuilder/src/teamsActivityHelpers.ts index 1d94aadc03..18870eef20 100644 --- a/libraries/botbuilder/src/teamsActivityHelpers.ts +++ b/libraries/botbuilder/src/teamsActivityHelpers.ts @@ -49,3 +49,13 @@ export function teamsNotifyUser(activity: Activity): void { const channelData: TeamsChannelData = activity.channelData as TeamsChannelData; channelData.notification = { alert: true } as NotificationInfo; } + +export function teamsGetTeamInfo(activity: Activity): TeamInfo { + if (!activity) { + throw new Error('Missing activity parameter'); + } + + const channelData: TeamsChannelData = activity.channelData as TeamsChannelData; + const team: TeamInfo = channelData ? channelData.team : null; + return team; +} diff --git a/libraries/botbuilder/tests/teamsHelpers.test.js b/libraries/botbuilder/tests/teamsHelpers.test.js index 2842b49091..7204499eec 100644 --- a/libraries/botbuilder/tests/teamsHelpers.test.js +++ b/libraries/botbuilder/tests/teamsHelpers.test.js @@ -11,7 +11,8 @@ const { BotFrameworkAdapter, teamsGetChannelId, teamsGetTeamId, - teamsNotifyUser + teamsNotifyUser, + teamsGetTeamInfo } = require('../'); @@ -125,6 +126,41 @@ describe('TeamsActivityHelpers method', function() { } }); }); + + describe('teamsGetTeamInfo()', () => { + it('should return team id', async function() { + const activity = createActivityTeamId(); + const teamInfo = teamsGetTeamInfo(activity); + assert(teamInfo.id === 'myId'); + }); + + it('should return undefined with no team id', async function() { + const activity = createActivityNoTeamId(); + const teamInfo = teamsGetTeamInfo(activity); + assert(teamInfo.id === undefined); + }); + + it('should return null with no channelData', async function() { + const activity = createActivityNoChannelData(); + const teamInfo = teamsGetTeamInfo(activity); + assert(teamInfo === null); + }); + + it('should return aadGroupId', async function() { + const activity = createActivityTeamId(); + const teamInfo = teamsGetTeamInfo(activity); + assert(teamInfo.aadGroupId === 'myaadGroupId'); + }); + + it('should throw an error if no activity is passed in', () => { + try { + teamsGetTeamInfo(undefined); + } catch (err) { + assert.strictEqual(err.message, 'Missing activity parameter'); + } + }); + }); + }); function createActivityNoTeamId() { @@ -163,7 +199,7 @@ function createActivityTeamId() { text: "testMessage", channelId: 'teams', from: { id: `User1` }, - channelData: { team: { id: 'myId'}}, + channelData: { team: { id: 'myId', aadGroupId: 'myaadGroupId'}}, conversation: { id: 'conversationId' }, recipient: { id: 'Bot1', name: '2' }, serviceUrl: 'http://foo.com/api/messages' diff --git a/libraries/botframework-connector/src/teams/models/mappers.ts b/libraries/botframework-connector/src/teams/models/mappers.ts index ed74c13a48..a185003f83 100644 --- a/libraries/botframework-connector/src/teams/models/mappers.ts +++ b/libraries/botframework-connector/src/teams/models/mappers.ts @@ -96,6 +96,12 @@ export const TeamInfo: msRest.CompositeMapper = { type: { name: 'String' } + }, + aadGroupId: { + serializedName: 'aadGroupId', + type: { + name: 'String' + } } } } diff --git a/libraries/botframework-schema/etc/botframework-schema.api.md b/libraries/botframework-schema/etc/botframework-schema.api.md index fa571153c1..d0fc791dfa 100644 --- a/libraries/botframework-schema/etc/botframework-schema.api.md +++ b/libraries/botframework-schema/etc/botframework-schema.api.md @@ -1292,6 +1292,7 @@ export interface TeamDetails { export interface TeamInfo { id?: string; name?: string; + aadGroupId?: string; } // @public (undocumented)