Adaptive Cards Guide

A code-free environment to design and build new directives. This easy-to-use interface will let you build engaging cards, for your chatbots, using drag and drop elements and customizable properties.

 

Why Adaptive cards?

Our goal is to provide you with all the necessary tools and packages that will help you develop visually attractive and engaging content for your chatbot. A step forward in this direction is the introduction of Adaptive Cards.

Using Adaptive Cards you can design intuitive and appealing cards for your chatbot that are not feasible with the traditional directives.

For example, you can create a date range picker, an amelioration of Orbita’s existing date picker directive.

Orbita’s Adaptive Cards

If you have a Sample design in mind, you can create an Adaptive card from scratch. Else, you can get started with any of the sample cards from https://adaptivecards.io/samples/ and tweak them to your liking.

You will find the adaptive cards at Experience Manager > Project > Side Menu > Hierarchy icon > Adaptive cards.

Click on the plus icon at the bottom of the page to create a new Adaptive Card.

Give a Title and Description to the card you are about to create.

You will land on the Adaptive Cards designer. It contains:

  1. Elements Palette - All the basic elements to create an attractive card for your chatbot.

  2. Canvas - You will drag and drop the elements from the Elements Palette to the Canvas. This is where you will design your card.

  3. Element Properties - Each element have customizable properties. You can edit them here.

  4. Custom Data Editor - You can set dynamic data content here and use them in the Elements.

  5. Card Payload Editor - The Final JSON code of the card you designed. This payload can be copied to the msg.payload.orbita.directive array in a function node to use the card in the Experience Designer.

Exporting and Importing an Adaptive card

Export

To export an Adaptive card, use the vertical ellipses against the Adaptive card you would like to export.

Click on the Export tab and then the Copy to Clipboard button.

Import

To import an Adaptive card, follow the steps above to export the code.

  1. Create a new Adaptive card.

  2. Click on the vertical ellipses button and select Import/export

  3. Select the Import tab, paste the code, and click on Import.

Using Adaptive Cards in Experience Designer

There are two ways to use Adaptive Cards in Experience Designer.

  1. Using Adaptive Card node. (Refer to Adaptive Card node documentation)

  2. Using the Card Payload code as a directive in a function node.

Using the Adaptive card node

Add an Adaptive Card node to the flow.

In the Adaptive Card node, select the Card you want to display.

Invoke the intent in the Chatbot.

Using the Card Payload

If you want to add additional functionality to the card such as invoking an intent after one card is submitted, you can do it by using the Card Payload as a directive in a function node.

Add a function node to the flow.

Add the below code to the function node.

if(!msg.payload.orbita) { msg.payload.orbita = {}; } if(!msg.payload.orbita.directive) { msg.payload.orbita.directive = []; } msg.payload.orbita.directive.push( { "type": "adaptivecard", "template": { //*****Paste the code from Card Payload Editor***** }, "templateData": { //*****Paste the code from Custom Data Editor***** }, "hostAppName": { "name": "default" } })

When using the Card in the function node. Make sure that the code contains the below four objects in msg.payload.orbita.directive array

  1. type - Should be the directive type. Here, it is adaptivecard.

  2. template - The code from Card Payload Editor.

  3. templateData - The code from Custom Data Editor.

  4. hostAppName - It should contain the name property with value default

Getting the template and templateData properties

You can get the template code from the Adaptive Cards Designer > Card Payload Editor.

Paste the code inside the template object in the function node.

You can get the templateData code from the Adaptive Cards Designer > Custom Data Editor.

Paste the code inside the templateData object in the function node.

Invoking an intent after an Action

In the Function node, find the Function node, find Actions property, and add the below code to it.

"data": { "message": "Thankyou for Selecting a Date Range", "eventName": "A-Wrong" }

Add the same event name to the Intent you want to fire after the Action.

Clicking on the submit button of the card in the chatbot will give the message from the data object and trigger the intent that contains the eventName.

Customizing Adaptive Cards

You can modify some of the properties of the Adaptive Cards elements by adding a function node after the directive or the Adaptive card node (Sample flow attached).

For example,

  1. You can set a range for the chatbot user to pick the dates from.

    You can restrict the user to select dates only between 16 Oct 2020 to 30 Oct 2020 as shown in the above card.

  2. You can set the date fields to have dynamic placeholder dates.

    You can display the date fields based on today’s date dynamically.

Callback functions

You can give success and error callback functions for the buttons on Adaptive cards.

In the Experience Designer, connect a function node to the Adaptive card node as shown in the screenshot.

Place the below code in the callback functions function node to replace the Actions object and execute the callback functions.

var _ = global.get('lodash'); var index = _.findIndex(msg.payload.orbita.directive, { type: 'adaptivecard'}); var adaptiveCard = _.find(msg.payload.orbita.directive, { type: 'adaptivecard'}); adaptiveCard.template.actions = [ { "type": "Action.Submit", "title": "Login", "style": "positive", "data": { "serviceCall": { "url": "https://sandbox5.orbita.cloud:8443/api/login", "type": 'POST', "orbitaAction": 'login', "successCallback": "function (data, status, xhr) {console.log(data,status,xhr,cardId); orbitaChatBot.init({logincompleted: true, token: data.token}); window.submitQuery('thank you')}", "errorCallback": "function(xhr,status, error){var card = document.getElementById(cardId); var image = card.getElementsByTagName('img'); $(image[0].parentElement).after(`<span style='text-align: center; padding:5px; color:red'> Invalid input </span>`);}" } } } ] msg.payload.orbita.directive[index] = adaptiveCard; return msg;

In this example, clicking on the button will call the login API.
successCallback: If the login is successful, the thankyou utterance is passed.
errorCallback: If the login is unsuccessful, the text “Invalid Input“ in red color will be shown on the Adaptive card.

You can use the success and error callbacks to execute your custom logic.

Host configuration

Using the host config, you can define common styles such as font family, font sizes, default spacing, and so on to all your adaptive cards within the environment.

You can access host config from the Global menu > Organization > Application Settings.

You will see a preview of the adaptive card on the host config page

Sample host config code

Sample CSS

Please refer to the Microsoft Adaptive Card Documentation for more information on the Elements and their properties.

  File Modified

File Adaptive_Card_flow.json

Oct 23, 2020 by Rajkiran Alla (Deactivated)

File Date_Picker_Card.json

Oct 23, 2020 by Rajkiran Alla (Deactivated)

Related Articles