Skip to content

Develop Teams Bot with Visual Studio

Created with Dall-E

Microsoft has provided tools to develop Teams Bot for a long time. I think the first tools were released around 2016(?). The first toolset included quite a bit of manual labor to get things done and working, but as of 2024 things have changed quite a bit. Now you can build, test, deploy and publish bots directly from Visual Studio (or code if you run into authentication troubles like I did with Visual Studio). Let’s see what tools you need to use to develop a Teams bot and how easily it can be done now.

Prerequisites

First we need to install development tools for Microsoft Teams. This can be done by running the Visual Studio Installer tool.

Modify your current installation and ensure that you have Microsoft teams development tools installed form the individual components tab.

Now we can create new Bot projects, which is a template with all the required files to run bots. Teams development tools also installs a new “Teams Toolkit” context menu into solution explorer. Through this menu we can do many useful things that are required to run bots successfully.

First click Prepare Teams App Dependencies to ensure that everything is setup correctly. This does following things:

  • Create a new or reuse an existing bot Microsoft Entra app.
  • Create or update deployment JSON file.
  • Creates or updates the bot registration on dev.botframework.com
  • Validate a Teams app manifest.
  • Build a Teams app package (zip).
  • Validate a Teams app package.
  • Update a Teams app.
  • Create or update JSON file (endpoints etc).

After that we can start debugging and running locally our Teams bot.

Running Bot Locally and Debugging

In 2022 Microsoft introduced Visual Studio Dev Tunnels. Dev Tunnels allows developers to create a public (or private) tunnels into their own local machine. In a nutshell that means that you will get unique public URL, that routes all the HTTP traffic into your Visual Studio. You can think about it as a reverse Postman. You don’t call things, but you get called. Teams app development is a perfect place to use this feature. We can use Dev Tunnels to create a public address, which can be then used by the Teams client. This way we can run bot in our local environment (without simulators) and attach web page Teams into it.

First create a new public dev tunnel. Search for dev tunnels in Visual Studio general search if you don’t have the window ready and create a new tunnel. Tunnel name can be anything, it is just used for you to recognize what tunnel to use. You need to have at least one active tunnel to run bot locally.

After the tunnel is created you can start the Bot simply by running the app (F5). If you encounter any problems, first check that Teams Toolkit output window. You can also try to use Teams App Test Tool (browser) build configuration by clicking the small arrow next to run button and select that configuration.

Now that bot is up and running you can put breakpoints into code, test it through the browser app and have a nice development experience. When things are ready to be deployed you can use the Teams Toolkit “Provision in the Cloud…” to set things ready (create Azure resources automatically etc.) and then click “Deploy the Cloud” to deploy the application into those newly created Azure resources. By default the Azure resources are created as B1 plan on App Service and F1 on bot framework, so the cost is around ~50€/month.

Finally when things look good click the “Open Teams Developer Portal to Publish” from the Teams Toolkit menu. This will publish the bot app for your organization (through developer portal). After you have done the publishing you will also need a Teams admin to accept the app before it can be downloaded and used. Accepting the app is done through https://admin.teams.microsoft.com/dashboard portal. After approval it takes usually ~two hours before the app can be installed through a Teams.

Leave a Reply

Your email address will not be published. Required fields are marked *