我一直在自定义botframework(https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot)的corebot示例
尝试使其工作后,我意识到所提供的示例未处理与Luis意图无关的用户答案。
例如,我希望机器人在用户说“ blabla”时提示其重复。
在主对话框的代码下面。当我说“ blabla”(很显然Luis无法识别)时,该机器人会停止并从头开始重新启动。
// Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
var luisResult = await _luisRecognizer.RecognizeAsync<FlightBooking>(stepContext.Context,cancellationToken);
switch (luisResult.TopIntent().intent)
{
case FlightBooking.Intent.BookFlight:
await ShowWarningForUnsupportedCities(stepContext.Context,luisResult,cancellationToken);
// Initialize BookingDetails with any entities we may have found in the response.
var bookingDetails = new BookingDetails()
{
// Get destination and origin from the composite entities arrays.
Destination = luisResult.ToEntities.Airport,Origin = luisResult.FromEntities.Airport,TravelDate = luisResult.TravelDate,};
// Run the BookingDialog giving it whatever details we have from the LUIS call,it will fill out the remainder.
return await stepContext.BeginDialogAsync(nameof(BookingDialog),bookingDetails,cancellationToken);
case FlightBooking.Intent.GetWeather:
// We haven't implemented the GetWeatherDialog so we just display a TODO message.
var getWeatherMessageText = "TODO: get weather flow here";
var getWeatherMessage = MessageFactory.Text(getWeatherMessageText,getWeatherMessageText,InputHints.IgnoringInput);
await stepContext.Context.SendactivityAsync(getWeatherMessage,cancellationToken);
break;
default:
// Catch all for unhandled intents
var didntUnderstandMessageText = $"Sorry,I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent})";
var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText,didntUnderstandMessageText,InputHints.IgnoringInput);
await stepContext.Context.SendactivityAsync(didntUnderstandMessage,cancellationToken);
break;
}
return await stepContext.NextAsync(null,cancellationToken);
}
我有办法解决这些问题吗? 这可能真的很有用,我可以将其他意图留在循环中。
编辑
基于@billoverton的回答,如果要在切换之前,我想添加此内容。
if (luisResult.TopIntent().score < 0.5)
{ FlightBooking.Intent = FlightBooking.Intent.None; }
但是它说FlightBooking.Intent是类型而不是变量。