Create a Power Virtual Agent and integrate it with a SharePoint list

by Danish Ali Detho | O365 & Power Platform Solution Architect///

Introduction

Virtual agents and bots have become an essential part of customer support in every business. It provides the fastest way to provide the information a customer is looking for without waiting for a customer support agent or searching through a website. They can cover large no of use-case scenarios including providing product information, helping with flight/hotel bookings, or tracking orders.
Today we will take a look at how easy it is to create a Power Virtual Agent and integrate it with a SharePoint list using PowerAutomate Flow.

Microsoft bot framework provides the capabilities for developers to create a bot using programming however Microsoft has recently introduced something for business users to create virtual agents to solve business problems in the form of Power Virtual Agents. Power Virtual Agent is the newest addition to the Power Platform family and is very much focused on the same type of low-code, accessible to everyone from business users to the professional developer in order to provide a platform for building conversational agent that’s AI-driven, tightly integrated with other platform components and can actually solve real business problems.

Scenario

Create a power virtual agent that provides information about the total price and total current stock of the product requested by the customer.

SharePoint List

First off, let’s create a product list that will hold the data of the products with the following fields.

Product list

Columns

  • Title (Single Line of Text)
  • Unit Price (Money)
  • Current Stock (Number)

Create a Power Virtual Agent

Let’s open the power virtual agent studio using the link https://powerva.microsoft.com/ and sign in.
Note: You can signup for a free trial to try it out.

Open bots panel and then click on new Bot. Enter name, select language, and Environment and then press create. This will spin up a new power virtual agent bot.

Note: It takes few minutes for the bot to setup.  

Once the bot is created, we need to define a topic and add some phases. The topic is a way of separating different jobs a bot can perform and phases are used to activate a specific topic. Bot can switch between various topics and a topic is triggered by a phrase. So, let’s add a topic “Search Product” and some common phrases.

Next step is to define the flow of conversation in the authoring canvas. This is where you will define the actions and responses of our bot and the questions to ask the user for information.

Let’s ask the user which product he is looking for and then save it in a product variable. Add a question on the canvas.

Now we will use “Call an Action” to call a PowerAutomate Flow for fetching the items from the SharePoint List. ProductName will be used as an input. In the flow, we will use GetItems with the FilterQuery Title eq ‘ProductName’ to get the items based on the user input and then return the items count and results back to bot.

Note: To get item count use the following expression length(body(‘Get_items’)?[‘value’])

Now we will concatenate the results using a compose action and the following expression concat(item()?[‘Title’],’ – ‘,item()?[‘UnitPrice’],’ – ‘,item()?[‘CurrentStock’]

Power automate flow will return two variables to the power virtual agent containing the item count and the results. Now we will use condition to check if Count =0, then inform user that no products are found and start over again. If Count > 0 then show the results.

Now our bot is ready for testing. We can test the bot in the chat window on the left.  You will notice that the execution of the flow of conversation is visible in the authoring canvas as well.

Summary

In this article, we covered the basics of the power virtual agents and how easy it is to create a bot that can serve as a virtual agent to provide information to the customer. We then implemented a search product scenario where the user can search for product pricing and stock from a SharePoint List using a power automate flow.