How to Call Luis intent method programatically and pass data from form flow

269 Views Asked by At

I have a form where i am getting user input. On completion of form i want to trigger luis intent.I have used json to trigger the intent but it gave me data with all the intent instead of triggering the top scoring intent. what are all the possible ways to call luis from c# code

Form code- public static IForm BuildForm() {

        OnCompletionAsyncDelegate<DocumentFormFlow> processDocumentSearch = async (context, Docdata) =>
        {
            string message = "Thanks for using chat bot Please wait while we search your document , Welcome Again !!! :)";
            await context.PostAsync(message);
            string query = "fetch me " + Docdata.ClientName + " " + Docdata.SelectDocument + "document";

//here i want to trigger luis intent method DocumentSearchIntent given below

            };

        return new FormBuilder<DocumentFormFlow>()
                .Message("Welcome to the  Chat bot !")
                .OnCompletion(processDocumentSearch)
                .Build();

}

Luis intent method- [LuisIntent("DocumentSearch")] public async Task DocumentSearchIntent(IDialogContext context, LuisResult result) {

        FilesFound.Clear();
        var msj = context.MakeMessage();
        var clientname = string.Empty;
        var documenttype = string.Empty;
        EntityRecommendation rec;
        if (result.TryFindEntity("ClientName", out rec))
            clientname = rec.Entity;
        if (result.TryFindEntity("DocumentType", out rec))
            documenttype = rec.Entity;
        if (documenttype.Contains("."))
            documenttype = documenttype.Replace(" ", "");

        if (clientname == string.Empty || documenttype == string.Empty)
            msj.Text = "Could you please provide both input for client name and document.";
        else
        {
            DirSearch(path, clientname, documenttype);



            int count = 0;
            do
            {
                if (FilesFound.Count == 0)
                {
                    msj.Text = "No document found for this search";
                    break;
                }

                msj.Text += FilesFound[count].ToString();
                count++;
            } while (count < FilesFound.Count);


        }
        await context.PostAsync(msj);
        context.Wait(MessageReceived);

    }
1

There are 1 best solutions below

0
RohitMungi On

I think this article might help you in using form as per your scenario in the bot framework, You can then call the required intent method based on the top scoring intent returned. I think this article might be useful for you to call the intent method.