简体   繁体   English

当消息没有意图时,Microsoft Bot Framework LUIS会采取一些措施

[英]Microsoft Bot Framework, LUIS, take some action when the message dont have a intent

I started learn the Microsoft Bot Framework recently, so I started make a Chatbot and I guess I making it wrong 我最近开始学习Microsoft Bot Framework,所以我开始制作一个Chatbot,我想我做错了

I making the chatbot this way: 我用这种方式制作聊天机器人:

--> I get the message's user - >我收到消息的用户
--> send to LUIS - >发送给LUIS
--> get the intent and the entities - >获取意图和实体
--> select my answer and send it. - >选择我的答案并发送。

it's ok, but get the following situation: 没关系,但得到以下情况:

USER: I wanna change my email. USER:我想改变我的电子邮件。 --> intent : ChangeInfo entities: email/value:email - > intent:ChangeInfo实体:电子邮件/值:电子邮件

CHATBOT: Tell me your new Email please. CHATBOT:请告诉我你的新电子邮件。 --> intent: noIntent entities: noEntities - > intent:noIntent entities:noEntities

USER: email@email.com --> intent: IDon'tKnow entities: email/value:email@email.com USER:email@email.com - > intent:IDon'tKnow实体:email / value:email@email.com

I take this situation, when the USER send his email, I send to LUIs, but a email dont have a intent, just have a entity, but a email can be used in a lot Different situations, My question is, How My bot know the context of conversation to understand this email is for change email and not send a email, or update this email or another thing. 我采取这种情况,当用户发送他的电子邮件时,我发送给LUI,但是电子邮件没有意图,只有一个实体,但是可以使用很多不同的情况,我的问题是,我的机器人如何知道对话的上下文,以了解此电子邮件是为了更改电子邮件,而不是发送电子邮件,或更新此电子邮件或其他东西。

my code on gitHub here , its a ugly code, i know, but i make this just to understand the bot framework, after I will let this code more beautiful 我的代码在gitHub 这里 ,它是一个丑陋的代码,我知道,但我这只是为了理解机器人框架,之后我会让这段代码更漂亮

In my bot flow, I'm using a step variable that I change from the front-end. 在我的bot流程中,我使用的是从前端更改的step变量。 And another step variable that I change from the bot. 还有我从机器人改变的另一个step变量。 This helps me identify which step I am in the conversation. 这有助于我确定我在谈话中的哪个步骤。 You can do the same to identify what your bot is asking the user. 您也可以这样做以确定您的机器人向用户询问的内容。

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

If you don't want to send a specific step to LUIS for recognition, you can handle that in the onBeginDialog handler: 如果您不想向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();
  }
});

You can find the reference to LUIS onBeginDialog here: https://docs.botframework.com/en-us/node/builder/chat/IntentDialog/#onbegin--ondefault-handlers 你可以在这里找到对LUIS onBeginDialog的引用: https ://docs.botframework.com/en-us/node/builder/chat/IntentDialog/#onbegin--ondefault-handlers

Details about message data can be found here: https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html#entities 有关消息数据的详细信息,请访问: https//docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html#entities

This should be as simple as using a LuisDialog and a set of Prompts to manage the users flow. 这应该像使用LuisDialog和一组提示来管理用户流一样简单。 Below you will find some quick code I put together to show you how this could be done. 下面你会找到一些快速的代码,我把它们放在一起,向你展示如何做到这一点。 You don't need extra steps or adding extra entities, or going to Luis with the email provided by the user. 您不需要额外的步骤或添加额外的实体,也不需要使用用户提供的电子邮件前往Luis。

I would recommend you to read a bit more about LuisDialog and Dialogs in general as the way you are using Luis in your controller I don't think is the way to go. 我建议你阅读更多关于LuisDialog和Dialogs的内容,因为你在控制器中使用Luis的方式我认为不是这样的。

Here is a good Luis Sample and here a good one around multi-dialogs . 是一个很好的Luis示例,这里有一个很好的围绕多对话框

Sample Code 示例代码

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's your current email?");
            }
            catch
            {
                // here handle your errors in case the user doesn't not provide an email
            }

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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