我的目标是使用他们的C#SDK将对话框和LUIS实现到Microsoft Bot Framework应用程序中。我试图遵循这个线程https://github.com/Microsoft/BotBuilder/issues/127及其相关帖子(在末尾引用),但无法让我的代码在实践中工作。这是我的RootDialog类。请注意,我创建了一个处理“GetProduct”意图的方法,当它获得此意图时,它应该使用context.Forward()方法将LuisResult转发到ProductsDialog,但我所看到的只是它直接转到ResumeAfter方法,ProductsDialogCompleted。现在,这可能是我失败的地方,但我找不到显示多个LUIS对话框的示例。
public class RootDialog : LuisDialog<object>
{
[LuisIntent("GetProduct")]
private async Task GetProduct(IDialogContext context, LuisResult result)
{
await context.PostAsync("Calling ProductsDialog...");
await context.Forward(Chain.From(() => new ProductsDialog()), ProductsDialogCompleted, context.Activity, CancellationToken.None);
}
private async Task ProductsDialogCompleted(IDialogContext context, IAwaitable<object> result)
{
var res = await result;
context.PostAsync("ProductsDialogCompleted" + result);
context.Wait(this.MessageReceived);
}
}
public class ProductsDialog : LuisDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Entered ProductsDialog");
context.Wait(this.MessageReceived);
}
[LuisIntent("None")]
private async Task None(IDialogContext context, LuisResult result)
{
context.Done(true);
}
}
预期的行为如下
好像我没有正确绑定对话框。我怎么解决这个问题?
编辑:添加了MessageController,版本是3.8.1
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
尝试从Chain.From(()
电话中删除context.Forward
。不确定为什么要添加它,但它根本不应该存在。
试试:
await context.Forward(new ProductsDialog(), ProductsDialogCompleted, context.Activity, CancellationToken.None);
顺便说一句,如果你转发的信息击中None
意图,ProductsDialogCompleted
方法将被击中因为你正在做context.Done
,它基本上结束了ProductsDialog
。
另外,请记住StartAsync
方法存在于LuisDialog<T>
基类中,因此您需要添加override
关键字。