Power Virtual Agents are the no-code/low-code Chatbot offering within its Power Platform offering. An intuitive drag and drop interface helps to get started quickly with building your first interactive bot that can assist your users with common queries with the ability to handover to human agent when it is beyond the bot to respond to the questions asked.
The good thing about Power Virtual Agent is the ability to call Power Automate flows to execute any action that requires integration with Dataverse or Dynamics 365 CRM or any 3rd party system for that matter empowering the citizen dev to create a powerful bot to assist their customers.
In this blog we will have a look at integrating Power Virtual Agents with an external api and displaying the responses returned to the user.
You can now go ahead and create chatbots from the maker portal at https://make.powerapps.com. You can take help of Microsoft document to create your bots.
I picked up an existing topic and using the canvas designer modified the flow per my requirements.
The conversation flow would be triggered if the user asks about store location
Next ask the user to enter location
Send the location to Azure Maps location service to determine the city and state
If an invalid zipcode was entered, we respond with “Currently not servicing this location” else “We deliver at this location”
Here is the what the Power Virtual agent flow looks like
Once the user provides the address location, we use Power Automate Flow for further processing.
You can use the Call and action option and Create a flow to perform your operations
When a flow is created from the context of Power Virtual Agent it automatically brings up a flow with the “When Power Virtual Agents calls a flow”
This trigger lets you define input parameters that you will pass from the chatbot to the flow. In this case I have defined postalcode parameter.
Next, we will use the http connector to send the request to Azure Maps to get the location details
Use the Parse JSON action to easily extract the required information from the response returned by the http request. Parse JSON requires you to provide a sample response template that it can use to generate dynamic properties that you can directly refer further down in your flow steps without the need for using expressions. To generate a sample response, you can execute the request through API tester like Postman
Copy the result and paste it in the window that comes up on clicking Generate from sample
With this done now you can use the Return values to Power Virtual Agents action to return the results back to PVA.
The complete flow looks as follows
Now that the flow is ready, we get back to our PVA canvas designer and go ahead and select this flow as a step in the PVA.
The flow was designed to accept a user input Postal Code and return City, Country and Result as output results. The same can be seen below.
Choose the value from the Chat bot that you would like to pass as the value for the Postal Code input.
We had accepted the user input of location in a variable and we pass the same as a parameter here
The output results of City and Country can be used in the Show Message action of the PVA
Lets go ahead and test our PVA
And if you enter an invalid post code
Integrating Power Automate Flows with Power Virtual Agents provides you with limitless opportunities to integrate with various 3rd party systems those that have their own connectors for Power Automate or use the http connector and connect with any API directly.