Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
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
office-teams
office
office-365
csharp
contentType createdDate
samples
07/07/2021 01:38:25 PM
officedev-microsoft-teams-samples-bot-calling-meeting-csharp

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 bot-calling-meeting

Frameworks

drop drop

Prerequisites

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.

  1. Clone the repository

    git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
  2. 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
  3. 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.

  1. 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.

  2. Click on "New registration", and create an Azure AD application.

  3. Name: The name of your Teams app - if you are following the template for a default deployment, we recommend "App catalog lifecycle".

  4. Supported account types: Select "Accounts in any organizational directory"

  5. Leave the "Redirect URL" field blank.

  6. Click on the "Register" button.

  7. 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.

  8. 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".

  9. 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.

  10. 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.

  11. 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.

  12. Global Administrator can grant consent using following link: https://login.microsoftonline.com/common/adminconsent?client_id=<%appId%>

  13. 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).
  14. 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"

    PolicySetup

  15. Update PolicyName, microsoft-app-id, policy-description, object-id-of-the-user-to-whom-policy-need-to-be-granted in powershell script.

  16. Run Windows Powershell PSI as an administrator and execute above script.

  17. Run following command to verify policy is create successfully or not: Get-CsApplicationAccessPolicy -Identity Meeting-policy-dev

Setup Bot Service

  1. In Azure portal, create a Azure Bot resource
  2. Select Type of App as "Multi Tenant"
  3. Select Creation type as "Use existing app registration"
  4. Use the copied App Id and Client secret from above step and fill in App Id and App secret respectively.
  5. Click on 'Create' on the Azure bot.
  6. Go to the created resource, ensure that you've enabled the Teams Channel
  7. In Settings/Configuration/Messaging endpoint, enter the current https URL you have given by running the tunneling application. Append with the path /api/messages
  8. 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 example https://contoso.com/teamsapp/callback EnableCallingEndpoint
  9. Save your changes.

Configuring the sample

  1. 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 your tunnel 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 replace your-keywith one of the keys for your resource.
    • Update cognitive-speech-key replace your-regionwith one of the regions for your resource.
    • Update cognitive-speech-language replace your-languagewith one of the language for your resource.
  2. This step is specific to Teams

    • Edit the manifest.json contained in the AppManifest 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 the manifest.json)
    • Edit the manifest.json for validDomains, replace <<domain-name>> with base Url domain. E.g. if you are using ngrok it would be https://1234.ngrok-free.app then your domain-name will be 1234.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 a manifest.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)

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. CallingBotInstallation

  • Select welcome card. BotCallingMeeting2

  • Bot will send adaptive card as mentioned below. BotCallingMeeting3

  • Select 'Create Call'. BotCallingMeeting4

  • 'Calling Bot' selected user. BotCallingMeeting5

  • User join call. BotCallingMeeting55

  • Successfully call . BotCallingMeeting6

  • Control this meeting. BotCallingMeeting7

  • Create Incident. BotCallingMeeting8

  • Transfer call. BotCallingMeeting9

  • 'Calling Bot' selected user. BotCallingMeeting10

  • Play record prompt. BotCallingMeeting11

  • Hang up. BotCallingMeeting12

  • Install app in team. BotCallingMeeting13

  • Add calling bot to a team. BotCallingMeeting14

  • Bot will send adaptive card as mentioned below. BotCallingMeeting16

  • Select 'Create Call'. BotCallingMeeting17

  • User join call. BotCallingMeeting18

  • Control this meeting. BotCallingMeeting19

  • Install app in meeting. BotCallingMeeting20

  • Add calling bot to a meeting. BotCallingMeeting21

  • Bot will send adaptive card as mentioned below. BotCallingMeeting22

  • Select 'Create Call'. BotCallingMeeting23

  • User join call.
    BotCallingMeeting24

  • Control this meeting. BotCallingMeeting25

  • Join scheduled meeting. BotCallingMeeting26

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.

Further reading