c# – Microsoft Bot Framework,LUIS,当消息没有意图时采取一些行动
作者:互联网
我最近开始学习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:emailCHATBOT: Tell me your new Email please. –> intent: noIntent
entities: noEntitiesUSER: email@email.com –> intent: IDon’tKnow entities:
email/value:email@email.com
我采取这种情况,当用户发送他的电子邮件时,我发送给LUI,但是电子邮件没有意图,只有一个实体,但是可以使用很多不同的情况,我的问题是,我的机器人如何知道对话的上下文,以了解此电子邮件是为了更改电子邮件,而不是发送电子邮件,或更新此电子邮件或其他东西.
我的代码在gitHub here上,它是一个丑陋的代码,我知道,但我这只是为了理解机器人框架,之后我会让这段代码更美观
解决方法:
这应该像使用LuisDialog和一组提示来管理用户流一样简单.下面你会找到一些快速的代码,我把它们放在一起,向你展示如何做到这一点.您不需要额外的步骤或添加额外的实体,也不需要使用用户提供的电子邮件前往Luis.
我建议你阅读更多关于LuisDialog和Dialogs的内容,因为你在控制器中使用Luis的方式我认为不是这样的.
Here是一个很好的路易斯样本,在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,botframework,luis 来源: https://codeday.me/bug/20190527/1165027.html