# Microsoft QnA Maker: Extend Virtual Agents with a Knowledgebase

**Cognigy Support**  
November 15, 2021

The Microsoft QnA Maker Extension helps to answer frequently asked questions in a Cognigy.AI virtual agent. Therefore, an already created **Knowledgebase** can be used as a backup if the virtual agent did not find an intent. **This tutorial** will explain **how to integrate** an organization's **QnA Maker** instance **to a Cognigy.AI virtual agent** and generate answers.

- [Source Code](https://github.com/Cognigy/Extensions/tree/master/extensions/microsoft-qna-maker)

* * *

## Table of Contents
1. [Install the Microsoft QnA Maker Extension](https://support.cognigy.com/hc/en-us/articles/4405645806866-Microsoft-QnA-Maker-Extend-Virtual-Agents-with-a-Knowledgebase#h_01F35G1EZ8B9T7DGEDJSE9T1M3)
2. [Create a QnA Maker Connection](https://support.cognigy.com/hc/en-us/articles/4405645806866-Microsoft-QnA-Maker-Extend-Virtual-Agents-with-a-Knowledgebase#h_01F330NS152GKEXBSRDXFZ5MGM)
3. [Generate an answer](https://support.cognigy.com/hc/en-us/articles/4405645806866-Microsoft-QnA-Maker-Extend-Virtual-Agents-with-a-Knowledgebase#h_01F67XCYZTAHBK65CXP9PKY5MX)

## Install the Microsoft QnA Maker Extension
The first step is to install the required integration. In this case, a so-called [Extension](https://docs.cognigy.com/docs/extensions) is installed to Cognigy.AI. Thus, navigate to the **Extensions Marketplace** inside of the Virtual Agent and add the **Microsoft QnA Maker** Extension by clicking on the **Install** button. Now follow [this installation guide and upload the Extension to Cognigy](https://support.cognigy.com/hc/en-us/articles/360016505680-Extensions-Installation#upload-an-extension-0-2), where it will be displayed as the following:

**Congrats! The installation of the Extension is finished!**

## Create a QnA Maker Connection
In this step, a so-called [Connection](https://docs.cognigy.com/docs/connections) will be created. If one, in Cognigy.AI, clicks on the previously uploaded Extension, the following details can be observed:

The red-marked part in the above figure shows, that there is one Connection required. Therefore, it needs to be created and filled with the QnA Maker instance information. In order to do so, one initial Flow Node needs to be added to a Flow:

1. Create a new Flow in Cognigy.AI
2. Inside of the Flow Chart, click on **+** and navigate to the Microsoft QnA Maker Extension:

3. Add the **Generate Answer** Flow Node by clicking on it:

4. In order to edit the Flow Node and create the Connection, please click on it. An _Edit Node_ menu will be opened on the right side of the screen:

5. Right next to the Connection field (the first one at the top), one needs to click on the + button. The Connection menu will be opened at the center of the screen:

6.  The required values can be copied from the **Settings** page of the referenced QnA Maker Knowledgebase:
    1. Login to [https://www.qnamaker.ai/](https://www.qnamaker.ai/)
    2. Select the Knowledgebase that should be connected
    3. On the top right, click on **Settings**
    4. Scroll down to the **Deployment details**

****

7. Insert the related Microsoft QnA Maker credentials/information of the organization to the fields.
    1. **runtimeEndpoint**
        - The URL of the hosted QnA Maker instance.
    2. **resourceKey**
        - The authentication key is provided after the "EndpointKey" name in the Authorization information.
    3. **knowledgebaseId**
        - The actual identifier (ID) of the used Knowledgebase in QnA Maker.
8. Click on the _Create_ button

## Generate an answer
Finally, a virtual agent could generate a fitting answer to a user's question if no intent was found in Cognigy.AI. A possible Flow Chart could look such as the following:

This straightforward configuration instantly extends the available list of possible FAQ answers in the chat/voice conversation. In this case, the **Generate Answer** Flow Node exposes two different so-called Child Nodes, helping the designer developing a valid logic.

### On Found Answer
If a fitting answer was found in the QnA Maker Knowledgebase, the **On Found** path is executed -- the dynamic answer can be sent to the user in a Say Node

while the used CognigyScript is:

```
{{input.answers[0].answer}}
```

The entire result JSON data information is stored in the Input or Context object:

```
{
    "answers": [
        {
            "questions": [
                "Who is Cognigy?"
            ],
            "answer": "Cognigy is an enterprise software provider for Conversational AI automation. Our platform, Cognigy.AI, automates customer and employee communications. Available in on-premises and SaaS environments, Cognigy.AI enables enterprises to have natural language conversations with their users on any channel – webchat, SMS, voice and mobile apps – and in any language.",
            "score": 62.8,
            "id": 2,
            "source": "https://www.cognigy.com/about",
            "isDocumentText": false,
            "metadata": [],
            "context": {
                "isContextOnly": false,
                "prompts": []
            }
        },
        "...": "..."
    ]
}
```

### On Not Found Answer
However, if even the QnA Maker database did not find a fitting answer, the **On Not Found** path is executed which could lead to a live chat handover event. Again, the Extension's result JSON data is stored in the Input or Context object -- based on the configuration:

```
{
    "answers": [
        {
            "questions": [],
            "answer": "No good match found in KB.",
            "score": 0,
            "id": -1,
            "isDocumentText": false,
            "metadata": []
        }
    ]
}
```

### Microsoft
- [Microsoft Graph: Login a user and provide internal assistance](https://support.cognigy.com/hc/en-us/articles/360021439899-Microsoft-Graph-Login-a-user-and-provide-internal-assistance)
- [Microsoft Dynamics 365: Maintain Contacts and Accounts](https://support.cognigy.com/hc/en-us/articles/360021845040-Microsoft-Dynamics-365-Maintain-Contacts-and-Accounts)
- [Microsoft QnA Maker: Extend Virtual Agents with a Knowledgebase](https://support.cognigy.com/hc/en-us/articles/4405645806866-Microsoft-QnA-Maker-Extend-Virtual-Agents-with-a-Knowledgebase)
- [Microsoft Power Automate: Trigger and Integrate a Flow](https://support.cognigy.com/hc/en-us/articles/360021334879-Microsoft-Power-Automate-Trigger-and-Integrate-a-Flow)
