Calling and Meeting Bot Sample V4
Summary
Calling and Meeting Bot provides basic functionality like Create Call, Join a call, Transfer/Redirect a call, Join a scheduled meeting and invite the participants by integrating cloud communications API Graph API.
- Interaction with bot
Frameworks
Prerequisites
Microsoft Teams is installed and you have an account
.NET Core SDK version 6.0
dev tunnel or ngrok latest version or equivalent tunnelling solution
PowerShell if on macOS (
brew install --cask powershell
)
Setup
Note these instructions are for running the sample on your local machine, the tunnelling solution is required because the Teams service needs to call into the bot.
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
If you are using Visual Studio
- Launch Visual Studio
- File -> Open -> Project/Solution
- Navigate to
samples/bot-calling-meeting/csharp
folder - Select
CallingBotSample.csproj
file
Run ngrok - point to port 3978
ngrok http 3978 --host-header="localhost:3978"
Alternatively, you can also use the
dev tunnels
. Please follow Create and host a dev tunnel and host the tunnel with anonymous user access command as shown below:devtunnel host -p 3978 --allow-anonymous
Register Azure AD application
Register one Azure AD application in your tenant's directory for the bot and tab app authentication.
Log in to the Azure portal from your subscription, and go to the "App registrations" blade here. Ensure that you use a tenant where admin consent for API permissions can be provided.
Click on "New registration", and create an Azure AD application.
Name: The name of your Teams app - if you are following the template for a default deployment, we recommend "App catalog lifecycle".
Supported account types: Select "Accounts in any organizational directory"
Leave the "Redirect URL" field blank.
Click on the "Register" button.
When the app is registered, you'll be taken to the app's "Overview" page. Copy the Application (client) ID; we will need it later. Verify that the "Supported account types" is set to Multiple organizations.
On the side rail in the Manage section, navigate to the "Certificates & secrets" section. In the Client secrets section, click on "+ New client secret". Add a description for the secret and select Expires as "Never". Click "Add".
Once the client secret is created, copy its Value, please take a note of the secret as it will be required later.
At this point you have 3 unique values:
- Application (client) ID which will be later used during Azure bot creation
- Client secret for the bot which will be later used during Azure bot creation
- Directory (tenant) ID
We recommend that you copy these values into a text file, using an application like Notepad. We will need these values later.
Under left menu, navigate to API Permissions, and make sure to add the following permissions of Microsoft Graph API > Application permissions:
Calls.AccessMedia.All
Calls.Initiate.All
Calls.InitiateGroupCall.All
Calls.JoinGroupCall.All
Calls.JoinGroupCallAsGuest.All
OnlineMeetings.ReadWrite.All
Click on Add Permissions to commit your changes.
If you are logged in as the Global Administrator, click on the "Grant admin consent for <%tenant-name%>" button to grant admin consent else, inform your admin to do the same through the portal or follow the steps provided here to create a link and send it to your admin for consent.
Global Administrator can grant consent using following link: https://login.microsoftonline.com/common/adminconsent?client_id=<%appId%>
Install Microsoft Teams PowerShell Module. For basic install, run
Import-Module MicrosoftTeams
in PowerShell, or check the link for detailed other advanced installs.- For macOS, the following command should be executed in PowerShell (
brew install --cask powershell
).
- For macOS, the following command should be executed in PowerShell (
Create a policy for a demo tenant user for creating the online meeting on behalf of that user using the following PowerShell script
# Import-Module MicrosoftTeams # Call Connect-MicrosoftTeams using no parameters to open a window allowing for MFA accounts to authenticate Connect-MicrosoftTeams New-CsApplicationAccessPolicy -Identity “<<policy-identity/policy-name>>” -AppIds "<<microsoft-app-id>>" -Description "<<policy-description>>" Grant-CsApplicationAccessPolicy -PolicyName “<<policy-identity/policy-name>>” -Identity "<<object-id-of-the-user-to-whom-policy-need-to-be-granted>>"
e.g.:
# Import-Module MicrosoftTeams Connect-MicrosoftTeams New-CsApplicationAccessPolicy -Identity Meeting-policy-dev -AppIds "d0bdaa0f-8be2-4e85-9e0d-2e446676b88c" -Description "Online meeting policy - contoso town" Grant-CsApplicationAccessPolicy -PolicyName Meeting-policy-dev -Identity "782f076f-f6f9-4bff-9673-ea1997283e9c"
Update
PolicyName
,microsoft-app-id
,policy-description
,object-id-of-the-user-to-whom-policy-need-to-be-granted
in powershell script.Run
Windows Powershell PSI
as an administrator and execute above script.Run following command to verify policy is create successfully or not:
Get-CsApplicationAccessPolicy -Identity Meeting-policy-dev
Setup Bot Service
- In Azure portal, create a Azure Bot resource
- Select Type of App as "Multi Tenant"
- Select Creation type as "Use existing app registration"
- Use the copied App Id and Client secret from above step and fill in App Id and App secret respectively.
- Click on 'Create' on the Azure bot.
- Go to the created resource, ensure that you've enabled the Teams Channel
- In Settings/Configuration/Messaging endpoint, enter the current
https
URL you have given by running the tunneling application. Append with the path/api/messages
- Select the Calling tab on the Teams channel page. Select Enable calling, and then update Webhook (for calling) with your HTTPS URL (
https://<your_tunnel_domain>/callback
) where you receive incoming notifications. For examplehttps://contoso.com/teamsapp/callback
- Save your changes.
Configuring the sample
Update appsettings.json for calling Bot
{ "MicrosoftAppId": "<<microsoft-app-id>>", "MicrosoftAppPassword": "<<microsoft-app-client-secret>>", "AzureAd": { "Instance": "https://login.microsoftonline.com/", "TenantId": "<<tenant-Id>>", "ClientId": "<<microsoft-app-id>>", "ClientSecret": "<<microsoft-app-client-secret>>" }, "Bot": { "AppId": "<<microsoft-app-id>>", "AppSecret": "<<microsoft-app-client-secret>>", "PlaceCallEndpointUrl": "https://graph.microsoft.com/v1.0", "BotBaseUrl": "https://<<subdomain>>.ngrok-free.app", "GraphApiResourceUrl": "https://graph.microsoft.com", "MicrosoftLoginUrl": "https://login.microsoftonline.com/", "RecordingDownloadDirectory": "temp", "CatalogAppId": "<<microsoft-app-id>>" }, "CognitiveServices": { "Enabled": false, "SpeechKey": "<<cognitive-speech-key>>", "SpeechRegion": "<<cognitive-speech-region>>", "SpeechRecognitionLanguage": "<<cognitive-speech-language>>" }, "Users": { "UserIdWithAssignedOnlineMeetingPolicy": "<<object-id-of-the-user-to-whom-online-meeting-policy-has-been-granted>>" } }
- Update
microsoft-app-id
,tenant-Id
,microsoft-app-client-secret
with your app's client id and client secret registered in demo tenant. - Update
BotBaseUrl
with yourtunnel
URL. - Update
object-id-of-the-user-to-whom-online-meeting-policy-has-been-granted
with the ID of the user who has had the policy assigned to them above
Create a Cognitive Services resource using the Azure portal: Create Cognitive Services resource
- Update
cognitive-speech-key
replaceyour-key
with one of the keys for your resource. - Update
cognitive-speech-key
replaceyour-region
with one of the regions for your resource. - Update
cognitive-speech-language
replaceyour-language
with one of the language for your resource.
- Update
This step is specific to Teams
- Edit the
manifest.json
contained in theAppManifest
folder to replace your Microsoft App Id (that was created when you registered your bot earlier) everywhere you see the place holder string<<YOUR-MICROSOFT-APP-ID>>
(depending on the scenario the Microsoft App Id may occur multiple times in themanifest.json
) - Edit the
manifest.json
forvalidDomains
, replace<<domain-name>>
with base Url domain. E.g. if you are using ngrok it would behttps://1234.ngrok-free.app
then your domain-name will be1234.ngrok-free.app
and if you are using dev tunnels then your domain will be like:12345.devtunnels.ms
. - Zip up the contents of the
AppManifest
folder to create amanifest.zip
(Make sure that zip file does not contains any subfolder otherwise you will get error while uploading your .zip package) - Upload the
manifest.zip
to Teams (In Teams Apps/Manage your apps click "Upload an app". Browse to and Open the .zip file. At the next dialog, click the Add button.) - Add the app to personal/team/groupChat scope (Supported scopes)
- Edit the
Note: If you are facing any issue in your app, please uncomment this line and put your debugger for local debug.
Running the sample
Install app in personal teams.
Select welcome card.
Bot will send adaptive card as mentioned below.
Select 'Create Call'.
'Calling Bot' selected user.
User join call.
Successfully call .
Control this meeting.
Create Incident.
Transfer call.
'Calling Bot' selected user.
Play record prompt.
Hang up.
Install app in team.
Add calling bot to a team.
Bot will send adaptive card as mentioned below.
Select 'Create Call'.
User join call.
Control this meeting.
Install app in meeting.
Add calling bot to a meeting.
Bot will send adaptive card as mentioned below.
Select 'Create Call'.
User join call.
Control this meeting.
Join scheduled meeting.
Deploy the bot to Azure
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.
Disclaimer
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.