Create Teams conversation bot
Teams conversation bots allow 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. The Bot Builder SDK provides the following features:
- Easy access to the Bot Framework connector.
- Additional functionality to manage conversation flow and state.
- Simple ways to incorporate cognitive services, such as natural language processing (NLP).
When your bot is first added to a group or 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 basic conversation bot in the Teams application. You'll see the following output:
Prerequisites
To set up your development environment, install the following tools:
- Office 365 tenant
- Ngrok or an equivalent tunneling solution
- Latest version of Visual Studio
- .NET Core SDK version 3.1
- Microsoft Teams and a Teams account
Set up conversation bot
Register bot with Azure bot service when you develop and host it in Azure. Perform the following steps:
- Use ngrok to create a tunnel to your web server's endpoints.
- Create bot channel registration in Azure account.
- Create client secret that enables SSO authentication of the bot.
- Add API permissions for downstream calls.
- Add messaging endpoint to the ngrok tunnel you created.
- Add Microsoft Teams channel to deploy the bot to a Teams channel.
Create 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
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.
Enter bot handle name in Bot handle field.
Select your Subscription from the dropdown list.
Select your Resource group from the dropdown list.
To create a new resource group, select Create new, enter resource name, select OK, and select required location from New resource group location dropdown list.
Select Type of App as Multi Tenant for Microsoft App ID.
Note
In Creation type of Microsoft App ID section, Create new Microsoft App ID is already selected to create a new bot. You can also select Use existing app registration, if you've already registered a bot. Enter Microsoft App ID in Existing app id field, and enter value in Existing app password field.
Select Review + create.
Select Create, if the validation passes. It takes a few moments for your bot service to be provisioned.
Select Go to resource. The bot and the related resources are listed in the resource group.
Now your Azure bot has been created.
To create client secret
In Settings, select Configuration. Save the Microsoft App ID (client ID) for future reference.
Select Manage adjacent to Microsoft App ID.
In the Client secrets section, select New client secret. The Add a client secret window appears.
Enter Description and select Add.
Select Copy to clipboard in the Value column and save the client secret ID for future reference.
To add API permissions for downstream calls
In Manage pane of your bot, select API permissions.
Select Add a permission. Request API permissions window appears.
Select Microsoft APIs and select Microsoft Graph.
Select Application permissions, and then select permissions.
Add any user permissions that your app requires to downstream APIs, for example,
User.Read.Select Add permissions.
To add messaging endpoint
Go to Home page of your bot and select Configuration under Settings from the left pane.
Go to ngrok.
Copy the HTTPS URL (https to io) as shown in the following image:
In Messaging endpoint, add the HTTPS URL available from ngrok and at the end of the URL add /api/messages.
Select Apply.
To add the Microsoft Teams channel
Go to Home.
From the Recent resources section, open your bot.
Select Channels in the left pane and select Microsoft Teams
from the list of available channels.
Select the checkbox to accept the terms of service and select Agree.
Select Save.
You have successfully set up a bot in Azure Bot Service and now you need to set up bot service connection.
Set up bot service connection
Configure the bot sample to understand how to authenticate conversation bot in Microsoft Teams and 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.
Update appsettings for conversation bot
Go to the repo https://github.com/Microsoft/botbuilder-samples.git.
Select Code and select the dropdown.
Select Download ZIP.
Ensure to note the path of the repository that you downloaded.
In the File Explorer, go to botbuilder-samples > samples > csharp_dotnetcore > 57.teams-conversation-bot.
Open the appsettings.json file in Visual Studio and update configuration for the bot.
Add your bot name for
MicrosoftAppType.You can obtain the
MicrosoftAppIdfrom the bot's configuration page. TheMicrosoftAppPasswordis the Value for client secret ID that you saved previously.You can obtain the
MicrosoftAppTenantIdorUserIdfrom the link of the account used to login to the Teams. Follow the path in the image to get the link fortenant id:
Copy the tenant id from the URL.
Select Save.
To update manifest
In the File Explorer, go to botbuilder-samples > samples > csharp_dotnetcore > 57.teams-conversation-bot > TeamsAppManifest.
Open the manifest.json file in Visual Studio.
In the manifest.json file, find {id}, {botId} and add your Microsoft App ID.
Add your ngrok url in validDomains excluding
https://and save.
Zip the contents of the TeamsAppManifest folder to create manifest.zip.
Note
The
manifest.zipshouldn't contain any additional folders in it. It should 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 Visual Studio.
Select File and select Open.
Select Project/Solution to open the
.csprojfile from the File Explorer.Go to botbuilder-samples > samples > csharp_dotnetcore > 57.teams-conversation-bot.
Select
TeamsConversationBot.csprojfile and select your bot from the Startup Projects list.
Select F5 to debug. You'll receive a confirmation screen when your bot is ready.
To upload the app to Teams
Go to Teams.
To upload manifest.zip, select Store > Manage your apps > Upload a custom app and open manifest.zip from the repo in File Explorer.
Select Add to install conversation bot in Teams.
You can interact with this bot now.
Interaction 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 following strings:
In the left pane of the Teams, select the ellipses ●●●, and then select your app from the list. The bot shows Suggestions as follows:
You can select an option from the command list by typing @TeamsConversationBot into the compose message area and What can I do? text above the compose area.
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