Teams calling and meeting bot
Microsoft Teams calling and meeting bot provides basic functionalities such as create a call, join a call, transfer or redirect a call, join a scheduled meeting, and invite the participants by integrating the cloud communications Graph API.
Bots can interact with Teams calls and meetings using real time voice, video, and screen sharing. Teams apps can interact with users using voice and video to enhance their experience with Microsoft Graph APIs for calls and online meetings. These APIs allow you to add the following new features:
- Use Interactive Voice Response (IVR).
- Use call control.
- Provide access to real time audio and video streams, including desktop and app sharing.
Create a bot and specify additional information and permissions to use these Graph APIs in a Teams app.
This step-by-step guide helps you to set up Teams calling and meeting bot. You'll see the following output:
Prerequisites
Ensure that you install the following tools and set up your development environment:
Install | For using... | |
---|---|---|
Microsoft 365 developer account | Access to Teams account with the appropriate permissions to install an app. | |
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. | |
.NET Core SDK | Customized bindings for local debugging and Azure Functions app deployments. Use the latest version or install the portable version. | |
Microsoft Teams | Microsoft Teams to collaborate with everyone you work with through apps for chat, meetings, and call all in one place. | |
Windows PowerShell | Install by executing all the commands. | |
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 local environment
Open Microsoft-Teams-Samples.
Select Code.
From the dropdown menu, select Open with GitHub Desktop.
Select Clone.
Register Microsoft Entra app
To register an application using the Microsoft Azure portal for your app to integrate with the Microsoft identity platform and call Microsoft Graph API, perform the following steps:
- Create a ngrok tunnel to the endpoints of your web server.
- Create Azure bot resource to register bot with Azure bot service.
- Create client secret that enables single sign-on (SSO) authentication of the bot.
- Create a policy for a demo tenant user to create online meetings using PowerShell.
- Add API permissions for downstream calls.
- Create bot channel registration in Azure account.
- Add Microsoft Teams channel to deploy the bot to a Teams channel.
- Add messaging endpoint to the ngrok tunnel you created.
Add App registration
Go to Azure portal.
Select App registrations.
Select + New registration.
Enter the name of your app.
Select Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant).
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
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 a 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-end
to the fully qualified domain name. For example,https://your-devtunnel-domain/auth-end
orhttps://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
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 for downstream calls
In the left pane, under Manage, select API permissions.
Select + Add a permission.
Select Microsoft Graph.
Select Application permissions.
Select the following permissions:
Calls.AccessMedia.All
Calls.Initiate.All
Calls.InitiateGroupCall.All
Calls.JoinGroupCall.All
Calls.JoinGroupCallAsGuest.All
OnlineMeetings.ReadWrite.All
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 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_user
appended 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:
Create a policy
To create a policy that allows a demo tenant user to create online meetings using a PowerShell script, perform the following steps:
Run Windows PowerShell PSI as an administrator and execute the script.
New-CsApplicationAccessPolicy -Identity "<<policy-identity/policy-name>>" -AppIds "<<azure-client-id>>" -Description "Policy-description" Grant-CsApplicationAccessPolicy -PolicyName "<<policy-identity/policy-name>>" -Identity "<<object-id-of-the-user-to-whom-policy-need-to-be-granted>>"
Note
If you're using the Windows PowerShell PSI for the first time, execute the following commands:
- Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
- Install-Module -Name MicrosoftTeams -Force -AllowClobber
Replace the following fields in Windows PowerShell script:
Field Description policy-identity/policy-name Name of the policy. azure-client-id Microsoft App ID, which you generated while registering the app in Azure portal. Policy-description Description of the policy. object-id-of-the-user-to-whom-policy-need-to-be-granted ID of the user for whom you need to generate the policy using the graph explorer. To generate object ID, sign in to Microsoft Graph Explorer using the credentials to whom the policy must be granted.
Select Graph Explorer from the tool bar.
Select Run query. A response is generated under Response preview.
Copy the value of the
id
property from the Response preview and replace with the object ID in the PowerShell script.Execute the PowerShell script.
Run
Connect-MicrosoftTeams
and sign in with the credentials to whom the policy must be granted.Run the following command in PowerShell to verify whether the policy is created successfully or not. Replace the policy name with your defined policy name.
Get-CsApplicationAccessPolicy -Identity “<<policy-identity/policy-name>>”
Note
Ensure running scripts aren't disabled in your system. For more information, see execution policies.
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.
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.
Set up app settings and manifest files
Get the
tenantId
orUserId
from Teams. To get thetenantId
, follow these steps:Select Teams.
Select More options (...).
Select Get link to team.
You can get the
displayName
andid
from site:Sign in to Microsoft Graph Explorer using your Teams tenant account.
Add
Users
at the end of the URL in the search box.Select Run query.
The display names and user IDs linked to your account are generated.
Select any three accounts and add them to the
DisplayName
andUserId
in the appsettings.json file.Note
TenantId
orUserId
of the Teams account denotes from where you want to initiate the call, andDisplayName
andUserId
of the users denote to whom you want to redirect or transfer the call.
Update app settings
Go to the appsettings.json file in the cloned repository.
Open the appsettings.json file in Visual Studio and update the following information:
- Replace
MicrosoftAppId
,ClientId
, andAppId
to your bot's Microsoft App ID. - Replace
MicrosoftAppPassword
,ClientSecret
, andAppSecret
to Value of your bot's Client secret. - Replace
BotBaseUrl
to the ngrok or dev tunnel domain name. - Replace
TenantId
to theUserId
. - Replace
DisplayName
to theId
.
- Replace
Select Save.
Update app manifest
Build and run the service
To build and run the service, use Visual Studio:
Add calling and meeting bot to Teams
In your cloned repository, go to csharp > Source > AppManifest.
Create a .zip file with the following files that are present in the AppManifest folder:
- manifest.json
- outline.png
- color.png
Note
The
manifest.zip
must not contain any extra folders in it. It must havemanifest json
source file,color
icon, andoutline
icon inside the zip folder.In the Teams client, select the Apps icon.
Select Manage your apps.
Select Upload an app.
In the pop-up window, select Upload a custom app. If you see the option, custom app upload is enabled.
Go to csharp > Source > AppManifest.
Select Open to upload the .zip file that you created in the AppManifest folder.
Select Add to install the calling bot app in Teams.
Select Open to open the app in personal scope.
Alternatively, you can either search and select the required scope or select a channel, chat, or meeting from the list, and move through the dialog to select Go.
Interact with calling and meeting bot
Bot allows you to access services and content in a dedicated space within a channel or in a chat.
Let's interact with the app in Teams!
In the left pane of the Teams, select View more apps (...) and select your app from the list.
Bot sends welcome text with Adaptive Card.
Select Create Call.
Select Transfer Call.
You can ask bot to schedule a meeting and invite the participants.
Complete challenge
Did you come up with output like this?
Congratulations!
You've completed the tutorial to get started with bot calling and meeting app for Microsoft Teams.
Have an issue with this section? If so, please give us some feedback so we can improve this section.
Platform Docs