-1

I'm trying to create a water fall model with the help of Adaptive cards in C# version 4.0. My scenario is like following:

On loading bot following cards will be shown: 1. SharePoint 2. Azure 3. O365

Once I click on any of them then new set of cards will be shown like: On selecting "SharePoint" following cards will be shown: 1. Create a Site 2. Create a sub site.

and on selecting any of the above choices a form is called with set of questions like: 1. what is site title 2. site owner and so on..

UI as shown below:

enter image description here

I tried creating the structure on https://adaptivecards.io/, but couldnt find any relevant code related to this type of scenario.

If any one has done it before please share the documentation or code snippet.

Thanks

user64870
  • 47
  • 5

1 Answers1

1

Here's a basic card with Input.ChoiceSet:

enter image description here

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "Input.ChoiceSet",
                    "id": "first",
                    "placeholder": "Placeholder text",
                    "choices": [
                        {
                            "title": "SharePoint",
                            "value": "SharePoint"
                        },
                        {
                            "title": "Azure",
                            "value": "Azure"
                        },
                        {
                            "title": "O365",
                            "value": "O365"
                        }
                    ],
                    "style": "expanded"
                }
            ]
        }
    ],
    "actions": [
      {
          "type": "Action.Submit",
          "title": "Submit"
      }  
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0"
}

Then, in your bot, follow these answers for dealing with User Input:

Basically, you'll want to:

  1. Send the card

  2. Capture the card's input by sending a blank text prompt right after sending the card (as explained in the first link)

  3. Use if or switch statements in the next step to determine which card to display next based off of the user's input. You could optionally create the card more dynamically using the second link


The AdaptiveCards Designer is pretty good, but it lacks the ability to set the actions property. You can do so manually, by adding (like I did above):

"actions": [
      {
          "type": "Action.Submit",
          "title": "Submit"
      }  
    ],

Using Images

If you'd like to use images instead of a ChoiceSet, you can do something like this:

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "Image",
                    "id": "choice1",
                    "selectAction": {
                        "type": "Action.Submit",
                        "title": "choice1",
                        "data": {
                            "choice": 1
                        }
                    },
                    "url": "https://acuvate.com/wp-content/uploads/2017/02/Microsoft-Botframework.fw_-thegem-person.png",
                    "altText": ""
                },
                {
                    "type": "Image",
                    "id": "choice2",
                    "selectAction": {
                        "type": "Action.Submit",
                        "title": "choice2",
                        "data": {
                            "choice": 2
                        }
                    },
                    "url": "https://acuvate.com/wp-content/uploads/2017/02/Microsoft-Botframework.fw_-thegem-person.png",
                    "altText": ""
                },
                {
                    "type": "Image",
                    "id": "choice3",
                    "selectAction": {
                        "type": "Action.Submit",
                        "title": "choice3",
                        "data": {
                            "choice": 3
                        }
                    },
                    "url": "https://acuvate.com/wp-content/uploads/2017/02/Microsoft-Botframework.fw_-thegem-person.png",
                    "altText": ""
                }
            ]
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0"
}

The important part is making sure that the Action.Submit:

  1. Is on the image
  2. Has data that you would use to capture which choice the user selected
mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • Thanks for your reply, I have edited the question and have uploaded an image. Is it possible to get that kind of UI instead of Choice set and on click of these get a new card similar to the above mentioned card. – user64870 Jun 14 '19 at 10:52
  • @user64870 You sure can! I updated the answer; it's at the end. Note: I just used the same image for a quick mockup. You can definitely use different ones and you can set the `data` to be anything you want. – mdrichardson Jun 14 '19 at 14:58
  • and then on the based on data selection i can call a new json with different cards.. right? – user64870 Jun 15 '19 at 13:47