Microsoft Teams Api C#

  1. Microsoft Teams Api C# Download
  2. Microsoft Teams Api C# Example

Microsoft Teams is the hub for team collaboration in Microsoft 365 that integrates the people, content, and tools your team needs to be more engaged and effective.

This tutorial helps you to create a Microsoft Teams app using C#. To do this, you must:

  • Prepare your environment
  • Get prerequisites
  • Download the sample
  • Build and run the sample
  • Host the sample app
  • Update the credentials for your hosted app
  • Configure the app tab

Apps in Microsoft Teams are web applications that provide one or more capabilities. For the Teams platform to load your app, your app must be available on the internet. To do this, you need to host your app. You can either host it in Microsoft Azure for free or create a tunnel to the local process on your computer using ngrok. Jan 22, 2021 Welcome to Microsoft Teams section of C# Corner. In this section, you will find various Microsoft Teams related source code samples, articles, tutorials, and tips.

Prepare your development environment

The first thing to do is to prepare your development environment. Custom app uploading must be enabled for the Office 365 organization where you want to build your app. If you need a dedicated development tenant, you can sign up for the Office 365 developer program. For more information, see setup your development environment.

Get prerequisites

To complete this tutorial, you need to install the following tools:

Microsoft Teams Api C#

You can install the free community edition of Visual Studio. During installation, if there is an option to add git to the path, select it. In a terminal window, run the following command to verify your git installation:


Use a suitable terminal window on your platform. These examples use Git Bash but can be run on most platforms.

Open the latest version of Visual Studio and install any updates.

You can use the same terminal window to run the commands in this tutorial.

Download the sample

You can get started with a simple Hello, World! sample in C#. In a terminal window, run the following command to clone the sample repository to your computer:


You can fork this repo to modify and save your changes to GitHub.

Build and run the sample

After the repo is cloned, use Visual Studio to open the solution file Microsoft.Teams.Samples.HelloWorld.sln from the Microsoft-Teams-Samples/samples/app-hello-world/csharp directory of the sample. Then, select Build Solution from the Build menu. To run the sample, press F5 or select Start Debugging from the Debug menu.

When the app starts, a browser window opens with the root of the app launched. You can go to the following URLs to verify that all the app URLs are loading:


If you receive an error Could not find a part of the path … binroslyncsc.exe, update the package with the command Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r. For more information, see this question on Stack Overflow.

Host the sample app

Apps in Microsoft Teams are web applications that provide one or more capabilities. For the Teams platform to load your app, your app must be available on the internet. To do this, you need to host your app. You can either host it in Microsoft Azure for free or create a tunnel to the local process on your computer using ngrok. After you host your app, note its root URL, such as or

Tunnel using ngrok

For quick testing, you can run the app on your computer and create a tunnel to it through a web endpoint. ngrok is a free tool with which you can get a web address, such as You can download and install ngrok and add it to a location in your PATH.

After you install ngrok, open a new terminal window and run the following command to create a tunnel:

Ngrok listens to requests from the internet and routes them to your app running on port 44327. To verify, open your browser and go to to load your app's hello page. Instead of this URL, use the forwarding address displayed by ngrok in your console session.


If you have used a different port in the build and run step, ensure you use the same port number to setup the ngrok tunnel.


It is a good idea to run ngrok in a different terminal window. This is done to keep ngrok from running without interfering with the app. You have to stop, rebuild, and rerun the app. The ngrok session provides useful debugging information in this window.

The app is only available during the current session on your computer. If the machine is shut down or goes to sleep, the service is no longer available. Remember this when you share the app for testing to other users. If you have to restart the service, the app returns a new address and you must update every location that uses that address. The paid version of ngrok does not have this limitation.

Host in Azure

Microsoft Azure hosts your .NET application on a free tier using shared infrastructure. This is sufficient to run the Hello World sample. For more information, see creating a new free Azure account.

Visual Studio has built-in support for app deployment to different providers, including Azure.

Use App Studio to update the app package

App Studio is a Teams app that you can install from the Teams store. It simplifies the creation and registration of an app.

Complete the following steps to update the app package:

  1. To install App Studio in Teams, select the Apps icon at the bottom of the left-hand bar, and search for App Studio.
  1. Select the App Studio tile and choose Install. The App Studio is installed.
  1. To create the app package for your Teams app, select the Manifest editor tab in App Studio.

The sample comes with its own manifest and is designed to build an app package when the project is built. On .NET this is done in Visual Studio and on Node.js this is done by typing gulp at the command line in the root directory of the project.

The name of the generated app package is You can search for this file if the location is not clear in the tool you are using.

  1. Now to modify this app package, select Import an existing app in the Manifest editor.
  1. Select the Hello World tile for your newly imported app.

The following image shows the imported app package in App Studio:

On the left-hand side of the Manifest editor there is a list of steps. On the right-hand side there is a list of properties that need to be filled in for each step. As you started with a sample app, much of the information is already completed. The next steps enable you to update the properties of the Hello World app.

App details

Select App details under Details. Select the Generate button to create a new App ID.

Your new App ID is similar to 2322041b-72bf-459d-b107-f4f335bc35bd.

Go through the app details in the right-hand pane including Developer information and Branding details. These details are important if you are writing a new app for distribution.


It is simple to add tabs to a Teams app. The sample app already supports several tabs, and you can enable them.

Team tab

Your app can only have one Team tab.

In this sample, the Team tab is where your configuration page is displayed. Select the ... symbol of the Tab configuration url and choose Edit from the drop-down menu. Change the URL to where must be replaced with the URL that you used when hosting your app.

Personal tabs

Your app can have up to 16 tabs, including the Team tab.

Personal tabs are different from the Team tab. Hello Tab is already listed in the personal tabs list with a placeholder value com.contoso.helloworld.hellotab. Select the ... symbol of the Tab configuration url and choose Edit from the drop-down menu. The following dialog box appears:

Update the following boxes with your app URL:

  • Change the Content URL box to
  • Change the Website URL box to

Replace by the URL that you used when hosting your app.


It is easy to add the bots functionality to your app. The Hello World sample app already has a bot as part of the sample, but you must register it with Microsoft.

The bot that was imported from the sample does not have an associated App ID. You must create a new bot so that App Studio can create a new App ID and register it with Microsoft.


The App ID created by App Studio for the bot is different from the App ID created for the app. Each bot in an app requires its own App ID.

Complete the following steps to setup your bot:

  1. Select Delete next to the imported bot in the bot list. Now there are no bots left to show.
  2. Select Setup to display the Set up a bot dialog box.
  1. Add a bot name Contoso bot and select all three check boxes under Scope.
  2. Choose Save to exit the dialog box. App Studio registers your bot with Microsoft and displays your new bot in the bot list.
  3. Now open a text file in notepad and copy and paste your new bot ID into it.
  4. Click Generate New Password, and note the password in the same text file you noted your bot App ID.
  5. Update the Bot endpoint address to, and replace with the URL that you used when hosting your app.
  6. Now save your text file as you must add the information from the file to your hosted app to allow secure communication with your bot.
Microsoft Graph API - How can I use

Messaging extensions

Messaging extensions let users ask for information from your service and post that information. The information is posted in the form of cards into the channel conversation. Messaging extensions appear at the bottom of the compose box.

Complete the following steps to setup your messaging extension:

  1. Select Messaging extensions under Capabilities in the left-hand pane of App Studio to configure the messaging extension.

The sample messaging extension is listed in the Messaging Extensions pane.

  1. Select Delete to remove the messaging extension, select Set up, and follow the same steps used for bots. The Messaging Extension dialog box is displayed.
  2. Select the Use existing bot tab and Select from one of my existing bots.
  3. Select the bot you created from the drop-down menu. Add a Bot name and select Save to close the dialog box.
  4. Under the Command section, select Add. To add a search-based command, select the Allow users to query your service for information and insert that into a message option.
  5. In the New command dialog box, enter the following values:

Under New command:

  • Command ID: Enter random text
  • Title: Enter random title
  • Description: Enter random description

Under Parameter:

  • Name: Enter the parameter name
  • Title: Enter the card title
  • Description: Enter card description
  1. After you enter the information, select Save to close the dialog box.

Register your app in Teams

After entering the details of your app, complete the following steps to register your app in Teams:

  1. Use Test and distribute of App Studio to install your app in Teams.
  2. Update your hosted application with the App ID and password for your bot. For the sample app, use the same App ID and password for both bot and messaging extension.
  3. Select Test and distribute under Finish in the left-hand pane of App Studio.
  1. To upload your app to Teams, select the Install button under Test and Distribute.

Microsoft Teams Api C# Download

  1. Select the Search box in the Add to a team section and select a team to add the sample app. You can set up a special team for testing.
  2. Select the Install button at the bottom of the dialog box.

Your app is now available in Teams. However, the bot and the messaging extension will not work until you update the hosted applications environment with the App IDs and passwords.

Update the credentials for your hosted app

The sample app requires the environment variables to be set to the values that you saved in the text file.

Open the appsettings.json file. Update the MicrosoftAppId value with your bot ID that you saved in the text file. Update the MicrosoftAppPassword with the bot password you saved.

After these changes are made, rebuild the app. If you are using ngrok, run the app locally, and if you are hosting in Azure, redeploy the app.

Configure the app tab

Once you install the app into a team, you must configure it to show content. Go to a channel in the team where you installed the sample app and select the '+' button to add a new tab. Choose Hello World from the Add a tab list. A configuration dialog box is displayed that enables you to choose the tab to display in this channel. After you select the tab and select Save the Hello World tab is loaded with the tab.

Test your bot in Teams

Now you can test the bot in Teams. Select a channel in the team where you registered your app and type @your-bot-name. This is called an @mention. The bot replies to any message that you send.

Test your messaging extension

To test your messaging extension, you can select ... below the input box in your conversation view. A menu with the 'Hello World' app is displayed. When you select it, a set of random texts is displayed. You can select one of the random text and that is inserted into your conversation.

Microsoft Teams Api C# Example

Select one of the random text. A card formatted and ready to send with your own message is shown.