Develop Bots for MS Teams with Bot Builder SDK v4

4 minute read

Develop Bots for MS Teams with Bot Builder SDK v4


MS Teams supports integration with various apps and services. Bot is one of them. Both v3 and v4 bots built on the Bot Framework work well with MS Teams. All new development should be targeting the Bot Builder v4 SDK. Bots can be developed using .NET or Node.js.

In this article, we will develop a bot framework bot and extend it to MS Teams. Please follow my previous article Getting Started with MS Teams Development to setup your development environment.

Visual Studio Bot Template

The Microsoft Bot Framework v4 Templates for Visual Studio can be downloaded from here ( It is available as a VSIX package. It helps to build new conversational AI bots using the Microsoft Bot Framework v4. Both v3 and v4 bots built on the Bot Framework work well with MS teams.

Once installed, the Bot Framework project creation option will be available for new project creation from Visual Studio.

Develop an Echo Bot

We will create a simple echo Bot in MS Teams. Follow below steps to start developing a Bot.

  1. Open Visual Studio 2017 as an administrator.
  2. Click File > New > Project.
  3. Under Visual C#, select Bot Framework > Echo Bot (Bot Framework v4).

  4. Click OK.
  5. Build the solution. This will download all referenced NuGet packages.
  6. Open Project properties.
  7. Under Debug, note down the App URL.

Run the ngrok

Ngrok is a free program that exposes a process running on your localhost to the public internet. Run the ngrok secure tunnel application by executing below steps.

  1. On the command prompt, navigate to ngrok.exe location.
  2. Execute below command.

ngrok.exe http [port] -host-header=localhost:[port]

Replace [port] with the port mentioned in the App URL of solution.


ngrok.exe http 3978 -host-header=localhost:3978

Register Bot in MS Azure

  1. Open MS Azure portal (
  2. Click Create a resource.
  3. Search for Bot in the marketplace.
  4. Select Bot Channels Registration.

  5. Click Create.
  6. Fill in the form details.
  7. For Messaging endpoint, specify below value.


    Replace token [ngrok-address] with forwarding address from ngrok window. (e.g.

  8. Choose Auto create App ID and password.

  9. Click Create.
  10. Navigate to the resource, when created.
  11. Under Bot Management section, click Channels.

  12. Click MS Teams icon under featured channel.

  13. Click Save.
  14. Agree to the Terms of Service.

Get the Bot Channel Registration Id and secret

  1. Under Bot Management section, click Settings.
  2. Note down Microsoft App ID.

  3. Click Manage link, next to Microsoft App ID.
  4. Under Client secrets, click New client secret.

  5. The dialog window will appear. Add description and expiration.
  6. Click Add.

  7. Copy the secret string.
  8. In the Visual Studio, add MicrosoftAppId and MicrosoftAppPassword under appsettings.json.

Package Bot from Visual Studio

We will add manifest file and related resources that will be compressed as zip file and added to MS Teams.

  1. In Visual Studio, add folder Manifest.
  2. Upload icons for color and outline.
  3. Add file manifest.json with below content.
  "$schema": "",  
  "manifestVersion": "1.3",  
  "version": "1.0.0",  
  "id": "[microsoft-app-id]",  
  "packageName": "io.ngrok.[ngrok-address]",  
  "developer": {  
    "name": "Office Developer",  
    "websiteUrl": "https://[ngrok-address]",  
    "privacyUrl": "https://[ngrok-address]",  
    "termsOfUseUrl": "https://[ngrok-address]"  
  "icons": {  
    "color": "bot-icon-color-192x192.png",  
    "outline": "bot-icon-outline-32x32.png"  
  "name": {  
    "short": "office-content-management-bot ",  
    "full": "Office Content Management Bot"  
  "description": {  
    "short": "Office Content Management",  
    "full": "Sample bot for the Office Content Management"  
  "accentColor": "#AB00B0",  
  "bots": [  
      "botId": "[microsoft-app-id]",  
      "supportsFiles": true,  
      "scopes": [  
  "composeExtensions": [],  
  "permissions": [  
  "validDomains": []  
  • Replace token [microsoft-app-id] with MicrosoftAppId.
  • Replace token [ngrok-address] with forwarding address from ngrok window. (e.g.

Compress Manifest folder

  1. In the Solution explorer, right click on the project and choose to unload.
  2. Again, right click on project and choose to edit.
  3. Since AfterBuild and AfterPublish targets are defined in the import it is expanded to include Sdk.props file before your project's content and Sdk.targets after them, the targets defined in the project will be overwritten by the targets defined by the Sdk / "common targets".
  4. Update the file content as below.

       <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.Web" />    
         <PackageReference Include="Microsoft.AspNetCore.App" />    
         <PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.4.3" />    
         <Content Update="appsettings.json">    
  5. Add below target at the end of file.

     <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />    
     <Target Name="AfterBuild">    
       <ZipDir InputBaseDirectory="manifest"    
               IncludeBaseDirectory="false" />    
  6. Add below task element at the end of file.

     <UsingTask TaskName="ZipDir" TaskFactory="CodeTaskFactory"    
         <InputBaseDirectory ParameterType="System.String" Required="true" />    
         <OutputFileName ParameterType="System.String" Required="true" />    
         <OverwriteExistingFile ParameterType="System.Boolean" Required="false" />    
         <IncludeBaseDirectory ParameterType="System.Boolean" Required="false" />    
         <Reference Include="System.IO.Compression" />    
         <Reference Include="System.IO.Compression.FileSystem" />    
         <Using Namespace="System.IO.Compression" />    
         <Code Type="Fragment" Language="cs">    
         if (File.Exists(OutputFileName))   
           if (!OverwriteExistingFile)   
             return false;   
           InputBaseDirectory, OutputFileName,   
           CompressionLevel.Optimal, IncludeBaseDirectory   
  7. In the solution explorer, right click and reload the project.
  8. Build the solution. The AfterBuild target will run and compressed .zip file will be available under bin folder.
  9. Run the Visual Studio solution by pressing F5 key.

Upload app into Microsoft Teams

  1. Open MS Teams.
  2. Right click on any existing team, click Manage team.

  3. Click Apps tab.
  4. Click Upload a custom app.

  5. Upload the zip file generated inside bin folder of Visual Studio solution.
  6. The bot app will be available to use.

Test the Bot in MS Teams

  1. Open MS Teams.
  2. From left menu, click Chat.
  3. Our Bot (named OfficeContentManagement) should be listed out.
  4. Send the messages to Bot, it should echo back.

In order to run the bot inside Microsoft Teams:

  • The bot must be accessible from the internet.
  • The bot must be registered with the bot connector.
  • The AppId and AppPassword from the bot framework registration page have to be recorded in the project’s web.config.
  • The bot must be added to Microsoft Teams.


MS Teams supports integration with various apps and services including Bot. Both v3 and v4 bots built on the Bot Framework work well with MS Teams. Visual Studio offers ready templates for Microsoft Bot Framework v4. Ngrok exposes a process running on your localhost to the public internet.

This content was originally posted here.

Leave a comment