Create Teams conversation bot
Microsoft Teams conversation bot allows users to interact with your web service through text, interactive cards, and task modules. Basic conversations are handled through the Bot Framework connector, a single REST API. This API enables your bot to communicate with Teams and other channels.
Key features of Bot Builder SDK
- Provides access to the Bot Framework connector.
- Manages conversation flow and state.
- Incorporates cognitive services, such as Natural Language Processing (NLP).
When your bot is added to a group or a team, an introduction message is sent. The message provides a brief description of the bot's features and how to use them.
This step-by-step guide helps you to create a conversation bot in the Teams application. You can see the following output:
Prerequisites
Ensure that you install the following tools and set up your development environment:
| Install | For using... | |
|---|---|---|
| Required | ||
| Microsoft 365 developer account | Access to Teams account with the appropriate permissions to install an app. | |
| ngrok | Teams app features (conversational bots, message extensions, and incoming webhooks) require inbound connections. A tunnel connects your development system to Teams. It isn't required for apps that only include tabs. This package is installed within the project directory (using npm devDependencies). |
|
| Visual Studio 2022 version 17.3 Install the ASP.NET and web development workload. |
You can install the enterprise version in Visual Studio 2022, and install the workloads. | |
| .NET Core SDK version 3.1 | Customized bindings for local debugging and Azure Functions app deployments. If you haven't installed the .NET 3.1 (or later) SDK globally, the portable version can be installed. | |
| Microsoft Teams and a Teams account | Microsoft Teams to collaborate with everyone you work with through apps for chat, meetings, call and all in one place. |
Create and register your bot
Register your bot with Azure Bot service when you develop and host it in Azure. Perform the following steps:
- Create a ngrok tunnel to your web server's endpoints.
- Create bot channel registration in Azure account.
- Create client secret that enables single sign-on (SSO) authentication of the bot.
- Add API permissions for downstream calls.
- Add messaging endpoint to the ngrok tunnel you created.
- Add Teams channel to deploy the bot to a Teams channel.
To create a ngrok tunnel
Use ngrok to create a tunnel to your locally running web server's publicly available HTTPS endpoints. Run the following command in ngrok:
ngrok http --host-header=rewrite 3978
To create bot channel registration in Azure account
Access the Azure portal.
Select Create a resource.
Search for Azure Bot in the search box.
Select Azure Bot.
Select Create.
In the Create an Azure Bot window that appears, enter the required bit handle name in Bot handle.
Select your Subscription and Resource group from the dropdown list.
You can optionally create a new resource group. Select Create new > enter resource name > select OK. Select the required location from the New resource group location dropdown list.
In the Microsoft App ID section, Select Type of App as Multi Tenant.
In the Creation Type, by default Create new Microsoft App ID is selected. You can optionally select Use existing app registration and enter App ID, App tenant ID, and MSI resource ID.
Note
You can't create more than one bot with the same Microsoft App ID.
Select Review + create.
If the validation passes, select Create.
It takes a few moments for your bot service to be provisioned.
Select Go to resource.
Your Azure Bot is created and you can see the Resource group and Subscription ID in the Azure Bot.
To create client secret
Perform the following steps if you've created a new Microsoft App ID:
In the left pane, select Configuration.
Tip
Save the Microsoft App ID or Client ID for future reference.
Next to Microsoft App ID, select Manage.
In the Client secrets section, select + New client secret.
In the Add a client secret window that appears, enter Description of the client secret and select Add.
Select Copy to clipboard to copy the Value details.
Tip
Save the Client secrets Value or app password for future reference.
To add API permissions for downstream calls
In the left pane, select API permissions.
Select Add a permission. Request API permissions window appears.
Select Microsoft APIs > Microsoft Graph.
Select Application permissions.
Select the required user permissions, for example,
User.Read.All.Select Add permissions.
To add messaging endpoint
From ngrok, copy the HTTPS URL.

Note
The HTTPS URL in your ngrok is a domain name that doesn't include
https://.In Settings, select Configuration.
In Messaging endpoint, add the HTTPS URL from ngrok and at the end of the URL add /api/messages.
Select Apply.
To add the Microsoft Teams channel
Go to Home.
Select your bot from Recent Resources.
Select Channels in the left pane.
Select Microsoft Teams.
Select the checkbox to accept the Terms of Service.
Select Agree.
Select Apply.
You have successfully set up a bot in Azure Bot service and you need to set up bot service connection.
Set up bot service connection
Configure the bot to understand how to authenticate conversation bot in Teams, create the Teams app package, and upload it to the organization.
- Update appsettings.json in Visual Studio.
- Update manifest.json in Visual Studio and compress it to the zip file in the File Explorer.
- Run your solution in Visual Studio.
- Upload the bot to Teams.
To update appsettings
Open Microsoft-Teams-Samples.
Select Code.
Select Open with GitHub Desktop from the dropdown menu.
Note
Ensure that you note the path of the repository that you cloned.
Select Clone.
In the File Explorer, go to Microsoft-Teams-Samples > samples > bot-conversation > csharp.
Open the appsettings.json file in Visual Studio and update the configuration for the bot.
Replace
"MicrosoftAppType"to Multitenant.Replace
"MicrosoftAppId"to your bot's Microsoft App ID.Replace
"MicrosoftAppPassword"to your bot's client secret ID Value.Replace your
"MicrosoftAppTenantId"to your tenant ID. You can obtain the tenant ID from the link of the account used to sign in to the Teams. Perform the following steps to get the link for tenantId:Select Teams.
Select ●●●.
Select Get link to team.
Select Copy.
Copy the tenant ID from the URL.
Select Save.
To update manifest
In the File Explorer, go to Microsoft-Teams-Samples > samples > bot-conversation > csharp > TeamsAppManifest.
Open the manifest.json file in Visual Studio and make the following changes:
- Replace
"id"and"botId"to your bot's Microsoft App ID. - Replace
"validDomains"to your ngrok domain excludinghttps://.
- Replace
Zip the contents of the TeamsAppManifest folder to create manifest.zip.
Note
The
manifest.zipmust not contain any other folders in it. It must havemanifest jsonsource file,coloricon, andoutlineicon inside the zip folder. Run your solution in Visual Studio and upload your manifest in your demo tenant for organization or your Teams account.
To run solution in Visual Studio
Open the latest version of Visual Studio.
Select File > Open > Project/Solution.

Go to Microsoft-Teams-Samples > samples > bot-conversation > csharp.
Select
TeamsConversationBot.csprojfile.
Select F5 to run the project.
Select Yes if the following dialog appears:
A webpage appears with a message Your bot is ready!
To upload the app to Teams
Go to Microsoft Teams.
Select Apps > Manage your apps.
Select Upload an app and select Upload a custom app.
Select Open to upload the .zip file that you created in the TeamAppManifest folder.
Select Add.
You can interact with the bot.
Interact with the conversation bot
You can interact with the bot in Teams by sending it a message, or selecting a command from the command list. The bot responds to the strings.
In the left pane of the Teams, select ●●●, and then select your app from the list. The bot shows Suggestions as follows:
- MentionMe
- Show Welcome
- MessageAllMembers
You can select an option from the command list by typing @TeamsConversationBot or What can I do? text in the compose area and send it.
Congratulations!
You've completed the tutorial to get started with conversation bot for Microsoft Teams.
Have an issue with this section? If so, please give us some feedback so we can improve this section.
Feedback
Submit and view feedback for