Sunday 8 March 2020

Search for Documents from Microsoft Teams Channel Conversations

This article illustrates a sample for finding the documents available on a team, with keyword search from channel conversations. This is achieved with the help of outgoing webhook service, where documents from Team are being pulled with the help of Microsoft Graph API.
#Azure #GraphAPI #MicrosoftTeams #Office365

The following screenshot shows the list of documents retrieved sending the keyword via the channel conversation.
Finding documents from channel using outgoing webhooks
Finding documents from channel using outgoing webhooks


In my previous article, we have seen how to retrieve Office365 People data on MS Team Channels via Outgoing Webhook and Azure App Service. The same concept and services are used here, with little tweeks on the code used on my previous article.
  • Invoke the webhook service from Teams channel, with search keyword. 
  • Keyword is passed to webhook service, where the service is hosted on azure. 
  • The service receives the text, manipulates, and uses graph API to find the documents on Teams. 
  • Once documents response received from graph API, pass and post it on Teams channel with MessageCard (JSON format). 


Configuring Services


Please follow my previous article for configuring the following services.
  • Creating an outgoing webhook feature on Microsoft Teams. 
  • Creating an Azure AD app for MS Graph authentications. - Additionally here, the permissions for reading the group data has to be enabled. So Group.Read.All scope under MS graph is added and granted necessary permission. 
Permissions granted on Azure AD for getting graph API data on Azure web app
Permissions granted on Azure AD for getting graph API data on Azure web app

  • And finally, create an azure web app with NodeJS, as explained in my previous article. Then modify the azure web app code as explained below to serve the requests for queries generated from Teams channel conversations. 


Configuring Webhook service on Azure web app


The webhook service hosted on azure web app does the following actions.
  • Receives the request from the channel conversations. 
  • Extracts only keywords from the conversation text. 
  • Generates authentication/bearer token using the client credentials, for searching files on the group. 
  • The GET request has been made with graph API to find files. 

Please find the snippet Node JS code for processing and sending the data from/to the teams channel.