George Rov
George Rov

Reputation: 46

Prompt the user for missing entities while in the intent and wait till they respond

I've been trying to solve this, I imagine it may be quite easy but I just can't find a way to achieve it yet.

I have a very simple Luis Intent as follows:

[LuisIntent("xxx")]
public async Task xxx(IDialogContext context, LuisResult result)
{
    var entities = new List<EntityRecommendation>(result.Entities);
    //do stuff eg. Prompt.Text(contenxt, "Enter your name");
    //await prompt
    //store new response into the variable
}

What I want to achieve is to prompt the user for any missing entities in their query and save it for later use in this intent. The problem is the intent does not await for the user to respond and just continues execution as normal.

What am I missing on this one?

Thanks in advance.

Upvotes: 0

Views: 252

Answers (2)

Mandar Dharmadhikari
Mandar Dharmadhikari

Reputation: 129

I think the easiest way for you is to use a form to collect the data from the user before hand. This will have following advantages 1) You will get all the mandatory data before hand which grants you a strong control over the conversation 2) Your number of calls to the LUIS app will be less as compared to what you will end up doing if you request user to add entity every time they miss it. Please believe me, saving number of LUIS will end up saving some money for you in the long run. So use a form flow to gather the data from the user before hand. I have added following links to help you get acquainted with the concept of form flow

https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-formflow-advanced?view=azure-bot-service-3.0
https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-formflow?view=azure-bot-service-3.0 https://www.c-sharpcorner.com/article/formflow-in-bot-framework/

Upvotes: 2

Ed Boykin
Ed Boykin

Reputation: 831

You need to call a new dialog to prompt for the rest of the entities. I would use a FormFlow dialog based on all the entities you are trying to capture. Basically, you want to assume none of you entities come through on the Luis intent, this way you can prompt the user for everything. So, with FormFlow, you can specify the initial state of the FromFlow. To do this, create an instance and fill in the properties with the entites you did receive. FormFlow will skip steps for any of the fields that are already populated. Optionally, when you launch you FormDialog, you can pass in 'FormOptions.PromptFieldsWithValues'. This will tell the dialog to still prompt the user for ALL values but will use the filled in value as the default. You would do this if you wanted to give the user the option of changing something.

Here's a basic example I pulled from github.

This is the class that defines your state. You would build this based on the entities you want to receive

public class SampleQuestion
{
    public string FavoriteColor;
    public string FavoritePizza;
}

This is a generic dialog method but it would be what your intent method would kind of look like

    async Task StartAsync(IDialogContext context)
    {
        var question = new SampleQuestion();

        // Pre-populate a field. This is where you fill in with the entities you got from LUIS
        question.FavoriteColor = "blue";

       //Now call FormBuilder to ask the user for the remaining entities
        context.Call<SampleQuestion>(new FormDialog<SampleQuestion>(question), OnSampleQuestionAnswered);
    }

    //this is the return from you FormBuilder. This is where you get back into you LUIS dialog and continue processing with, hopefully, all the entities you need now
    public async Task OnSampleQuestionAnswered(IDialogContext context, IAwaitable<SampleQuestion> sampleQuestion)
    {
        var result = await sampleQuestion;
    }

Hope this helps.

Upvotes: 2

Related Questions