...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…
- Fetch a list of channels in a team
- Fetch tenant-id from an incoming message to bot
- Create 1:1 chat with a specific user (CreateOrGetDirectConversation)
- Consume various events like channel-created, team-renamed, etc.
- Accept messages only from specific tenants (TenantFilter attribute)
- Write Compose Extensions
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.
That’s it for now. Please adjust the spices in these recipes according to your taste!
Questions or comments? Email microsoftteamsdev@microsoft.com
Links:
- .NET Bot Builder Extension for Teams
- Node Bot Builder Extension for Teams
- Developer preview announcement on msdn.com
- Developer platform overview
- List of all preview features
- Submitting your app to the Office Store
--Chef Sid
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".
Updated Jan 26, 2021
Version 7.0Sid Uppal
Microsoft
Joined June 14, 2017
Microsoft Teams Blog
Welcome to the Microsoft Teams Blog! Learn best practices, news, and trends directly from the team behind Microsoft Teams.