c# - Microsoft Bot Framework,LUIS,在消息没有意图时采取一些行动

标签 c# botframework azure-language-understanding

我最近开始学习Microsoft Bot Framework,所以我开始制作Chatbot,我想我做错了

我是这样制作聊天机器人的:

--> I get the message's user
--> send to LUIS
--> get the intent and the entities
--> select my answer and send it.

没问题,但是遇到如下情况:

USER: I wanna change my email. --> intent : ChangeInfo entities: email/value:email

CHATBOT: Tell me your new Email please. --> intent: noIntent entities: noEntities

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

我采取这种情况,当用户发送他的电子邮件时,我发送给 LUI,但是电子邮件没有意图,只有一个实体,但是电子邮件可以在很多不同的情况下使用,我的问题是,如何我的机器人知道对话的上下文来理解这封电子邮件是为了更改电子邮件而不是发送电子邮件,或更新这封电子邮件或其他东西。

我在 gitHub 上的代码 here ,这是一个丑陋的代码,我知道,但我这样做只是为了了解bot框架,之后我会让这段代码更漂亮

最佳答案

这应该像使用 LuisDialog 和一组提示来管理用户流一样简单。您将在下面找到一些我放在一起的快速代码,向您展示如何完成此操作。您不需要额外的步骤或添加额外的实体,也不需要使用用户提供的电子邮件联系 Luis。

我建议您阅读更多关于 LuisDialog 和 Dialogs 的内容,因为您在 Controller 中使用 Luis 的方式我认为不是正确的方法。

Here是一个很好的 Luis 样本,这里有一个很好的 multi-dialogs .

示例代码

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

关于c# - Microsoft Bot Framework,LUIS,在消息没有意图时采取一些行动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41332257/

相关文章:

c# - 在 Mac 上学习 C#?

c# - 我将如何使用其他类的以下静态变量?

c# - 在新创建的团队中进行测试时,团队 UpdateActivity 事件会有所不同

Azure 测试网络聊天无法正常工作

azure - LUIS 编程 API : Publish 400 Error

c# - 使用 MVVM 以编程方式创建 XAML Canvas

c# - 使用 ReactiveUI 监听复杂对象变化的最佳方式是什么?

azure - 发送至 Microsoft Bot 的 Directline API 消息

botframework - Web 应用程序机器人创建 (Azure) - 没有可见的 LUIS 应用程序

azure-language-understanding - 短语列表中的 "The values are interchangable"选项如何在 LUIS 中工作?