Created
March 2, 2022 23:54
-
-
Save sunnyy02/efbd23173f39826c681ac155cf16426d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) | |
{ | |
if (!_luisRecognizer.IsConfigured) | |
{ | |
// LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance. | |
return await stepContext.BeginDialogAsync(nameof(AppointmentBookingDialog), new AppointmentDetails(), cancellationToken); | |
} | |
// Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.) | |
var luisResult = await _luisRecognizer.RecognizeAsync<DoctorBooking>(stepContext.Context, cancellationToken); | |
switch (luisResult.TopIntent().intent) | |
{ | |
case DoctorBooking.Intent.BookAppointment: | |
var validDoctor = await ValidateDoctors(stepContext.Context, luisResult, cancellationToken); | |
if (!validDoctor) | |
{ | |
return await stepContext.ReplaceDialogAsync(InitialDialogId, "Doctor Peter, Susan and Kathy are available?", cancellationToken); | |
} | |
// Initialize BookingDetails with any entities we may have found in the response. | |
var bookingDetails = new AppointmentDetails() | |
{ | |
// Get destination and origin from the composite entities arrays. | |
Doctor = luisResult.Doctor, | |
AppointmenDate = luisResult.AppointmentDate, | |
}; | |
// Run the AppointmentBookingDialog giving it whatever details we have from the LUIS call, it will fill out the remainder. | |
return await stepContext.BeginDialogAsync(nameof(AppointmentBookingDialog), bookingDetails, cancellationToken); | |
case DoctorBooking.Intent.GetAvailableDoctors: | |
// We haven't implemented the GetAvailableDoctorsDialog so we just display a mock message. | |
var getAvailableDoctorsMessageText = "Doctor Kathy, Doctor Peter are available today"; | |
var getAvailableDoctorsMessage = MessageFactory.Text(getAvailableDoctorsMessageText, getAvailableDoctorsMessageText, InputHints.IgnoringInput); | |
await stepContext.Context.SendActivityAsync(getAvailableDoctorsMessage, 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment