Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this article, learn more about building Teams app capabilities. Here's a list of the step-by-step guides available for Teams platform capabilities.
| # | Capability | Step-by-step guide |
|---|---|---|
| 1. | Bot | Debug your AI chat bot using Microsoft 365 Agents Playground |
| 2. | Message extension | Build API-based message extension |
| 3. | Tab | Build your first tab app using C sharp |
| 4. | SSO | Build a bot with SSO authentication |
Debug your AI chat bot using Microsoft 365 Agents Playground
Start Microsoft Teams app development with your Teams AI chat bot app and debug with Microsoft 365 Agents Playground (previously known as Teams App Test Tool). Agents Playground makes debugging bot-based apps effortless. You don't need a Microsoft 365 developer account, tunneling, or Teams app and bot registration to use Agents Playground.
Tutorial: Debug your AI chat bot
Prerequisites
You can chat with your bot and view the messages and Adaptive Cards as they appear in Teams. You can also mock an activity in Agents Playground using activity triggers.
Note
- Agents Playground is available only in v5.4.0 of Microsoft 365 Agents Toolkit (previously known as Teams Toolkit).
- Agents Playground is supported only for desktop and web clients.
This step-by-step guide helps you to build an AI chat bot using Agents Toolkit and debug with the Test Tool. You'll see the following output after you've completed this guide, where the user can access and use the AI chat bot:
| Install | For using... |
|---|---|
| Visual Studio Code or Visual Studio | JavaScript, TypeScript, or C# build environments. Use the latest version. |
| Microsoft 365 Agents Toolkit | Microsoft Visual Studio Code extension that creates a project scaffolding for your app. Use Agents Toolkit v5.4.0. For more information, see install Agents Toolkit. |
| Node.js | Back-end JavaScript runtime environment. For more information, see Node.js version compatibility table for project type. |
| OpenAI or Azure OpenAI | First create your OpenAI API key to use OpenAI's GPT. If you want to host your app or access resources in Azure, you must create an Azure OpenAI service. |
| Microsoft Edge (recommended) or Google Chrome | A browser with developer tools. |
Create project workspace for your AI chat bot app
The bot capability of a Teams app creates a chatbot or a conversational bot. It communicates with a web service, facilitating the use of its services. The bot can execute simple, automated tasks such as delivering customer service. You can get weather forecast, make reservations, or any other service offered using a conversational bot.
As you've already prepared for creating these apps, you can set up a new Teams project for creating the AI chat bot app.
Create your bot project workspace
If the prerequisites are in place, let's begin!
Open Visual Studio Code.
Select the Microsoft 365 Agents Toolkit
icon in the Visual Studio Code Activity Bar.Select Create a New Agent/App.
Select Agents for Teams > Azure OpenAI > enter an input in Input Azure API service key now
Select Basic Agents for Teams. If you need a different functionality for your bot, select the required option.
Select the programming language as JavaScript.
Select Default folder.
To change the default location, follow these steps:
Select Browse.
Select the location for the project workspace.
Select Select Folder.
Enter a suitable name for your app and then select the Enter key.
A dialog appears, where you need to choose yes or no to trust the authors of the files in this folder.
Now, you've successfully created your AI chat bot project workspace.
Take a tour of the bot app source code
After you finish scaffolding, explore the project directories and files in the EXPLORER section of the Visual Studio Code.
| Folder or file name | Contents |
|---|---|
env/.env.playground |
The configuration file with environment variables that can be committed to Git. |
env/.env.playground.user |
The configuration file with environment variables, including credentials, which aren't committed to Git by default. |
appPackage |
App manifest template files and app icons (color.png and outline.png). |
appPackage/manifest.json |
App manifest for running the app in local and remote environment. |
src/app.js |
Handles business logics for the AI chat bot. |
m365agents.yml |
This is the main Agents Toolkit project file. The project file defines two primary things: Properties and configuration and stage definitions. |
m365agents.local.yml |
This overrides m365agents.yml with actions that enable local execution and debugging. |
m365agents.playground.yml |
This overrides m365agents.yml with actions that enable local execution and debugging in Test Tool. |
Build and run your AI chat bot app
Create Open AI key and endpoint for your AI chat bot
Go to Azure portal.
Select Create a resource and search for Azure Open AI.
Select Azure Open AI and select Create.
Fill the required details and select Next.
Select All networks, including the internet, can access this resource and then select Next.
Fill the required details and select Next.
Select Create.
You've successfully created key and endpoint for your AI chat bot.
Note
You can also get OpenAI API key to debug your AI chat bot.
Get Azure Open AI keys and endpoint
Select Go to resources.
Select Keys and Endpoint from the left pane and copy the KEY and Endpoint. You can copy either KEY 1 or KEY 2.
Save the KEY and Endpoint for further use.
Select Model deployments from the left pane and select Manage Deployments.
The Azure Open AI Studio window appears.
Select Deployments from the left pane and select + Create new deployment.
Select the following details:
Update Azure Open AI key and endpoints
Open your project in Visual Studio Code.
Under EXPLORER, go to env > .env.playground.user file.
Enter your SECRET_AZURE_OPENAI_API_KEY and SECRET_AZURE_OPENAI_ENDPOINT.
... SECRET_AZURE_OPENAI_API_KEY=<azure-openai-api-key> SECRET_AZURE_OPENAI_ENDPOINT=<azure-openai-endpoint>Go to src > app.js file.
Comment the
OpenAIcode and uncomment theAzure OpenAIcode.Enter your Azure Open AI deployment name in
azureDefaultDeployment.// Use OpenAI // apiKey: config.openAIKey, // defaultModel: "gpt-3.5-turbo", azureApiKey: config.azureOpenAIKey, azureDefaultDeployment: "gpt-35-turbo", azureEndpoint: config.azureOpenAIEndpoint,
Debug and run your AI chat bot app
From the left pane, select RUN and DEBUG (Ctrl+Shift+D), and then select Debug in Agents Playground from the dropdown list.
Agents Playground opens your AI chat bot in a webpage.
Activity triggers
There are two types of activity triggers:
Predefined activity triggers
Agents Playground provides predefined activity triggers to test the functionalities of your bot.
| Category | Activity | Handler |
|---|---|---|
| Trigger Installation Update Activity | Install bot Uninstall bot |
onInstallationUpdate onInstallationUpdateAdded onInstallationUpdate onInstallationUpdateRemove |
| Trigger Conversation Update Activity | Add user Add bot Add channel |
onMembersAdded onTeamsMembersAddedEvent onMembersAdded onTeamsMembersAddedEvent onTeamsChannelCreatedEvent |
| Remove user Remove bot Remove channel Remove team |
onMembersRemoved onTeamsMembersRemovedEvent onMembersRemoved onTeamsMembersRemovedEvent onTeamsChannelDeletedEvent onTeamsTeamDeletedEvent |
|
| Rename channel Rename team |
onTeamsChannelRenamedEvent onTeamsTeamRenamedEvent |
Note
All types of activities aren't available in all scopes. For example, you can't add or remove a channel in a personal chat or a group chat.
Predefined activity triggers are available in the Mock an Activity menu in Agents Playground.
To mock an Add user activity, follow these steps:
In Agents Playground, go to Mock an Activity > Add user.
A dialog appears to preview the activity handler.
Select Send activity.
Bot sends the following response:
Custom activity triggers
You can use Custom activity to customize activity triggers, for example, reactionsAdded to meet the requirements of your bot app. Agents Playground automatically populates the required properties of the activity. You can also modify the activity type and add more properties.
Select Mock an Activity > Custom activity.
Add
messageReactionto customize the activity under thetypeproperty:{ "type": "messageReaction", "reactionsAdded": [ { "type": "like" } ], "replyToId": "d60fd1cb-3e8f-44ef-849c-404806ba1b47" }Select Send activity.
Bot sends an
onReactionsAddedhandler in response.
Complete challenge
Did you come up with output like this?
Congratulations! You've successfully created an AI chat bot app. Now, you've learned to debug your AI chat bot app in Agents Playground.
Build API-based message extension
Message extensions built using API (API-based) significantly enhance the functionality of your Teams apps by allowing them to interact with external services. API-based message extensions can help streamline workflows by reducing the need to switch between different applications.
Tutorial: Build API-based message extension
Note
API-based message extensions only support search commands.
You can use API-based message extensions to integrate external services that are commonly used in the business workflow. For example, a business that frequently uses a CRM system for customer management could use a message extension to fetch and display customer data directly from Teams. This app helps save time and improves efficiency by reducing the need to switch between different applications. This feature is supported on all platforms where Teams is available, including desktop, web, and mobile.
Prerequisites for building a message extension
Here's a list of tools you need for building and deploying your apps.
| Install | For using... |
|---|---|
| Microsoft Teams | Microsoft Teams to collaborate with everyone you work with through apps for chat, meetings, or call - all in one place. |
| Microsoft Edge (recommended) or Google Chrome | A browser with developer tools. |
| Visual Studio Code | JavaScript, TypeScript, or SharePoint Framework (SPFx) build environments. Use version 1.55 or later. |
| Microsoft 365 developer account | Access to Teams account with the appropriate permissions to install an app. |
| Azure account | Access to Azure resources. |
| OpenAPI Description (OAD) document | A document that describes the capabilities of your API. For more information, see OpenAPI Description. |
Set up your Teams development tenant
A tenant is like a space, or a container for your organization in Teams, where you chat, share files, and run meetings. This space is also where your upload and test your custom app. Let's verify if you're ready to develop with the tenant.
Check for custom app upload option
After creating the app, you must load your app in Teams without distributing it. This process is known as custom app upload. Sign in to your Microsoft 365 account to view this option.
Note
Custom app upload is necessary for previewing and testing apps in Teams local environment. If it isn't enabled, you can't preview and test your app in Teams local environment.
Do you already have a tenant, and do you have the admin access? Let's check if you really do!
Verify if you can upload a custom app in Teams:
In the Teams client, select the Apps icon.
Select Manage your apps.
Select Upload an app.
Look for the option to Upload a custom app. If you see the option, custom app upload is enabled.
Note
Contact your Teams administrator if you don't find the option to upload a custom app.
Create a free Teams developer tenant (optional)
If you don't have a Teams developer account, you can get it free. Join the Microsoft 365 developer program!
Go to the Microsoft 365 developer program.
Select Join Now and follow the onscreen instructions.
In the welcome screen, select Set up E5 subscription.
Set up your administrator account. After you finish, the following screen appears.
Sign in to Teams using the administrator account you just set up. Verify that you have the Upload a custom app option in Teams.
Get a free Azure account
If you want to host your app or access resources in Azure, you must have an Azure subscription. Create a free account before you begin.
You have all the tools to set up your account. Next, let's set up your development environment and start building! Select the app you want to build first.
Create OpenAPI Description document
OpenAPI Description (OAD) is the industry-standard specification that outlines how OpenAPI files are structured and outlined. It's a language-agnostic, human-readable format for describing APIs. It's easy for both humans and machines to read and write. The schema is machine-readable and represented in either YAML or JSON.
To interact with the APIs, an OpenAPI Description document is necessary. The OpenAPI Description document must meet the following criteria:
The
authproperty must not be specified.JSON and YAML are the supported formats.
OpenAPI Versions 2.0 and 3.0.x are supported.
Teams doesn't support the oneOf, anyOf, allOf, and not (swagger.io) constructs.
Constructing arrays for the request isn't supported, however, nested objects within a JSON request body are supported.
The request body, if present, must be application/Json to ensure compatibility with a wide range of APIs.
Define an HTTPS protocol server URL for the
servers.urlproperty.Only single parameter search is supported.
Only one required parameter without a default value is allowed.
Only POST and GET HTTP methods are supported.
The OpenAPI Description document must have an
operationId.The operation mustn't require Header or Cookie parameters without default values.
A command must have exactly one parameter.
Ensure that there are no remote references in the OpenAPI Description document.
A required parameter with a default value is considered optional.
We used the following OpenAPI Description as an example for this tutorial:
OpenAPI Description
openapi: 3.0.1 info: title: OpenTools Plugin description: A plugin that allows the user to find the most appropriate AI tools for their use cases, with their pricing information. version: 'v1' servers: - url: https://gptplugin.opentools.ai paths: /tools: get: operationId: searchTools summary: Search for AI Tools parameters: - in: query name: search required: true schema: type: string description: Used to search for AI tools by their category based on the keywords. For example, a search for "tool to create music" provides a list of tools that can create music. responses: "200": description: OK content: application/json: schema: $ref: '#/components/schemas/searchToolsResponse' "400": description: Search Error content: application/json: schema: ref: '#/components/schemas/searchToolsError' components: schemas: searchToolsResponse: required: - search type: object properties: tools: type: array items: type: object properties: name: type: string description: The name of the tool. opentools_url: type: string description: The URL to access the tool. main_summary: type: string description: A summary of what the tool is. pricing_summary: type: string description: A summary of the pricing of the tool. categories: type: array items: type: string description: The categories assigned to the tool. platforms: type: array items: type: string description: The platforms that this tool is available on. description: The list of AI tools. searchToolsError: type: object properties: message: type: string description: Message of the error.Note
Ensure that the
required: trueproperty is available for only one parameter. If there are more than one required parameters, you can update the required property torequired: falsefor the other parameters.
You can validate if the OpenAPI Description document is valid. To verify, follow these steps:
Go to Swagger or OpenAPI validator and validate the OpenAPI Description document.
Save the OpenAPI Description document.
Go to Swagger Editor.
In the left pane, paste the OpenAPI Description in the editor.
In the right pane, select GET.
Select Try it out.
Enter the values for the search parameter as Tool to create music.
Select Execute. The swagger editor displays a response with a list of products.
Go to Server response > Response Body.
Under
products, copy the first product from the list and save it for future reference.
Create response rendering template
An OpenAPI Description document requires a response rendering template for the app to respond to the GET or POST requests. The response rendering template consists of an Adaptive Card template, Preview card template, and metadata.
Adaptive Card template
To create an Adaptive Card template, follow these steps:
Go to ChatGPT and ask the following query in the message compose area:
Create an Adaptive Card Template that binds to the following response: "categories": [ "Music Generation", "AI Detection" ], "chatbot_short_url": "https://goto.opentools.ai/c/ai-music-generator", "main_summary": "AI Music Generator is an AI-powered music composing tool that allows users to create original and personalized music for various purposes. It can generate melodies, harmonies, and rhythms tailored to specific needs and preferences, with customization options such as genre, mood, length, and instrumentation. The tool is designed for creative individuals, from beginners to professionals, and can produce high-quality music in seconds. Every generated piece of music is royalty-free and can be used instantly, with no limitations on beat creation. With advanced AI technology, AI Music Generator makes music production accessible to everyone.", "name": "AI Music Generator", "opentools_url": "https://goto.opentools.ai/ai-music-generator", "platforms": [ "Web", "App", "API" ]Select Send message.
ChatGPT generates a response with an Adaptive Card template that binds to the sample data. Save the Adaptive Card template for future reference.
Following is an example of the Adaptive Card template:
Adaptive Card template
{ "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.4", "body": [ { "type": "TextBlock", "text": "AI Music Generator", "weight": "Bolder", "size": "Large" }, { "type": "TextBlock", "text": "Categories", "size": "Medium" }, { "type": "TextBlock", "text": "Music Generation, AI Detection", "wrap": true }, { "type": "TextBlock", "text": "Description", "size": "Medium" }, { "type": "TextBlock", "text": "AI Music Generator is an AI-powered music composing tool that allows users to create original and personalized music for various purposes. It can generate melodies, harmonies, and rhythms tailored to specific needs and preferences, with customization options such as genre, mood, length, and instrumentation. The tool is designed for creative individuals, from beginners to professionals, and can produce high-quality music in seconds. Every generated piece of music is royalty-free and can be used instantly, with no limitations on beat creation. AI Music Generator is powered by advanced AI technology, and it makes music production accessible to everyone.", "wrap": true }, { "type": "TextBlock", "text": "Platform", "size": "Medium" }, { "type": "TextBlock", "text": "Web, App, API", "wrap": true } ], "actions": [ { "type": "Action.OpenUrl", "title": "Learn More", "url": "https://goto.opentools.ai/ai-music-generator" }, { "type": "Action.OpenUrl", "title": "Try It", "url": "https://goto.opentools.ai/c/ai-music-generator" } ] }To verify if the Adaptive Card generated binds to the sample data, follow these steps:
Go to Adaptive Card Designer.
Go to Select host app, and then select Microsoft Teams from the dropdown.
Go to CARD PAYLOAD EDITOR and paste the Adaptive Card template code.
Go to SAMPLE DATA EDITOR and paste the GET API response that you saved earlier.
Select Preview mode. The Adaptive Card designer displays an Adaptive Card with the data that binds the response to the template.
Create a preview card template
The preview card template can contain a title, subtitle and image properties. If the API response doesn't have an image, you can remove the image property.
Following is an example of a preview card template:
Preview card template
"previewCardTemplate": {
"title": "${if(name, name, 'N/A')}",
"subtitle": "$${if(price, price, 'N/A')}"
}
Create an if condition for the title and subtitle, where:
- If name exists, the bot uses the name.
- If name doesn't exist, the bot uses NA.
For example, "title": "Name: ${if(name, name, 'N/A')}".
Save the preview card template for future reference.
Response rendering template
The response rendering template must conform to the schema hosted at https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.ResponseRenderingTemplate.schema.json.
To create a response rendering template, follow these steps:
Create a JSON file and add the following code to the file:
{ "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.ResponseRenderingTemplate.schema.json", "version": "1.0", "jsonPath": "", "responseLayout": "", "responseCardTemplate": { }, "previewCardTemplate": { } }Update the properties in the response rendering template as follows:
# Property name Value 1. "$schema""https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.ResponseRenderingTemplate.schema.json"2. "version""1.0"
versionis the version of the rendering template to use.3. "jsonPath""tools"
jsonPathis the path to one or more results in the response JSON response. Add thejsonPathto the relevant data/array from the product list in the API response. In this case, thejsonPathis tools. For more information on how to determiner the JSON path, see Querying JSON with JSON path.4. "responseLayout""list"
responseLayoutspecifies the layout of the attachments. Used for responses of type result. Supported types are list and grid. If the response body contains an object with multiple elements like text, title, and image, then the response layout must be set tolist. If the API response contains only images or thumbnails, then the response layout must be set togrid.5. "responseCardTemplate"Paste the Adaptive Card template code that you saved earlier.
responseCardTemplateis an Adaptive Card template to map the JSON response to an Adaptive Card.6. "previewCardTemplate"Paste the preview card template code that you saved earlier.
previewCardTemplateis a preview card template is used to show a preview of results in the message extension flyout.Save the response rendering template in the same folder you saved the OpenAPI Description document.
The following code is an example of a Response rendering template:
Response rendering template
{
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.ResponseRenderingTemplate.schema.json",
"version": "1.0",
"jsonPath": "tools",
"responseLayout": "list",
"responseCardTemplate": {
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "TextBlock",
"text": "AI Music Generator",
"weight": "Bolder",
"size": "Large"
},
{
"type": "TextBlock",
"text": "Categories",
"size": "Medium"
},
{
"type": "TextBlock",
"text": "Music Generation, AI Detection",
"wrap": true
},
{
"type": "TextBlock",
"text": "Description",
"size": "Medium"
},
{
"type": "TextBlock",
"text": "AI Music Generator is an AI-powered music composing tool that allows users to create original and personalized music for various purposes. It can generate melodies, harmonies, and rhythms tailored to specific needs and preferences, with customization options such as genre, mood, length, and instrumentation. The tool is designed for creative individuals, from beginners to professionals, and can produce high-quality music in seconds. Every generated piece of music is royalty-free and can be used instantly, with no limitations on beat creation. With advanced AI technology, AI Music Generator makes music production accessible to everyone.",
"wrap": true
},
{
"type": "TextBlock",
"text": "Platform",
"size": "Medium"
},
{
"type": "TextBlock",
"text": "Web, App, API",
"wrap": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Learn More",
"url": "https://goto.opentools.ai/ai-music-generator"
},
{
"type": "Action.OpenUrl",
"title": "Try It",
"url": "https://goto.opentools.ai/c/ai-music-generator"
}
]
},
"previewCardTemplate": {
"title": "${if(name, name, 'N/A')}",
"subtitle": "$${if(price, price, 'N/A')}"
}
}
Create app manifest
Now, you need to create an app manifest (previously called Teams app manifest). The app manifest describes how your app integrates into the Microsoft Teams product.
Create a Teams app manifest
To create the manifest, follow these steps:
Create a new JSON file. Your app manifest must conform to the 1.20 version of the schema defined in App manifest schema.
Add the following code to the JSON file:
App manifest
{ "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.schema.json", "manifestVersion": "1.20", "version": "1.0.3", "id": "<<YOUR-MICROSOFT-APP-ID>>", "packageName": "com.microsoft.teams.extension", "developer": { "name": "Teams App, Inc.", "websiteUrl": "https://www.example.com", "privacyUrl": "https://www.example.com/termofuse", "termsOfUseUrl": "https://www.example.com/privacy" }, "icons": { "color": "color.png", "outline": "outline.png" }, "name": { "short": "Search ME API", "full": "Search ME API full" }, "description": { "short": "product app for testing API Message Extensions", "full": "product app for testing API Message Extensions" }, "accentColor": "#FFFFFF", "composeExtensions": [ { "composeExtensionType": "", "apiSpecificationFile": "", "commands": [ { "context": [ "compose" ], "type": "query", "title": "API for fetching Klarna.", "id": "", "parameters": [ { "name": "", "title": "", "description": "" } ], "description": "", "apiResponseRenderingTemplateFile": "" } ] } ], "permissions": [ "identity", "messageTeamMembers" ], "validDomains": [] }Update the app manifest properties as follows:
- Replace
<<YOUR-MICROSOFT-APP-ID>>with bot's Microsoft App ID. - Update the value for
composeExtensionTypetoapiBased. - Update the value for
apiSpecificationFileto the path of your OpenAPI Description file. - Update the value for
commands.idtosearchTools. - Update the value for
commands.titletoSearch for AI Tools. - Update the value for
commands.descriptiontoSearch for AI Tools. - Update the value for
parameters.nametosearch. If there are no parameters, then the values must be query parameters orproperties.nameif referencing a property in the request body schema. - Update the
apiResponseRenderingTemplateFileto the path of your response rendering template file. - Update the value for
validDomainsto theservice URLendpoint defined in the OpenAPI Description file.
- Replace
Save the Teams app manifest in the same folder you saved the OpenAPI Description document and the response rendering template.
You need a color image and outline image. These images should be included in the folder and referenced in your Teams app manifest.
Zip up the contents of the folder. The zip file must include the following files:
- OpenAPI Description document
- Response rendering template
- App manifest
- Color icon
- Outline icon
Upload a custom app to Teams
Sign into Teams test environment to test your app in Teams. To upload a custom app in Teams, follow these steps:
Go to Microsoft Teams and sign in using your test tenant credentials.
Go to Apps > Manage your app > Upload an app.
Select Upload a customized app.
Select the zip file created and select Open.
Select Add.
Select Open.
Go to a chat, then select + from the message compose area, and search for your app.
Select the app and make a search query.
The app responds with an Adaptive Card in the chat window.
Select Send.
Congratulations! You did it! You learned to create an API-based message extension using OpenAPI Description document.
Build a bot with SSO authentication
Conversational bots in Microsoft Teams perform repetitive automated tasks initiated by users, such as customer service. The user needs to sign in multiple times without single sign-on (SSO) authentication. With SSO authentication methods, the users don't need to sign in to the bot multiple times.
Tutorial: Build a bot with SSO authentication
A bot behaves differently depending on the conversation it's involved in:
- Bots in channel and group chat conversations require the users to @mention the bot.
- Bots in a one-to-one conversation don't require an @mention. All messages sent by the user routes to the bot.
This step-by-step guide helps you to build a bot with SSO authentication. You'll see the following output:
Prerequisites for building a bot
Ensure that you install the following tools and set up your development environment:
| Install | For using... |
|---|---|
| Microsoft Teams | Microsoft Teams to collaborate with everyone you work with through apps for chat, meetings, and calls all in one place. |
| Visual Studio 2022 | You can install the enterprise version in Visual Studio 2022, and install the ASP.NET and web development workloads. Use the latest version. |
| Microsoft 365 developer account | Access to Teams account with the appropriate permissions to install an app. |
| Dev tunnel | Teams app features (conversational bots, message extensions, and incoming webhooks) need inbound connections. A tunnel connects your development system to Teams. Dev tunnel is a powerful tool to securely open your localhost to the internet and control who has access. Dev tunnel is available in Visual Studio 2022 version 17.7.0 or later. or You can also use ngrok as a tunnel to connect 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). |
Note
After downloading ngrok, sign up, and install authtoken.
Set up the Teams development tenant
A tenant is like a space or a container where you chat, share files, and run meetings for your organization in Teams. You can also upload and test the custom app.
Check for a custom app upload option
After creating the app, you must load your app in Teams without distributing it. This process is known as custom app upload. Sign in to your Microsoft 365 account to view this option.
Note
Custom app upload is necessary for previewing and testing apps in Teams local environment. Enable app upload to preview and test your app in Teams locally.
Do you already have a tenant, and do you have the admin access? Let's check if you really do!
To verify custom upload apps in Teams:
In the Teams client, select the Apps icon.
Select Manage your apps.
Select Upload an app
Look for the option Upload a custom app. If you see the option, custom app upload is enabled.
Note
Contact Teams administrator, if you don't have the option to upload a custom app.
Create a free Teams developer tenant
If you don't have a Teams developer account, you can get it for free. Join the Microsoft 365 developer program!
Go to the Microsoft 365 developer program.
Select Join Now and follow the onscreen instructions.
In the welcome screen, select Setup E5 subscription.
Set up an administrator account. After you finish, the following screen displays.
Sign in to Teams using the new administrator account you just set up. Verify that you have the Upload a custom app option in Teams.
Set up local environment
Follow these steps to clone the repository:
Open Microsoft-Teams-Samples.
Select Code.
From the dropdown menu, select Open with GitHub Desktop.
Select Clone.
Register Microsoft Entra app
The following steps help you to create and register your bot in the Azure portal:
- Create and register your Azure app.
- Create client secret to enable SSO authentication of the bot.
- Add Teams channel to deploy the bot.
- Create a tunnel to your web server's endpoints using dev tunnel (recommended) or ngrok.
- Add messaging endpoint to the dev tunnel that you created.
Add App registration
Go to Azure portal.
Select App registrations.
Select + New registration.
Enter the name of your app.
Select the tenant option, as required.
Select Register.
Your app is registered in Microsoft Entra ID. The app overview page appears.
Note
Save the app ID from Application (client) ID and Directory (tenant) ID for further use.
Create a tunnel
Follow one of the following two methods to create a tunnel.
Open Visual Studio.
Select Create a new project.
In the search box, enter ASP.NET. From the search results, select ASP.NET Core Web App.
Select Next.
Enter Project name and select Next.
Select Create.
An overview window appears.
In the debug dropdown list, select Dev Tunnels (no active tunnel) > Create a Tunnel....
A pop-up window appears.
Update the following details in the pop-up window:
- Account: Enter a Microsoft or GitHub account.
- Name: Enter a name for your tunnel.
- Tunnel Type: From the dropdown list, select Temporary.
- Access: From the dropdown list, select Public.
Select OK.
A pop-up window appears showing that dev tunnel is successfully created.
Select OK.
You can find the tunnel you've created in the debug dropdown list as follows:
Select F5 to run the application in the debug mode.
If a Security Warning dialog appears, select Yes.
A pop-up window appears.
Select Continue.
The dev tunnel home page opens in a new browser window and the dev tunnel is now active.
Go to Visual Studio, select View > Output.
From the Output console dropdown menu, select Dev Tunnels.
The Output console shows the dev tunnel URL.
Add web authentication
In the left pane, under Manage, select Authentication.
Select Add a platform > Web.
Enter the redirect URI for your app by appending
auth-endto the fully qualified domain name. For example,https://your-devtunnel-domain/auth-endorhttps://your-ngrok-domain/auth-end.Under Implicit grant and hybrid flows, select the Access tokens and ID tokens checkboxes.
Select Configure.
Under Web, select Add URI.
Enter
https://token.botframework.com/.auth/web/redirect.Select Save.
Create a client secret
Note
If you encounter the error Client secrets are blocked by tenant-wide policy. Contact your tenant administrator for more information., you can create a certificate instead. For step-by-step instructions, refer to create a certificate for app registration.
In the left pane, under Manage, select Certificates & secrets.
Under Client secrets, select + New client secret.
The Add a client secret window appears.
Enter Description.
Select Add.
Under Value, select Copy to clipboard to save the client secret value for further use.
Add API permissions
In the left pane, select API permissions.
Select + Add a permission.
Select Microsoft Graph.
Select Delegated permissions.
Select User > User.Read.
Select Add permissions.
Note
- If an app isn't granted IT admin consent, users must provide consent the first time they use an app.
- Users need to consent to the API permissions only if the Microsoft Entra app is registered in a different tenant.
Add application ID URI
In the left pane, under Manage, select Expose an API.
Next to Application ID URI, select Add.
Update the Application ID URI in the
api://botid-{AppID}format and select Save.
Add a scope
In the left pane, under Manage, select Expose an API.
Select + Add a scope.
Enter access_as_user as the Scope name.
Under Who can consent?, select Admins and users.
Update the values for the rest of the fields as follows:
Enter Teams can access the user’s profile as Admin consent display name.
Enter Allows Teams to call the app’s web APIs as the current user as Admin consent description.
Enter Teams can access the user profile and make requests on the user’s behalf as User consent display name.
Enter Enable Teams to call this app’s APIs with the same rights as the user as User consent description.
Ensure that State is set to Enabled.
Select Add scope.
The following image shows the fields and the values:
Note
The Scope name must match with the Application ID URI with
/access_as_userappended at the end.
Add client application
In the left pane, under Manage, select Expose an API.
Under Authorized client applications, identify the applications that you want to authorize for your app’s web application.
Select + Add a client application.
Add Teams mobile or desktop and Teams web application.
For Teams mobile or desktop: Enter the Client ID as
1fec8e78-bce4-4aaf-ab1b-5451cc387264.
For Teams web: Enter the Client ID as
5e3ce6c0-2b1f-4285-8d4b-75ee78787346.
Select the Authorized scopes checkbox.
Select Add application.
The following image displays the Client Id:
Update the manifest
In the left pane, select Manifest.
Set the value for the
requestedAccessTokenVersionto2and select Save.
Create your bot
Create an Azure bot resource
Note
If you're already testing your bot in Teams, sign out of this app and Teams. To see this change, sign in again.
Go to Home.
Select + Create a resource.
In the search box, enter Azure Bot.
Select Enter.
Select Azure Bot.
Select Create.
Enter the bot name in Bot handle.
Select your Subscription from the dropdown list.
Select your Resource group from the dropdown list.
If you don't have an existing resource group, you can create a new resource group. To create a new resource group, follow these steps:
- Select Create new.
- Enter the resource name and select OK.
- Select a location from New resource group location dropdown list.
Under Pricing, select Change plan.
Select FO Free > Select.
Under Microsoft App ID, select Type of App as Multi Tenant.
In the Creation type, select Use existing app registration.
Enter the App ID.
Note
You can't create more than one bot with the same Microsoft App ID.
Select Review + create.
After the validation passes, select Create.
The bot takes a few minutes to provision.
Select Go to resource.
You've successfully created your Azure bot.
Add a Teams channel
In the left pane, select Channels.
Under Available Channels, select Microsoft Teams.
Select the checkbox to accept the Terms of Service.
Select Agree.
Select Apply.
Add a messaging endpoint
Use one of the following ways to add a messaging endpoint:
Use the dev tunnel URL in the Output console as the messaging endpoint.
In the left pane, under Settings, select Configuration.
Update the Messaging endpoint in the format
https://your-devtunnel-domain/api/messages.
Select Apply.
You've successfully set up a bot in Azure Bot service.
Note
If the Application Insights Instrumentation key shows an error, update with App ID.
Add an OAuth connection settings
In the left pane, select Configuration.
Select Add OAuth Connection Settings.
Under New Connection Setting, update the following details:
- Name: Enter a name for your new connection setting. You can use the name in the settings of your bot service code.
- Service Provider: From the dropdown list, select Azure Active Directory v2.
- Client id: Update your Microsoft App ID.
- Client secret: Update the client secrets Value.
- Token Exchange URL: Update the Application ID URI.
- Tenant ID: Enter Common.
- Scopes: Enter User.Read.
Select Save.
Set up app settings and manifest files
Go to the appsettings.json file in the cloned repository.
Open the appsettings.json file and update the following information:
- Set
"MicrosoftAppId"to your bot's Microsoft App ID. - Set
"MicrosoftAppPassword"to your bot's client secret ID value. - Set
ConnectionNameas OAuth connection name. - Set
"MicrosoftAppType"to MultiTenant. - Set
"MicrosoftAppTenantId"to common.
- Set
Go to the manifest.json file in the cloned repository.
Open the manifest.json file and update the following changes:
- Replace all occurrences of
"{TODO: MicrosoftAppId}"with your Microsoft App ID. - Set
"<<domain-name>>"to your ngrok or dev tunnel domain.
- Replace all occurrences of
Build and run the service
Open Visual Studio.
Go to File > Open > Project/Solution....
From bot-conversation-sso-quickstart > csharp_dotnetcore folder, and select BotConversationSsoQuickstart.sln file.
Select F5 to run the project.
If a Security Warning dialog appears, select Yes.
A webpage opens with a message Your bot is ready!.
Note
This page appears only when you navigate to the localhost URL.
Troubleshooting
If you get the Unable to find package error, follow these steps:
- Go to Tools > NuGet Package Manager > Package Manager Settings.
- In the Options window that appears, select NuGet Package Manager > Package Sources.
- Select Add.
- In Name, enter
nuget.organd in Source, enterhttps://api.nuget.org/v3/index.json. - Select Update and OK.
- Rebuild your project.
Upload the bot in Teams
In your cloned repository, go to Microsoft-Teams-Samples > samples > bot-conversation-sso-quickstart > csharp_dotnetcore > TeamsApp > appPackage.
Create a .zip file with the following files that are present in the appPackage folder:
- manifest.json
- outline.png
- color.png
Go to Microsoft Teams.
- In the Teams client, select Apps.
- Select Manage your apps.
- Select Upload an app.
- Look for the option to Upload a custom app.
Select Open to upload the .zip file that you've created in the Manifest folder.
Select Add to add the bot to your chat.
Select Open.
You can interact with the bot by sending it a message. The bot exchanges an SSO token and calls the Graph API on your behalf. It keeps you signed in unless you send a message to sign out.
Send a message to the bot. The conversation bot asks for consent for the first time.
For desktop: Select Continue to give permissions to Teams client for accessing the bot.
Note
Now you’ve configured SSO with your bot app and it's the only time you'll have to give consent.
For mobile: Select Accept.
Note
Now you’ve configured SSO with your bot app in mobile, and it's the only time you'll have to give consent.
Did you come up with something like this?
You've completed the tutorial to get started with build a bot with SSO authentication.
Build your first tab app using C sharp
Start Microsoft Teams app development by building your first Teams app with a tab capability.
In this tutorial, you'll learn:
- How to set up a new project.
- How to build apps with tab capability using C# and Microsoft Visual Studio 2022.
Tutorial: Build your first tab app using C#
This step-by-step guide helps you to build a tab with Microsoft 365 Agents Toolkit (previously known as Teams Toolkit). You'll see the following output after you've completed this guide:
Prerequisites for building your app
Here's a list of tools you need to install for building and deploying a Teams app.
| Install | For using... |
|---|---|
| Microsoft Teams | Microsoft Teams to collaborate with everyone you work with through apps for chat, meetings, and call all in one place. |
| Visual Studio 2022 |
You can install the enterprise version in Visual Studio 2022, and install the ASP.NET and web development workloads. Use the latest version. |
| Microsoft 365 Agents Toolkit | A Visual Studio extension that creates a project scaffolding for your app. Use the latest version. |
Install Agents Toolkit
Agents Toolkit helps simplify the development process with tools to create a project scaffolding for your app. It creates the necessary directory structure for all selected capabilities with the required files in place, ready to build the project.
You can download the latest Visual Studio installer. Agents Toolkit is available as an extension in Visual Studio.
After you open the Visual Studio installer, in the pop-up workloads window.
Select ASP.NET and web development.
Under installation details > Optional, select Microsoft Teams development tools.
Select Install.
Select Launch. Visual Studio 2022 app window appears.
Go to Extensions > Manage Extensions.
The Manage Extension window appears:
From the left pane, select Installed. The Microsoft 365 Agents Toolkit extension is avaialble.
Set up your Teams development tenant
A tenant is like a space or a container for your organization in Teams, where you chat, share files, and run meetings. This space is also where you upload and test your custom app. Let's verify if you're ready to develop with the tenant.
Check for custom app upload option
After creating the app, you must load your app in Teams without distributing it. This process is known as custom app upload. Sign in to your Microsoft 365 account to view this option.
Note
Custom app upload is necessary for previewing and testing apps in Teams local environment. If it isn't enabled, you won't be able to preview and test your app in Teams local environment.
Do you already have a tenant, and admin access? Let's check if you do!
Verify if you can upload a custom apps in Teams:
Open Microsoft Teams, select the Apps icon.
Select Manage your apps.
Select Upload an app.
Look for the Upload a custom app option. If you see the option, custom app upload is enabled.
Note
If you don't find the option to upload a custom app, contact your Teams administrator.
Create a free Teams developer tenant (optional)
If you don't have a Teams account, you can get it for free. Join the Microsoft 365 developer program!
Go to the Microsoft 365 developer program.
Select Join Now and follow the onscreen instructions.
In the welcome screen, select Setup E5 subscription.
Set up your administrator account. After you finish, the following screen appears:
Sign in to Teams using the administrator account you set up. Verify that you've the Upload a custom app option in Teams.
Get a free Azure account
If you wish to host your app or access resources in Azure, you must have an Azure subscription. Create a free account before you begin.
Now you've got all the tools to set up your account. Next, let's set up your development environment and start building! Select the app you want to create first.
Create project workspace for your tab app using C sharp
Start Microsoft Teams app development by creating your first app. This app uses the tab capability. If the prerequisites are in place, let's begin!
The following steps help you to create project workspace for your tab app in Visual Studio:
Open Visual Studio.
Select New Project.
In the search box, enter Teams.
Select Microsoft 365 Agents > Next.
Enter the following details to configure your new project.
Enter required project name in Project name.
Select required location to save project files and folders.
Select Create.
Select Tab > Create.
The Teams tab app is created in few seconds.
Build and run your first tab app using C sharp
After you set up your project workspace with Agents Toolkit, build your tab app.
Sign in to your Microsoft 365 account
Use your Microsoft 365 account to sign in to Teams. If you're using a Microsoft 365 developer program tenant, the admin account you set up while registering is your Microsoft 365 account.
In the Solution Explorer, under Solution MyTeamsApp, right-click on MyTeamsApp.
Select Microsoft 365 Agents Toolkit > Select Microsoft 365 Account.
Select Microsoft 365 Account > Continue.
Build and run your app locally in Visual Studio
To build and run your app locally:
Select Debug > Start Debugging or select F5.
Visual Studio starts the debugging process and opens the Teams web client in a browser. If prompted, sign in with your Microsoft 365 account.
Select Add.
Select Open to open the app in personal scope.
Alternatively, you can either search and select the required scope or select a channel or chat from the list, and move through the dialog to select Go.
Congratulations, your first tab app is running on Teams!
Learn how to troubleshoot if your app doesn't run locally.
To successfully run your app in Teams, ensure that you've enabled custom app upload in your Teams account. You can learn more about custom app upload in the prerequisites section.
You have successfully created a tab app using C#. Agents Toolkit has added the necessary scaffolding to your app's directory structure. The tutorial is now complete.
Platform Docs