I want to create a list of multiple options where users can select any option on a multiple choice list and get a response back based on selection. here is an example in the image.
Does this solution work only with PVA premium version?
@HenryJammes This has been really helpful! Is there a way of passing a record after clicking an action button?
For example I have an adaptive card with:
{
type: "ActionSet",
actions: ForAll(
Table(ParseJSON(Topic.cdtrOutputs)),
{
type: "Action.Submit",
title: Text(ThisRecord.Value.OutputCode) & " - " & Text(ThisRecord.Value.Title),
data: {cdtrItem: Text(ThisRecord.Value)}
}
)
}
And in my schema:
kind: Record
properties:
actionSubmitId: String
cdtrItem:
type:
kind: Record
But this returns Null for cdtrItem.
The dataset is:
[
{
"OutputId": 5700,
"OutputCode": "2023-WCR-0027",
"Title": "Weekly Report"
},
{
"OutputId": 5698,
"OutputCode": "2023-DCR-0130",
"Title": "Daily Report"
}
]
Great to hear @Anonymous – we plan to create a few MS Learn articles out of these and hopefully they will be easier to follow. Feel free to reach out by private message to share the steps that require more guidance 🙂
Excellent illustration. Despite my nil knowledge on PA, I strived to follow your guide, attempting to induce a "better solution" to my own situation. I finally got it working with numerous trial-and-error in those PA flows/external data source etc.
I had a breakthrough in my learning!
Thank you so much HenryJammes!
PVA unified authoring canvas to display a dynamic adaptive card
In this second answer, I use the unified authoring canvas to provide an example on how to present a chatbot user with an adaptive card that contains dynamic content that is retrieved from an external data source. I use Dataverse in this example, but the approach should be similar for any other data source, as I retrieve data with a Power Automate cloud flow and pass the data back to Power Virtual Agents.
In Power Virtual Agents, using the unified authoring canvas:
Before going to Power Automate (to retrieve my data) the first thing I need to do is create and design an adaptive card.
I designed a sample card that looks like this:
The corresponding card JSON payload is:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "️ Our Locations in X"
},
{
"type": "FactSet",
"facts": [
{
"title": "Option A",
"value": "Address 1"
},
{
"title": "Option B",
"value": "Address 2"
}
]
},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": " Open for more details",
"wrap": true,
"size": "Default",
"weight": "Bolder",
"color": "Accent",
"isSubtle": false
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"title": " Option A",
"url": "https://www.bing.com/search?q=Option A"
},
{
"type": "Action.OpenUrl",
"title": " Option B",
"url": "https://www.bing.com/search?q=Option B"
}
],
"spacing": "None",
"separator": true
},
{
"type": "TextBlock",
"text": " Select store",
"wrap": true,
"size": "Default",
"weight": "Bolder",
"color": "Accent",
"isSubtle": false,
"horizontalAlignment": "Left",
"spacing": "Large"
}
],
"spacing": "Large"
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": " Option A",
"id": "A",
"data": "Option A"
},
{
"type": "Action.Submit",
"title": " Option B",
"id": "B",
"data": "Option B"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3"
}
To make the adaptive card dynamic, I use Power Automate to provide the various JSON arrays my card needs in the expected format. Because I have 3 datasets that are slighthly different, I create 3 array variables in my cloud flow: "List Of Accounts" for the FactSet, "List Of Accounts Actions" for the first ActionSet, and "List Of Accounts Actions Submit" for the second Action Set.
From my topic in Power Virtual Agents:
In Power Automate:
Now I need to use the data returned from my query to build the various variables I want to pass back to Power Virtual Agents and to my adaptive cards in Bot Framework Composer:
Back in Power Virtual Agents:
Under "All other conditions", I add:
{
type: "AdaptiveCard",
body: [
{
type: "TextBlock",
size: "Medium",
weight: "Bolder",
text: "🗺️ Our Locations in " & Topic.UserCity
},
{
type: "FactSet",
facts: ForAll(
Table(ParseJSON(Topic.ListOfAccounts)),
{
title: Text(ThisRecord.Value.title),
value: Text(ThisRecord.Value.value)
}
)
},
{
type: "Container",
items: [
{
type: "TextBlock",
text: "🔎 Open for more details",
wrap: true,
size: "Default",
weight: "Bolder",
color: "Accent",
isSubtle: false
},
{
type: "ActionSet",
actions: ForAll(
Table(ParseJSON(Topic.ListOfAccountsActions)),
{
type: Text(ThisRecord.Value.type),
title: Text(ThisRecord.Value.title),
url: Text(ThisRecord.Value.url)
}
),
spacing: "None",
separator: true
},
{
type: "TextBlock",
text: "👆 Select store",
wrap: true,
size: "Default",
weight: "Bolder",
color: "Accent",
isSubtle: false,
horizontalAlignment: "Left",
spacing: "Large"
}
],
spacing: "Large"
},
{
type: "ActionSet",
actions: ForAll(
Table(ParseJSON(Topic.ListOfAccountsActionsSubmit)),
{
type: Text(ThisRecord.Value.type),
title: Text(ThisRecord.Value.title),
id: Text(ThisRecord.Value.id),
data: Text(ThisRecord.Value.data)
}
)
}
],
'$schema': "http://adaptivecards.io/schemas/adaptive-card.json",
version: "1.3"
}
I then can:
And that's it.
The adaptive card with dynamic content is presented to the user:
PVA + Bot Framework Composer to display a dynamic adaptive card
For this example, I will use the current version of Power Virtual Agents that's extensible with the Bot Framework Composer. I will provide an example on how to present a chatbot user with an adaptive card that contains dynamic content that is retrieved from an external data source. I use Dataverse in this example, but the approach should be similar for any other data source, as I retrieve data with a Power Automate cloud flow and pass the data back to Power Virtual Agents.
In my scenario, I start in Power Virtual Agents:
Before going to Power Automate (to retrieve my data) or in Bot Framework Composer (to enrich my dialog with an adaptive card), the first thing I need to do is create and design an adaptive card.
I designed a sample card that looks like this:
The corresponding card JSON payload is:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "️ Our Locations in X"
},
{
"type": "FactSet",
"facts": [
{
"title": "Option A",
"value": "Address 1"
},
{
"title": "Option B",
"value": "Address 2"
}
]
},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": " Open for more details",
"wrap": true,
"size": "Default",
"weight": "Bolder",
"color": "Accent",
"isSubtle": false
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"title": " Option A",
"url": "https://www.bing.com/search?q=Option A"
},
{
"type": "Action.OpenUrl",
"title": " Option B",
"url": "https://www.bing.com/search?q=Option B"
}
],
"spacing": "None",
"separator": true
},
{
"type": "TextBlock",
"text": " Select store",
"wrap": true,
"size": "Default",
"weight": "Bolder",
"color": "Accent",
"isSubtle": false,
"horizontalAlignment": "Left",
"spacing": "Large"
}
],
"spacing": "Large"
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": " Option A",
"id": "A",
"data": "Option A"
},
{
"type": "Action.Submit",
"title": " Option B",
"id": "B",
"data": "Option B"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3"
}
To make the adaptive card dynamic, I will use Power Automate to provide the various JSON arrays my card needs in the expected format. Because I have 3 datasets that are slighthly different, I will create 3 array variables in my cloud flow: "List Of Accounts" for the FactSet, "List Of Accounts Actions" for the first ActionSet, and "List Of Accounts Actions Submit" for the second Action Set.
From my topic in Power Virtual Agents:
In Power Automate:
Now I need to use the data returned from my query to build the various variables I want to pass back to Power Virtual Agents and to my adaptive cards in Bot Framework Composer:
Back in Power Virtual Agents:
I'm now going to move over to the Bot Framework Composer.
In Bot Framework Composer:
Example:
- ```{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "️ Our Locations in ${virtualagent.UserCity}"
},
{
"type": "FactSet",
"facts": ${virtualagent.ListOfAccounts}
},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": " Open for more details",
"wrap": true,
"size": "Default",
"weight": "Bolder",
"color": "Accent",
"isSubtle": false
},
{
"type": "ActionSet",
"actions": ${virtualagent.ListOfAccountsActions},
"spacing": "None",
"separator": true
},
{
"type": "TextBlock",
"text": " Select store",
"wrap": true,
"size": "Default",
"weight": "Bolder",
"color": "Accent",
"isSubtle": false,
"horizontalAlignment": "Left",
"spacing": "Large"
}
],
"spacing": "Large"
},
{
"type": "ActionSet",
"actions": ${virtualagent.ListOfAccountsActionsSubmit}
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3"
}```
I return to my Power Virtual Agents "Store Locations" topic, and under "All other conditions", I add:
And that's it.
The adaptive card with dynamic content is presented to the user:
Good-day
My bot behaves unexpectedly, sustaining the state of the first call of Array and didn't get through. I reviewed quite many times and had no clue. Appreciate any insight given.
Details:
1. created a PVC topic, called Main menu, redirect to a BFC dialog called BFCmainMenu
2. created a BFC dialog, called BFCmainMenu, with:
3. The branching dialog BFCbranchMenu mentioned at last bullet point above eventually redirect to a PVC topic
4. The abovementioned PVC topic eventually redirect to BFCmainMenu
However, chatbot does not display the main-Menu anymore, instead it displays the branch-Menu.
I am trying the same and the only way I can think of is (if the list of items is dynamic), call Power Automate and have Power Automate generate a adaptive card with buttons. Although adaptive cards support templating / data mapping, I am not able to find a way to map buttons to a list, so right now I am composing the card json and sending that into a "Post adaptive card to MS Teams and wait for response" action. That's for teams though, but if you want generic multiple choice, then have you seen this? https://learn.microsoft.com/en-us/composer/how-to-ask-for-user-input?tabs=v2x
Thanks!