I have been working on customizing corebot example of botframework (https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot)
After trying to make it work i realized that the example provided was not handling user answer that were not associated to Luis intent.
For example, i would like the bot to prompt the user to repeat when he says "blabla".
Below the code of main dialog. When i say "blabla" (which is obviously not recognized by Luis), the bot stops and restart from scratch.
// 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);
}
Is there a way i can handle these? It could be really useful and i could leave the loop with any other intents.
EDIT
Based on the answer from @billoverton, i am trying to add this if before the switch.
if (luisResult.TopIntent().score < 0.5)
{ FlightBooking.Intent = FlightBooking.Intent.None; }
but it says that FlightBooking.Intent is a type and not a variable.
var topIntent = luisResult.TopIntent().intent
. I'd still put that if statement underneath:if (luisResult.TopIntent().score < 0.5) { topIntent = FlightBooking.Intent.None; }
. I'm not 100% sure that assignment will work (I assign mine to just the text intent name 'None'), but I'd give that a go and see how it works. – billoverton