簡體   English   中英

當消息沒有意圖時,Microsoft Bot Framework LUIS會采取一些措施

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

我最近開始學習Microsoft Bot Framework,所以我開始制作一個Chatbot,我想我做錯了

我用這種方式制作聊天機器人:

- >我收到消息的用戶
- >發送給LUIS
- >獲取意圖和實體
- >選擇我的答案並發送。

沒關系,但得到以下情況:

USER:我想改變我的電子郵件。 - > intent:ChangeInfo實體:電子郵件/值:電子郵件

CHATBOT:請告訴我你的新電子郵件。 - > intent:noIntent entities:noEntities

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

我采取這種情況,當用戶發送他的電子郵件時,我發送給LUI,但是電子郵件沒有意圖,只有一個實體,但是可以使用很多不同的情況,我的問題是,我的機器人如何知道對話的上下文,以了解此電子郵件是為了更改電子郵件,而不是發送電子郵件,或更新此電子郵件或其他東西。

我的代碼在gitHub 這里 ,它是一個丑陋的代碼,我知道,但我這只是為了理解機器人框架,之后我會讓這段代碼更漂亮

在我的bot流程中,我使用的是從前端更改的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

這應該像使用LuisDialog和一組提示來管理用戶流一樣簡單。 下面你會找到一些快速的代碼,我把它們放在一起,向你展示如何做到這一點。 您不需要額外的步驟或添加額外的實體,也不需要使用用戶提供的電子郵件前往Luis。

我建議你閱讀更多關於LuisDialog和Dialogs的內容,因為你在控制器中使用Luis的方式我認為不是這樣的。

是一個很好的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'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