Introducing the Microsoft Teams Bot Builder SDK Extension
Published Jun 15 2017 04:15 PM 10.3K Views
Microsoft

howdoi.png
...mention a user in a team?

...get the list of members in a team?

...create a new direct message to a team member?


Have you found yourself scratching your head trying to figure these questions out? Frustrated trying to access some of the goodies unique to the Microsoft Teams platform?  Well, fear not, Bot Builder SDK Extension for Teams in .NET and Node flavors is here! 

Just head on over to Nuget or NPM to download our tasty helpers, sure to speed up your prep time so you can spend more time maximizing the flavor of the bots you're cooking up.

Here’s a small sample of some recipes to whet your appetite.

How to mention a user?


Just need a dash of AddMentionToText in your C# code:

// Create reply activity 
Activity replyActivity = activity.CreateReply(); 

// Construct text of the form @sender Hello 
replyActivity.Text = "Hello ";
replyActivity.AddMentionToText(activity.From, MentionTextLocation.AppendText); 

// Send the reply activity 
await client.Conversations.ReplyToActivityAsync(replyActivity);

If Node.js is more your style, use:

// User to mention 
var toMention: builder.IIdentity = { 
  name: 'John Doe',
  id: userId 
}; 

// Create a new message and add mention to it 
var msg = new teams.TeamsMessage(session).text(teams.TeamsMessage.getTenantId(session.message)); 
var mentionedMsg = (msg).addMentionToText(toMention); 

// Post the message 
var generalMessage = mentionedMsg.routeReplyToGeneralChannel(); session.send(generalMessage);


How to get the list of members in a team?


Just add a sprinkle of GetTeamsConversationMembersAsync:

// Fetch the members in the current conversation 
var connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
var members = await connector.Conversations.GetTeamsConversationMembersAsync(activity.Conversation.Id, activity.GetTenantId()); 

// Concatenate information about all the members into a string 
var sb = new StringBuilder(); 
foreach (var member in members) 
{
  sb.AppendFormat( "GivenName = {0}, Surname = {1}, Email = {2}, UserPrincipalName = {3}, AADObjectId = {4}, TeamsMemberId = {5}", 
  member.GivenName, member.Surname, member.Email, member.UserPrincipalName, member.ObjectId, member.Id); sb.AppendLine(); 
} 

// Post the member info back into the conversation 
await context.PostAsync($"People in this conversation: {sb.ToString()}");

If your code is in Node, use:

var conversationId = session.message.address.conversation.id; 
connector.fetchMemberList( 
  (session.message.address).serviceUrl, 
  conversationId, 
  teams.TeamsMessage.getTenantId(session.message), 
  (err, result) => { 
    if (err) { 
      session.endDialog('There is some error'); 
    } else { 
      session.endDialog('%s', JSON.stringify(result)); 
    } 
  }
);

 

There are a lot more helpers available to help you easily…

 

So go get our new SDK and get cooking!

But wait, there's more...


Visual Studio project template – Teams Bot Application


If you are building a brand-new bot, take note of the new Visual Studio project template for building a Teams Bot Application. It starts your bot off with a reference to the right nuget and adds some helpers to get you started with compose extensions as well.

 

  • Just grab the project template from https://aka.ms/bf-teams-template
  • Save the .zip file to your Visual Studio 2017 or Visual Studio 2015 project templates directory, typically located at %USERPROFILE%\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\.
  • Now just open Visual Studio, create a new C# project, and choose Teams Bot Application template.

newteamsbotapplication.png
That’s it for now. Please adjust the spices in these recipes according to your taste!

Questions or comments? Email microsoftteamsdev@microsoft.com

Links:


--Chef Sid

MicrosoftTeams-image (2).png
P.S.:
The stickers in this post were created inside Teams. To find out how to create some of your own, just ask T-Bot - "how do I send a sticker".

Version history
Last update:
‎Jan 26 2021 09:36 AM
Updated by: