diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 23795d91af..ce861ff967 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -145,6 +145,17 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide this.credentials.oAuthEndpoint = GovernmentConstants.ToChannelFromBotLoginUrl; this.credentials.oAuthScope = GovernmentConstants.ToChannelFromBotOAuthScope; } + + // Relocate the tenantId field used by MS Teams to a new location (from channelData to conversation) + // This will only occur on actities from teams that include tenant info in channelData but NOT in conversation, + // thus should be future friendly. However, once the the transition is complete. we can remove this. + this.use(async(context, next) => { + if (context.activity.channelId === 'msteams' && context.activity && context.activity.conversation && !context.activity.conversation.tenantId && context.activity.channelData && context.activity.channelData.tenant) { + context.activity.conversation.tenantId = context.activity.channelData.tenant.id; + } + await next(); + }); + } /** diff --git a/libraries/botbuilder/tests/botFrameworkAdapter.test.js b/libraries/botbuilder/tests/botFrameworkAdapter.test.js index 4e3b4c15d2..8e419a024c 100644 --- a/libraries/botbuilder/tests/botFrameworkAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkAdapter.test.js @@ -251,6 +251,18 @@ describe(`BotFrameworkAdapter`, function () { }); }); + it(`should migrate location of tenantId for MS Teams processActivity().`, function (done) { + const incoming = TurnContext.applyConversationReference({ type: 'message', text: 'foo', channelData: { tenant: { id: '1234' } } }, reference, true); + incoming.channelId = 'msteams'; + const req = new MockBodyRequest(incoming); + const res = new MockResponse(); + const adapter = new AdapterUnderTest(); + adapter.processActivity(req, res, (context) => { + assert(context.activity.conversation.tenantId === '1234', `should have copied tenant id from channelData to conversation address`); + done(); + }); + }); + it(`should fail to auth on call to processActivity().`, function (done) { const req = new MockRequest(incomingMessage); const res = new MockResponse();