page_type | description | products | languages | extensions | urlFragment | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
This sample app demonstrates how a Bot can create a call, join a meeting and transfer the call |
|
|
|
officedev-microsoft-teams-samples-bot-calling-meeting-csharp |
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.
-
Microsoft Teams is installed and you have an account
-
.NET Core SDK version 6.0
-
ngrok or equivalent tunnelling solution
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"
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%>
-
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
# Calling Connect-MicrosoftTeams using no parameters will 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>>"
eg:
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 -PolicyName Meeting-policy-dev -Identity "<<microsoft-app-id>>"
- 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 ngrok. 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://yourNgrok/callback
) where you receive incoming notifications. For examplehttps://contoso.com/teamsapp/callback
- Save your changes.
- 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 yourngrok
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.
- This step is specific to Teams
- Edit the
manifest.json
contained in theTeamsAppManifest
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
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
. - Zip up the contents of the
TeamsAppManifest
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.
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.
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.