Add actions to a bot using Power Automate
Select the version of Power Virtual Agents you're using here:
You can enable your bot to perform an action by calling a Microsoft Power Automate flow. Flows can help you automate activities, or call backend systems. For example, you can use flows with end-user authentication to retrieve information about a user after they've signed in.
You call flows from within topics, as a discrete Call an action node. You can utilize flows that have already been created in your Power Apps environment, or you can create a flow from within the Power Virtual Agents authoring canvas.
Important
To use flows within Power Virtual Agents, they must meet the following requirements:
A flow can only be called from a topic located in the same Microsoft Dataverse environment as your bot.
Flows must also be in a solution in Power Automate. You can move flows into solutions so they are listed in the authoring canvas.
Flow values must be returned synchronously to Power Virtual Agents.
Flows typically use variables to input and output information. The variables can then be used in other nodes within the topic.
Prerequisites
Create a new flow from the Power Virtual Agents authoring canvas
Go to the Topics page for the bot you want to edit.
Open the authoring canvas for the topic from which you want to call a flow.
Select the plus (+) button below an existing node to add a new node.
In the node selection window, select Call an action, and then select Create a flow.
Using the Create a flow option opens a starter flow template in the Power Automate portal in a separate tab.
Note
The Power Automate portal automatically opens in the same environment as the bot (using the same user credentials).
This template is an example of a flow that can be used by bots. To be suitable for bots, a Power Automate flow requires a special Power Virtual Agents flow trigger and response action:
Flow trigger: When Power Virtual Agents calls a flow
Response action: Return value(s) to Power Virtual Agents
Input and output parameters
There is no upper limit on how many input or output parameters Power Automate flow for a bot can have. Bots can use the following types of inputs and outputs with Power Automate flows:
- Number
- String
- Boolean
The following types are not supported:
- Object
- Date
- Timestamp
- List [String]
- List [Number]
- List [Boolean]
- List [Object]
- List [Date]
- List [Timestamp]
Note
A bot is able to receive up to 1 MB of data from a Power Automate flow in a single action. There is no upper limit on the maximum size of data that a bot can pass to a Power Automate flow.
Input parameters
To specify a flow to accept input parameters from a bot, select the Add an input option in the Power Virtual Agents flow trigger, and then select the type a - string, number, or a boolean.
For example, you can select Text and Number to add the following input parameters to the flow:
- String_Input of type
string - Number_Input ot type
number
Output parameters
To return output parameters to the bot that can be a string, number, or a boolean, select Add an output option in Return value(s) to Power Virtual Agents response, and then select the type for the output.
For example, you can select Text and Number to add the following output parameters to the flow and assign return values for them.
- String_Output of type
string - Number_Output ot type
number
This example creates a fully functional flow that accepts two parameters, a string and a number, and returns them to a bot as outputs.
Select Save to save your new flow.
Your flow is saved to the Default Solution under the Solutions tab on the Power Automate portal.
Flows created from the Power Virtual Agents authoring canvas are immediately available to the bot
All flows created from the Power Virtual Agents authoring canvas are saved in a Default Solution in Power Automate. They can be used by your bots immediately.
In Power Virtual Agents, you can now see this new flow on the list of available actions when you use the Call an action node in the authoring canvas.
Optionally move a flow from Default Solution to another solution
To be available to your bots, flows must be stored in a solution in Power Automate. If you do not want to use the Default Solution for this purpose, you can move your flows to another solution.
On the Power Automate portal, go to the Solutions tab where you can see the available solutions. Use any of the existing solutions or create a new solution for your flows.
To create a new solution, select New solution.
Give your new solution a name, select CDS Default Publisher in the Publisher field, enter a Version number, and then select Create.
On the Solutions tab, go to the solution you want to use. Select Add existing to add a flow.
On the Add existing flow page, select the From solutions tab, and then select your flow. Select Add to add your flow to the solution.
To move a flow from My flows tab to a solution, select the Outside solutions option. Select Add to add your flow to the solution.
Modify a flow on the Power Automate portal
You can rename and modify your flow on the Power Automate portal. For example, the flow you just created using the template can be updated to provide a weather forecast when called from a bot.
In Power Virtual Agents, you can open a flow by using the flow's View flow details link on the list of available actions when you use the Call an action node in the authoring canvas.
If you want to update a flow that is already used in your dialog, the same View flow details link is available directly in the Action node.
Using the flow's View flow details link launches the Power Automate portal in a separate browser tab, and opens the flow in a Details page where you can modify it using the Edit command.
If you want to open a flow on the Power Automate portal, go to the Solutions tab and then open your flow's solution. Use the flow's Edit menu to open the flow for editing.
Rename the flow to Get weather forecast and then add the following flow input parameters to Power Virtual Agents flow trigger:
- City (String)
- Zipcode (Number)
Choose Add an action to create a new action below the Power Virtual Agents flow trigger.
Enter MSN weather into the search box, and then select the Get forecast for today action from the list.
A new MSN Weather Connector is added to the flow. Under Location, select Add dynamic content. Select City and Zipcode from the list.
In the response node Return value(s) to Power Virtual Agents, add the output parameters that you want to return to the bot. Save your flow.
- day_summary (String)
- location (String)
- chance_of_rain (Number)
This flow is now ready to be used in your bots.
Call a Power Automate flow as an action from a bot
You can call a Power Automate flow from a bot topic using the Call an action node. You can then pass variables to the flow and receive flow outputs that can be used in a bot conversation.
These instructions use adding weather information to a flow as an example. If you haven't already, follow the steps under the Modify a flow on the Power Automate portal section in this topic to create a weather forecast flow.
Call a flow from within a topic:
In Power Virtual Agents, go to the Topics page for the bot you want to edit.
Create a new topic, and name it Get weather.
Add the following trigger phrases:
- will it rain
- today's forecast
- get weather
- what's the weather
By default, a message node is created. Enter I can help you with that into the node, and then select the plus (+) button under it to add a new node.
Add two new Ask a question nodes to ask users for the City (String) and Zipcode (Number) inputs.
Select the plus (+) button under the question nodes to add a new node. In the node selection window, select Call an action, and then select the flow you created earlier called Get weather forecast.
Map the flow input blocks to the output variables from the question nodes. City (text) gets its value from
Var1 (text)and Zipcode (number) gets its value fromVar2 (number).Under the flow's node, add a Message node and then enter a message that uses the flow's outputs. For example:
Today's forecast for
(x)location:{x}day_summary. Chance of rain is{x}chance_of_rain%
Select Save to save your topic.
Pass literal values into action input fields
Alternatively, if you'd rather type in a literal value for an action input instead of using a variable as an action input, you can type the value directly into the field.
Test your flow and topic
In the Test chat pane, start a conversation with the bot by typing in a trigger phrase for the topic that contains the flow.
Enter your city and zip code at the prompt to get today's weather forecast from the bot.
Disable asynchronous responses from flows
Power Virtual Agents doesn't support Power Automate flows that return values asynchronously. When creating a new flow from within Power Virtual Agents, this behavior is disabled by default.
Flows that have the Asynchronous Response feature enabled may cause an error when your bot tries to run the flow. Instead of running the flow, the bot will say "Something unexpected happened. We're looking into it. Error code: 3000.".
If you've enabled Asynchronous Response, you'll need to disable it for the bot to work properly when it runs the flow:
To disable Asynchronous Response
In your Power Automate flow, locate the Power Virtual Agents step that returns values.
Next to the name of the flow, select the three dots, and then select Settings.
Set Asynchronous Response to Off, and then select Done.
Troubleshoot your bot
Test your bot when you make changes to your topics and flows, to ensure everything is working as expected. When a bot encounters a problem during a conversation, it will respond with an error message.
Most flow-related issues can be found in the Flow Checker, but any issues on the authoring canvas will appear in topic checker.
Feedback
Issottometti u ara feedback għal