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:

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

  1. Go to the Topics page for the bot you want to edit.

  2. Open the authoring canvas for the topic from which you want to call a flow.

  3. Select the plus (+) button below an existing node to add a new node.

  4. In the node selection window, select Call an action, and then select Create a flow.

    Create a new Power Automate flow.

Using the Create a flow option opens a starter flow template in the Power Automate portal in a separate tab.

Power Automate flow template.

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

    Power Virtual Agents flow trigger.

  • Response action: Return value(s) to Power Virtual Agents

    Power Virtual Agents response.

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.

Power Virtual Agents flow trigger input types.

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

Power Virtual Agents flow trigger inputs.

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.

Power Virtual Agents response output types.

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

Power Virtual Agents response outputs.

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.

Power Automate flow template - Save.

Your flow is saved to the Default Solution under the Solutions tab on the Power Automate portal.

Power Automate flow template - Default Solution.

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.

New flow shows up in Action picker.

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.

  1. 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.

  2. To create a new solution, select New solution.

    Create a solution.

  3. Give your new solution a name, select CDS Default Publisher in the Publisher field, enter a Version number, and then select Create.

    Save a new solution.

  4. On the Solutions tab, go to the solution you want to use. Select Add existing to add a flow.

    Add existing menu.

  5. 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.

    Add flow to a 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.

    Add flow from outside solutions.

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.

  1. 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.

    Modify a flow from Action Picker.

    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.

    Modify a flow from 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.

    Edit your flow using the Details page.

    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.

    Open your flow for editing.

  2. 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)

    Add inputs to the flow.

  3. Choose Add an action to create a new action below the Power Virtual Agents flow trigger.

    Add flow action.

  4. Enter MSN weather into the search box, and then select the Get forecast for today action from the list.

    Add Get forecast action.

  5. A new MSN Weather Connector is added to the flow. Under Location, select Add dynamic content. Select City and Zipcode from the list.

    Pass flow's input parameters to MSN Weather connector as location.

  6. 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)

    Add dynamic variables to the flow's response.

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:

  1. In Power Virtual Agents, go to the Topics page for the bot you want to edit.

  2. Create a new topic, and name it Get weather.

  3. Add the following trigger phrases:

    • will it rain
    • today's forecast
    • get weather
    • what's the weather

    Create a new Topic.

  4. 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.

    Screenshot of adding a node.

  5. Add two new Ask a question nodes to ask users for the City (String) and Zipcode (Number) inputs.

    Add Topic Dialog questions.

  6. 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.

    Call action.

  7. 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 from Var2 (number).

  8. 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%

    Input the variables.

  9. 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.

Pass literal values into action inputs.

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.

Test Dialog.

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

  1. Locate and modify your flow.

  2. In your Power Automate flow, locate the Power Virtual Agents step that returns values.

  3. Next to the name of the flow, select the three dots, and then select Settings.

    Open step settings.

  4. Set Asynchronous Response to Off, and then select Done.

    Disable asynchronous response.

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.