Search code examples
c#botframework

How to hit Luis Intent with Adaptive Cards in Microsoft Chatbot .Net Core 2.0


I have some intents set up in LUIS which work perfectly when the bot is asked a question. I want to convert some of these Q&A to an adaptive card. Currently I am able to achieve something like this:

If i click on any of the questions below the reply shows up within the card rather than as a reply from the bot.

This is my JSON (only the relevant part):

  "actions": [
{
  "type": "Action.Submit",
  "title": "About ",
  "data": {
    "action": "about"
  }
},
{
  "type": "Action.ShowCard",
  "title": "FAQs",
  "card": {
    "type": "AdaptiveCard",
    "style": "emphasis",
    "actions": [
      {
        "type": "Action.ShowCard",
        "title": "When are you open?",
        "card": {
          "type": "AdaptiveCard",
          "style": "emphasis",
          "body": [
            {
              "type": "TextBlock",
              "text": "We are open from Monday through Friday from 8:00am to 6:00pm.",
              "wrap": true
            }
          ],
          "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
        }
      },
      {
        "type": "Action.ShowCard",
        "title": "Do you have an office near me? ",
        "card": {
          "type": "AdaptiveCard",
          "style": "emphasis",
          "body": [
            {
              "type": "Image",
              "horizontalAlignment": "Center",
              "url": "https://i.imgur.com/gBVgI25.png",
              "size": "Stretch"
            },
            {
              "type": "TextBlock",
              "text": "AZ, CA, CO, FL, GA, HI, NC, NV, OR, SC, TN, TX, UT, VA & WA",
              "wrap": true
            }
          ],
          "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
        }
      },
      {
        "type": "Action.ShowCard",
        "title": "How quickly can we close? ",
        "card": {
          "type": "AdaptiveCard",
          "style": "emphasis",
          "body": [
            {
              "type": "TextBlock",
              "text": "8 to 10 days, it all depends on how it takes to get access to the property.",
              "wrap": true
            }
          ],
          "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
        }
      }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
  }
}

]

And this is my Code:

 protected async Task<DialogTurnResult> BeginChildDialogAsync(DialogContext dc, OnTurnProperty onTurnProperty)
    {
        var activity = dc.Context.Activity;
        var actionValue = onTurnProperty.Intent;
        switch (onTurnProperty.Intent)
        {

            case "Greeting":
                await dc.Context.SendActivityAsync("Hello there!");
                return new DialogTurnResult(DialogTurnStatus.Empty);
                break;
            case "LendingStates":
                await dc.Context.SendActivityAsync("AZ, CA, CO, FL, GA, HI, NC, NV, OR, SC, TN, TX, UT, VA & WA");
                return new DialogTurnResult(DialogTurnStatus.Empty);
                break;
            case "CloseCase":
                await dc.Context.SendActivityAsync("8 to 10 days, it all depends on how long it takes to get access to the property.");
                return new DialogTurnResult(DialogTurnStatus.Empty);
                break;

            case MenuDialog.Name:
                // todo: need to implement this one
                return await dc.BeginDialogAsync(MenuDialog.Name);

                break;


            break;


            default:
                await dc.Context.SendActivityAsync($"I don't know how to handle the action \"{actionValue}\"");
                return new DialogTurnResult(DialogTurnStatus.Empty);
        }
        return new DialogTurnResult(DialogTurnStatus.Empty);

    }

At this point I am not sure how to change my JSON or code so that if a user clicks on an option on the adaptive card it hits the right Case in my code. If I don't use the card and ask the bot "When are you open?" directly, i get the correct reply.


Solution

  • @B. Lec is correct. You need to use something like:

    "type": "Action.Submit",
        "title": "How quickly can we close?",
        "data": {
        "intent": "CloseCase"
         }
    

    Note: There's really no point in sending "How quickly can we close?" to LUIS. You already know that this should map to the "CloseCase" intent.

    I have an answer to a similar SO question, if you need additional context/help.