更新到 1.2.0.1 后 LuisDialog 不再工作
LuisDialog not working anymore after update to 1.2.0.1
我已经更新了我的 NuGet 包以使用 Microsoft Bot Framework 1.2.0.1 版。
一些重大更改是 reported here,我设法修复了构建错误。但是应用程序不再工作了..
我有两个问题:
- 当我向控制器发送消息语句时,代码抛出 InvalidIntentHandlerException。
在我的 'intent' 方法(装饰有 LuisIntent 属性)中,可以读取实体的值。像这样:
[Serializable]
[LuisModel("xxxxx", "xxxx")]
public class BookFlightDialog : LuisDialog<BookFlightForm>
{
private readonly BuildFormDelegate<BookFlightForm> BuildForm;
internal BookFlightDialog(BuildFormDelegate<BookFlightForm> buildForm)
{
BuildForm = buildForm;
}
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync("I'm sorry. I didn't understand you.");
context.Wait(MessageReceived);
}
[LuisIntent("BookAFlight")]
public async Task BookAFlight(IDialogContext context, LuisResult result)
{
var form = new BookFlightForm();
// var entities = new List<EntityRecommendation>(result.Entities);
var locations = result.Entities.Where(e => e.Type.Equals("builtin.geography") || e.Type.Equals("builtin.geography.city")).OrderBy(e => e.StartIndex);
if (locations.Any())
{
form.LocationFrom = locations.First().Name;
if (locations.Count() == 2)
{
form.LocationTo = locations.Skip(1).First().Name;
}
}
var date = result.Entities.FirstOrDefault(e => e.Type == "builtin.datetime.date");
if (date != null) form.DepartureDate = DateTime.Parse(date.Name);
var formDialog = new FormDialog<BookFlightForm>(form, BuildForm, FormOptions.PromptInStart);
context.Call(formDialog, OnComplete);
}
private async Task OnComplete(IDialogContext context, IAwaitable<BookFlightForm> result)
{
BookFlightForm booking;
try
{
booking = await result;
}
catch (OperationCanceledException)
{
await context.PostAsync("Ok, see you later.");
return;
}
if (booking != null)
{
var service = new SkyScannerService();
var possibilities = await service.Search(booking);
await context.PostAsync(possibilities);
}
else
{
await context.PostAsync("Form returned empty response!");
}
context.Wait(MessageReceived);
}
}
如何修复异常以及如何读取实体的值?
再次感谢!
这是因为您没有通过 using LuisResult = Bots.Results.LuisResult;
使用内置 LuisResult
class。将其替换为 using Microsoft.Bot.Builder.Luis.Models;
.
我已经更新了我的 NuGet 包以使用 Microsoft Bot Framework 1.2.0.1 版。
一些重大更改是 reported here,我设法修复了构建错误。但是应用程序不再工作了..
我有两个问题:
- 当我向控制器发送消息语句时,代码抛出 InvalidIntentHandlerException。
在我的 'intent' 方法(装饰有 LuisIntent 属性)中,可以读取实体的值。像这样:
[Serializable] [LuisModel("xxxxx", "xxxx")] public class BookFlightDialog : LuisDialog<BookFlightForm> { private readonly BuildFormDelegate<BookFlightForm> BuildForm; internal BookFlightDialog(BuildFormDelegate<BookFlightForm> buildForm) { BuildForm = buildForm; } [LuisIntent("")] [LuisIntent("None")] public async Task None(IDialogContext context, LuisResult result) { await context.PostAsync("I'm sorry. I didn't understand you."); context.Wait(MessageReceived); } [LuisIntent("BookAFlight")] public async Task BookAFlight(IDialogContext context, LuisResult result) { var form = new BookFlightForm(); // var entities = new List<EntityRecommendation>(result.Entities); var locations = result.Entities.Where(e => e.Type.Equals("builtin.geography") || e.Type.Equals("builtin.geography.city")).OrderBy(e => e.StartIndex); if (locations.Any()) { form.LocationFrom = locations.First().Name; if (locations.Count() == 2) { form.LocationTo = locations.Skip(1).First().Name; } } var date = result.Entities.FirstOrDefault(e => e.Type == "builtin.datetime.date"); if (date != null) form.DepartureDate = DateTime.Parse(date.Name); var formDialog = new FormDialog<BookFlightForm>(form, BuildForm, FormOptions.PromptInStart); context.Call(formDialog, OnComplete); } private async Task OnComplete(IDialogContext context, IAwaitable<BookFlightForm> result) { BookFlightForm booking; try { booking = await result; } catch (OperationCanceledException) { await context.PostAsync("Ok, see you later."); return; } if (booking != null) { var service = new SkyScannerService(); var possibilities = await service.Search(booking); await context.PostAsync(possibilities); } else { await context.PostAsync("Form returned empty response!"); } context.Wait(MessageReceived); } }
如何修复异常以及如何读取实体的值?
再次感谢!
这是因为您没有通过 using LuisResult = Bots.Results.LuisResult;
使用内置 LuisResult
class。将其替换为 using Microsoft.Bot.Builder.Luis.Models;
.