How do I use both Data and DataJson property of AdaptiveSubmitAction in Webchat channel

60 Views Asked by At

I am using Adaptive Card SDK in Microsoft Bot Framework for Webchat. Code for my adaptive card submit button looks like :

var action_nothanks = new AdaptiveSubmitAction
{
Title = "No, Thanks",
Type = "Action.Submit",
DataJson = "{ \"action\":\"" + "No,Thanks" + ":" + "false" + "\"}"
};

This doesn't display the user selected value until I use "Data" property instead of "DataJson". But, I want to use as following:

var action_nothanks = new AdaptiveSubmitAction
{
Title = "No, Thanks",
Type = "Action.Submit",
Data = "No, Thanks",
DataJson = "{ \"action\":\"" + "No,Thanks" + ":" + "false" + "\"}"
};

So that user selected value is displayed as "No, Thanks" while bot is returned "false".

1

There are 1 best solutions below

0
Rishabh Meshram On

One of the possible solution is by adding the displayText andaction properties from the Data object. Below is the modified AdaptiveSubmitAction code :

var action_nothanks = new AdaptiveSubmitAction
{
    Title = "No, Thanks",
    Type = "Action.Submit",
    Data = new { displayText = "No, Thanks", action = "No,Thanks:false" }
};

With a sample bot code, I was able to get both the properties from the data object.

So, when you receive the submitted action, The user-selected value will be displayed as "No, Thanks", while the bot will receive the "false" value. enter image description here

Bot is created with Echo Bot Sample and modified with required AdaptiveCards code snippet.