/BotBuilder-MicrosoftTeams-node

BotBuilder v4 SDK extension for Microsoft Teams

Primary LanguageTypeScriptMIT LicenseMIT

This functionality is now in the core Bot Framework SDK

This functionality has been moved into the core Bot Framework SDK. You should update your Bot Framework SDK to version 4.6 rather than using this SDK.

This SDK will be deprecated, and will not receive further updates.

Bot Builder SDK4 - Microsoft Teams Extensions

Build status

The Microsoft Bot Builder SDK Teams Extensions allow bots built using Bot Builder SDK to consume Teams functionality easily. Review the documentation to get started!

Samples

Get started quickly with our samples:

This SDK allows you to easily...

  • Fetch a list of channels in a team
  • Fetch profile info about all members of a team
  • Fetch tenant-id from an incoming message to bot
  • Create 1:1 chat with a specific user
  • Mention a specific user
  • Consume various events like channel-created, team-renamed, etc.
  • Accept messages only from specific tenants
  • Write Compose Extensions
  • and more!

Getting started

npm install botbuilder-teams@4.0.0-beta1
  • To extend your bot to support Microsoft Teams, add middleware to adapter:
// use Teams middleware
adapter.use(new teams.TeamsMiddleware());  
  • Now in the onTurn method of your bot, to do any Teams specific stuff, first grab the TeamsContext as shown below:
import { TeamsContext } from 'botbuilder-teams';

export class Bot {
  async onTurn(turnContext: TurnContext) {
    const teamsCtx: TeamsContext = TeamsContext.from(ctx);
  }
}
  • And once you have teamsContext, you may utilize code autocomplete provided by Visual Studio Code to discover all the operations you can do. For instance, here's how you can fetch the list of channels in the team and fetch information about the team:
// Now fetch the Team ID, Channel ID, and Tenant ID off of the incoming activity
const incomingTeamId = teamsCtx.team.id;
const incomingChannelid = teamsCtx.channel.id;
const incomingTenantId = teamsCtx.tenant.id;

// Make an operation call to fetch the list of channels in the team, and print count of channels.
var channels = await teamsCtx.teamsConnectorClient.teams.fetchChannelList(incomingTeamId);
await turnContext.sendActivity(`You have ${channels.conversations.length} channels in this team`);

// Make an operation call to fetch details of the team where the activity was posted, and print it.
var teamInfo = await teamsCtx.teamsConnectorClient.teams.fetchTeamDetails(incomingTeamId);
await turnContext.sendActivity(`Name of this team is ${teamInfo.name} and group-id is ${teamInfo.aadGroupId}`);

Questions, bugs, feature requests, and contributions

Please review the information here.

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.