0

How do I parse the submit action value in Adaptive cards? I know am somewhere near but unable to resolve it. If I type a text manually, I move forward to the new dialog in the waterfall model

Cards.json

{  
    "type": "AdaptiveCard",
  "body": [
    {
      "type": "TextBlock",
      "id": "textBlock",
      "text": "CREATE AN INCIDENT. "
    },
    {
      "type": "Input.Text",
      "id": "username",
      "placeholder": "Enter your email address"

    },
    {
      "type": "Input.Text",
      "id": "shortdescription",
      "placeholder": "Enter a short description"

    },
    {
      "type": "Input.Number",
      "id": "phonenumber",
      "placeholder": "Enter your phonenumber"

    }

  ],  
    "actions": [  
        {  
            "type": "Action.Submit",  
            "id": "submit",  
            "title": "Submit",  
            "data":{  
                        "action": "mychoices"  

            }  
        }  
    ],  
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",  
    "version": "1.0"  
}  

RequestDialog.cs

var askforSelectionSteps = new WaterfallStep[]
            {
                askForSelection,
                askForSelectionResult,
                CreateTicketFor_InstallSoftware
            };



public async Task<DialogTurnResult> askForSelection(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            _state = new GenericRequestState();
            await _accessor.SetAsync(sc.Context, _state);
            //return await sc.PromptAsync(choiceprompt, new PromptOptions()
            //{
            //    Prompt = MessageFactory.Text("Can you please let me know if the request is for you or someone else?"),
            //    Choices = new List<Choice> { new Choice("MySelf"), new Choice("Someone Else") },
            //    RetryPrompt = MessageFactory.Text("Please enter MySelf or Someone Else."),
            //});
            return await sc.PromptAsync(TextPrompt, new PromptOptions()
            {
                Prompt = CardHelper.GenericRequestIncidentChoices(sc, cancellationToken),
            });
        }
        public async Task<DialogTurnResult> askForSelectionResult(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var isSuccess = sc.Result.ToString().ToLower();
            if (isSuccess == "incident" || isSuccess == "inc")
            {
                //return await sc.BeginDialogAsync(GenericRequestationStep_OneId);
                return await sc.PromptAsync(TextPrompt, new PromptOptions()
                {
                    Prompt = CardHelper.GenericCreateIncident(sc, cancellationToken),
                });


            }}

I have looked into some of the samples and stackoverflow itself but am not able to pass the submit action back to the dialog. Any help would be appreciated!

Progressuntilnow

Sash Sheen
  • 105
  • 2
  • 14

2 Answers2

1
protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
    {
        var value = dc.Context.Activity.Value;

        if (value.GetType() == typeof(JObject))
        {
            var result = await dc.ContinueDialogAsync();
            return;
        }
    }

Have you written the JObject handling in OnEventAsync as above?

And Please see the link

How to retrieve Adaptive Card's form submission in subsequent waterfall step

ContinueDialogAsync does not work when I use the input form of adaptive-cards in the waterfall dialog

SLock
  • 29
  • 11
0

Want to know how to handle JToken? If so, see the code below.

                var token = JToken.Parse(turnContext.Activity.ChannelData.ToString());
                if (token["postBack"].Value<bool>())
                {
                    JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString());
                    var data = commandToken["Your_Data_ID"].Value<Your_Data_Type>();
                }

"Your_Data_ID" is phonenumber, shortdescription, etc... Your_Data_Type is int, string, etc...

SLock
  • 29
  • 11