Note
This guide mainly covers Provisioning, not creation of the agent. But here is a simplified version of that...
If you use the sdk's CLI, you can have an app set up in just a few commands. Here's the command for python for example:
npx @microsoft/teams.cli new python my-super-agent -t echo
This creates an echo agent in python using our CLI. More details are in https://microsoft.github.io/teams-ai/python/getting-started/quickstart. Use whatever language you like.
The process of having your agent run on Teams involves a few major steps:
- Have your app running and accepting requests at some endpoint. Using the SDK simplifies this process for you.
- Provision your agent (i.e. bot registration)
- Install your app to Microsoft Teams
Note
In the sections below, I use the Azure CLI. You need to make sure you have this cli installed and you're logged into Azure CLI using az login
. Typically this means you need to select a subscription as well.
Tip
Details of the commands etc are collapsed in each bullet point. You can expand it to take a deeper look.
An agent that is allowed to run on Teams must be provisioned. Provisioning basically means this:
1. An Application needs to be registered with Microsoft Entra. This application needs to have a unique _global_ name. You get an application id when you register your application with Entra.
appId=$(az ad app create --display-name $botName --sign-in-audience "AzureADMyOrg" --query appId -o tsv)
echo "App ID: $appId"
az ad sp create --id $appId
appCred=$(az ad app credential reset --id $appId)
tenantId=$(echo $appCred | jq -r '.tenant')
clientSecret=$(echo $appCred | jq -r '.password')
echo "Tenant ID: $tenantId"
echo "Client Secret: $clientSecret"
What just happened:
- We created an Azure AD application with a display name and got back an App ID
- We created a service principal for that application
- We reset the application credentials to get a fresh client secret
2. Next, you need to create an Azure Bot. This is a particular type of resource which you create in a particular tenant. The Azure Bot points to the application id for identification.
echo "Resource Group: $(az group create --name $resourceGroup --location $location --query name -o tsv)"
echo "Bot Resource ID: $(az bot create --resource-group $resourceGroup --name $botName --app-type SingleTenant --appid $appId --endpoint $endpointUrl --sku F0 --query id -o tsv)"
What just happened:
- We created a resource group to contain our Azure resources
- We created an Azure Bot resource in that resource group
- We linked it to our Azure AD application using the App ID
- We configured the bot endpoint where Teams will send messages
- We used the F0 (free) pricing tier
3. Finally, you need to enable the Azure Bot to work in Microsoft Teams.
echo "Teams Channel: $(az bot msteams create --name $botName --resource-group $resourceGroup --query name -o tsv)"
What just happened:
- We enabled the Microsoft Teams channel for our Azure Bot
- This allows the bot to receive messages from Teams users
4. Save the credentials to a .env file for your application.
botDomain=$(echo "$endpointUrl" | sed -E 's#^https?://##' | sed 's#/.*##')
echo "TENANT_ID=$tenantId" > .env
echo "CLIENT_ID=$appId" >> .env
echo "CLIENT_SECRET=$clientSecret" >> .env
echo "BOT_DOMAIN=$botDomain" >> .env
echo "Environment variables saved to .env"
What just happened:
- We extracted the domain from the bot endpoint URL
- We created a .env file with all the credentials your application needs
- The file contains TENANT_ID, CLIENT_ID, CLIENT_SECRET, and BOT_DOMAIN
With the above, your agent is provisioned successfully and is able to receive messages from Teams.
Tip
There is a script you can run that will automate this for you at the bottom of this gist
Run it like this: ./provision_bot.sh
. It'll ask you a few questions and run the above commands for you and output a .env file.
Next, we need to tell Microsoft Teams about your Agent. For this, we use an app package, which essentially contains:
- A manifest - This manifest contains all the details for your agent including its application id.
- Icons
So once you provision, you build this app package (which results in a zip file asset). You need to open the manifest.json file that was automatically created for you, and replace all the values with the values from the provisioning step.
Tip
There is a script you can run that will automate this for you at the bottom of this gist
Run it like ./build_apppackage.sh ./apppackage .env
. Make sure your .env file is up-to-date. It'll produce a zip file that you can sideload into Teams.
Once you have provisioned your agent AND you have built the app package, you need to install it into Teams. Follow these steps to do that - https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/deploy-and-publish/apps-upload#prerequisites