简体   繁体   中英

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

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);

    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM