Azure Bot Services: Using Adaptive Cards

Adaptive Cards enables you to render rich content that the user can interact with channels like Microsoft Teams. When the user interacts with an action on an Adaptive Card, their input will be sent to your Flow and it is accessible in ci.data.request.value

Triggering NLU for Card Actions

If you for instance ask the user to pick a date, then you might want the selected date to be parsed using Cognigy NLU so that you can use our DATE Slot. To enable NLU parsing of certain fields in an Adaptive Card, you need to prefix the id of the field with cognigy_.

Example:

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "text": "Default text input"
    },
    {
      "type": "Input.Text",
      "id": "cognigy_input1",
      "placeholder": "enter comment",
      "maxLength": 500
    },
    {
      "type": "TextBlock",
      "text": "Multiline text input"
    },
    {
      "type": "Input.Text",
      "id": "cognigy_input2",
      "placeholder": "enter comment",
      "maxLength": 500,
      "isMultiline": true
    },
    {
      "type": "TextBlock",
      "text": "Pre-filled value"
    },
    {
      "type": "Input.Text",
      "id": "input3",
      "placeholder": "enter comment",
      "maxLength": 500,
      "isMultiline": true,
      "value": "This value was pre-filled"
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "OK"
    }
  ]
}

In the example above, a card with three text fields will be rendered. Since the ids of the first two text field is set to cognigy_input1and cognigy_input2 the value of these fields will be added to ci.text in your Flow and will therefore be parsed with our NLU. You can therefore e.g. trigger an intent or slots based on the value of the two first input fields in the Adaptive Card above.

Using Postbacks with Adaptive cards

You can also use postback buttons on your Adaptive Cards and have them send pre-configured data to your Flow, which can even be parsed by our NLU. In the example below, an Adaptive Card to create a user in Hubspot with two buttons is created - one button to confirm creating an account for the user and one button to decline. In order to send the information of which button the user clicked to your Flow, you can add the key cognigy_postback to the data object of the Action.Submit with an appropriate value. In the example below, clicking on the confirm button will send the text "yes" to your flow, and clicking the decline button will send the text "no" to your Flow. You can combine this functionality with the Trigger Intent to manually trigger an intent in your Flow after a postback button is clicked on an Adaptive Card.

{
  "type": "AdaptiveCard",
  "body": [
    {
      "type": "Image",
      "style": "default",
      "url": "https://sharpspring.com/wp-content/uploads/2017/12/hubspot-400x200.png",
      "size": "Large"
    },
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "text": "We found a user matching the email address {{cc.user.email}} in Hubspot CRM!\n\n",
              "wrap": true
            },
            {
              "type": "FactSet",
              "facts": [
                {
                  "title": "Firstname:",
                  "value": "{{cc.hubspot.properties.firstname.value}}"
                },
                {
                  "title": "Lastname:",
                  "value": "{{cc.hubspot.properties.lastname.value}}"
                },
                {
                  "title": "Company:",
                  "value": "{{cc.hubspot.properties.company.value}}"
                }
              ]
            },
            {
              "type": "TextBlock",
              "text": "Do you want to create an account for this user?\n\n",
              "wrap": true
            }
          ],
          "width": "stretch"
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Yes please",
      "data": {
        "id": "_qkQW8dJlUeLVi7ZMEzYVw",
        "cognigy_postback": "yes"
      }
    },
    {
      "type": "Action.Submit",
      "title": "No, a different user",
      "data": {
        "id": "_qkQW8dJlUeLVi7ZMEzYVw",
        "cognigy_postback": "no"
      }
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.0"
}

Link: Adaptive Card Designer

Limitations

  • Different implementations are required depending on endpoint

    • In Cognigy's Agent space the containers for the Adaptive Card JSON differs slightly and requires slightly different implementations.  This means when creating nodes to house the adaptive card content you may need to add separate channels.
      mceclip0.png

  • Response handling may differ based on endpoint.

    • Responses vary slightly when a user submits a card depending on endpoint so handling responses requires slight adjustments per endpoint.

      Teams response comes through in the object input.data.request.value

      Web response comes through in the object input.data.adaptivecards

  • Styling and features may be limited depending on the endpoint

    • As an example button types may show different colors depending on how the endpoint renders the json. If a brand wants strict control over looks Adaptive Cards might not be for them.

Debugging

  • Check for invalid elements like extra commas, Teams unlike some other endpoints will fail to render invalid Adaptive Card JSON.
  • Adding backgroundImage attributes like the following will cause Teams to fail to render an Adaptive Card

    "backgroundImage": { "verticalAlignment": "Bottom"}
  • Using the wrong container for the wrong endpoint can cause issues.  For instance mixing the web and teams container json can cause issues.  

Comments

13 comments

  • Dear Cognigy Team,

    Could you please update how do we collect the value like a date in Cognigy flow like from a date picker in an Adaptive card.

     

    3
  • Dear Cognigy Team,

    The current documentation doesn't have much on how the user input appears when user submits the data. Could you please point to some sample of capture of the inputs from adaptive cards?

    3
  • Hi Cognigy Team,

    Could you help me understand what the "id" represents in your example for Action Submit, above, please?

    e.g.

     { "type": "Action.Submit", "title": "Yes please", "data": { "id": "_qkQW8dJlUeLVi7ZMEzYVw", "cognigy_postback": "yes" }

    1
  • Hi Graham,

    The ID is another parameter, which will be attached to the submitted data together with cognigy_postback. If you don't need it in your design, feel free to try the adaptivecard without it.

    0
  • Dear Cognigy team, Can I use adaptive cards in WhatsApp I guess using transformers ? If so, is this documented somewhere ?

    0
  • Hi Simon,

     

    No, you can't use adaptive cards with WhatsApp as channel because WhatsApp would not render adaptivecards. You can check WhatsApp API documentation for supported message types.

    0
  • The data block that comes back via Teams just has the "microsoftSsoToken" and "microsoftSsoPermissionRequest" fields. When going through webchat, I get both "input.data.request.value" and "input.data.adaptivecards". I'm trying to use an adaptive card that has a drop down of choices (Input.ChoiceSet) for numeric values and a text field (Input.Text) for text. Trying to have the user select a rating and provide additional feedback. The only way to get that input back via teams is to use "cognigy_" for the two ID fields, but then it goes to slots and tokens and Cognigy is trying to process that in the NLU. With or without "cognigy_", the IDs are nowhere to be found in the input. The ID fields themselves are lost.

    0
  • We really just need to get the two fields back, the user's rating and optional feedback. What they provide here does not need to be processed by the NLU, but we can't get anything back without "cognigy_" in front of id value.

     

    0
  • This is how the answers only prefixed with "cognigy_" come back in Teams:

     

    This particular adaptive card has 3 checkboxes and 4 text fields. One checkbox has "cognigy_" prefixed on ID and comes back only as "true". So we're not even sure which checkbox they've checked if the answer is The only things that come from {{input.data}} are SSO-related. The article above says it should come back as {{input.data.request.value}} in Teams. Similarly, the same SSO items come back in {{input.result.value}}. Either way, neither are what the article claims.

    Data tagged as "cognigy_" in the "id" field come back in the {{input.result.answer}}, but this won't work with multiple text inputs as you won't know where one stops and the next one starts. The "ticketSubmitted" was put on the "id" field of the Submit button for a different use case so we know a user interacted with the card.

    Ideally the ID fields also come back with the data so we know what is what. otherwise, there's no point in an ID field. If an "ID" doesn't have "cognigy_" in front of it, it doesn't come back at all. If it does, then it is processed through NLU. We don't need a user's ticket description be handled by the NLU, just need to pass it through to some ITSM. 

    We really need some support on this. No one has responded to my previous comments from almost a month ago. Please advise.

    0
  • Data comes back via webchat perfectly:

     

    Mirroring this response for Teams is the goal. Maybe we're am setting something up incorrectly. But we've tried say and question nodes as adaptive cards set to text, data, custom, etc. Added Microsoft Bot Framework and Teams channels with adaptive cards instead of the default AI, etc. At a loss with Teams.

    0
  • The data does come through in debug, strangely enough:

    0
  • Hi Paul,

    I would like to help, but I could not reproduce the issue. I created an Azure Bot, connected it to Cognigy and tested both in Webchat and in Teams. I have also put together an adaptive card form with a dropdown. Both in the webchat and in Teams through Azure Bot Cognigy endpoint, I received all submitted values from the adaptive card.

    Can I take a look at your setup? We can have a call about this in the following days. Joseph Pelicano can arrange it.

    Looking forward to talking to you,
    Anton Trukhanyonok | Solutions Architect at Cognigy

    1
  • For posterity, Anton was able to help us out by adding 

    const data = { request: request.body }
     
    to our transformer. We were overwriting the data with 
     
    const data = { }
     
    Thanks!
    0

Please sign in to leave a comment.

Was this article helpful?
1 out of 3 found this helpful