Ali Almahdi

Ali Almahdi

  • NA
  • 9
  • 2.7k

How can I retrieve and capture Adaptive card action.submit

Apr 8 2019 2:24 AM
I have created a LUIS Template Bot Application (Version 3) and I need to capture the output of an Adaptive Card drop down list. I am currently able to create and render the drop down list but facing difficulty capturing the result once the button is clicked. Can you please give me a solution or give link to appropriate tutorial for version 3 as resources for this issue is mostly for version 4.
 
  1. public Attachment PolicyAdaptiveCard() {  
  2.  var card = new AdaptiveCard();  
  3.  var choices = new List < AdaptiveChoice > ();  
  4.  choices.Add(new AdaptiveChoice() {  
  5.   Title = "Category 1", Value = "c1"  
  6.  });  
  7.  choices.Add(new AdaptiveChoice() {  
  8.   Title = "Category 2", Value = "c2"  
  9.  });  
  10.  var choiceSet = new AdaptiveChoiceSetInput() {  
  11.   IsMultiSelect = false, Choices = choices, Style = AdaptiveChoiceInputStyle.Compact, Id = "Category"  
  12.  };  
  13.  card.Body.Add(choiceSet);  
  14.  card.Actions.Add(new AdaptiveSubmitAction() {  
  15.   Title = "Select Category", Data = Newtonsoft.Json.Linq.JObject.FromObject(new {  
  16.    button = "select"  
  17.   })  
  18.  });  
  19.  Attachment attachment = new Attachment() {  
  20.   ContentType = AdaptiveCard.ContentType, Content = card, Name = $ "Card"  
  21.  };  
  22.  return attachment;  
  23. }  
This is JSON output that I am capturing in Bot Emmulator
  1. {  
  2. "channelData":{  
  3. "clientActivityID":"15547009411880.yfus2yy2mao",  
  4. "postBack":true  
  5. },  
  6. "channelId":"emulator",  
  7. "conversation":{  
  8. "id":"3f50f7c1-59be-11e9-98bd-17dcaa70e8d3|livechat"  
  9. },  
  10. "from":{  
  11. "id":"r_tckd4zoa8h",  
  12. "name":"User",  
  13. "role":"user"  
  14. },  
  15. "id":"48d27080-59be-11e9-93ff-a77a4eb2d000",  
  16. "localTimestamp":"2019-04-08T08:22:21+03:00",  
  17. "locale":"en-US",  
  18. "recipient":{  
  19. "id":"97e06f60-496a-11e9-9541-3d37a55e03cc",  
  20. "name":"Bot",  
  21. "role":"bot"  
  22. },  
  23. "serviceUrl":"http://localhost:56373",  
  24. "showInInspector":true,  
  25. "timestamp":"2019-04-08T05:22:21.192Z",  
  26. "type":"message",  
  27. "value":{  
  28. "Category":"c1",  
  29. "button":"select"  
  30. }  
  31. }  
How can I read the value and output "c1" in the next method ? This is the code that I am following. Can you please give me the method I can use to capture the category value
  1. var reply = context.MakeMessage();  
  2. var activityValue = context.Activity.AsMessageActivity().Value as Newtonsoft.Json.Linq.JObject;  
  3. if (activityValue != null) {  
  4.  var categorySelection = activityValue.ToObject < CategorySelection > ();  
  5.  var category = categorySelection.Category;  
  6.  await context.PostAsync(reply);  
  7. }

Answers (2)