3
votes

Im trying to integrate Luis with botframework. From what i see (p/s. still new on this), Luis handle the response based on the text input of the user. So when im trying to use Adaptive Card Submit Button action, i can set the value but not the text value. Even if i use dataJson on submit button, it still produce null error. Im still confuse on how to approach this. Code is as follows:

LuisIntent("Greet.Welcome")]
    public async Task QueryGPN(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult luisResult)
    {
        AdaptiveCard gpnCard = new AdaptiveCard();

        gpnCard.Body.Add(new TextBlock()
        {
            Text = "GPN Lookup Form",
            Size = TextSize.Large,
            Weight = TextWeight.Bolder
        });

        TextInput gpnInput = new TextInput()
        {
            Id = "GPN",
            IsMultiline = false
        };

        gpnCard.Body.Add(gpnInput);

        gpnCard.Actions.Add(new SubmitAction()
        {
            Title = "Submit"
        });

        Attachment gpnCardAttachment = new Attachment()
        {
            ContentType = AdaptiveCard.ContentType,
            Content = gpnCard
        };

        IMessageActivity gpnFormMessage = context.MakeMessage();
        gpnFormMessage.Attachments = new List<Attachment>();
        gpnFormMessage.Attachments.Add(gpnCardAttachment);

        await context.PostAsync(gpnFormMessage);
        context.Wait(this.MessageReceived);
    }


[LuisIntent("Curse")]
    public async Task Cursing(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult luisResult)
    {
        Console.WriteLine("Curse");
        await context.PostAsync($"Curse");
        context.Wait(this.MessageReceived);
    }

The situation is i will input curse on the text input and im expecting the bot will redirect to the "Curse" LuisIntent.

TQVM in advanced.

1
It's unclear what you're asking. Could you detail what is your functional case? What do you want to display in your card? It looks like you are mixing thingsNicolas R
Is there a data property on the activity that you receive back after submitting information via the TextInput?Steven G.
I just provided an answer based on my understanding of the scenarioEzequiel Jadib
@NicolasR Its not about the card. The situation is that i will input text into AdaptiveCard textInput and i would like for it to hit one of the Luis Intent. In this situation, I will put curse in it and LuisIntent("Curse") will be hit. I use DataJson property of SubmitAction button and this will fill in the value property of Activity. In my understanding, Luis will not read the value property but text property of Activity so im not getting the hit on LuisIntentArif Sam
@StevenG. Yup. The textInput text is filled in 'Value' property of activity.Arif Sam

1 Answers

4
votes

I think the problem is because you are using a LuisDialog and you are expecting the value sent from the AdaptiveCards's submit action to be used by the dialog as input for LUIS.

The main problem around this is that the value of the submit action is not coming in the (new) activity's Text property and instead it comes in the Value property. I suspect that it's because of that that you are getting a NullReference exception, since the LuisDialog uses that property to extract the value to be sent to LUIS.

The good news is that solving this should be pretty straightforward. Behind the scenes, the LuisDialog calls the GetLuisQueryTextAsync method to extract the text from the IMessageActivity that will be sent to LUIS. This happens on the MessageReceivedAsync method.

So, I believe that by overriding the GetLuisQueryTextAsync method you should be able to update the logic and retrieve the text from the Value property instead of the Text property. Something like:

protected override Task<string> GetLuisQueryTextAsync(IDialogContext context, IMessageActivity message)
{
    if (message.Value != null) 
    {
         dynamic value = message.Value;
         // assuming your DataJson has a type property like :
         // DataJson = "{ \"Type\": \"Curse\" }" 
         string submitType = value.Type.ToString();

         return Task.FromResult(submitType);
    }
    else 
    {
       // no Adaptive Card value, let's call the base
       return base.GetLuisQueryTextAsync(context, message);
    }
}

The above code assummes that your SubmitAction has a DataJson property with a value of "{ \"Type\": \"Curse\" }" but of course, you can update that.

More Resources