Tell me a joke— How to add Small Talk support to your Power Virtual Agents Chatbot. | by Sebastian Zolg 🤝 | Towards Data Science

Whatever your Chatbot is designed for, and no matter how clear or simple its purpose is, your users will always try to chit-chat first.
Knowing this, it becomes essential that even your simplest Chatbot has decent small talk skills. But this could be a challenge — especially when you work with low-code products like Power Virtual Agents (Power VA) as such products might not have a good Small Talk feature out of the box.
In this guide, I’ll show you how to add a small talk capability to any Power VA Chatbot using QnA Maker as part of the Azure Cognitive Services Suite and combine both products with the help of Power Automate.
If you’re new to Power VA, I got you covered with a simple step-by-step introduction here on Medium.
Let’s get started.
With the help of Microsoft’s QnA Maker, we can create a knowledge base for our Chatbot with a prepopulated dataset for ~100 chit-chat scenarios, which include responses and sample queries. We can choose between 5 different personalities and 9 languages. You can learn more about it on GitHub.
To create our Small Talk knowledge base, go to https://www.qnamaker.ai/, sign in, and click Create a knowledge base.
Click the Create a QnA service button to get redirected to the Azure Portal to create your own QnA Maker instance.
In the Azure Portal, you have to name a couple of resources. Choose the appropriate name and location for every service that is created.
If you don’t have an Azure subscription, sign up for an Azure free trial first.
Furthermore, if you’re not an Azure expert, this might be a bit confusing. Don’t worry, and use the same settings as I did. Only replace West Europe with your nearest location and MyBot with the name of your Chatbot. The rest follows some best practices for naming and simple deployment.
Click your way all through the end of the wizard, verify your settings one last time, and hit Create.
Wait for the Your deployment is completed message and jump back to the QnA Maker Portal in your browser.
Back in the QnA Maker portal, click the Refresh button and select the previously created Azure QnA Service instance from the drop-down list. Note that it might require you to refresh (F5) multiple times or wait some more minutes for the instance to show up.
Give your QnA Maker knowledge base a speaking name, as I did.
Now we can add some Small Talk (aka Chit-Chat) scenarios and choose between the 5 different personalities.
When ready, click Create your KB.
When your knowledge base is ready, we can optionally tweak it a little bit. For instance, you could search for ‘Who are you?’ and change its response to include a personalized welcome message from your Chatbot.
It’s also possible to add new QnA pairs, like a basic FAQ for your business. Play around with it and hit Save and train when you feel ready.
Now we can go to Publish tab and hit the Publish button.
After publishing was successful, the portal provides us with the necessary details like the knowledge base id, host, and endpoint key. Keep this page open, as we later need this information.
In the Power VA admin portal, open your Chatbot, click the Gear icon, and select System fallback.
By clicking the Add button, we enable the Fallback system topic. This replaces the default behavior of automatically prompting for information and allows us to hook in our custom logic.
After the Fallback system topic was added, click Go to fallback topic to open the designer.
First, we remove the default message and the escalate redirect using the three dots on each canvas.
Click the + icon at the end of the connector, choose Call an action and click Create a flow.
This fires up the Power Automate admin portal with a trigger and output action for Power VA. We’ll now make a couple of modifications to that flow.
First, we add a new Input for our trigger with a click on +Add an input. Choose a Text input and name it Question.
Also, we add the Generate answer (preview) action using the + icon.
In the next step, we have to configure the connection to our QnA Maker instance. We need the connection details displayed when you published your knowledge base in QnA Maker before (refer back to the screenshot above).
Enter a Connection Name as you want — map API Key to the Endpoint Key and Site URL to Host. Verify your settings once more and click Create.
In the next step, the Generate answer action asks for the same parameter once again. We also need the Knowledge Base Id, which is just the GUID part from the deployment details in the QnA Maker portal.
Finally, we map the Question field to the new Question input of our trigger from above.
QnA Maker might respond with multiple answers to a single question. This is why we ‘pick’ the best answer from the response with the next two steps.
First, we add an Initialize variable step and create a new object named BestAnswer. We initialize the object with the first answer entry we get from the Generate answer action. For this, we use the following simple expression.
first(outputs('Generate_answer')?['body/answers'])
This expression selects the first answer from above.
Now that we have this answer, we add a Parse JSON action to construct an object from our Best Answer. For this, we use the below JSON schema that you can copy and paste into the action’s schema field.
As the final step in our flow, we add two outputs.
First, we add a text output named Answer and map it to the answer property of our best answer.
Second, we add a number output named Score and map it to the score property, respectively. The score is a confidence value, which indicates how sure QnA Maker is about the response. We’ll use this value at a later point.
Before you hit save, give your flow a better name.
Back on the fallback system topic in Power VA, we can now add the new flow and link the UnrecognizedTriggerPhase variable to the flow’s Question input. This way, we simply pass what the user said to our flow.
After that, we add a new condition using the + icon at the end of the connector.
We test if the Score variable is greater 0. With this condition, we make sure that we received a proper answer from QnA Maker, which is worth displaying to the user, which we do with a simple message that uses the Answer variable.
For any other case, we respond with a static message that indicates that even our QnA Small Talk database has absolutely no idea what the user said.
Finally, hit the Save button and we’re good to test the small talk skills of our Chatbot. Just drop a bunch of silly questions and see how the Chatbot reacts.
That’s it. Our Chatbot behaves very naturally and can answer many of the most common questions. Even an imperfect answer could lead to hilarious and humorous conversations. Your Chatbot will definitively stand your first user interaction, and there is always the chance to improve the results by adding new QnA pairs.