3

I would like to return an Adaptive card via SendActivity in an Adaptive Dialog.

The code to do this looks like:

new OnIntent("Help")
{
    Actions = new List<Dialog>()
    {
        new SendActivity("${Help-Root-Dialog()}")
    }
},

But, I'd like to include a parameter in the call to create the adaptive card. Let's say a username (and therefore personalize the message to the user. Is there a way this can be done?

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
Irwin
  • 12,551
  • 11
  • 67
  • 97
  • OK, as I've read more in the space, I've learnt I can use SetProperty() to provide a property I want the adaptive card to show and then reference that property in the card's definition. Literally, $(user.name) for example. – Irwin Apr 26 '20 at 20:30
  • Would you like to post this as an answer? – Kyle Delaney Apr 27 '20 at 16:59
  • While looking at the "AdaptorWithErrorHandler" middleware, stumbled upon this: // Send a catch-all apology to the user. await turnContext.SendActivityAsync(ActivityFactory.FromObject( _templates.Evaluate("SomethingWentWrong", exception))); Which is passing a param into the template specified by language generator. This might be it! – Irwin Apr 29 '20 at 08:22
  • I don't understand how that's related to your question. Are you saying you still need help? – Kyle Delaney Apr 29 '20 at 17:38
  • Will put an answer based on what I've seen. – Irwin Apr 30 '20 at 07:52

1 Answers1

0

Found a few ways to do this:

  1. Use SetProperty before the card is invoked in the conversation
new SetProperty()
{
    Property = "conversation.gameCreateDate",
    Value = DateTime.Now.ToString()
},

new SendActivity("${PlayGameCard()}"),
//In .lg file:
# PlayGameCard
[Activity
    Attachments = ${json(AdaptiveCard.Definition())}
]

//...
{
    "type": "TextBlock",
    "spacing": "None",
    "text": "Created ${conversation.gameCreateDate}",
    "isSubtle": true,
    "wrap": true
}
//...
  1. Send a parameter when calling the card, as is done in the AdaptorWithErrorHandler middleware.
await turnContext.SendActivityAsync(ActivityFactory.FromObject( _templates.Evaluate("SomethingWentWrong", exception)));

I used option 1, but 2 seems to be the way.

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
Irwin
  • 12,551
  • 11
  • 67
  • 97