Skip to main content

The API Client

BotBuilder exposes a static class TeamsInfo that allows you to query the api. In Teams SDK we pass an instance of our ApiClient into all our activity handlers through the context.

tip

The Teams SDK ApiClient uses a fluent API pattern that makes it easier to discover available methods through IDE autocompletion.

-  using Microsoft.Bot.Builder;
- using Microsoft.Bot.Builder.Teams;
+ using Microsoft.Teams.Apps;

- public class MyActivityHandler : ActivityHandler
- {
- protected override async Task OnMessageActivityAsync(
- ITurnContext<IMessageActivity> turnContext,
- CancellationToken cancellationToken)
- {
- var members = await TeamsInfo.GetMembersAsync(turnContext, cancellationToken);
- }
- }
+ var teams = app.UseTeams();
+ teams.OnMessage(async (context) =>
+ {
+ var members = await context.Api.Conversations.Members.GetAsync(context.Activity.Conversation.Id);
+ });

Mapping TeamsInfo APIs to Teams SDK ApiClient Methods​

The following table shows common BotBuilder TeamsInfo methods and their equivalent Teams SDK ApiClient methods:

BotBuilder (TeamsInfo)Teams SDK (ApiClient)
TeamsInfo.GetMemberAsync(context, userId)Api.Conversations.Members.GetByIdAsync(conversationId, userId)
TeamsInfo.GetTeamDetailsAsync(context, teamId)Api.Teams.GetByIdAsync(teamId)
TeamsInfo.GetMeetingInfoAsync(context, meetingId)Api.Meetings.GetByIdAsync(meetingId)
TeamsInfo.SendMessageToTeamsChannelAsync(context, teamId, message)Api.Conversations.CreateAsync(CreateRequest) then Api.Conversations.Activities.CreateAsync(conversationId, activity)