2

I am currently implementing a Teams bot that has to get the user name (first name and last name) and the user's email address of the person communicating with the bot via a personal chat.

I am using SDK v4 of the bot framework and tried to implement the approach mentioned here (https://github.com/OfficeDev/BotBuilder-MicrosoftTeams-dotnet). The only parameter returned when fetching the teams context is the Tenant Id. Both channel and team are null (I presume this is because I am in a private chat?).

Since I now have the tenant id from the Teams context, how do I use it to retrieve the user's info?

To retrieve the Teams context I'm calling the following:

ITeamsContext teamsContext = turnContext.TurnState.Get<ITeamsContext>();

1 Answer 1

4

Once you retrieve the IDs using the ITeamsContext object, you need to use those Ids to fully populate the Teams object. You can do so using the Operations.FetchTeamDetailsAsync method.

To get a roster of members in the conversation, you'll use the GetConversationParametersForCreateOrGetDirectConversation() method. #epicmethodname.

using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema.Teams;
using Microsoft.Bot.Connector.Teams;
...
ConversationList channels = await teamsContext.Operations.FetchChannelListAsync(incomingTeamId);

TeamDetails teamInfo = await teamsContext.Operations.FetchTeamDetailsAsync(incomingTeamId);

var roster = teamsContext.GetConversationParametersForCreateOrGetDirectConversation(turnContext.Activity.From).Members;

List<TeamsChannelAccount> rosterTC = roster.ToList().ConvertAll(member =>
  {
    return teamsContext.AsTeamsChannelAccount(member);
  });

await turnContext.SendActivityAsync($"You have {roster.Count} number of people in this group. You are {from.Name}");

You can find some getting started help, and additional resources here: https://developer.microsoft.com/en-us/office/blogs/preview-release-of-net-teams-bot-builder-v4-sdk/

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Andrew. Thanks for getting back to me. I will give this a shot and let you know if it works.
Hey Andrew, thank you for the response. Do you know why my teamsContext.Team.Id == teamsContext.Channel.Id and after getting the result from FetchChannelListAsync() it has ChannelInfo.Name == null?
Oh, I have found the reason. Main general Channel has name == null and and Id == TeamsId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.