Demonstrates the ability to answer and manage a call with Teams service hosted media capabilities exposed through Microsoft Graph.
Disclaimer 1: This sample is an extension of the Echo bot, available through bot builder as a Yeoman generator
Disclaimer 2: This code is provided as is.
Disclaimer 3: Official samples (including C#) are available in the following link.
- Node.js
- Git
- Visual Studio Code
- ngrok
- Initiate ngrok "ngrok http 8080" and take note of the Forwarding Address
- Create a new Azure AD Application Registration in your tenant and assign and consent to proper permissions - Azure AD (https://aad.portal.azure.com) | Calling Bot Permissions according to the documentation
- Create a new "Bot Channel Registration" in Azure and configure its identity to that of your Azure AD app registration id and secret/password
- Fill out the bot messages and calling endpoints as follow: ngrokForwardingAddress/api/messages and ngrokForwardingAddress/api/calls
- Git clone this repository
- Create a new .env file, if not available, and add (and fill out) the following items: MicrosoftAppId, MicrosoftAppPassword, tenantID, ngrok and playPromptURL. For the playPromptURL, I recommend a small wav file, that could be hosted in an Azure blob storage. If you want to configure the bot to join a meeting, add also the following values: userId, userDisplayName and threadId.
- Install all dependencies (npm install)
- From a console, e.g. PowerShell, run "node index.js"
- Install the Teams App Studio and call the bot
Moreover, it is highly recommended to inspect calls being made to your ngrok Forwarding Address endpoint through the following URL (http://localhost:4040/inspect/http), and optionally, additional calls, once the call has been established, can be made directly through Postman or Fiddler (e.g. play prompt, record audio clip or subscribe to tone).
The usage flow for this demo bot is as follows:
- User calls bot from within a Team custom app
- Bot answers with a default audio message
- Bot listens for tones pressed by the user: Tone 1 will route the bot to record an audio clip, whose content can be obtained from the location and token specified in the request through the ngrok inspector. Tone 2 will hang up. Besides the ngrok inspector, bot actions are logged (console.log) to the node terminal.
This bot implements the following Microsoft Graph calling endpoints:
- Answer call
- Play Prompt
- Subscribe to tone
- Record Audio Clip
- Delete (Hang Up)
- Listen for notification events
In addition, if you want to test joining a meeting from your bot:
- Create a meeting in Teams and grab from the URL its threadId (ex: 19:meeting_"MEETINGID"@thread.v2)
- Copy as well the organizer Display Name and ID and paste them in the respective .env values (userId, userDisplayName and threadId)
- Join the call from the organizer (or any other invited user)
- From Postman (or the tool of your choice), call the endpoint "localhost:8080/api/calls/join" to join the meeting
- If it works as expected, your bot should join the call
If you want to, there's also an endpoint for muting, that you can use to mute your bot in the meeting, or you can leverage the documentation to play a prompt or other support IVR interaction.
Following are some items that could be considered for improvements of this sample:
- Validate bot incoming requests (best practice)
- Integrate with Cognitive Services to leverage the audio clips to understand what was said and act accordingly
- Implement additional endpoints, such as Redirect Call, Create and Participants management scenarios.