Microsoft Bot Framework, LUIS, take action when the message is not intended

I started learning the Microsoft Bot Framework recently, so I started making Chatbot, and I guess I'm wrong

I am doing chatbot this way:

-> I get a user message
-> send to LUIS
-> get intent and entity
-> select my answer and send it.

this is normal, but get the following situation:

USER: I want to change my email address. → target: ChangeInfo objects: email / value: email

CHATBOT: Please tell me your new email address. → target: noIntent objects: noEntities

USER: email@email.com → intent: IDon'tKnow: email / value: email@email.com

I take this situation when the USER sends his email, I send to the LUI, but the letter has no intention, just has the essence, but the letter can be used in many different situations. My question is: how does My bot know the context of the conversation in order to understand that this letter is intended to change the email, and not to send an email or update this message or another.

my gitHub code is here , its ugly code, I know, but I only do this to understand the scope of the bot, after I make this code more beautiful

+4
2

, LuisDialog . , , , . , .

LuisDialog Dialogs , Luis . , .

- , -.

namespace MyNamespace
{
    using System;
    using System.Threading.Tasks;
    using Microsoft.Bot.Builder.Dialogs;
    using Microsoft.Bot.Builder.Internals.Fibers;
    using Microsoft.Bot.Builder.Luis;
    using Microsoft.Bot.Builder.Luis.Models;
    using Microsoft.Bot.Connector;

    [Serializable]
    [LuisModel("YourModelId", "YourSubscriptionKey")]
    public class MyLuisDialog : LuisDialog<object>
    {
        [LuisIntent("")]
        [LuisIntent("None")]
        public async Task None(IDialogContext context, LuisResult result)
        {
            string message = "Não entendi, me diga com outras palavras!";

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

        [LuisIntent("ChangeInfo")]
        public async Task ChangeInfo(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
        {
            // no need to go to luis again..
            PromptDialog.Text(context, AfterEmailProvided, "Tell me your new email please?");
        }

        private async Task AfterEmailProvided(IDialogContext context, IAwaitable<string> result)
        {
            try
            {
                var email = await result;

                // logic to store your email...
            }
            catch
            {
                // here handle your errors in case the user doesn't not provide an email
            }

          context.Wait(this.MessageReceived);
        }

        [LuisIntent("PaymentInfo")]
        public async Task Payment(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
        {
            // logic to retrieve the current payment info..
            var email = "test@email.com";

            PromptDialog.Confirm(context, AfterEmailConfirmation, $"Is it {email} your current email?");
        }

        private async Task AfterEmailConfirmation(IDialogContext context, IAwaitable<bool> result)
        {
            try
            {
                var response = await result;

                // if the way to store the payment email is the same as the one used to store the email when going through the ChangeInfo intent, then you can use the same After... method; otherwise create a new one
                PromptDialog.Text(context, AfterEmailProvided, "What your current email?");
            }
            catch
            {
                // here handle your errors in case the user doesn't not provide an email
            }

            context.Wait(this.MessageReceived);
        }
    }
}
+3

step, . step, . , . , , .

var data = {step: "asked_email"};
var msg = builder.Message(session).addEntity(data).text("Your message.");
session.send(msg);

LUIS , onBeginDialog:

intents.onBegin(function (session, args, next) {
  if (session.message.step !== "email") {
    next();
  } else {
    //Do something else and not go to LUIS.
    session.endDialog();
  }
});

LUIS onBeginDialog: https://docs.botframework.com/en-us/node/builder/chat/IntentDialog/#onbegin--ondefault-handlers

: https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html#entities

+3

Source: https://habr.com/ru/post/1664920/


All Articles