Я работал над настройкой примера бот-фрейма для corebot (https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot)
После попытки заставить его работать, я понял, что предоставленный пример не обрабатывает ответы пользователей, которые не связаны с намерением Луиса.
Например, я хотел бы, чтобы бот подсказывал пользователю повторить, когда он говорит «блабла».
Ниже кодаГлавный диалог. Когда я говорю «блабла» (что явно не распознается Луисом), бот останавливается и перезапускается с нуля.
// 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 - это тип, а не переменная.