Esempio n. 1
0
    /// <summary>
    ///     Step 1: Get the number of guest
    /// </summary>
    /// <param name="stepContext"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    private async Task <DialogTurnResult> NumberOfGuestStepAsync(WaterfallStepContext stepContext,
                                                                 CancellationToken cancellationToken)
    {
        var bookingDetails = (BookingDetails)stepContext.Options;

        var luisResult = await _recognizer.RecognizeAsync <LuisResult>(stepContext.Context, cancellationToken);

        _logger.LogDebug($"LUIS Result: {luisResult}");

        if (bookingDetails.NumberOfGuests != 0)
        {
            return(await stepContext.NextAsync(bookingDetails.NumberOfGuests, cancellationToken));
        }

        var promptMessage = MessageFactory.Text(NumberOfGuestsStepMsgText, NumberOfGuestsStepMsgText,
                                                InputHints.ExpectingInput);

        return(await stepContext.PromptAsync("IntPrompt", new PromptOptions { Prompt = promptMessage },
                                             cancellationToken));
    }
Esempio n. 2
0
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_recognizer.IsConfigured)
            {
                // LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.
                //return await stepContext.BeginDialogAsync(nameof(BookingDialog), new BookingDetails(), cancellationToken);
            }

            // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
            //var luisResult = await _recognizer.RecognizeAsync<FlightBooking>(stepContext.Context, cancellationToken);
            var luisResult = await _recognizer.RecognizeAsync <LuisResult>(stepContext.Context, cancellationToken);

            Logger.LogDebug($"LUIS Result: {luisResult.ToString()}");

            switch (luisResult.TopIntent().intent)
            {
            case LuisResult.Intent.Book_A_Room:
                // 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(RoomBookingDialog), bookingDetails, cancellationToken));

            case LuisResult.Intent.Help:
                // We haven't implemented the GetWeatherDialog so we just display a TO-DO 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));
        }