Rajesh 👨🏻‍💻developer, architect, consultant focussed on modernization, cognitive services, and conversational ai.

Manage QnA Maker KB from SharePoint with PowerAutomate (Microsoft Flow)

Manage QnA Maker KB from SharePoint with PowerAutomate (Microsoft Flow)

QnAMaker is a cloud API service offered by Microsoft Azure Cognitive Services, which enables you to create a knowledge base(KB) from your existing content such as FAQs, manuals, documents and other questions and answers.

After knowledge base creation and training, then the service will be able to answer to users’ questions in natural language by matching for best possible answers (by ranking) from the KB. The common scenario is to connect this QnAMaker service to conversational bots and provide answers to users questions through dialog.

Admin user who created the service will be able to share the Knowledge-base (KB) with the other users in the organization for contribution, but requires some training for non-IT users on adding questions and save/train.

If we can integrate with the existing familiar systems like SharePoint, that will really improve the contributions. In this article, let’s see how we can integrate the SharePoint custom list with QnAMaker KB using Microsoft Flow.

In order to do that we need to establish a relation between the SharePoint list and KB in QnAMaker service. We will doing that by storing the Question ID from the KB in the list item and list item’s Id in the question in KB. This relation will be used to manage questions when it’s modified/deleted in the SharePoint list. QnAMaker provides the option to classify the questions added using the metadata, we will be creating a metadata “spid” and store the corresponding SharePoint list item Id with questions.

SharePoint List

I created a custom list and added a multiline column as Answer and qnaId as single line of text to store the question Id from the KB. Use the same name for the columns otherwise you need the edit the flows to change the column. I’m not going to hide the qnaId from the forms.

Microsoft Flow

There is a QnAMaker (preview) connector available in Flow and LogicApps but it does not provide the options to add/edit and delete the individual questions. I used the Cognitive Services APIs instead of preview connector.

We will be creating two flows,

  1. Add/Edit Question
  2. Delete Question

Add/Edit Question

When an item is created or modified in SharePoint list, Flow will be triggered checks whether its a new item or existing item and makes HTTP call with the right JSON object as payload. If new item, then downloads the KB and does some JSON parsing to get the right qnaId and store it back to the list item.

I have enabled some preview features in my QnAMaker my JSON schema was different then the API documentation , so watch out for the JSON schema while parsing the downloaded KB in Flow.

Delete Question

You can find all the artifacts in my Github repo here.

Deployment instructions

  • Create list in SharePoint
  • Download packages from GitHub repo
  • Import packages to Microsoft flow and create new flow
  • Fix SharePoint connection and change site URL and list
  • Update the subscription id and KB id in the variables by editing the flow

Things to be noted

  • This flow will be adding questions to the prod version of QnAMaker KB.
  • Its unidirectional, which means the changes will be always from SharePoint list and not the other way around, so any changes made directly in QnA Maker or through other direct APIs will not reflect on SharePoint list.
  • Updating the question in SharePoint will add an alternate question in KB and it won’t remove the previous question. Delete and newly add the question if required.
  • Currently no other meta data is added to the question, add Github to your watch list for the future updates.
  • Create an issue in the Github repo, I’ll address if time permits

Download the Microsoft Flow packages from my Github repo here.

comments powered by Disqus