Tuesday 18 February 2020

Retrieve Office365 People data on MS Team Channels via Outgoing Webhook and Azure App Service

Here, let us see how office 365 people information can be integrated into Microsoft Teams, with the help of outgoing webhooks on Teams. The use case is to pull the people present at a location, on posting a message to a service from Microsoft Teams.  

This could be easily achieved with the help of outgoing webhook feature under teams. The webhook has to interact with a service to get data processed based on data posted. 

Why Outgoing Webhook?: The outgoing webhook is used here instead of incoming webhook, since the data needs to be retrieved only when it is required.

No BOT Framework, only Azure App Service: This article helps us to understand creating outgoing webhook services for Microsoft Teams, without creating BOT service/app. Here the intent of service is clear, so we are not leveraging the BOT framework, instead hosting a simple service with Azure web app. From azure web app, the people data is being pulled from Azure AD with the help of Microsoft Graph API.


Create an outgoing webhook for a Microsoft Team 


Locate a team under Microsoft Teams, and navigate to manage team. Under App, in the bottom right corner, you will find an outgoing webhook link. From the link, create a webhook.  

Outgoing Webhook creation on Teams
Outgoing Webhook creation on Teams


NOTE: This will generate a security code for communication, which needs to be copied and pasted on sharedSecret variable on for later use on Azure web app server.js code. 


Create an Azure AD app for MS Graph authentications 


Azure app service needs to get the people information for a specific city from Azure AD, via Microsoft Graph API. 
  • Graph API used on Azure App: https://graph.microsoft.com/v1.0/users?$filter=City eq '<cityname>’ 

For authenticating the above graph API end, the azure AD app needs to be created, where necessary permissions will be provisioned. In this case, the user permission needs to be granted from application type as shown below. The client credentials can be generated and copied to Azure web app service for authentications. 


Create an Azure web app 


From azure portal, create a web app with Node JS capability. The following server side code shows the web app service (i.e., webhook service), which reacts to the data from teams.  

Please note to change the shared secret value and client credentials, from the configurations explained above. Install the necessary modules, and publish the app service.



Test Outgoing Webhook on Microsoft Teams 


Now, the outgoing webhook can be tested from Teams. Post the webhook name, along with city name on Teams as shown below. The azure app service will be triggered via webhook and the repsonse will be posted to the message thread as shown below.
Teams integrated with App service for retrieving people information
Teams integrated with App service for retrieving people information

Advantage of using App Service over BOT framework: There are little complexities involved in building Azure BOT service than Azure App service, where proper data training needs to provided, along with intent creations on LUIS. Also, my requirement was straight forward, where no intent and data training is required.