Skip to content

Latest commit

 

History

History
 
 
page_type description products languages extensions contentType createdDate
sample
This sample app demonstarte how an Bot can create a call, join a meeting and transfer the call
office-teams
office
office-365
csharp
samples
07-07-2021 13:38:25

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.

Frameworks

drop drop

Prerequisites

  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
  1. Run ngrok - point to port 3978

    ngrok http -host-header=rewrite 3978

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.


Setup Calling and Meeting Bot

  • Register an App in Azure using demo tenant
  • Create client_secret for your app
  • Copy client_Id client_secret for your app in Notepad.
  • Register a bot with Azure Bot Service, following the instructions here.
  • Ensure that you've enabled the Teams Channel
  • While registering the bot, use https://<your_ngrok_url>/api/messages as the messaging endpoint.
  • 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
	$userCredential = Get-Credential
	Connect-MicrosoftTeams -Credential $userCredential

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

  ex:
  Import-Module MicrosoftTeams
	$userCredential = Get-Credential
	Connect-MicrosoftTeams -Credential $userCredential

	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, azure-client-id, policy-description, object-id for user 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 "<<azure-client-Id>>"
  • Add following Graph API Applications permissions to your Azure App.
  • Calls.AccessMedia.All
  • Calls.Initiate.All
  • Calls.InitiateGroupCall.All
  • Calls.JoinGroupCall.All
  • Calls.JoinGroupCallAsGuest.All
  • OnlineMeetings.ReadWrite.All
  • Grant Admin consent for the above permissions

  • Create Bot Channel Registeration in Azure account which have subscription enabled.

  • Provide App-Name, Resource Group and other required information

  • Update messgaing endpoint https://{yourngrok}/api/messages

  • Click on Create AppId and Secret

  • Enter Client_Id and Client_Secret of your azure app registered in demo tenant

  • Add the Teams channel.

  • 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 example https://contoso.com/teamsapp/callback. image

  • Save your changes.

Update appsetting.json for calling Bot

{
  "MicrosoftAppId": "",
  "MicrosoftAppPassword": "",
  "BotBaseUrl": "https://{yourngrok}.ngrok.io",
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "TenantId": "",
    "ClientId": "",
    "ClientSecret": ""
  },
  "Bot": {
    "AppId": "",
    "AppSecret": "",
    "PlaceCallEndpointUrl": "https://graph.microsoft.com/v1.0",
    "BotBaseUrl": "https://{yourngrok}.ngrok.io",
    "GraphApiResourceUrl": "https://graph.microsoft.com",
    "MicrosoftLoginUrl": "https://login.microsoftonline.com/"
  },
  "UserId": "",
  "Users": [
    {
      "DisplayName": "",
      "Id": ""
    },
    {
      "DisplayName": "",
      "Id": ""
    },
    {
      "DisplayName": "",
      "Id": ""
    }
  ]
}
  • Update MicrosoftAppId, MicrosoftAppPassword, AppId, AppSecret with your client_id and client_secret app registered in demo tenant.
  • Update BotBaseUrl with your ngrok URL.
  • Update UserId and DisplayName of the users from where you want to initiate the call and to whom you want to redirect or transfer the call

Create Teams App Package and upload it for organisation

  • Open your project in Visual Studio
  • Go to Manifest folder
  • Update your Bot Id with client_Id and base URL with ngrok URL.
  • Zip your manifest along with two icons
  • upload your manifest in your demo tenant for organisation in run your solution in Visual studio.

Interaction with Calling and Meeting Bot

  • Install Calling Bot in Teams image

  • Bot will throw welcome Text with Adaptive Card as mentioned below image

  • User can ask Bot to Create a call, Transfer a call image

  • User can ask Bot to schedule a Meeting and invite the participants image

Further reading